forked from googlearchive/ShadowDOM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Element.js
68 lines (54 loc) · 2.08 KB
/
Element.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
// Copyright 2013 The Toolkitchen Authors. All rights reserved.
// Use of this source code is goverened by a BSD-style
// license that can be found in the LICENSE file.
(function(scope) {
'use strict';
var ChildNodeInterface = scope.ChildNodeInterface;
var GetElementsByInterface = scope.GetElementsByInterface;
var Node = scope.wrappers.Node;
var ParentNodeInterface = scope.ParentNodeInterface;
var SelectorsInterface = scope.SelectorsInterface;
var addWrapNodeListMethod = scope.addWrapNodeListMethod;
var mixin = scope.mixin;
var registerWrapper = scope.registerWrapper;
var wrappers = scope.wrappers;
var shadowRootTable = new SideTable();
var OriginalElement = window.Element;
var originalMatches =
OriginalElement.prototype.matches ||
OriginalElement.prototype.mozMatchesSelector ||
OriginalElement.prototype.msMatchesSelector ||
OriginalElement.prototype.webkitMatchesSelector;
function Element(node) {
Node.call(this, node);
}
Element.prototype = Object.create(Node.prototype);
mixin(Element.prototype, {
createShadowRoot: function() {
var newShadowRoot = new wrappers.ShadowRoot(this);
shadowRootTable.set(this, newShadowRoot);
scope.getRendererForHost(this);
this.invalidateShadowRenderer(true);
return newShadowRoot;
},
get shadowRoot() {
return shadowRootTable.get(this) || null;
},
setAttribute: function(name, value) {
this.impl.setAttribute(name, value);
// This is a bit agressive. We need to invalidate if it affects
// the rendering content[select] or if it effects the value of a content
// select.
this.invalidateShadowRenderer();
},
matches: function(selector) {
return originalMatches.call(this.impl, selector);
}
});
mixin(Element.prototype, ChildNodeInterface);
mixin(Element.prototype, GetElementsByInterface);
mixin(Element.prototype, ParentNodeInterface);
mixin(Element.prototype, SelectorsInterface);
registerWrapper(OriginalElement, Element);
scope.wrappers.Element = Element;
})(this.ShadowDOMPolyfill);