forked from aminin/jquery-emojiarea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dom.js
52 lines (45 loc) · 1.36 KB
/
dom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], function () {
return (root.dom = factory());
});
} else if (typeof module === 'object' && module.exports) {
module.exports = (root.dom = factory());
} else {
root.dom = factory();
}
})(this, function() {
function addEventListener(node, events, callback) {
if (events.constructor !== Array)
events = [events];
events.forEach(function(event) {
node.addEventListener(event, callback);
});
}
function dispatchEvent(node, type) {
var event = document.createEvent('HTMLEvents');
event.initEvent(type, true, false);
node.dispatchEvent(event);
}
function appendChildren(node, children) {
if (children.constructor !== Array) {
children = [children];
}
children.forEach(function(child) {
node.appendChild(child);
});
}
function isTextNode(node) {
return node instanceof Text;
}
function isImageNode(node) {
return node instanceof HTMLImageElement;
}
return {
addEventListener: addEventListener,
dispatchEvent: dispatchEvent,
appendChildren: appendChildren,
isTextNode: isTextNode,
isImageNode: isImageNode
};
});