1 /*! |
1 /*! |
2 * jQuery Migrate - v1.2.1 - 2013-05-08 |
2 * jQuery Migrate - v1.4.1 - 2016-05-19 |
3 * https://github.com/jquery/jquery-migrate |
3 * Copyright jQuery Foundation and other contributors |
4 * Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors; Licensed MIT |
|
5 */ |
4 */ |
6 (function( jQuery, window, undefined ) { |
5 (function( jQuery, window, undefined ) { |
7 // See http://bugs.jquery.com/ticket/13335 |
6 // See http://bugs.jquery.com/ticket/13335 |
8 // "use strict"; |
7 // "use strict"; |
9 |
8 |
10 |
9 |
|
10 jQuery.migrateVersion = "1.4.1"; |
|
11 |
|
12 |
11 var warnedAbout = {}; |
13 var warnedAbout = {}; |
12 |
14 |
13 // List of warnings already given; public read only |
15 // List of warnings already given; public read only |
14 jQuery.migrateWarnings = []; |
16 jQuery.migrateWarnings = []; |
15 |
17 |
16 // Set to true to prevent console output; migrateWarnings still maintained |
18 // Set to true to prevent console output; migrateWarnings still maintained |
17 // jQuery.migrateMute = false; |
19 // jQuery.migrateMute = false; |
18 |
20 |
19 // Show a message on the console so devs know we're active |
21 // Show a message on the console so devs know we're active |
20 if ( !jQuery.migrateMute && window.console && window.console.log ) { |
22 if ( window.console && window.console.log ) { |
21 window.console.log("JQMIGRATE: Logging is active"); |
23 window.console.log( "JQMIGRATE: Migrate is installed" + |
|
24 ( jQuery.migrateMute ? "" : " with logging active" ) + |
|
25 ", version " + jQuery.migrateVersion ); |
22 } |
26 } |
23 |
27 |
24 // Set to false to disable traces that appear with warnings |
28 // Set to false to disable traces that appear with warnings |
25 if ( jQuery.migrateTrace === undefined ) { |
29 if ( jQuery.migrateTrace === undefined ) { |
26 jQuery.migrateTrace = true; |
30 jQuery.migrateTrace = true; |
187 }; |
191 }; |
188 |
192 |
189 |
193 |
190 var matched, browser, |
194 var matched, browser, |
191 oldInit = jQuery.fn.init, |
195 oldInit = jQuery.fn.init, |
|
196 oldFind = jQuery.find, |
192 oldParseJSON = jQuery.parseJSON, |
197 oldParseJSON = jQuery.parseJSON, |
|
198 rspaceAngle = /^\s*</, |
|
199 rattrHashTest = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/, |
|
200 rattrHashGlob = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g, |
193 // Note: XSS check is done below after string is trimmed |
201 // Note: XSS check is done below after string is trimmed |
194 rquickExpr = /^([^<]*)(<[\w\W]+>)([^>]*)$/; |
202 rquickExpr = /^([^<]*)(<[\w\W]+>)([^>]*)$/; |
195 |
203 |
196 // $(html) "looks like html" rule change |
204 // $(html) "looks like html" rule change |
197 jQuery.fn.init = function( selector, context, rootjQuery ) { |
205 jQuery.fn.init = function( selector, context, rootjQuery ) { |
198 var match; |
206 var match, ret; |
199 |
207 |
200 if ( selector && typeof selector === "string" && !jQuery.isPlainObject( context ) && |
208 if ( selector && typeof selector === "string" ) { |
201 (match = rquickExpr.exec( jQuery.trim( selector ) )) && match[ 0 ] ) { |
209 if ( !jQuery.isPlainObject( context ) && |
202 // This is an HTML string according to the "old" rules; is it still? |
210 (match = rquickExpr.exec( jQuery.trim( selector ) )) && match[ 0 ] ) { |
203 if ( selector.charAt( 0 ) !== "<" ) { |
211 |
204 migrateWarn("$(html) HTML strings must start with '<' character"); |
212 // This is an HTML string according to the "old" rules; is it still? |
205 } |
213 if ( !rspaceAngle.test( selector ) ) { |
206 if ( match[ 3 ] ) { |
214 migrateWarn("$(html) HTML strings must start with '<' character"); |
207 migrateWarn("$(html) HTML text after last tag is ignored"); |
215 } |
208 } |
216 if ( match[ 3 ] ) { |
209 // Consistently reject any HTML-like string starting with a hash (#9521) |
217 migrateWarn("$(html) HTML text after last tag is ignored"); |
210 // Note that this may break jQuery 1.6.x code that otherwise would work. |
218 } |
211 if ( match[ 0 ].charAt( 0 ) === "#" ) { |
219 |
212 migrateWarn("HTML string cannot start with a '#' character"); |
220 // Consistently reject any HTML-like string starting with a hash (gh-9521) |
213 jQuery.error("JQMIGRATE: Invalid selector string (XSS)"); |
221 // Note that this may break jQuery 1.6.x code that otherwise would work. |
214 } |
222 if ( match[ 0 ].charAt( 0 ) === "#" ) { |
215 // Now process using loose rules; let pre-1.8 play too |
223 migrateWarn("HTML string cannot start with a '#' character"); |
216 if ( context && context.context ) { |
224 jQuery.error("JQMIGRATE: Invalid selector string (XSS)"); |
217 // jQuery object as context; parseHTML expects a DOM object |
225 } |
218 context = context.context; |
226 |
219 } |
227 // Now process using loose rules; let pre-1.8 play too |
220 if ( jQuery.parseHTML ) { |
228 // Is this a jQuery context? parseHTML expects a DOM element (#178) |
221 return oldInit.call( this, jQuery.parseHTML( match[ 2 ], context, true ), |
229 if ( context && context.context && context.context.nodeType ) { |
222 context, rootjQuery ); |
230 context = context.context; |
223 } |
231 } |
224 } |
232 |
225 return oldInit.apply( this, arguments ); |
233 if ( jQuery.parseHTML ) { |
|
234 return oldInit.call( this, |
|
235 jQuery.parseHTML( match[ 2 ], context && context.ownerDocument || |
|
236 context || document, true ), context, rootjQuery ); |
|
237 } |
|
238 } |
|
239 } |
|
240 |
|
241 ret = oldInit.apply( this, arguments ); |
|
242 |
|
243 // Fill in selector and context properties so .live() works |
|
244 if ( selector && selector.selector !== undefined ) { |
|
245 // A jQuery object, copy its properties |
|
246 ret.selector = selector.selector; |
|
247 ret.context = selector.context; |
|
248 |
|
249 } else { |
|
250 ret.selector = typeof selector === "string" ? selector : ""; |
|
251 if ( selector ) { |
|
252 ret.context = selector.nodeType? selector : context || document; |
|
253 } |
|
254 } |
|
255 |
|
256 return ret; |
226 }; |
257 }; |
227 jQuery.fn.init.prototype = jQuery.fn; |
258 jQuery.fn.init.prototype = jQuery.fn; |
|
259 |
|
260 jQuery.find = function( selector ) { |
|
261 var args = Array.prototype.slice.call( arguments ); |
|
262 |
|
263 // Support: PhantomJS 1.x |
|
264 // String#match fails to match when used with a //g RegExp, only on some strings |
|
265 if ( typeof selector === "string" && rattrHashTest.test( selector ) ) { |
|
266 |
|
267 // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0 |
|
268 // First see if qS thinks it's a valid selector, if so avoid a false positive |
|
269 try { |
|
270 document.querySelector( selector ); |
|
271 } catch ( err1 ) { |
|
272 |
|
273 // Didn't *look* valid to qSA, warn and try quoting what we think is the value |
|
274 selector = selector.replace( rattrHashGlob, function( _, attr, op, value ) { |
|
275 return "[" + attr + op + "\"" + value + "\"]"; |
|
276 } ); |
|
277 |
|
278 // If the regexp *may* have created an invalid selector, don't update it |
|
279 // Note that there may be false alarms if selector uses jQuery extensions |
|
280 try { |
|
281 document.querySelector( selector ); |
|
282 migrateWarn( "Attribute selector with '#' must be quoted: " + args[ 0 ] ); |
|
283 args[ 0 ] = selector; |
|
284 } catch ( err2 ) { |
|
285 migrateWarn( "Attribute selector with '#' was not fixed: " + args[ 0 ] ); |
|
286 } |
|
287 } |
|
288 } |
|
289 |
|
290 return oldFind.apply( this, args ); |
|
291 }; |
|
292 |
|
293 // Copy properties attached to original jQuery.find method (e.g. .attr, .isXML) |
|
294 var findProp; |
|
295 for ( findProp in oldFind ) { |
|
296 if ( Object.prototype.hasOwnProperty.call( oldFind, findProp ) ) { |
|
297 jQuery.find[ findProp ] = oldFind[ findProp ]; |
|
298 } |
|
299 } |
228 |
300 |
229 // Let $.parseJSON(falsy_value) return null |
301 // Let $.parseJSON(falsy_value) return null |
230 jQuery.parseJSON = function( json ) { |
302 jQuery.parseJSON = function( json ) { |
231 if ( !json && json !== null ) { |
303 if ( !json ) { |
232 migrateWarn("jQuery.parseJSON requires a valid JSON string"); |
304 migrateWarn("jQuery.parseJSON requires a valid JSON string"); |
233 return null; |
305 return null; |
234 } |
306 } |
235 return oldParseJSON.apply( this, arguments ); |
307 return oldParseJSON.apply( this, arguments ); |
236 }; |
308 }; |
272 } |
344 } |
273 |
345 |
274 // Warn if the code tries to get jQuery.browser |
346 // Warn if the code tries to get jQuery.browser |
275 migrateWarnProp( jQuery, "browser", jQuery.browser, "jQuery.browser is deprecated" ); |
347 migrateWarnProp( jQuery, "browser", jQuery.browser, "jQuery.browser is deprecated" ); |
276 |
348 |
|
349 // jQuery.boxModel deprecated in 1.3, jQuery.support.boxModel deprecated in 1.7 |
|
350 jQuery.boxModel = jQuery.support.boxModel = (document.compatMode === "CSS1Compat"); |
|
351 migrateWarnProp( jQuery, "boxModel", jQuery.boxModel, "jQuery.boxModel is deprecated" ); |
|
352 migrateWarnProp( jQuery.support, "boxModel", jQuery.support.boxModel, "jQuery.support.boxModel is deprecated" ); |
|
353 |
277 jQuery.sub = function() { |
354 jQuery.sub = function() { |
278 function jQuerySub( selector, context ) { |
355 function jQuerySub( selector, context ) { |
279 return new jQuerySub.fn.init( selector, context ); |
356 return new jQuerySub.fn.init( selector, context ); |
280 } |
357 } |
281 jQuery.extend( true, jQuerySub, this ); |
358 jQuery.extend( true, jQuerySub, this ); |
282 jQuerySub.superclass = this; |
359 jQuerySub.superclass = this; |
283 jQuerySub.fn = jQuerySub.prototype = this(); |
360 jQuerySub.fn = jQuerySub.prototype = this(); |
284 jQuerySub.fn.constructor = jQuerySub; |
361 jQuerySub.fn.constructor = jQuerySub; |
285 jQuerySub.sub = this.sub; |
362 jQuerySub.sub = this.sub; |
286 jQuerySub.fn.init = function init( selector, context ) { |
363 jQuerySub.fn.init = function init( selector, context ) { |
287 if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) { |
364 var instance = jQuery.fn.init.call( this, selector, context, rootjQuerySub ); |
288 context = jQuerySub( context ); |
365 return instance instanceof jQuerySub ? |
289 } |
366 instance : |
290 |
367 jQuerySub( instance ); |
291 return jQuery.fn.init.call( this, selector, context, rootjQuerySub ); |
|
292 }; |
368 }; |
293 jQuerySub.fn.init.prototype = jQuerySub.fn; |
369 jQuerySub.fn.init.prototype = jQuerySub.fn; |
294 var rootjQuerySub = jQuerySub(document); |
370 var rootjQuerySub = jQuerySub(document); |
295 migrateWarn( "jQuery.sub() is deprecated" ); |
371 migrateWarn( "jQuery.sub() is deprecated" ); |
296 return jQuerySub; |
372 return jQuerySub; |
|
373 }; |
|
374 |
|
375 // The number of elements contained in the matched element set |
|
376 jQuery.fn.size = function() { |
|
377 migrateWarn( "jQuery.fn.size() is deprecated; use the .length property" ); |
|
378 return this.length; |
|
379 }; |
|
380 |
|
381 |
|
382 var internalSwapCall = false; |
|
383 |
|
384 // If this version of jQuery has .swap(), don't false-alarm on internal uses |
|
385 if ( jQuery.swap ) { |
|
386 jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) { |
|
387 var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get; |
|
388 |
|
389 if ( oldHook ) { |
|
390 jQuery.cssHooks[ name ].get = function() { |
|
391 var ret; |
|
392 |
|
393 internalSwapCall = true; |
|
394 ret = oldHook.apply( this, arguments ); |
|
395 internalSwapCall = false; |
|
396 return ret; |
|
397 }; |
|
398 } |
|
399 }); |
|
400 } |
|
401 |
|
402 jQuery.swap = function( elem, options, callback, args ) { |
|
403 var ret, name, |
|
404 old = {}; |
|
405 |
|
406 if ( !internalSwapCall ) { |
|
407 migrateWarn( "jQuery.swap() is undocumented and deprecated" ); |
|
408 } |
|
409 |
|
410 // Remember the old values, and insert the new ones |
|
411 for ( name in options ) { |
|
412 old[ name ] = elem.style[ name ]; |
|
413 elem.style[ name ] = options[ name ]; |
|
414 } |
|
415 |
|
416 ret = callback.apply( elem, args || [] ); |
|
417 |
|
418 // Revert the old values |
|
419 for ( name in options ) { |
|
420 elem.style[ name ] = old[ name ]; |
|
421 } |
|
422 |
|
423 return ret; |
297 }; |
424 }; |
298 |
425 |
299 |
426 |
300 // Ensure that $.ajax gets the new parseJSON defined in core.js |
427 // Ensure that $.ajax gets the new parseJSON defined in core.js |
301 jQuery.ajaxSetup({ |
428 jQuery.ajaxSetup({ |
386 eventRemove = jQuery.event.remove, |
507 eventRemove = jQuery.event.remove, |
387 eventTrigger = jQuery.event.trigger, |
508 eventTrigger = jQuery.event.trigger, |
388 oldToggle = jQuery.fn.toggle, |
509 oldToggle = jQuery.fn.toggle, |
389 oldLive = jQuery.fn.live, |
510 oldLive = jQuery.fn.live, |
390 oldDie = jQuery.fn.die, |
511 oldDie = jQuery.fn.die, |
|
512 oldLoad = jQuery.fn.load, |
391 ajaxEvents = "ajaxStart|ajaxStop|ajaxSend|ajaxComplete|ajaxError|ajaxSuccess", |
513 ajaxEvents = "ajaxStart|ajaxStop|ajaxSend|ajaxComplete|ajaxError|ajaxSuccess", |
392 rajaxEvent = new RegExp( "\\b(?:" + ajaxEvents + ")\\b" ), |
514 rajaxEvent = new RegExp( "\\b(?:" + ajaxEvents + ")\\b" ), |
393 rhoverHack = /(?:^|\s)hover(\.\S+|)\b/, |
515 rhoverHack = /(?:^|\s)hover(\.\S+|)\b/, |
394 hoverHack = function( events ) { |
516 hoverHack = function( events ) { |
395 if ( typeof( events ) !== "string" || jQuery.event.special.hover ) { |
517 if ( typeof( events ) !== "string" || jQuery.event.special.hover ) { |
420 }; |
542 }; |
421 jQuery.event.remove = function( elem, types, handler, selector, mappedTypes ){ |
543 jQuery.event.remove = function( elem, types, handler, selector, mappedTypes ){ |
422 eventRemove.call( this, elem, hoverHack( types ) || "", handler, selector, mappedTypes ); |
544 eventRemove.call( this, elem, hoverHack( types ) || "", handler, selector, mappedTypes ); |
423 }; |
545 }; |
424 |
546 |
425 jQuery.fn.error = function() { |
547 jQuery.each( [ "load", "unload", "error" ], function( _, name ) { |
426 var args = Array.prototype.slice.call( arguments, 0); |
548 |
427 migrateWarn("jQuery.fn.error() is deprecated"); |
549 jQuery.fn[ name ] = function() { |
428 args.splice( 0, 0, "error" ); |
550 var args = Array.prototype.slice.call( arguments, 0 ); |
429 if ( arguments.length ) { |
551 |
430 return this.bind.apply( this, args ); |
552 // If this is an ajax load() the first arg should be the string URL; |
431 } |
553 // technically this could also be the "Anything" arg of the event .load() |
432 // error event should not bubble to window, although it does pre-1.7 |
554 // which just goes to show why this dumb signature has been deprecated! |
433 this.triggerHandler.apply( this, args ); |
555 // jQuery custom builds that exclude the Ajax module justifiably die here. |
434 return this; |
556 if ( name === "load" && typeof args[ 0 ] === "string" ) { |
435 }; |
557 return oldLoad.apply( this, args ); |
|
558 } |
|
559 |
|
560 migrateWarn( "jQuery.fn." + name + "() is deprecated" ); |
|
561 |
|
562 args.splice( 0, 0, name ); |
|
563 if ( arguments.length ) { |
|
564 return this.bind.apply( this, args ); |
|
565 } |
|
566 |
|
567 // Use .triggerHandler here because: |
|
568 // - load and unload events don't need to bubble, only applied to window or image |
|
569 // - error event should not bubble to window, although it does pre-1.7 |
|
570 // See http://bugs.jquery.com/ticket/11820 |
|
571 this.triggerHandler.apply( this, args ); |
|
572 return this; |
|
573 }; |
|
574 |
|
575 }); |
436 |
576 |
437 jQuery.fn.toggle = function( fn, fn2 ) { |
577 jQuery.fn.toggle = function( fn, fn2 ) { |
438 |
578 |
439 // Don't mess with animation or css toggles |
579 // Don't mess with animation or css toggles |
440 if ( !jQuery.isFunction( fn ) || !jQuery.isFunction( fn2 ) ) { |
580 if ( !jQuery.isFunction( fn ) || !jQuery.isFunction( fn2 ) ) { |
515 } |
655 } |
516 }; |
656 }; |
517 } |
657 } |
518 ); |
658 ); |
519 |
659 |
|
660 jQuery.event.special.ready = { |
|
661 setup: function() { |
|
662 if ( this === document ) { |
|
663 migrateWarn( "'ready' event is deprecated" ); |
|
664 } |
|
665 } |
|
666 }; |
|
667 |
|
668 var oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack, |
|
669 oldFnFind = jQuery.fn.find; |
|
670 |
|
671 jQuery.fn.andSelf = function() { |
|
672 migrateWarn("jQuery.fn.andSelf() replaced by jQuery.fn.addBack()"); |
|
673 return oldSelf.apply( this, arguments ); |
|
674 }; |
|
675 |
|
676 jQuery.fn.find = function( selector ) { |
|
677 var ret = oldFnFind.apply( this, arguments ); |
|
678 ret.context = this.context; |
|
679 ret.selector = this.selector ? this.selector + " " + selector : selector; |
|
680 return ret; |
|
681 }; |
|
682 |
|
683 |
|
684 // jQuery 1.6 did not support Callbacks, do not warn there |
|
685 if ( jQuery.Callbacks ) { |
|
686 |
|
687 var oldDeferred = jQuery.Deferred, |
|
688 tuples = [ |
|
689 // action, add listener, callbacks, .then handlers, final state |
|
690 [ "resolve", "done", jQuery.Callbacks("once memory"), |
|
691 jQuery.Callbacks("once memory"), "resolved" ], |
|
692 [ "reject", "fail", jQuery.Callbacks("once memory"), |
|
693 jQuery.Callbacks("once memory"), "rejected" ], |
|
694 [ "notify", "progress", jQuery.Callbacks("memory"), |
|
695 jQuery.Callbacks("memory") ] |
|
696 ]; |
|
697 |
|
698 jQuery.Deferred = function( func ) { |
|
699 var deferred = oldDeferred(), |
|
700 promise = deferred.promise(); |
|
701 |
|
702 deferred.pipe = promise.pipe = function( /* fnDone, fnFail, fnProgress */ ) { |
|
703 var fns = arguments; |
|
704 |
|
705 migrateWarn( "deferred.pipe() is deprecated" ); |
|
706 |
|
707 return jQuery.Deferred(function( newDefer ) { |
|
708 jQuery.each( tuples, function( i, tuple ) { |
|
709 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ]; |
|
710 // deferred.done(function() { bind to newDefer or newDefer.resolve }) |
|
711 // deferred.fail(function() { bind to newDefer or newDefer.reject }) |
|
712 // deferred.progress(function() { bind to newDefer or newDefer.notify }) |
|
713 deferred[ tuple[1] ](function() { |
|
714 var returned = fn && fn.apply( this, arguments ); |
|
715 if ( returned && jQuery.isFunction( returned.promise ) ) { |
|
716 returned.promise() |
|
717 .done( newDefer.resolve ) |
|
718 .fail( newDefer.reject ) |
|
719 .progress( newDefer.notify ); |
|
720 } else { |
|
721 newDefer[ tuple[ 0 ] + "With" ]( |
|
722 this === promise ? newDefer.promise() : this, |
|
723 fn ? [ returned ] : arguments |
|
724 ); |
|
725 } |
|
726 }); |
|
727 }); |
|
728 fns = null; |
|
729 }).promise(); |
|
730 |
|
731 }; |
|
732 |
|
733 deferred.isResolved = function() { |
|
734 migrateWarn( "deferred.isResolved is deprecated" ); |
|
735 return deferred.state() === "resolved"; |
|
736 }; |
|
737 |
|
738 deferred.isRejected = function() { |
|
739 migrateWarn( "deferred.isRejected is deprecated" ); |
|
740 return deferred.state() === "rejected"; |
|
741 }; |
|
742 |
|
743 if ( func ) { |
|
744 func.call( deferred, deferred ); |
|
745 } |
|
746 |
|
747 return deferred; |
|
748 }; |
|
749 |
|
750 } |
520 |
751 |
521 })( jQuery, window ); |
752 })( jQuery, window ); |