inputmask.dependencyLib.jqlite.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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"], factory);
  10. } else if (typeof exports === "object") {
  11. module.exports = factory(require("jqlite"));
  12. } else {
  13. factory(jQuery);
  14. }
  15. }
  16. (function ($) {
  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. var class2type = {},
  30. classTypes = "Boolean Number String Function Array Date RegExp Object Error".split(" ");
  31. for (var nameNdx = 0; nameNdx < classTypes.length; nameNdx++) {
  32. class2type["[object " + classTypes[nameNdx] + "]"] = classTypes[nameNdx].toLowerCase();
  33. }
  34. function type(obj) {
  35. if (obj == null) {
  36. return obj + "";
  37. }
  38. // Support: Android<4.0, iOS<6 (functionish RegExp)
  39. return typeof obj === "object" || typeof obj === "function" ?
  40. class2type[class2type.toString.call(obj)] || "object" :
  41. typeof obj;
  42. }
  43. function isWindow(obj) {
  44. return obj != null && obj === obj.window;
  45. }
  46. function isArraylike(obj) {
  47. // Support: iOS 8.2 (not reproducible in simulator)
  48. // `in` check used to prevent JIT error (gh-2145)
  49. // hasOwn isn't used here due to false negatives
  50. // regarding Nodelist length in IE
  51. var length = "length" in obj && obj.length,
  52. ltype = type(obj);
  53. if (ltype === "function" || isWindow(obj)) {
  54. return false;
  55. }
  56. if (obj.nodeType === 1 && length) {
  57. return true;
  58. }
  59. return ltype === "array" || length === 0 ||
  60. typeof length === "number" && length > 0 && (length - 1) in obj;
  61. }
  62. $.inArray = function (elem, arr, i) {
  63. return arr == null ? -1 : indexOf(arr, elem, i);
  64. };
  65. $.isFunction = function (obj) {
  66. return type(obj) === "function";
  67. };
  68. $.isArray = Array.isArray;
  69. $.isPlainObject = function (obj) {
  70. // Not plain objects:
  71. // - Any object or value whose internal [[Class]] property is not "[object Object]"
  72. // - DOM nodes
  73. // - window
  74. if (type(obj) !== "object" || obj.nodeType || isWindow(obj)) {
  75. return false;
  76. }
  77. if (obj.constructor && !class2type.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf")) {
  78. return false;
  79. }
  80. // If the function hasn't returned already, we're confident that
  81. // |obj| is a plain object, created by {} or constructed with new Object
  82. return true;
  83. };
  84. $.extend = function () {
  85. var options, name, src, copy, copyIsArray, clone,
  86. target = arguments[0] || {},
  87. i = 1,
  88. length = arguments.length,
  89. deep = false;
  90. // Handle a deep copy situation
  91. if (typeof target === "boolean") {
  92. deep = target;
  93. // Skip the boolean and the target
  94. target = arguments[i] || {};
  95. i++;
  96. }
  97. // Handle case when target is a string or something (possible in deep copy)
  98. if (typeof target !== "object" && !$.isFunction(target)) {
  99. target = {};
  100. }
  101. // Extend jQuery itself if only one argument is passed
  102. if (i === length) {
  103. target = this;
  104. i--;
  105. }
  106. for (; i < length; i++) {
  107. // Only deal with non-null/undefined values
  108. if ((options = arguments[i]) != null) {
  109. // Extend the base object
  110. for (name in options) {
  111. src = target[name];
  112. copy = options[name];
  113. // Prevent never-ending loop
  114. if (target === copy) {
  115. continue;
  116. }
  117. // Recurse if we're merging plain objects or arrays
  118. if (deep && copy && ($.isPlainObject(copy) || (copyIsArray = $.isArray(copy)))) {
  119. if (copyIsArray) {
  120. copyIsArray = false;
  121. clone = src && $.isArray(src) ? src : [];
  122. } else {
  123. clone = src && $.isPlainObject(src) ? src : {};
  124. }
  125. // Never move original objects, clone them
  126. target[name] = $.extend(deep, clone, copy);
  127. // Don't bring in undefined values
  128. } else if (copy !== undefined) {
  129. target[name] = copy;
  130. }
  131. }
  132. }
  133. }
  134. // Return the modified object
  135. return target;
  136. };
  137. $.each = function (obj, callback) {
  138. var value, i = 0;
  139. if (isArraylike(obj)) {
  140. for (var length = obj.length; i < length; i++) {
  141. value = callback.call(obj[i], i, obj[i]);
  142. if (value === false) {
  143. break;
  144. }
  145. }
  146. } else {
  147. for (i in obj) {
  148. value = callback.call(obj[i], i, obj[i]);
  149. if (value === false) {
  150. break;
  151. }
  152. }
  153. }
  154. return obj;
  155. };
  156. $.map = function (elems, callback) {
  157. var value,
  158. i = 0,
  159. length = elems.length,
  160. isArray = isArraylike(elems),
  161. ret = [];
  162. // Go through the array, translating each of the items to their new values
  163. if (isArray) {
  164. for (; i < length; i++) {
  165. value = callback(elems[i], i);
  166. if (value != null) {
  167. ret.push(value);
  168. }
  169. }
  170. // Go through every key on the object,
  171. } else {
  172. for (i in elems) {
  173. value = callback(elems[i], i);
  174. if (value != null) {
  175. ret.push(value);
  176. }
  177. }
  178. }
  179. // Flatten any nested arrays
  180. return [].concat(ret);
  181. };
  182. $.data = function (elem, name, data) {
  183. return $(elem).data(name, data);
  184. };
  185. $.Event = $.Event || function CustomEvent(event, params) {
  186. params = params || {
  187. bubbles: false,
  188. cancelable: false,
  189. detail: undefined
  190. };
  191. var evt = document.createEvent("CustomEvent");
  192. evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
  193. return evt;
  194. };
  195. $.Event.prototype = window.Event.prototype;
  196. window.dependencyLib = $;
  197. return $;
  198. }));