jquery.migration.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. /*
  17. * Repo for missing jQuery 2 functions, this ease the transition without updating every other plugin in Hue
  18. *
  19. */
  20. jQuery.uaMatch = function (ua) {
  21. ua = ua.toLowerCase();
  22. var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
  23. /(webkit)[ \/]([\w.]+)/.exec(ua) ||
  24. /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
  25. /(msie) ([\w.]+)/.exec(ua) ||
  26. ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
  27. [];
  28. return {
  29. browser: match[ 1 ] || "",
  30. version: match[ 2 ] || "0"
  31. };
  32. };
  33. // Don't clobber any existing jQuery.browser in case it's different
  34. if (!jQuery.browser) {
  35. matched = jQuery.uaMatch(navigator.userAgent);
  36. browser = {};
  37. if (matched.browser) {
  38. browser[ matched.browser ] = true;
  39. browser.version = matched.version;
  40. }
  41. // Chrome is Webkit, but Webkit is also Safari.
  42. if (browser.chrome) {
  43. browser.webkit = true;
  44. } else if (browser.webkit) {
  45. browser.safari = true;
  46. }
  47. jQuery.browser = browser;
  48. }
  49. // Since jQuery.clean is used internally on older versions, we only shim if it's missing
  50. if (!jQuery.clean) {
  51. jQuery.clean = function (elems, context, fragment, scripts) {
  52. // Set context per 1.8 logic
  53. context = context || document;
  54. context = !context.nodeType && context[0] || context;
  55. context = context.ownerDocument || context;
  56. var i, elem, handleScript, jsTags,
  57. ret = [];
  58. jQuery.merge(ret, jQuery.buildFragment(elems, context).childNodes);
  59. // Complex logic lifted directly from jQuery 1.8
  60. if (fragment) {
  61. // Special handling of each script element
  62. handleScript = function (elem) {
  63. // Check if we consider it executable
  64. if (!elem.type || rscriptType.test(elem.type)) {
  65. // Detach the script and store it in the scripts array (if provided) or the fragment
  66. // Return truthy to indicate that it has been handled
  67. return scripts ?
  68. scripts.push(elem.parentNode ? elem.parentNode.removeChild(elem) : elem) :
  69. fragment.appendChild(elem);
  70. }
  71. };
  72. for (i = 0; (elem = ret[i]) != null; i++) {
  73. // Check if we're done after handling an executable script
  74. if (!( jQuery.nodeName(elem, "script") && handleScript(elem) )) {
  75. // Append to fragment and handle embedded scripts
  76. fragment.appendChild(elem);
  77. if (typeof elem.getElementsByTagName !== "undefined") {
  78. // handleScript alters the DOM, so use jQuery.merge to ensure snapshot iteration
  79. jsTags = jQuery.grep(jQuery.merge([], elem.getElementsByTagName("script")), handleScript);
  80. // Splice the scripts into ret after their former ancestor and advance our index beyond them
  81. ret.splice.apply(ret, [i + 1, 0].concat(jsTags));
  82. i += jsTags.length;
  83. }
  84. }
  85. }
  86. }
  87. return ret;
  88. };
  89. }
  90. var rscriptType = /\/(java|ecma)script/i,
  91. oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack;
  92. jQuery.fn.andSelf = function () {
  93. return oldSelf.apply(this, arguments);
  94. };