inputmask.dependencyLib.jqlite.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. Input Mask plugin dependencyLib
  3. http://github.com/RobinHerbots/jquery.inputmask
  4. Copyright (c) 2010 - Robin Herbots
  5. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. */
  7. (function (factory) {
  8. if (typeof define === "function" && define.amd) {
  9. define(["jqlite", "../global/window", "../global/document"], factory);
  10. } else if (typeof exports === "object") {
  11. module.exports = factory(require("jqlite"), require("../global/window"), require("../global/document"));
  12. } else {
  13. window.dependencyLib = factory(jqlite, window, document);
  14. }
  15. }
  16. (function ($, window, document) {
  17. // Use a stripped-down indexOf as it's faster than native
  18. // http://jsperf.com/thor-indexof-vs-for/5
  19. function indexOf(list, elem) {
  20. var i = 0,
  21. len = list.length;
  22. for (; i < len; i++) {
  23. if (list[i] === elem) {
  24. return i;
  25. }
  26. }
  27. return -1;
  28. }
  29. function isWindow(obj) {
  30. return obj != null && obj === obj.window;
  31. }
  32. function isArraylike(obj) {
  33. // Support: iOS 8.2 (not reproducible in simulator)
  34. // `in` check used to prevent JIT error (gh-2145)
  35. // hasOwn isn't used here due to false negatives
  36. // regarding Nodelist length in IE
  37. var length = "length" in obj && obj.length,
  38. ltype = typeof obj;
  39. if (ltype === "function" || isWindow(obj)) {
  40. return false;
  41. }
  42. if (obj.nodeType === 1 && length) {
  43. return true;
  44. }
  45. return ltype === "array" || length === 0 ||
  46. typeof length === "number" && length > 0 && (length - 1) in obj;
  47. }
  48. $.inArray = function (elem, arr, i) {
  49. return arr == null ? -1 : indexOf(arr, elem, i);
  50. };
  51. $.isFunction = function (obj) {
  52. return typeof obj === "function";
  53. };
  54. $.isArray = Array.isArray;
  55. $.isPlainObject = function (obj) {
  56. // Not plain objects:
  57. // - Any object or value whose internal [[Class]] property is not "[object Object]"
  58. // - DOM nodes
  59. // - window
  60. if (typeof obj !== "object" || obj.nodeType || isWindow(obj)) {
  61. return false;
  62. }
  63. if (obj.constructor && !Object.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf")) {
  64. return false;
  65. }
  66. // If the function hasn't returned already, we're confident that
  67. // |obj| is a plain object, created by {} or constructed with new Object
  68. return true;
  69. };
  70. $.extend = function () {
  71. var options, name, src, copy, copyIsArray, clone,
  72. target = arguments[0] || {},
  73. i = 1,
  74. length = arguments.length,
  75. deep = false;
  76. // Handle a deep copy situation
  77. if (typeof target === "boolean") {
  78. deep = target;
  79. // Skip the boolean and the target
  80. target = arguments[i] || {};
  81. i++;
  82. }
  83. // Handle case when target is a string or something (possible in deep copy)
  84. if (typeof target !== "object" && !$.isFunction(target)) {
  85. target = {};
  86. }
  87. // Extend jQuery itself if only one argument is passed
  88. if (i === length) {
  89. target = this;
  90. i--;
  91. }
  92. for (; i < length; i++) {
  93. // Only deal with non-null/undefined values
  94. if ((options = arguments[i]) != null) {
  95. // Extend the base object
  96. for (name in options) {
  97. src = target[name];
  98. copy = options[name];
  99. // Prevent never-ending loop
  100. if (target === copy) {
  101. continue;
  102. }
  103. // Recurse if we're merging plain objects or arrays
  104. if (deep && copy && ($.isPlainObject(copy) || (copyIsArray = $.isArray(copy)))) {
  105. if (copyIsArray) {
  106. copyIsArray = false;
  107. clone = src && $.isArray(src) ? src : [];
  108. } else {
  109. clone = src && $.isPlainObject(src) ? src : {};
  110. }
  111. // Never move original objects, clone them
  112. target[name] = $.extend(deep, clone, copy);
  113. // Don't bring in undefined values
  114. } else if (copy !== undefined) {
  115. target[name] = copy;
  116. }
  117. }
  118. }
  119. }
  120. // Return the modified object
  121. return target;
  122. };
  123. $.each = function (obj, callback) {
  124. var value, i = 0;
  125. if (isArraylike(obj)) {
  126. for (var length = obj.length; i < length; i++) {
  127. value = callback.call(obj[i], i, obj[i]);
  128. if (value === false) {
  129. break;
  130. }
  131. }
  132. } else {
  133. for (i in obj) {
  134. value = callback.call(obj[i], i, obj[i]);
  135. if (value === false) {
  136. break;
  137. }
  138. }
  139. }
  140. return obj;
  141. };
  142. $.data = function (elem, name, data) {
  143. return $(elem).data(name, data);
  144. };
  145. $.Event = $.Event || function CustomEvent(event, params) {
  146. params = params || {
  147. bubbles: false,
  148. cancelable: false,
  149. detail: undefined
  150. };
  151. var evt = document.createEvent("CustomEvent");
  152. evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
  153. return evt;
  154. };
  155. $.Event.prototype = window.Event.prototype;
  156. return $;
  157. }));