forked from ibm-js/delite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeatures.js
85 lines (75 loc) · 2.88 KB
/
features.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
define(["requirejs-dplugins/has"], function (has) {
// Flag for whether to create background iframe behind popups like Menus and Dialog.
// A background iframe is useful to prevent problems with popups appearing behind applets/pdf files.
has.add("config-bgIframe", false);
// Flag to enable advanced bidi support
has.add("bidi", false);
// Flag to enable inheritance direction from any ancestor
has.add("inherited-dir", false);
if (typeof window !== "undefined") {
// Returns the name of the method to test if an element matches a CSS selector.
has.add("dom-matches", function () {
var node = document.body;
if (node.matches) {
return "matches";
}
if (node.webkitMatchesSelector) {
return "webkitMatchesSelector";
}
if (node.mozMatchesSelector) {
return "mozMatchesSelector";
}
if (node.msMatchesSelector) {
return "msMatchesSelector";
}
});
// Does platform have native support for document.registerElement() or a polyfill to simulate it?
has.add("document-register-element", !!document.registerElement);
// Test for how to monitor DOM nodes being inserted and removed from the document.
// For DOMNodeInserted events, there are two variations:
// "root" - just notified about the root of each tree added to the document
// "all" - notified about all nodes added to the document
has.add("MutationObserver", window.MutationObserver ? "MutationObserver" : window.WebKitMutationObserver ?
"WebKitMutationObserver" : "");
has.add("DOMNodeInserted", function () {
var root = document.createElement("div"),
child = document.createElement("div"),
sawRoot, sawChild;
root.id = "root";
child.id = "child";
root.appendChild(child);
function listener(event) {
if (event.target.id === "root") {
sawRoot = true;
}
if (event.target.id === "child") {
sawChild = true;
}
}
document.body.addEventListener("DOMNodeInserted", listener);
document.body.appendChild(root);
document.body.removeChild(root);
document.body.removeEventListener("DOMNodeInserted", listener);
return sawChild ? "all" : sawRoot ? "root" : "";
});
// Can we use __proto__ to reset the prototype of DOMNodes?
// It's not available on IE<11, and even on IE11 it makes the node's attributes
// (ex: node.attributes, node.textContent) disappear, so disabling it on IE11 too.
has.add("dom-proto-set", function () {
var node = document.createElement("div");
/* jshint camelcase: false */
/* jshint proto: true */
if (!node.__proto__) {
return false;
}
node.__proto__ = {};
/* jshint camelcase: true */
/* jshint proto: false */
return !!node.attributes;
});
// Support for <template> elements (specifically, that their content is available via templateNode.content
// rather than templateNode.children[] etc.
has.add("dom-template", !!document.createElement("template").content);
}
return has;
});