MDL-53455 libraries: upgrade jquery migrate to version 1.4.0
[moodle.git] / lib / jquery / jquery-migrate-1.4.0.js
1 /*!\r
2  * jQuery Migrate - v1.4.0 - 2016-02-26\r
3  * Copyright jQuery Foundation and other contributors\r
4  */\r
5 (function( jQuery, window, undefined ) {\r
6 // See http://bugs.jquery.com/ticket/13335\r
7 // "use strict";\r
8 \r
9 \r
10         jQuery.migrateVersion = "1.4.0";\r
11 \r
12 \r
13         var warnedAbout = {};\r
14 \r
15 // List of warnings already given; public read only\r
16         jQuery.migrateWarnings = [];\r
17 \r
18 // Set to true to prevent console output; migrateWarnings still maintained\r
19 // jQuery.migrateMute = false;\r
20 \r
21 // Show a message on the console so devs know we're active\r
22         if ( window.console && window.console.log ) {\r
23                 window.console.log( "JQMIGRATE: Migrate is installed" +\r
24                                 ( jQuery.migrateMute ? "" : " with logging active" ) +\r
25                                 ", version " + jQuery.migrateVersion );\r
26         }\r
27 \r
28 // Set to false to disable traces that appear with warnings\r
29         if ( jQuery.migrateTrace === undefined ) {\r
30                 jQuery.migrateTrace = true;\r
31         }\r
32 \r
33 // Forget any warnings we've already given; public\r
34         jQuery.migrateReset = function() {\r
35                 warnedAbout = {};\r
36                 jQuery.migrateWarnings.length = 0;\r
37         };\r
38 \r
39         function migrateWarn( msg) {\r
40                 var console = window.console;\r
41                 if ( !warnedAbout[ msg ] ) {\r
42                         warnedAbout[ msg ] = true;\r
43                         jQuery.migrateWarnings.push( msg );\r
44                         if ( console && console.warn && !jQuery.migrateMute ) {\r
45                                 console.warn( "JQMIGRATE: " + msg );\r
46                                 if ( jQuery.migrateTrace && console.trace ) {\r
47                                         console.trace();\r
48                                 }\r
49                         }\r
50                 }\r
51         }\r
52 \r
53         function migrateWarnProp( obj, prop, value, msg ) {\r
54                 if ( Object.defineProperty ) {\r
55                         // On ES5 browsers (non-oldIE), warn if the code tries to get prop;\r
56                         // allow property to be overwritten in case some other plugin wants it\r
57                         try {\r
58                                 Object.defineProperty( obj, prop, {\r
59                                         configurable: true,\r
60                                         enumerable: true,\r
61                                         get: function() {\r
62                                                 migrateWarn( msg );\r
63                                                 return value;\r
64                                         },\r
65                                         set: function( newValue ) {\r
66                                                 migrateWarn( msg );\r
67                                                 value = newValue;\r
68                                         }\r
69                                 });\r
70                                 return;\r
71                         } catch( err ) {\r
72                                 // IE8 is a dope about Object.defineProperty, can't warn there\r
73                         }\r
74                 }\r
75 \r
76                 // Non-ES5 (or broken) browser; just set the property\r
77                 jQuery._definePropertyBroken = true;\r
78                 obj[ prop ] = value;\r
79         }\r
80 \r
81         if ( document.compatMode === "BackCompat" ) {\r
82                 // jQuery has never supported or tested Quirks Mode\r
83                 migrateWarn( "jQuery is not compatible with Quirks Mode" );\r
84         }\r
85 \r
86 \r
87         var attrFn = jQuery( "<input/>", { size: 1 } ).attr("size") && jQuery.attrFn,\r
88                         oldAttr = jQuery.attr,\r
89                         valueAttrGet = jQuery.attrHooks.value && jQuery.attrHooks.value.get ||\r
90                                         function() { return null; },\r
91                         valueAttrSet = jQuery.attrHooks.value && jQuery.attrHooks.value.set ||\r
92                                         function() { return undefined; },\r
93                         rnoType = /^(?:input|button)$/i,\r
94                         rnoAttrNodeType = /^[238]$/,\r
95                         rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,\r
96                         ruseDefault = /^(?:checked|selected)$/i;\r
97 \r
98 // jQuery.attrFn\r
99         migrateWarnProp( jQuery, "attrFn", attrFn || {}, "jQuery.attrFn is deprecated" );\r
100 \r
101         jQuery.attr = function( elem, name, value, pass ) {\r
102                 var lowerName = name.toLowerCase(),\r
103                                 nType = elem && elem.nodeType;\r
104 \r
105                 if ( pass ) {\r
106                         // Since pass is used internally, we only warn for new jQuery\r
107                         // versions where there isn't a pass arg in the formal params\r
108                         if ( oldAttr.length < 4 ) {\r
109                                 migrateWarn("jQuery.fn.attr( props, pass ) is deprecated");\r
110                         }\r
111                         if ( elem && !rnoAttrNodeType.test( nType ) &&\r
112                                         (attrFn ? name in attrFn : jQuery.isFunction(jQuery.fn[name])) ) {\r
113                                 return jQuery( elem )[ name ]( value );\r
114                         }\r
115                 }\r
116 \r
117                 // Warn if user tries to set `type`, since it breaks on IE 6/7/8; by checking\r
118                 // for disconnected elements we don't warn on $( "<button>", { type: "button" } ).\r
119                 if ( name === "type" && value !== undefined && rnoType.test( elem.nodeName ) && elem.parentNode ) {\r
120                         migrateWarn("Can't change the 'type' of an input or button in IE 6/7/8");\r
121                 }\r
122 \r
123                 // Restore boolHook for boolean property/attribute synchronization\r
124                 if ( !jQuery.attrHooks[ lowerName ] && rboolean.test( lowerName ) ) {\r
125                         jQuery.attrHooks[ lowerName ] = {\r
126                                 get: function( elem, name ) {\r
127                                         // Align boolean attributes with corresponding properties\r
128                                         // Fall back to attribute presence where some booleans are not supported\r
129                                         var attrNode,\r
130                                                         property = jQuery.prop( elem, name );\r
131                                         return property === true || typeof property !== "boolean" &&\r
132                                         ( attrNode = elem.getAttributeNode(name) ) && attrNode.nodeValue !== false ?\r
133 \r
134                                                         name.toLowerCase() :\r
135                                                         undefined;\r
136                                 },\r
137                                 set: function( elem, value, name ) {\r
138                                         var propName;\r
139                                         if ( value === false ) {\r
140                                                 // Remove boolean attributes when set to false\r
141                                                 jQuery.removeAttr( elem, name );\r
142                                         } else {\r
143                                                 // value is true since we know at this point it's type boolean and not false\r
144                                                 // Set boolean attributes to the same name and set the DOM property\r
145                                                 propName = jQuery.propFix[ name ] || name;\r
146                                                 if ( propName in elem ) {\r
147                                                         // Only set the IDL specifically if it already exists on the element\r
148                                                         elem[ propName ] = true;\r
149                                                 }\r
150 \r
151                                                 elem.setAttribute( name, name.toLowerCase() );\r
152                                         }\r
153                                         return name;\r
154                                 }\r
155                         };\r
156 \r
157                         // Warn only for attributes that can remain distinct from their properties post-1.9\r
158                         if ( ruseDefault.test( lowerName ) ) {\r
159                                 migrateWarn( "jQuery.fn.attr('" + lowerName + "') might use property instead of attribute" );\r
160                         }\r
161                 }\r
162 \r
163                 return oldAttr.call( jQuery, elem, name, value );\r
164         };\r
165 \r
166 // attrHooks: value\r
167         jQuery.attrHooks.value = {\r
168                 get: function( elem, name ) {\r
169                         var nodeName = ( elem.nodeName || "" ).toLowerCase();\r
170                         if ( nodeName === "button" ) {\r
171                                 return valueAttrGet.apply( this, arguments );\r
172                         }\r
173                         if ( nodeName !== "input" && nodeName !== "option" ) {\r
174                                 migrateWarn("jQuery.fn.attr('value') no longer gets properties");\r
175                         }\r
176                         return name in elem ?\r
177                                         elem.value :\r
178                                         null;\r
179                 },\r
180                 set: function( elem, value ) {\r
181                         var nodeName = ( elem.nodeName || "" ).toLowerCase();\r
182                         if ( nodeName === "button" ) {\r
183                                 return valueAttrSet.apply( this, arguments );\r
184                         }\r
185                         if ( nodeName !== "input" && nodeName !== "option" ) {\r
186                                 migrateWarn("jQuery.fn.attr('value', val) no longer sets properties");\r
187                         }\r
188                         // Does not return so that setAttribute is also used\r
189                         elem.value = value;\r
190                 }\r
191         };\r
192 \r
193 \r
194         var matched, browser,\r
195                         oldInit = jQuery.fn.init,\r
196                         oldParseJSON = jQuery.parseJSON,\r
197                         rspaceAngle = /^\s*</,\r
198                         rattrHash = /\[\s*\w+\s*[~|^$*]?=\s*(?![\s'"])[^#\]]*#/,\r
199         // Note: XSS check is done below after string is trimmed\r
200                         rquickExpr = /^([^<]*)(<[\w\W]+>)([^>]*)$/;\r
201 \r
202 // $(html) "looks like html" rule change\r
203         jQuery.fn.init = function( selector, context, rootjQuery ) {\r
204                 var match, ret;\r
205 \r
206                 if ( selector && typeof selector === "string" && !jQuery.isPlainObject( context ) &&\r
207                                 (match = rquickExpr.exec( jQuery.trim( selector ) )) && match[ 0 ] ) {\r
208                         // This is an HTML string according to the "old" rules; is it still?\r
209                         if ( !rspaceAngle.test( selector ) ) {\r
210                                 migrateWarn("$(html) HTML strings must start with '<' character");\r
211                         }\r
212                         if ( match[ 3 ] ) {\r
213                                 migrateWarn("$(html) HTML text after last tag is ignored");\r
214                         }\r
215 \r
216                         // Consistently reject any HTML-like string starting with a hash (#9521)\r
217                         // Note that this may break jQuery 1.6.x code that otherwise would work.\r
218                         if ( match[ 0 ].charAt( 0 ) === "#" ) {\r
219                                 migrateWarn("HTML string cannot start with a '#' character");\r
220                                 jQuery.error("JQMIGRATE: Invalid selector string (XSS)");\r
221                         }\r
222                         // Now process using loose rules; let pre-1.8 play too\r
223                         if ( context && context.context ) {\r
224                                 // jQuery object as context; parseHTML expects a DOM object\r
225                                 context = context.context;\r
226                         }\r
227                         if ( jQuery.parseHTML ) {\r
228                                 return oldInit.call( this,\r
229                                                 jQuery.parseHTML( match[ 2 ], context && context.ownerDocument ||\r
230                                                                 context || document, true ), context, rootjQuery );\r
231                         }\r
232                 }\r
233 \r
234                 if ( selector === "#" ) {\r
235 \r
236                         // jQuery( "#" ) is a bogus ID selector, but it returned an empty set before jQuery 3.0\r
237                         migrateWarn( "jQuery( '#' ) is not a valid selector" );\r
238                         selector = [];\r
239 \r
240                 } else if ( rattrHash.test( selector ) ) {\r
241 \r
242                         // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0\r
243                         // Note that this doesn't actually fix the selector due to potential false positives\r
244                         migrateWarn( "Attribute selectors with '#' must be quoted: '" + selector + "'" );\r
245                 }\r
246 \r
247                 ret = oldInit.apply( this, arguments );\r
248 \r
249                 // Fill in selector and context properties so .live() works\r
250                 if ( selector && selector.selector !== undefined ) {\r
251                         // A jQuery object, copy its properties\r
252                         ret.selector = selector.selector;\r
253                         ret.context = selector.context;\r
254 \r
255                 } else {\r
256                         ret.selector = typeof selector === "string" ? selector : "";\r
257                         if ( selector ) {\r
258                                 ret.context = selector.nodeType? selector : context || document;\r
259                         }\r
260                 }\r
261 \r
262                 return ret;\r
263         };\r
264         jQuery.fn.init.prototype = jQuery.fn;\r
265 \r
266 // Let $.parseJSON(falsy_value) return null\r
267         jQuery.parseJSON = function( json ) {\r
268                 if ( !json ) {\r
269                         migrateWarn("jQuery.parseJSON requires a valid JSON string");\r
270                         return null;\r
271                 }\r
272                 return oldParseJSON.apply( this, arguments );\r
273         };\r
274 \r
275         jQuery.uaMatch = function( ua ) {\r
276                 ua = ua.toLowerCase();\r
277 \r
278                 var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||\r
279                                 /(webkit)[ \/]([\w.]+)/.exec( ua ) ||\r
280                                 /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||\r
281                                 /(msie) ([\w.]+)/.exec( ua ) ||\r
282                                 ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||\r
283                                 [];\r
284 \r
285                 return {\r
286                         browser: match[ 1 ] || "",\r
287                         version: match[ 2 ] || "0"\r
288                 };\r
289         };\r
290 \r
291 // Don't clobber any existing jQuery.browser in case it's different\r
292         if ( !jQuery.browser ) {\r
293                 matched = jQuery.uaMatch( navigator.userAgent );\r
294                 browser = {};\r
295 \r
296                 if ( matched.browser ) {\r
297                         browser[ matched.browser ] = true;\r
298                         browser.version = matched.version;\r
299                 }\r
300 \r
301                 // Chrome is Webkit, but Webkit is also Safari.\r
302                 if ( browser.chrome ) {\r
303                         browser.webkit = true;\r
304                 } else if ( browser.webkit ) {\r
305                         browser.safari = true;\r
306                 }\r
307 \r
308                 jQuery.browser = browser;\r
309         }\r
310 \r
311 // Warn if the code tries to get jQuery.browser\r
312         migrateWarnProp( jQuery, "browser", jQuery.browser, "jQuery.browser is deprecated" );\r
313 \r
314 // jQuery.boxModel deprecated in 1.3, jQuery.support.boxModel deprecated in 1.7\r
315         jQuery.boxModel = jQuery.support.boxModel = (document.compatMode === "CSS1Compat");\r
316         migrateWarnProp( jQuery, "boxModel", jQuery.boxModel, "jQuery.boxModel is deprecated" );\r
317         migrateWarnProp( jQuery.support, "boxModel", jQuery.support.boxModel, "jQuery.support.boxModel is deprecated" );\r
318 \r
319         jQuery.sub = function() {\r
320                 function jQuerySub( selector, context ) {\r
321                         return new jQuerySub.fn.init( selector, context );\r
322                 }\r
323                 jQuery.extend( true, jQuerySub, this );\r
324                 jQuerySub.superclass = this;\r
325                 jQuerySub.fn = jQuerySub.prototype = this();\r
326                 jQuerySub.fn.constructor = jQuerySub;\r
327                 jQuerySub.sub = this.sub;\r
328                 jQuerySub.fn.init = function init( selector, context ) {\r
329                         var instance = jQuery.fn.init.call( this, selector, context, rootjQuerySub );\r
330                         return instance instanceof jQuerySub ?\r
331                                         instance :\r
332                                         jQuerySub( instance );\r
333                 };\r
334                 jQuerySub.fn.init.prototype = jQuerySub.fn;\r
335                 var rootjQuerySub = jQuerySub(document);\r
336                 migrateWarn( "jQuery.sub() is deprecated" );\r
337                 return jQuerySub;\r
338         };\r
339 \r
340 // The number of elements contained in the matched element set\r
341         jQuery.fn.size = function() {\r
342                 migrateWarn( "jQuery.fn.size() is deprecated; use the .length property" );\r
343                 return this.length;\r
344         };\r
345 \r
346 \r
347         var internalSwapCall = false;\r
348 \r
349 // If this version of jQuery has .swap(), don't false-alarm on internal uses\r
350         if ( jQuery.swap ) {\r
351                 jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {\r
352                         var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;\r
353 \r
354                         if ( oldHook ) {\r
355                                 jQuery.cssHooks[ name ].get = function() {\r
356                                         var ret;\r
357 \r
358                                         internalSwapCall = true;\r
359                                         ret = oldHook.apply( this, arguments );\r
360                                         internalSwapCall = false;\r
361                                         return ret;\r
362                                 };\r
363                         }\r
364                 });\r
365         }\r
366 \r
367         jQuery.swap = function( elem, options, callback, args ) {\r
368                 var ret, name,\r
369                                 old = {};\r
370 \r
371                 if ( !internalSwapCall ) {\r
372                         migrateWarn( "jQuery.swap() is undocumented and deprecated" );\r
373                 }\r
374 \r
375                 // Remember the old values, and insert the new ones\r
376                 for ( name in options ) {\r
377                         old[ name ] = elem.style[ name ];\r
378                         elem.style[ name ] = options[ name ];\r
379                 }\r
380 \r
381                 ret = callback.apply( elem, args || [] );\r
382 \r
383                 // Revert the old values\r
384                 for ( name in options ) {\r
385                         elem.style[ name ] = old[ name ];\r
386                 }\r
387 \r
388                 return ret;\r
389         };\r
390 \r
391 \r
392 // Ensure that $.ajax gets the new parseJSON defined in core.js\r
393         jQuery.ajaxSetup({\r
394                 converters: {\r
395                         "text json": jQuery.parseJSON\r
396                 }\r
397         });\r
398 \r
399 \r
400         var oldFnData = jQuery.fn.data;\r
401 \r
402         jQuery.fn.data = function( name ) {\r
403                 var ret, evt,\r
404                                 elem = this[0];\r
405 \r
406                 // Handles 1.7 which has this behavior and 1.8 which doesn't\r
407                 if ( elem && name === "events" && arguments.length === 1 ) {\r
408                         ret = jQuery.data( elem, name );\r
409                         evt = jQuery._data( elem, name );\r
410                         if ( ( ret === undefined || ret === evt ) && evt !== undefined ) {\r
411                                 migrateWarn("Use of jQuery.fn.data('events') is deprecated");\r
412                                 return evt;\r
413                         }\r
414                 }\r
415                 return oldFnData.apply( this, arguments );\r
416         };\r
417 \r
418 \r
419         var rscriptType = /\/(java|ecma)script/i;\r
420 \r
421 // Since jQuery.clean is used internally on older versions, we only shim if it's missing\r
422         if ( !jQuery.clean ) {\r
423                 jQuery.clean = function( elems, context, fragment, scripts ) {\r
424                         // Set context per 1.8 logic\r
425                         context = context || document;\r
426                         context = !context.nodeType && context[0] || context;\r
427                         context = context.ownerDocument || context;\r
428 \r
429                         migrateWarn("jQuery.clean() is deprecated");\r
430 \r
431                         var i, elem, handleScript, jsTags,\r
432                                         ret = [];\r
433 \r
434                         jQuery.merge( ret, jQuery.buildFragment( elems, context ).childNodes );\r
435 \r
436                         // Complex logic lifted directly from jQuery 1.8\r
437                         if ( fragment ) {\r
438                                 // Special handling of each script element\r
439                                 handleScript = function( elem ) {\r
440                                         // Check if we consider it executable\r
441                                         if ( !elem.type || rscriptType.test( elem.type ) ) {\r
442                                                 // Detach the script and store it in the scripts array (if provided) or the fragment\r
443                                                 // Return truthy to indicate that it has been handled\r
444                                                 return scripts ?\r
445                                                                 scripts.push( elem.parentNode ? elem.parentNode.removeChild( elem ) : elem ) :\r
446                                                                 fragment.appendChild( elem );\r
447                                         }\r
448                                 };\r
449 \r
450                                 for ( i = 0; (elem = ret[i]) != null; i++ ) {\r
451                                         // Check if we're done after handling an executable script\r
452                                         if ( !( jQuery.nodeName( elem, "script" ) && handleScript( elem ) ) ) {\r
453                                                 // Append to fragment and handle embedded scripts\r
454                                                 fragment.appendChild( elem );\r
455                                                 if ( typeof elem.getElementsByTagName !== "undefined" ) {\r
456                                                         // handleScript alters the DOM, so use jQuery.merge to ensure snapshot iteration\r
457                                                         jsTags = jQuery.grep( jQuery.merge( [], elem.getElementsByTagName("script") ), handleScript );\r
458 \r
459                                                         // Splice the scripts into ret after their former ancestor and advance our index beyond them\r
460                                                         ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) );\r
461                                                         i += jsTags.length;\r
462                                                 }\r
463                                         }\r
464                                 }\r
465                         }\r
466 \r
467                         return ret;\r
468                 };\r
469         }\r
470 \r
471         var eventAdd = jQuery.event.add,\r
472                         eventRemove = jQuery.event.remove,\r
473                         eventTrigger = jQuery.event.trigger,\r
474                         oldToggle = jQuery.fn.toggle,\r
475                         oldLive = jQuery.fn.live,\r
476                         oldDie = jQuery.fn.die,\r
477                         oldLoad = jQuery.fn.load,\r
478                         ajaxEvents = "ajaxStart|ajaxStop|ajaxSend|ajaxComplete|ajaxError|ajaxSuccess",\r
479                         rajaxEvent = new RegExp( "\\b(?:" + ajaxEvents + ")\\b" ),\r
480                         rhoverHack = /(?:^|\s)hover(\.\S+|)\b/,\r
481                         hoverHack = function( events ) {\r
482                                 if ( typeof( events ) !== "string" || jQuery.event.special.hover ) {\r
483                                         return events;\r
484                                 }\r
485                                 if ( rhoverHack.test( events ) ) {\r
486                                         migrateWarn("'hover' pseudo-event is deprecated, use 'mouseenter mouseleave'");\r
487                                 }\r
488                                 return events && events.replace( rhoverHack, "mouseenter$1 mouseleave$1" );\r
489                         };\r
490 \r
491 // Event props removed in 1.9, put them back if needed; no practical way to warn them\r
492         if ( jQuery.event.props && jQuery.event.props[ 0 ] !== "attrChange" ) {\r
493                 jQuery.event.props.unshift( "attrChange", "attrName", "relatedNode", "srcElement" );\r
494         }\r
495 \r
496 // Undocumented jQuery.event.handle was "deprecated" in jQuery 1.7\r
497         if ( jQuery.event.dispatch ) {\r
498                 migrateWarnProp( jQuery.event, "handle", jQuery.event.dispatch, "jQuery.event.handle is undocumented and deprecated" );\r
499         }\r
500 \r
501 // Support for 'hover' pseudo-event and ajax event warnings\r
502         jQuery.event.add = function( elem, types, handler, data, selector ){\r
503                 if ( elem !== document && rajaxEvent.test( types ) ) {\r
504                         migrateWarn( "AJAX events should be attached to document: " + types );\r
505                 }\r
506                 eventAdd.call( this, elem, hoverHack( types || "" ), handler, data, selector );\r
507         };\r
508         jQuery.event.remove = function( elem, types, handler, selector, mappedTypes ){\r
509                 eventRemove.call( this, elem, hoverHack( types ) || "", handler, selector, mappedTypes );\r
510         };\r
511 \r
512         jQuery.each( [ "load", "unload", "error" ], function( _, name ) {\r
513 \r
514                 jQuery.fn[ name ] = function() {\r
515                         var args = Array.prototype.slice.call( arguments, 0 );\r
516 \r
517                         // If this is an ajax load() the first arg should be the string URL;\r
518                         // technically this could also be the "Anything" arg of the event .load()\r
519                         // which just goes to show why this dumb signature has been deprecated!\r
520                         // jQuery custom builds that exclude the Ajax module justifiably die here.\r
521                         if ( name === "load" && typeof args[ 0 ] === "string" ) {\r
522                                 return oldLoad.apply( this, args );\r
523                         }\r
524 \r
525                         migrateWarn( "jQuery.fn." + name + "() is deprecated" );\r
526 \r
527                         args.splice( 0, 0, name );\r
528                         if ( arguments.length ) {\r
529                                 return this.bind.apply( this, args );\r
530                         }\r
531 \r
532                         // Use .triggerHandler here because:\r
533                         // - load and unload events don't need to bubble, only applied to window or image\r
534                         // - error event should not bubble to window, although it does pre-1.7\r
535                         // See http://bugs.jquery.com/ticket/11820\r
536                         this.triggerHandler.apply( this, args );\r
537                         return this;\r
538                 };\r
539 \r
540         });\r
541 \r
542         jQuery.fn.toggle = function( fn, fn2 ) {\r
543 \r
544                 // Don't mess with animation or css toggles\r
545                 if ( !jQuery.isFunction( fn ) || !jQuery.isFunction( fn2 ) ) {\r
546                         return oldToggle.apply( this, arguments );\r
547                 }\r
548                 migrateWarn("jQuery.fn.toggle(handler, handler...) is deprecated");\r
549 \r
550                 // Save reference to arguments for access in closure\r
551                 var args = arguments,\r
552                                 guid = fn.guid || jQuery.guid++,\r
553                                 i = 0,\r
554                                 toggler = function( event ) {\r
555                                         // Figure out which function to execute\r
556                                         var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;\r
557                                         jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );\r
558 \r
559                                         // Make sure that clicks stop\r
560                                         event.preventDefault();\r
561 \r
562                                         // and execute the function\r
563                                         return args[ lastToggle ].apply( this, arguments ) || false;\r
564                                 };\r
565 \r
566                 // link all the functions, so any of them can unbind this click handler\r
567                 toggler.guid = guid;\r
568                 while ( i < args.length ) {\r
569                         args[ i++ ].guid = guid;\r
570                 }\r
571 \r
572                 return this.click( toggler );\r
573         };\r
574 \r
575         jQuery.fn.live = function( types, data, fn ) {\r
576                 migrateWarn("jQuery.fn.live() is deprecated");\r
577                 if ( oldLive ) {\r
578                         return oldLive.apply( this, arguments );\r
579                 }\r
580                 jQuery( this.context ).on( types, this.selector, data, fn );\r
581                 return this;\r
582         };\r
583 \r
584         jQuery.fn.die = function( types, fn ) {\r
585                 migrateWarn("jQuery.fn.die() is deprecated");\r
586                 if ( oldDie ) {\r
587                         return oldDie.apply( this, arguments );\r
588                 }\r
589                 jQuery( this.context ).off( types, this.selector || "**", fn );\r
590                 return this;\r
591         };\r
592 \r
593 // Turn global events into document-triggered events\r
594         jQuery.event.trigger = function( event, data, elem, onlyHandlers  ){\r
595                 if ( !elem && !rajaxEvent.test( event ) ) {\r
596                         migrateWarn( "Global events are undocumented and deprecated" );\r
597                 }\r
598                 return eventTrigger.call( this,  event, data, elem || document, onlyHandlers  );\r
599         };\r
600         jQuery.each( ajaxEvents.split("|"),\r
601                         function( _, name ) {\r
602                                 jQuery.event.special[ name ] = {\r
603                                         setup: function() {\r
604                                                 var elem = this;\r
605 \r
606                                                 // The document needs no shimming; must be !== for oldIE\r
607                                                 if ( elem !== document ) {\r
608                                                         jQuery.event.add( document, name + "." + jQuery.guid, function() {\r
609                                                                 jQuery.event.trigger( name, Array.prototype.slice.call( arguments, 1 ), elem, true );\r
610                                                         });\r
611                                                         jQuery._data( this, name, jQuery.guid++ );\r
612                                                 }\r
613                                                 return false;\r
614                                         },\r
615                                         teardown: function() {\r
616                                                 if ( this !== document ) {\r
617                                                         jQuery.event.remove( document, name + "." + jQuery._data( this, name ) );\r
618                                                 }\r
619                                                 return false;\r
620                                         }\r
621                                 };\r
622                         }\r
623         );\r
624 \r
625         jQuery.event.special.ready = {\r
626                 setup: function() {\r
627                         if ( this === document ) {\r
628                                 migrateWarn( "'ready' event is deprecated" );\r
629                         }\r
630                 }\r
631         };\r
632 \r
633         var oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack,\r
634                         oldFind = jQuery.fn.find;\r
635 \r
636         jQuery.fn.andSelf = function() {\r
637                 migrateWarn("jQuery.fn.andSelf() replaced by jQuery.fn.addBack()");\r
638                 return oldSelf.apply( this, arguments );\r
639         };\r
640 \r
641         jQuery.fn.find = function( selector ) {\r
642                 var ret = oldFind.apply( this, arguments );\r
643                 ret.context = this.context;\r
644                 ret.selector = this.selector ? this.selector + " " + selector : selector;\r
645                 return ret;\r
646         };\r
647 \r
648 \r
649 // jQuery 1.6 did not support Callbacks, do not warn there\r
650         if ( jQuery.Callbacks ) {\r
651 \r
652                 var oldDeferred = jQuery.Deferred,\r
653                                 tuples = [\r
654                                         // action, add listener, callbacks, .then handlers, final state\r
655                                         [ "resolve", "done", jQuery.Callbacks("once memory"),\r
656                                                 jQuery.Callbacks("once memory"), "resolved" ],\r
657                                         [ "reject", "fail", jQuery.Callbacks("once memory"),\r
658                                                 jQuery.Callbacks("once memory"), "rejected" ],\r
659                                         [ "notify", "progress", jQuery.Callbacks("memory"),\r
660                                                 jQuery.Callbacks("memory") ]\r
661                                 ];\r
662 \r
663                 jQuery.Deferred = function( func ) {\r
664                         var deferred = oldDeferred(),\r
665                                         promise = deferred.promise();\r
666 \r
667                         deferred.pipe = promise.pipe = function( /* fnDone, fnFail, fnProgress */ ) {\r
668                                 var fns = arguments;\r
669 \r
670                                 migrateWarn( "deferred.pipe() is deprecated" );\r
671 \r
672                                 return jQuery.Deferred(function( newDefer ) {\r
673                                         jQuery.each( tuples, function( i, tuple ) {\r
674                                                 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];\r
675                                                 // deferred.done(function() { bind to newDefer or newDefer.resolve })\r
676                                                 // deferred.fail(function() { bind to newDefer or newDefer.reject })\r
677                                                 // deferred.progress(function() { bind to newDefer or newDefer.notify })\r
678                                                 deferred[ tuple[1] ](function() {\r
679                                                         var returned = fn && fn.apply( this, arguments );\r
680                                                         if ( returned && jQuery.isFunction( returned.promise ) ) {\r
681                                                                 returned.promise()\r
682                                                                                 .done( newDefer.resolve )\r
683                                                                                 .fail( newDefer.reject )\r
684                                                                                 .progress( newDefer.notify );\r
685                                                         } else {\r
686                                                                 newDefer[ tuple[ 0 ] + "With" ](\r
687                                                                                 this === promise ? newDefer.promise() : this,\r
688                                                                                 fn ? [ returned ] : arguments\r
689                                                                 );\r
690                                                         }\r
691                                                 });\r
692                                         });\r
693                                         fns = null;\r
694                                 }).promise();\r
695 \r
696                         };\r
697 \r
698                         deferred.isResolved = function() {\r
699                                 migrateWarn( "deferred.isResolved is deprecated" );\r
700                                 return deferred.state() === "resolved";\r
701                         };\r
702 \r
703                         deferred.isRejected = function() {\r
704                                 migrateWarn( "deferred.isRejected is deprecated" );\r
705                                 return deferred.state() === "rejected";\r
706                         };\r
707 \r
708                         if ( func ) {\r
709                                 func.call( deferred, deferred );\r
710                         }\r
711 \r
712                         return deferred;\r
713                 };\r
714 \r
715         }\r
716 \r
717 })( jQuery, window );