MCPcopy Create free account
hub / github.com/ampproject/amphtml / factory

Function factory

third_party/inputmask/inputmask.dependencyLib.js:9–292  ·  view source on GitHub ↗
(window, document)

Source from the content-addressed store, hash-verified

7*/
8
9export function factory(window, document) {
10 function indexOf(list, elem) {
11 var i = 0, len = list.length;
12 for (;i < len; i++) {
13 if (list[i] === elem) {
14 return i;
15 }
16 }
17 return -1;
18 }
19 function isWindow(obj) {
20 return obj != null && obj === obj.window;
21 }
22 function isArraylike(obj) {
23 var length = "length" in obj && obj.length, ltype = typeof obj;
24 if (ltype === "function" || isWindow(obj)) {
25 return false;
26 }
27 if (obj.nodeType === 1 && length) {
28 return true;
29 }
30 return ltype === "array" || length === 0 || typeof length === "number" && length > 0 && length - 1 in obj;
31 }
32 function isValidElement(elem) {
33 return elem instanceof window.Element;
34 }
35 function DependencyLib(elem) {
36 if (elem instanceof DependencyLib) {
37 return elem;
38 }
39 if (!(this instanceof DependencyLib)) {
40 return new DependencyLib(elem);
41 }
42 if (elem !== undefined && elem !== null && elem !== window) {
43 this[0] = elem.nodeName ? elem : elem[0] !== undefined && elem[0].nodeName ? elem[0] : document.querySelector(elem);
44 if (this[0] !== undefined && this[0] !== null) {
45 this[0].eventRegistry = this[0].eventRegistry || {};
46 }
47 }
48 }
49 function getWindow(elem) {
50 return isWindow(elem) ? elem : elem.nodeType === 9 ? elem.defaultView || elem.parentWindow : false;
51 }
52 DependencyLib.prototype = {
53 on: function(events, handler) {
54 if (isValidElement(this[0])) {
55 var eventRegistry = this[0].eventRegistry, elem = this[0];
56 function addEvent(ev, namespace) {
57 if (elem.addEventListener) {
58 elem.addEventListener(ev, handler, false);
59 } else if (elem.attachEvent) {
60 elem.attachEvent("on" + ev, handler);
61 }
62 eventRegistry[ev] = eventRegistry[ev] || {};
63 eventRegistry[ev][namespace] = eventRegistry[ev][namespace] || [];
64 eventRegistry[ev][namespace].push(handler);
65 }
66 var _events = events.split(" ");

Callers

nothing calls this directly

Calls 9

isValidElementFunction · 0.85
addEventFunction · 0.85
resolveNamespaceFunction · 0.85
removeEventFunction · 0.85
isWindowFunction · 0.85
isArraylikeFunction · 0.85
fireEventMethod · 0.80
applyMethod · 0.80
indexOfFunction · 0.70

Tested by

no test coverage detected