inputmask.dependencyLib.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*!
  2. * dependencyLibs/inputmask.dependencyLib.js
  3. * https://github.com/RobinHerbots/Inputmask
  4. * Copyright (c) 2010 - 2017 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 3.3.11
  7. */
  8. !function(factory) {
  9. "function" == typeof define && define.amd ? define([ "../global/window", "../global/document" ], factory) : "object" == typeof exports ? module.exports = factory(require("../global/window"), require("../global/document")) : window.dependencyLib = factory(window, document);
  10. }(function(window, document) {
  11. function indexOf(list, elem) {
  12. for (var i = 0, len = list.length; i < len; i++) if (list[i] === elem) return i;
  13. return -1;
  14. }
  15. function type(obj) {
  16. return null == obj ? obj + "" : "object" == typeof obj || "function" == typeof obj ? class2type[class2type.toString.call(obj)] || "object" : typeof obj;
  17. }
  18. function isWindow(obj) {
  19. return null != obj && obj === obj.window;
  20. }
  21. function isArraylike(obj) {
  22. var length = "length" in obj && obj.length, ltype = type(obj);
  23. return "function" !== ltype && !isWindow(obj) && (!(1 !== obj.nodeType || !length) || ("array" === ltype || 0 === length || "number" == typeof length && length > 0 && length - 1 in obj));
  24. }
  25. function isValidElement(elem) {
  26. return elem instanceof Element;
  27. }
  28. function DependencyLib(elem) {
  29. return elem instanceof DependencyLib ? elem : this instanceof DependencyLib ? void (void 0 !== elem && null !== elem && elem !== window && (this[0] = elem.nodeName ? elem : void 0 !== elem[0] && elem[0].nodeName ? elem[0] : document.querySelector(elem),
  30. void 0 !== this[0] && null !== this[0] && (this[0].eventRegistry = this[0].eventRegistry || {}))) : new DependencyLib(elem);
  31. }
  32. for (var class2type = {}, classTypes = "Boolean Number String Function Array Date RegExp Object Error".split(" "), nameNdx = 0; nameNdx < classTypes.length; nameNdx++) class2type["[object " + classTypes[nameNdx] + "]"] = classTypes[nameNdx].toLowerCase();
  33. return DependencyLib.prototype = {
  34. on: function(events, handler) {
  35. if (isValidElement(this[0])) for (var eventRegistry = this[0].eventRegistry, elem = this[0], _events = events.split(" "), endx = 0; endx < _events.length; endx++) {
  36. var nsEvent = _events[endx].split(".");
  37. !function(ev, namespace) {
  38. elem.addEventListener ? elem.addEventListener(ev, handler, !1) : elem.attachEvent && elem.attachEvent("on" + ev, handler),
  39. eventRegistry[ev] = eventRegistry[ev] || {}, eventRegistry[ev][namespace] = eventRegistry[ev][namespace] || [],
  40. eventRegistry[ev][namespace].push(handler);
  41. }(nsEvent[0], nsEvent[1] || "global");
  42. }
  43. return this;
  44. },
  45. off: function(events, handler) {
  46. if (isValidElement(this[0])) for (var eventRegistry = this[0].eventRegistry, elem = this[0], _events = events.split(" "), endx = 0; endx < _events.length; endx++) for (var nsEvent = _events[endx].split("."), offEvents = function(ev, namespace) {
  47. var hndx, hndL, evts = [];
  48. if (ev.length > 0) if (void 0 === handler) for (hndx = 0, hndL = eventRegistry[ev][namespace].length; hndx < hndL; hndx++) evts.push({
  49. ev: ev,
  50. namespace: namespace && namespace.length > 0 ? namespace : "global",
  51. handler: eventRegistry[ev][namespace][hndx]
  52. }); else evts.push({
  53. ev: ev,
  54. namespace: namespace && namespace.length > 0 ? namespace : "global",
  55. handler: handler
  56. }); else if (namespace.length > 0) for (var evNdx in eventRegistry) for (var nmsp in eventRegistry[evNdx]) if (nmsp === namespace) if (void 0 === handler) for (hndx = 0,
  57. hndL = eventRegistry[evNdx][nmsp].length; hndx < hndL; hndx++) evts.push({
  58. ev: evNdx,
  59. namespace: nmsp,
  60. handler: eventRegistry[evNdx][nmsp][hndx]
  61. }); else evts.push({
  62. ev: evNdx,
  63. namespace: nmsp,
  64. handler: handler
  65. });
  66. return evts;
  67. }(nsEvent[0], nsEvent[1]), i = 0, offEventsL = offEvents.length; i < offEventsL; i++) !function(ev, namespace, handler) {
  68. if (ev in eventRegistry == 1) if (elem.removeEventListener ? elem.removeEventListener(ev, handler, !1) : elem.detachEvent && elem.detachEvent("on" + ev, handler),
  69. "global" === namespace) for (var nmsp in eventRegistry[ev]) eventRegistry[ev][nmsp].splice(eventRegistry[ev][nmsp].indexOf(handler), 1); else eventRegistry[ev][namespace].splice(eventRegistry[ev][namespace].indexOf(handler), 1);
  70. }(offEvents[i].ev, offEvents[i].namespace, offEvents[i].handler);
  71. return this;
  72. },
  73. trigger: function(events) {
  74. if (isValidElement(this[0])) for (var eventRegistry = this[0].eventRegistry, elem = this[0], _events = "string" == typeof events ? events.split(" ") : [ events.type ], endx = 0; endx < _events.length; endx++) {
  75. var nsEvent = _events[endx].split("."), ev = nsEvent[0], namespace = nsEvent[1] || "global";
  76. if (void 0 !== document && "global" === namespace) {
  77. var evnt, i, params = {
  78. bubbles: !0,
  79. cancelable: !0,
  80. detail: Array.prototype.slice.call(arguments, 1)
  81. };
  82. if (document.createEvent) {
  83. try {
  84. evnt = new CustomEvent(ev, params);
  85. } catch (e) {
  86. (evnt = document.createEvent("CustomEvent")).initCustomEvent(ev, params.bubbles, params.cancelable, params.detail);
  87. }
  88. events.type && DependencyLib.extend(evnt, events), elem.dispatchEvent(evnt);
  89. } else (evnt = document.createEventObject()).eventType = ev, events.type && DependencyLib.extend(evnt, events),
  90. elem.fireEvent("on" + evnt.eventType, evnt);
  91. } else if (void 0 !== eventRegistry[ev]) if (arguments[0] = arguments[0].type ? arguments[0] : DependencyLib.Event(arguments[0]),
  92. "global" === namespace) for (var nmsp in eventRegistry[ev]) for (i = 0; i < eventRegistry[ev][nmsp].length; i++) eventRegistry[ev][nmsp][i].apply(elem, arguments); else for (i = 0; i < eventRegistry[ev][namespace].length; i++) eventRegistry[ev][namespace][i].apply(elem, arguments);
  93. }
  94. return this;
  95. }
  96. }, DependencyLib.isFunction = function(obj) {
  97. return "function" === type(obj);
  98. }, DependencyLib.noop = function() {}, DependencyLib.isArray = Array.isArray, DependencyLib.inArray = function(elem, arr, i) {
  99. return null == arr ? -1 : indexOf(arr, elem);
  100. }, DependencyLib.valHooks = void 0, DependencyLib.isPlainObject = function(obj) {
  101. return "object" === type(obj) && !obj.nodeType && !isWindow(obj) && !(obj.constructor && !class2type.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf"));
  102. }, DependencyLib.extend = function() {
  103. var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {}, i = 1, length = arguments.length, deep = !1;
  104. for ("boolean" == typeof target && (deep = target, target = arguments[i] || {},
  105. i++), "object" == typeof target || DependencyLib.isFunction(target) || (target = {}),
  106. i === length && (target = this, i--); i < length; i++) if (null != (options = arguments[i])) for (name in options) src = target[name],
  107. target !== (copy = options[name]) && (deep && copy && (DependencyLib.isPlainObject(copy) || (copyIsArray = DependencyLib.isArray(copy))) ? (copyIsArray ? (copyIsArray = !1,
  108. clone = src && DependencyLib.isArray(src) ? src : []) : clone = src && DependencyLib.isPlainObject(src) ? src : {},
  109. target[name] = DependencyLib.extend(deep, clone, copy)) : void 0 !== copy && (target[name] = copy));
  110. return target;
  111. }, DependencyLib.each = function(obj, callback) {
  112. var i = 0;
  113. if (isArraylike(obj)) for (var length = obj.length; i < length && !1 !== callback.call(obj[i], i, obj[i]); i++) ; else for (i in obj) if (!1 === callback.call(obj[i], i, obj[i])) break;
  114. return obj;
  115. }, DependencyLib.map = function(elems, callback) {
  116. var value, i = 0, length = elems.length, ret = [];
  117. if (isArraylike(elems)) for (;i < length; i++) null != (value = callback(elems[i], i)) && ret.push(value); else for (i in elems) null != (value = callback(elems[i], i)) && ret.push(value);
  118. return [].concat(ret);
  119. }, DependencyLib.data = function(owner, key, value) {
  120. if (void 0 === value) return owner.__data ? owner.__data[key] : null;
  121. owner.__data = owner.__data || {}, owner.__data[key] = value;
  122. }, "function" == typeof window.CustomEvent ? DependencyLib.Event = window.CustomEvent : (DependencyLib.Event = function(event, params) {
  123. params = params || {
  124. bubbles: !1,
  125. cancelable: !1,
  126. detail: void 0
  127. };
  128. var evt = document.createEvent("CustomEvent");
  129. return evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail),
  130. evt;
  131. }, DependencyLib.Event.prototype = window.Event.prototype), DependencyLib;
  132. });