jquery-migrate.js 22 KB

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