[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/jquery/ -> jquery-migrate.js (source)

   1  /*!
   2   * jQuery Migrate - v3.4.1 - 2023-02-23T15:31Z
   3   * Copyright OpenJS Foundation and other contributors
   4   */
   5  ( function( factory ) {
   6      "use strict";
   7  
   8      if ( typeof define === "function" && define.amd ) {
   9  
  10          // AMD. Register as an anonymous module.
  11          define( [ "jquery" ], function( jQuery ) {
  12              return factory( jQuery, window );
  13          } );
  14      } else if ( typeof module === "object" && module.exports ) {
  15  
  16          // Node/CommonJS
  17          // eslint-disable-next-line no-undef
  18          module.exports = factory( require( "jquery" ), window );
  19      } else {
  20  
  21          // Browser globals
  22          factory( jQuery, window );
  23      }
  24  } )( function( jQuery, window ) {
  25  "use strict";
  26  
  27  jQuery.migrateVersion = "3.4.1";
  28  
  29  // Returns 0 if v1 == v2, -1 if v1 < v2, 1 if v1 > v2
  30  function compareVersions( v1, v2 ) {
  31      var i,
  32          rVersionParts = /^(\d+)\.(\d+)\.(\d+)/,
  33          v1p = rVersionParts.exec( v1 ) || [ ],
  34          v2p = rVersionParts.exec( v2 ) || [ ];
  35  
  36      for ( i = 1; i <= 3; i++ ) {
  37          if ( +v1p[ i ] > +v2p[ i ] ) {
  38              return 1;
  39          }
  40          if ( +v1p[ i ] < +v2p[ i ] ) {
  41              return -1;
  42          }
  43      }
  44      return 0;
  45  }
  46  
  47  function jQueryVersionSince( version ) {
  48      return compareVersions( jQuery.fn.jquery, version ) >= 0;
  49  }
  50  
  51  // A map from disabled patch codes to `true`. This should really
  52  // be a `Set` but those are unsupported in IE.
  53  var disabledPatches = Object.create( null );
  54  
  55  // Don't apply patches for specified codes. Helpful for code bases
  56  // where some Migrate warnings have been addressed and it's desirable
  57  // to avoid needless patches or false positives.
  58  jQuery.migrateDisablePatches = function() {
  59      var i;
  60      for ( i = 0; i < arguments.length; i++ ) {
  61          disabledPatches[ arguments[ i ] ] = true;
  62      }
  63  };
  64  
  65  // Allow enabling patches disabled via `jQuery.migrateDisablePatches`.
  66  // Helpful if you want to disable a patch only for some code that won't
  67  // be updated soon to be able to focus on other warnings - and enable it
  68  // immediately after such a call:
  69  // ```js
  70  // jQuery.migrateDisablePatches( "workaroundA" );
  71  // elem.pluginViolatingWarningA( "pluginMethod" );
  72  // jQuery.migrateEnablePatches( "workaroundA" );
  73  // ```
  74  jQuery.migrateEnablePatches = function() {
  75      var i;
  76      for ( i = 0; i < arguments.length; i++ ) {
  77          delete disabledPatches[ arguments[ i ] ];
  78      }
  79  };
  80  
  81  jQuery.migrateIsPatchEnabled = function( patchCode ) {
  82      return !disabledPatches[ patchCode ];
  83  };
  84  
  85  ( function() {
  86  
  87      // Support: IE9 only
  88      // IE9 only creates console object when dev tools are first opened
  89      // IE9 console is a host object, callable but doesn't have .apply()
  90      if ( !window.console || !window.console.log ) {
  91          return;
  92      }
  93  
  94      // Need jQuery 3.x-4.x and no older Migrate loaded
  95      if ( !jQuery || !jQueryVersionSince( "3.0.0" ) ||
  96              jQueryVersionSince( "5.0.0" ) ) {
  97          window.console.log( "JQMIGRATE: jQuery 3.x-4.x REQUIRED" );
  98      }
  99      if ( jQuery.migrateWarnings ) {
 100          window.console.log( "JQMIGRATE: Migrate plugin loaded multiple times" );
 101      }
 102  
 103      // Show a message on the console so devs know we're active
 104      window.console.log( "JQMIGRATE: Migrate is installed" +
 105          ( jQuery.migrateMute ? "" : " with logging active" ) +
 106          ", version " + jQuery.migrateVersion );
 107  
 108  } )();
 109  
 110  var warnedAbout = {};
 111  
 112  // By default each warning is only reported once.
 113  jQuery.migrateDeduplicateWarnings = true;
 114  
 115  // List of warnings already given; public read only
 116  jQuery.migrateWarnings = [];
 117  
 118  // Set to false to disable traces that appear with warnings
 119  if ( jQuery.migrateTrace === undefined ) {
 120      jQuery.migrateTrace = true;
 121  }
 122  
 123  // Forget any warnings we've already given; public
 124  jQuery.migrateReset = function() {
 125      warnedAbout = {};
 126      jQuery.migrateWarnings.length = 0;
 127  };
 128  
 129  function migrateWarn( code, msg ) {
 130      var console = window.console;
 131      if ( jQuery.migrateIsPatchEnabled( code ) &&
 132          ( !jQuery.migrateDeduplicateWarnings || !warnedAbout[ msg ] ) ) {
 133          warnedAbout[ msg ] = true;
 134          jQuery.migrateWarnings.push( msg + " [" + code + "]" );
 135          if ( console && console.warn && !jQuery.migrateMute ) {
 136              console.warn( "JQMIGRATE: " + msg );
 137              if ( jQuery.migrateTrace && console.trace ) {
 138                  console.trace();
 139              }
 140          }
 141      }
 142  }
 143  
 144  function migrateWarnProp( obj, prop, value, code, msg ) {
 145      Object.defineProperty( obj, prop, {
 146          configurable: true,
 147          enumerable: true,
 148          get: function() {
 149              migrateWarn( code, msg );
 150              return value;
 151          },
 152          set: function( newValue ) {
 153              migrateWarn( code, msg );
 154              value = newValue;
 155          }
 156      } );
 157  }
 158  
 159  function migrateWarnFuncInternal( obj, prop, newFunc, code, msg ) {
 160      var finalFunc,
 161          origFunc = obj[ prop ];
 162  
 163      obj[ prop ] = function() {
 164  
 165          // If `msg` not provided, do not warn; more sophisticated warnings
 166          // logic is most likely embedded in `newFunc`, in that case here
 167          // we just care about the logic choosing the proper implementation
 168          // based on whether the patch is disabled or not.
 169          if ( msg ) {
 170              migrateWarn( code, msg );
 171          }
 172  
 173          // Since patches can be disabled & enabled dynamically, we
 174          // need to decide which implementation to run on each invocation.
 175          finalFunc = jQuery.migrateIsPatchEnabled( code ) ?
 176              newFunc :
 177  
 178              // The function may not have existed originally so we need a fallback.
 179              ( origFunc || jQuery.noop );
 180  
 181          return finalFunc.apply( this, arguments );
 182      };
 183  }
 184  
 185  function migratePatchAndWarnFunc( obj, prop, newFunc, code, msg ) {
 186      if ( !msg ) {
 187          throw new Error( "No warning message provided" );
 188      }
 189      return migrateWarnFuncInternal( obj, prop, newFunc, code, msg );
 190  }
 191  
 192  function migratePatchFunc( obj, prop, newFunc, code ) {
 193      return migrateWarnFuncInternal( obj, prop, newFunc, code );
 194  }
 195  
 196  if ( window.document.compatMode === "BackCompat" ) {
 197  
 198      // jQuery has never supported or tested Quirks Mode
 199      migrateWarn( "quirks", "jQuery is not compatible with Quirks Mode" );
 200  }
 201  
 202  var findProp,
 203      class2type = {},
 204      oldInit = jQuery.fn.init,
 205      oldFind = jQuery.find,
 206  
 207      rattrHashTest = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/,
 208      rattrHashGlob = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g,
 209  
 210      // Require that the "whitespace run" starts from a non-whitespace
 211      // to avoid O(N^2) behavior when the engine would try matching "\s+$" at each space position.
 212      rtrim = /^[\s\uFEFF\xA0]+|([^\s\uFEFF\xA0])[\s\uFEFF\xA0]+$/g;
 213  
 214  migratePatchFunc( jQuery.fn, "init", function( arg1 ) {
 215      var args = Array.prototype.slice.call( arguments );
 216  
 217      if ( jQuery.migrateIsPatchEnabled( "selector-empty-id" ) &&
 218          typeof arg1 === "string" && arg1 === "#" ) {
 219  
 220          // JQuery( "#" ) is a bogus ID selector, but it returned an empty set
 221          // before jQuery 3.0
 222          migrateWarn( "selector-empty-id", "jQuery( '#' ) is not a valid selector" );
 223          args[ 0 ] = [];
 224      }
 225  
 226      return oldInit.apply( this, args );
 227  }, "selector-empty-id" );
 228  
 229  // This is already done in Core but the above patch will lose this assignment
 230  // so we need to redo it. It doesn't matter whether the patch is enabled or not
 231  // as the method is always going to be a Migrate-created wrapper.
 232  jQuery.fn.init.prototype = jQuery.fn;
 233  
 234  migratePatchFunc( jQuery, "find", function( selector ) {
 235      var args = Array.prototype.slice.call( arguments );
 236  
 237      // Support: PhantomJS 1.x
 238      // String#match fails to match when used with a //g RegExp, only on some strings
 239      if ( typeof selector === "string" && rattrHashTest.test( selector ) ) {
 240  
 241          // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
 242          // First see if qS thinks it's a valid selector, if so avoid a false positive
 243          try {
 244              window.document.querySelector( selector );
 245          } catch ( err1 ) {
 246  
 247              // Didn't *look* valid to qSA, warn and try quoting what we think is the value
 248              selector = selector.replace( rattrHashGlob, function( _, attr, op, value ) {
 249                  return "[" + attr + op + "\"" + value + "\"]";
 250              } );
 251  
 252              // If the regexp *may* have created an invalid selector, don't update it
 253              // Note that there may be false alarms if selector uses jQuery extensions
 254              try {
 255                  window.document.querySelector( selector );
 256                  migrateWarn( "selector-hash",
 257                      "Attribute selector with '#' must be quoted: " + args[ 0 ] );
 258                  args[ 0 ] = selector;
 259              } catch ( err2 ) {
 260                  migrateWarn( "selector-hash",
 261                      "Attribute selector with '#' was not fixed: " + args[ 0 ] );
 262              }
 263          }
 264      }
 265  
 266      return oldFind.apply( this, args );
 267  }, "selector-hash" );
 268  
 269  // Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
 270  for ( findProp in oldFind ) {
 271      if ( Object.prototype.hasOwnProperty.call( oldFind, findProp ) ) {
 272          jQuery.find[ findProp ] = oldFind[ findProp ];
 273      }
 274  }
 275  
 276  // The number of elements contained in the matched element set
 277  migratePatchAndWarnFunc( jQuery.fn, "size", function() {
 278      return this.length;
 279  }, "size",
 280  "jQuery.fn.size() is deprecated and removed; use the .length property" );
 281  
 282  migratePatchAndWarnFunc( jQuery, "parseJSON", function() {
 283      return JSON.parse.apply( null, arguments );
 284  }, "parseJSON",
 285  "jQuery.parseJSON is deprecated; use JSON.parse" );
 286  
 287  migratePatchAndWarnFunc( jQuery, "holdReady", jQuery.holdReady,
 288      "holdReady", "jQuery.holdReady is deprecated" );
 289  
 290  migratePatchAndWarnFunc( jQuery, "unique", jQuery.uniqueSort,
 291      "unique", "jQuery.unique is deprecated; use jQuery.uniqueSort" );
 292  
 293  // Now jQuery.expr.pseudos is the standard incantation
 294  migrateWarnProp( jQuery.expr, "filters", jQuery.expr.pseudos, "expr-pre-pseudos",
 295      "jQuery.expr.filters is deprecated; use jQuery.expr.pseudos" );
 296  migrateWarnProp( jQuery.expr, ":", jQuery.expr.pseudos, "expr-pre-pseudos",
 297      "jQuery.expr[':'] is deprecated; use jQuery.expr.pseudos" );
 298  
 299  // Prior to jQuery 3.1.1 there were internal refs so we don't warn there
 300  if ( jQueryVersionSince( "3.1.1" ) ) {
 301      migratePatchAndWarnFunc( jQuery, "trim", function( text ) {
 302          return text == null ?
 303              "" :
 304              ( text + "" ).replace( rtrim, "$1" );
 305      }, "trim",
 306      "jQuery.trim is deprecated; use String.prototype.trim" );
 307  }
 308  
 309  // Prior to jQuery 3.2 there were internal refs so we don't warn there
 310  if ( jQueryVersionSince( "3.2.0" ) ) {
 311      migratePatchAndWarnFunc( jQuery, "nodeName", function( elem, name ) {
 312          return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
 313      }, "nodeName",
 314      "jQuery.nodeName is deprecated" );
 315  
 316      migratePatchAndWarnFunc( jQuery, "isArray", Array.isArray, "isArray",
 317          "jQuery.isArray is deprecated; use Array.isArray"
 318      );
 319  }
 320  
 321  if ( jQueryVersionSince( "3.3.0" ) ) {
 322  
 323      migratePatchAndWarnFunc( jQuery, "isNumeric", function( obj ) {
 324  
 325              // As of jQuery 3.0, isNumeric is limited to
 326              // strings and numbers (primitives or objects)
 327              // that can be coerced to finite numbers (gh-2662)
 328              var type = typeof obj;
 329              return ( type === "number" || type === "string" ) &&
 330  
 331                  // parseFloat NaNs numeric-cast false positives ("")
 332                  // ...but misinterprets leading-number strings, e.g. hex literals ("0x...")
 333                  // subtraction forces infinities to NaN
 334                  !isNaN( obj - parseFloat( obj ) );
 335          }, "isNumeric",
 336          "jQuery.isNumeric() is deprecated"
 337      );
 338  
 339      // Populate the class2type map
 340      jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".
 341          split( " " ),
 342      function( _, name ) {
 343          class2type[ "[object " + name + "]" ] = name.toLowerCase();
 344      } );
 345  
 346      migratePatchAndWarnFunc( jQuery, "type", function( obj ) {
 347          if ( obj == null ) {
 348              return obj + "";
 349          }
 350  
 351          // Support: Android <=2.3 only (functionish RegExp)
 352          return typeof obj === "object" || typeof obj === "function" ?
 353              class2type[ Object.prototype.toString.call( obj ) ] || "object" :
 354              typeof obj;
 355      }, "type",
 356      "jQuery.type is deprecated" );
 357  
 358      migratePatchAndWarnFunc( jQuery, "isFunction",
 359          function( obj ) {
 360              return typeof obj === "function";
 361          }, "isFunction",
 362          "jQuery.isFunction() is deprecated" );
 363  
 364      migratePatchAndWarnFunc( jQuery, "isWindow",
 365          function( obj ) {
 366              return obj != null && obj === obj.window;
 367          }, "isWindow",
 368          "jQuery.isWindow() is deprecated"
 369      );
 370  }
 371  
 372  // Support jQuery slim which excludes the ajax module
 373  if ( jQuery.ajax ) {
 374  
 375  var oldAjax = jQuery.ajax,
 376      rjsonp = /(=)\?(?=&|$)|\?\?/;
 377  
 378  migratePatchFunc( jQuery, "ajax", function() {
 379      var jQXHR = oldAjax.apply( this, arguments );
 380  
 381      // Be sure we got a jQXHR (e.g., not sync)
 382      if ( jQXHR.promise ) {
 383          migratePatchAndWarnFunc( jQXHR, "success", jQXHR.done, "jqXHR-methods",
 384              "jQXHR.success is deprecated and removed" );
 385          migratePatchAndWarnFunc( jQXHR, "error", jQXHR.fail, "jqXHR-methods",
 386              "jQXHR.error is deprecated and removed" );
 387          migratePatchAndWarnFunc( jQXHR, "complete", jQXHR.always, "jqXHR-methods",
 388              "jQXHR.complete is deprecated and removed" );
 389      }
 390  
 391      return jQXHR;
 392  }, "jqXHR-methods" );
 393  
 394  // Only trigger the logic in jQuery <4 as the JSON-to-JSONP auto-promotion
 395  // behavior is gone in jQuery 4.0 and as it has security implications, we don't
 396  // want to restore the legacy behavior.
 397  if ( !jQueryVersionSince( "4.0.0" ) ) {
 398  
 399      // Register this prefilter before the jQuery one. Otherwise, a promoted
 400      // request is transformed into one with the script dataType and we can't
 401      // catch it anymore.
 402      jQuery.ajaxPrefilter( "+json", function( s ) {
 403  
 404          // Warn if JSON-to-JSONP auto-promotion happens.
 405          if ( s.jsonp !== false && ( rjsonp.test( s.url ) ||
 406                  typeof s.data === "string" &&
 407                  ( s.contentType || "" )
 408                      .indexOf( "application/x-www-form-urlencoded" ) === 0 &&
 409                  rjsonp.test( s.data )
 410          ) ) {
 411              migrateWarn( "jsonp-promotion", "JSON-to-JSONP auto-promotion is deprecated" );
 412          }
 413      } );
 414  }
 415  
 416  }
 417  
 418  var oldRemoveAttr = jQuery.fn.removeAttr,
 419      oldToggleClass = jQuery.fn.toggleClass,
 420      rmatchNonSpace = /\S+/g;
 421  
 422  migratePatchFunc( jQuery.fn, "removeAttr", function( name ) {
 423      var self = this,
 424          patchNeeded = false;
 425  
 426      jQuery.each( name.match( rmatchNonSpace ), function( _i, attr ) {
 427          if ( jQuery.expr.match.bool.test( attr ) ) {
 428  
 429              // Only warn if at least a single node had the property set to
 430              // something else than `false`. Otherwise, this Migrate patch
 431              // doesn't influence the behavior and there's no need to set or warn.
 432              self.each( function() {
 433                  if ( jQuery( this ).prop( attr ) !== false ) {
 434                      patchNeeded = true;
 435                      return false;
 436                  }
 437              } );
 438          }
 439  
 440          if ( patchNeeded ) {
 441              migrateWarn( "removeAttr-bool",
 442                  "jQuery.fn.removeAttr no longer sets boolean properties: " + attr );
 443              self.prop( attr, false );
 444          }
 445      } );
 446  
 447      return oldRemoveAttr.apply( this, arguments );
 448  }, "removeAttr-bool" );
 449  
 450  migratePatchFunc( jQuery.fn, "toggleClass", function( state ) {
 451  
 452      // Only deprecating no-args or single boolean arg
 453      if ( state !== undefined && typeof state !== "boolean" ) {
 454  
 455          return oldToggleClass.apply( this, arguments );
 456      }
 457  
 458      migrateWarn( "toggleClass-bool", "jQuery.fn.toggleClass( boolean ) is deprecated" );
 459  
 460      // Toggle entire class name of each element
 461      return this.each( function() {
 462          var className = this.getAttribute && this.getAttribute( "class" ) || "";
 463  
 464          if ( className ) {
 465              jQuery.data( this, "__className__", className );
 466          }
 467  
 468          // If the element has a class name or if we're passed `false`,
 469          // then remove the whole classname (if there was one, the above saved it).
 470          // Otherwise bring back whatever was previously saved (if anything),
 471          // falling back to the empty string if nothing was stored.
 472          if ( this.setAttribute ) {
 473              this.setAttribute( "class",
 474                  className || state === false ?
 475                  "" :
 476                  jQuery.data( this, "__className__" ) || ""
 477              );
 478          }
 479      } );
 480  }, "toggleClass-bool" );
 481  
 482  function camelCase( string ) {
 483      return string.replace( /-([a-z])/g, function( _, letter ) {
 484          return letter.toUpperCase();
 485      } );
 486  }
 487  
 488  var origFnCss, internalCssNumber,
 489      internalSwapCall = false,
 490      ralphaStart = /^[a-z]/,
 491  
 492      // The regex visualized:
 493      //
 494      //                         /----------\
 495      //                        |            |    /-------\
 496      //                        |  / Top  \  |   |         |
 497      //         /--- Border ---+-| Right  |-+---+- Width -+---\
 498      //        |                 | Bottom |                    |
 499      //        |                  \ Left /                     |
 500      //        |                                               |
 501      //        |                              /----------\     |
 502      //        |          /-------------\    |            |    |- END
 503      //        |         |               |   |  / Top  \  |    |
 504      //        |         |  / Margin  \  |   | | Right  | |    |
 505      //        |---------+-|           |-+---+-| Bottom |-+----|
 506      //        |            \ Padding /         \ Left /       |
 507      // BEGIN -|                                               |
 508      //        |                /---------\                    |
 509      //        |               |           |                   |
 510      //        |               |  / Min \  |    / Width  \     |
 511      //         \--------------+-|       |-+---|          |---/
 512      //                           \ Max /       \ Height /
 513      rautoPx = /^(?:Border(?:Top|Right|Bottom|Left)?(?:Width|)|(?:Margin|Padding)?(?:Top|Right|Bottom|Left)?|(?:Min|Max)?(?:Width|Height))$/;
 514  
 515  // If this version of jQuery has .swap(), don't false-alarm on internal uses
 516  if ( jQuery.swap ) {
 517      jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {
 518          var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;
 519  
 520          if ( oldHook ) {
 521              jQuery.cssHooks[ name ].get = function() {
 522                  var ret;
 523  
 524                  internalSwapCall = true;
 525                  ret = oldHook.apply( this, arguments );
 526                  internalSwapCall = false;
 527                  return ret;
 528              };
 529          }
 530      } );
 531  }
 532  
 533  migratePatchFunc( jQuery, "swap", function( elem, options, callback, args ) {
 534      var ret, name,
 535          old = {};
 536  
 537      if ( !internalSwapCall ) {
 538          migrateWarn( "swap", "jQuery.swap() is undocumented and deprecated" );
 539      }
 540  
 541      // Remember the old values, and insert the new ones
 542      for ( name in options ) {
 543          old[ name ] = elem.style[ name ];
 544          elem.style[ name ] = options[ name ];
 545      }
 546  
 547      ret = callback.apply( elem, args || [] );
 548  
 549      // Revert the old values
 550      for ( name in options ) {
 551          elem.style[ name ] = old[ name ];
 552      }
 553  
 554      return ret;
 555  }, "swap" );
 556  
 557  if ( jQueryVersionSince( "3.4.0" ) && typeof Proxy !== "undefined" ) {
 558      jQuery.cssProps = new Proxy( jQuery.cssProps || {}, {
 559          set: function() {
 560              migrateWarn( "cssProps", "jQuery.cssProps is deprecated" );
 561              return Reflect.set.apply( this, arguments );
 562          }
 563      } );
 564  }
 565  
 566  // In jQuery >=4 where jQuery.cssNumber is missing fill it with the latest 3.x version:
 567  // https://github.com/jquery/jquery/blob/3.6.0/src/css.js#L212-L233
 568  // This way, number values for the CSS properties below won't start triggering
 569  // Migrate warnings when jQuery gets updated to >=4.0.0 (gh-438).
 570  if ( jQueryVersionSince( "4.0.0" ) ) {
 571  
 572      // We need to keep this as a local variable as we need it internally
 573      // in a `jQuery.fn.css` patch and this usage shouldn't warn.
 574      internalCssNumber = {
 575          animationIterationCount: true,
 576          columnCount: true,
 577          fillOpacity: true,
 578          flexGrow: true,
 579          flexShrink: true,
 580          fontWeight: true,
 581          gridArea: true,
 582          gridColumn: true,
 583          gridColumnEnd: true,
 584          gridColumnStart: true,
 585          gridRow: true,
 586          gridRowEnd: true,
 587          gridRowStart: true,
 588          lineHeight: true,
 589          opacity: true,
 590          order: true,
 591          orphans: true,
 592          widows: true,
 593          zIndex: true,
 594          zoom: true
 595      };
 596  
 597      if ( typeof Proxy !== "undefined" ) {
 598          jQuery.cssNumber = new Proxy( internalCssNumber, {
 599              get: function() {
 600                  migrateWarn( "css-number", "jQuery.cssNumber is deprecated" );
 601                  return Reflect.get.apply( this, arguments );
 602              },
 603              set: function() {
 604                  migrateWarn( "css-number", "jQuery.cssNumber is deprecated" );
 605                  return Reflect.set.apply( this, arguments );
 606              }
 607          } );
 608      } else {
 609  
 610          // Support: IE 9-11+
 611          // IE doesn't support proxies, but we still want to restore the legacy
 612          // jQuery.cssNumber there.
 613          jQuery.cssNumber = internalCssNumber;
 614      }
 615  } else {
 616  
 617      // Make `internalCssNumber` defined for jQuery <4 as well as it's needed
 618      // in the `jQuery.fn.css` patch below.
 619      internalCssNumber = jQuery.cssNumber;
 620  }
 621  
 622  function isAutoPx( prop ) {
 623  
 624      // The first test is used to ensure that:
 625      // 1. The prop starts with a lowercase letter (as we uppercase it for the second regex).
 626      // 2. The prop is not empty.
 627      return ralphaStart.test( prop ) &&
 628          rautoPx.test( prop[ 0 ].toUpperCase() + prop.slice( 1 ) );
 629  }
 630  
 631  origFnCss = jQuery.fn.css;
 632  
 633  migratePatchFunc( jQuery.fn, "css", function( name, value ) {
 634      var camelName,
 635          origThis = this;
 636  
 637      if ( name && typeof name === "object" && !Array.isArray( name ) ) {
 638          jQuery.each( name, function( n, v ) {
 639              jQuery.fn.css.call( origThis, n, v );
 640          } );
 641          return this;
 642      }
 643  
 644      if ( typeof value === "number" ) {
 645          camelName = camelCase( name );
 646  
 647          // Use `internalCssNumber` to avoid triggering our warnings in this
 648          // internal check.
 649          if ( !isAutoPx( camelName ) && !internalCssNumber[ camelName ] ) {
 650              migrateWarn( "css-number",
 651                  "Number-typed values are deprecated for jQuery.fn.css( \"" +
 652                  name + "\", value )" );
 653          }
 654      }
 655  
 656      return origFnCss.apply( this, arguments );
 657  }, "css-number" );
 658  
 659  var origData = jQuery.data;
 660  
 661  migratePatchFunc( jQuery, "data", function( elem, name, value ) {
 662      var curData, sameKeys, key;
 663  
 664      // Name can be an object, and each entry in the object is meant to be set as data
 665      if ( name && typeof name === "object" && arguments.length === 2 ) {
 666  
 667          curData = jQuery.hasData( elem ) && origData.call( this, elem );
 668          sameKeys = {};
 669          for ( key in name ) {
 670              if ( key !== camelCase( key ) ) {
 671                  migrateWarn( "data-camelCase",
 672                      "jQuery.data() always sets/gets camelCased names: " + key );
 673                  curData[ key ] = name[ key ];
 674              } else {
 675                  sameKeys[ key ] = name[ key ];
 676              }
 677          }
 678  
 679          origData.call( this, elem, sameKeys );
 680  
 681          return name;
 682      }
 683  
 684      // If the name is transformed, look for the un-transformed name in the data object
 685      if ( name && typeof name === "string" && name !== camelCase( name ) ) {
 686  
 687          curData = jQuery.hasData( elem ) && origData.call( this, elem );
 688          if ( curData && name in curData ) {
 689              migrateWarn( "data-camelCase",
 690                  "jQuery.data() always sets/gets camelCased names: " + name );
 691              if ( arguments.length > 2 ) {
 692                  curData[ name ] = value;
 693              }
 694              return curData[ name ];
 695          }
 696      }
 697  
 698      return origData.apply( this, arguments );
 699  }, "data-camelCase" );
 700  
 701  // Support jQuery slim which excludes the effects module
 702  if ( jQuery.fx ) {
 703  
 704  var intervalValue, intervalMsg,
 705      oldTweenRun = jQuery.Tween.prototype.run,
 706      linearEasing = function( pct ) {
 707          return pct;
 708      };
 709  
 710  migratePatchFunc( jQuery.Tween.prototype, "run", function( ) {
 711      if ( jQuery.easing[ this.easing ].length > 1 ) {
 712          migrateWarn(
 713              "easing-one-arg",
 714              "'jQuery.easing." + this.easing.toString() + "' should use only one argument"
 715          );
 716  
 717          jQuery.easing[ this.easing ] = linearEasing;
 718      }
 719  
 720      oldTweenRun.apply( this, arguments );
 721  }, "easing-one-arg" );
 722  
 723  intervalValue = jQuery.fx.interval;
 724  intervalMsg = "jQuery.fx.interval is deprecated";
 725  
 726  // Support: IE9, Android <=4.4
 727  // Avoid false positives on browsers that lack rAF
 728  // Don't warn if document is hidden, jQuery uses setTimeout (#292)
 729  if ( window.requestAnimationFrame ) {
 730      Object.defineProperty( jQuery.fx, "interval", {
 731          configurable: true,
 732          enumerable: true,
 733          get: function() {
 734              if ( !window.document.hidden ) {
 735                  migrateWarn( "fx-interval", intervalMsg );
 736              }
 737  
 738              // Only fallback to the default if patch is enabled
 739              if ( !jQuery.migrateIsPatchEnabled( "fx-interval" ) ) {
 740                  return intervalValue;
 741              }
 742              return intervalValue === undefined ? 13 : intervalValue;
 743          },
 744          set: function( newValue ) {
 745              migrateWarn( "fx-interval", intervalMsg );
 746              intervalValue = newValue;
 747          }
 748      } );
 749  }
 750  
 751  }
 752  
 753  var oldLoad = jQuery.fn.load,
 754      oldEventAdd = jQuery.event.add,
 755      originalFix = jQuery.event.fix;
 756  
 757  jQuery.event.props = [];
 758  jQuery.event.fixHooks = {};
 759  
 760  migrateWarnProp( jQuery.event.props, "concat", jQuery.event.props.concat,
 761      "event-old-patch",
 762      "jQuery.event.props.concat() is deprecated and removed" );
 763  
 764  migratePatchFunc( jQuery.event, "fix", function( originalEvent ) {
 765      var event,
 766          type = originalEvent.type,
 767          fixHook = this.fixHooks[ type ],
 768          props = jQuery.event.props;
 769  
 770      if ( props.length ) {
 771          migrateWarn( "event-old-patch",
 772              "jQuery.event.props are deprecated and removed: " + props.join() );
 773          while ( props.length ) {
 774              jQuery.event.addProp( props.pop() );
 775          }
 776      }
 777  
 778      if ( fixHook && !fixHook._migrated_ ) {
 779          fixHook._migrated_ = true;
 780          migrateWarn( "event-old-patch",
 781              "jQuery.event.fixHooks are deprecated and removed: " + type );
 782          if ( ( props = fixHook.props ) && props.length ) {
 783              while ( props.length ) {
 784                  jQuery.event.addProp( props.pop() );
 785              }
 786          }
 787      }
 788  
 789      event = originalFix.call( this, originalEvent );
 790  
 791      return fixHook && fixHook.filter ?
 792          fixHook.filter( event, originalEvent ) :
 793          event;
 794  }, "event-old-patch" );
 795  
 796  migratePatchFunc( jQuery.event, "add", function( elem, types ) {
 797  
 798      // This misses the multiple-types case but that seems awfully rare
 799      if ( elem === window && types === "load" && window.document.readyState === "complete" ) {
 800          migrateWarn( "load-after-event",
 801              "jQuery(window).on('load'...) called after load event occurred" );
 802      }
 803      return oldEventAdd.apply( this, arguments );
 804  }, "load-after-event" );
 805  
 806  jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
 807  
 808      migratePatchFunc( jQuery.fn, name, function() {
 809          var args = Array.prototype.slice.call( arguments, 0 );
 810  
 811          // If this is an ajax load() the first arg should be the string URL;
 812          // technically this could also be the "Anything" arg of the event .load()
 813          // which just goes to show why this dumb signature has been deprecated!
 814          // jQuery custom builds that exclude the Ajax module justifiably die here.
 815          if ( name === "load" && typeof args[ 0 ] === "string" ) {
 816              return oldLoad.apply( this, args );
 817          }
 818  
 819          migrateWarn( "shorthand-removed-v3",
 820              "jQuery.fn." + name + "() is deprecated" );
 821  
 822          args.splice( 0, 0, name );
 823          if ( arguments.length ) {
 824              return this.on.apply( this, args );
 825          }
 826  
 827          // Use .triggerHandler here because:
 828          // - load and unload events don't need to bubble, only applied to window or image
 829          // - error event should not bubble to window, although it does pre-1.7
 830          // See http://bugs.jquery.com/ticket/11820
 831          this.triggerHandler.apply( this, args );
 832          return this;
 833      }, "shorthand-removed-v3" );
 834  
 835  } );
 836  
 837  jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
 838      "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
 839      "change select submit keydown keypress keyup contextmenu" ).split( " " ),
 840      function( _i, name ) {
 841  
 842      // Handle event binding
 843      migratePatchAndWarnFunc( jQuery.fn, name, function( data, fn ) {
 844          return arguments.length > 0 ?
 845              this.on( name, null, data, fn ) :
 846              this.trigger( name );
 847          },
 848          "shorthand-deprecated-v3",
 849          "jQuery.fn." + name + "() event shorthand is deprecated" );
 850  } );
 851  
 852  // Trigger "ready" event only once, on document ready
 853  jQuery( function() {
 854      jQuery( window.document ).triggerHandler( "ready" );
 855  } );
 856  
 857  jQuery.event.special.ready = {
 858      setup: function() {
 859          if ( this === window.document ) {
 860              migrateWarn( "ready-event", "'ready' event is deprecated" );
 861          }
 862      }
 863  };
 864  
 865  migratePatchAndWarnFunc( jQuery.fn, "bind", function( types, data, fn ) {
 866      return this.on( types, null, data, fn );
 867  }, "pre-on-methods", "jQuery.fn.bind() is deprecated" );
 868  migratePatchAndWarnFunc( jQuery.fn, "unbind", function( types, fn ) {
 869      return this.off( types, null, fn );
 870  }, "pre-on-methods", "jQuery.fn.unbind() is deprecated" );
 871  migratePatchAndWarnFunc( jQuery.fn, "delegate", function( selector, types, data, fn ) {
 872      return this.on( types, selector, data, fn );
 873  }, "pre-on-methods", "jQuery.fn.delegate() is deprecated" );
 874  migratePatchAndWarnFunc( jQuery.fn, "undelegate", function( selector, types, fn ) {
 875      return arguments.length === 1 ?
 876          this.off( selector, "**" ) :
 877          this.off( types, selector || "**", fn );
 878  }, "pre-on-methods", "jQuery.fn.undelegate() is deprecated" );
 879  migratePatchAndWarnFunc( jQuery.fn, "hover", function( fnOver, fnOut ) {
 880      return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver );
 881  }, "pre-on-methods", "jQuery.fn.hover() is deprecated" );
 882  
 883  var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi,
 884      makeMarkup = function( html ) {
 885          var doc = window.document.implementation.createHTMLDocument( "" );
 886          doc.body.innerHTML = html;
 887          return doc.body && doc.body.innerHTML;
 888      },
 889      warnIfChanged = function( html ) {
 890          var changed = html.replace( rxhtmlTag, "<$1></$2>" );
 891          if ( changed !== html && makeMarkup( html ) !== makeMarkup( changed ) ) {
 892              migrateWarn( "self-closed-tags",
 893                  "HTML tags must be properly nested and closed: " + html );
 894          }
 895      };
 896  
 897  /**
 898   * Deprecated, please use `jQuery.migrateDisablePatches( "self-closed-tags" )` instead.
 899   * @deprecated
 900   */
 901  jQuery.UNSAFE_restoreLegacyHtmlPrefilter = function() {
 902      jQuery.migrateEnablePatches( "self-closed-tags" );
 903  };
 904  
 905  migratePatchFunc( jQuery, "htmlPrefilter", function( html ) {
 906      warnIfChanged( html );
 907      return html.replace( rxhtmlTag, "<$1></$2>" );
 908  }, "self-closed-tags" );
 909  
 910  // This patch needs to be disabled by default as it re-introduces
 911  // security issues (CVE-2020-11022, CVE-2020-11023).
 912  jQuery.migrateDisablePatches( "self-closed-tags" );
 913  
 914  var origOffset = jQuery.fn.offset;
 915  
 916  migratePatchFunc( jQuery.fn, "offset", function() {
 917      var elem = this[ 0 ];
 918  
 919      if ( elem && ( !elem.nodeType || !elem.getBoundingClientRect ) ) {
 920          migrateWarn( "offset-valid-elem", "jQuery.fn.offset() requires a valid DOM element" );
 921          return arguments.length ? this : undefined;
 922      }
 923  
 924      return origOffset.apply( this, arguments );
 925  }, "offset-valid-elem" );
 926  
 927  // Support jQuery slim which excludes the ajax module
 928  // The jQuery.param patch is about respecting `jQuery.ajaxSettings.traditional`
 929  // so it doesn't make sense for the slim build.
 930  if ( jQuery.ajax ) {
 931  
 932  var origParam = jQuery.param;
 933  
 934  migratePatchFunc( jQuery, "param", function( data, traditional ) {
 935      var ajaxTraditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
 936  
 937      if ( traditional === undefined && ajaxTraditional ) {
 938  
 939          migrateWarn( "param-ajax-traditional",
 940              "jQuery.param() no longer uses jQuery.ajaxSettings.traditional" );
 941          traditional = ajaxTraditional;
 942      }
 943  
 944      return origParam.call( this, data, traditional );
 945  }, "param-ajax-traditional" );
 946  
 947  }
 948  
 949  migratePatchAndWarnFunc( jQuery.fn, "andSelf", jQuery.fn.addBack, "andSelf",
 950      "jQuery.fn.andSelf() is deprecated and removed, use jQuery.fn.addBack()" );
 951  
 952  // Support jQuery slim which excludes the deferred module in jQuery 4.0+
 953  if ( jQuery.Deferred ) {
 954  
 955  var oldDeferred = jQuery.Deferred,
 956      tuples = [
 957  
 958          // Action, add listener, callbacks, .then handlers, final state
 959          [ "resolve", "done", jQuery.Callbacks( "once memory" ),
 960              jQuery.Callbacks( "once memory" ), "resolved" ],
 961          [ "reject", "fail", jQuery.Callbacks( "once memory" ),
 962              jQuery.Callbacks( "once memory" ), "rejected" ],
 963          [ "notify", "progress", jQuery.Callbacks( "memory" ),
 964              jQuery.Callbacks( "memory" ) ]
 965      ];
 966  
 967  migratePatchFunc( jQuery, "Deferred", function( func ) {
 968      var deferred = oldDeferred(),
 969          promise = deferred.promise();
 970  
 971  	function newDeferredPipe( /* fnDone, fnFail, fnProgress */ ) {
 972          var fns = arguments;
 973  
 974          return jQuery.Deferred( function( newDefer ) {
 975              jQuery.each( tuples, function( i, tuple ) {
 976                  var fn = typeof fns[ i ] === "function" && fns[ i ];
 977  
 978                  // Deferred.done(function() { bind to newDefer or newDefer.resolve })
 979                  // deferred.fail(function() { bind to newDefer or newDefer.reject })
 980                  // deferred.progress(function() { bind to newDefer or newDefer.notify })
 981                  deferred[ tuple[ 1 ] ]( function() {
 982                      var returned = fn && fn.apply( this, arguments );
 983                      if ( returned && typeof returned.promise === "function" ) {
 984                          returned.promise()
 985                              .done( newDefer.resolve )
 986                              .fail( newDefer.reject )
 987                              .progress( newDefer.notify );
 988                      } else {
 989                          newDefer[ tuple[ 0 ] + "With" ](
 990                              this === promise ? newDefer.promise() : this,
 991                              fn ? [ returned ] : arguments
 992                          );
 993                      }
 994                  } );
 995              } );
 996              fns = null;
 997          } ).promise();
 998      }
 999  
1000      migratePatchAndWarnFunc( deferred, "pipe", newDeferredPipe, "deferred-pipe",
1001          "deferred.pipe() is deprecated" );
1002      migratePatchAndWarnFunc( promise, "pipe", newDeferredPipe, "deferred-pipe",
1003          "deferred.pipe() is deprecated" );
1004  
1005      if ( func ) {
1006          func.call( deferred, deferred );
1007      }
1008  
1009      return deferred;
1010  }, "deferred-pipe" );
1011  
1012  // Preserve handler of uncaught exceptions in promise chains
1013  jQuery.Deferred.exceptionHook = oldDeferred.exceptionHook;
1014  
1015  }
1016  
1017  return jQuery;
1018  } );


Generated : Wed May 1 08:20:02 2024 Cross-referenced by PHPXref