polymer-rails 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/polymer/polymer-micro.html +528 -21
- data/app/assets/javascripts/polymer/polymer-mini.html +1304 -27
- data/app/assets/javascripts/polymer/polymer.html +3771 -51
- data/app/assets/javascripts/webcomponentsjs/webcomponents-lite.js +44 -14
- data/app/assets/javascripts/webcomponentsjs/webcomponents.js +7106 -0
- data/lib/polymer-rails/version.rb +1 -1
- metadata +4 -64
- data/app/assets/javascripts/polymer/src/lib/annotations/annotations.html +0 -262
- data/app/assets/javascripts/polymer/src/lib/annotations/demo/app-chrome.html +0 -60
- data/app/assets/javascripts/polymer/src/lib/array-observe.html +0 -118
- data/app/assets/javascripts/polymer/src/lib/array-splice.html +0 -262
- data/app/assets/javascripts/polymer/src/lib/async.html +0 -68
- data/app/assets/javascripts/polymer/src/lib/base.html +0 -117
- data/app/assets/javascripts/polymer/src/lib/bind/accessors.html +0 -223
- data/app/assets/javascripts/polymer/src/lib/bind/demo/app-chrome.html +0 -28
- data/app/assets/javascripts/polymer/src/lib/bind/demo/app.html +0 -29
- data/app/assets/javascripts/polymer/src/lib/bind/demo/src/annotations-bind-demo.html +0 -76
- data/app/assets/javascripts/polymer/src/lib/bind/demo/src/bind-demo.html +0 -83
- data/app/assets/javascripts/polymer/src/lib/bind/effects.html +0 -80
- data/app/assets/javascripts/polymer/src/lib/case-map.html +0 -46
- data/app/assets/javascripts/polymer/src/lib/collection.html +0 -179
- data/app/assets/javascripts/polymer/src/lib/css-parse.html +0 -131
- data/app/assets/javascripts/polymer/src/lib/debounce.html +0 -69
- data/app/assets/javascripts/polymer/src/lib/dom-api.html +0 -467
- data/app/assets/javascripts/polymer/src/lib/dom-module.html +0 -68
- data/app/assets/javascripts/polymer/src/lib/event-api.html +0 -92
- data/app/assets/javascripts/polymer/src/lib/expr/focus.html +0 -22
- data/app/assets/javascripts/polymer/src/lib/expr/gestures.html +0 -1
- data/app/assets/javascripts/polymer/src/lib/expr/log.html +0 -21
- data/app/assets/javascripts/polymer/src/lib/expr/sinspect.html +0 -235
- data/app/assets/javascripts/polymer/src/lib/expr/style-auditor.html +0 -123
- data/app/assets/javascripts/polymer/src/lib/expr/style-protector.html +0 -52
- data/app/assets/javascripts/polymer/src/lib/gestures.html +0 -284
- data/app/assets/javascripts/polymer/src/lib/lang.html +0 -21
- data/app/assets/javascripts/polymer/src/lib/module.html +0 -56
- data/app/assets/javascripts/polymer/src/lib/polymer-bootstrap.html +0 -78
- data/app/assets/javascripts/polymer/src/lib/resolve-url.html +0 -82
- data/app/assets/javascripts/polymer/src/lib/settings.html +0 -52
- data/app/assets/javascripts/polymer/src/lib/style-defaults.html +0 -32
- data/app/assets/javascripts/polymer/src/lib/style-transformer.html +0 -185
- data/app/assets/javascripts/polymer/src/lib/style-util.html +0 -77
- data/app/assets/javascripts/polymer/src/lib/template/templatizer.html +0 -132
- data/app/assets/javascripts/polymer/src/lib/template/x-array-selector.html +0 -178
- data/app/assets/javascripts/polymer/src/lib/template/x-autobind.html +0 -80
- data/app/assets/javascripts/polymer/src/lib/template/x-if.html +0 -115
- data/app/assets/javascripts/polymer/src/lib/template/x-repeat.html +0 -510
- data/app/assets/javascripts/polymer/src/lib/template/x-template.html +0 -39
- data/app/assets/javascripts/polymer/src/lib/x-style.html +0 -115
- data/app/assets/javascripts/polymer/src/micro/attributes.html +0 -180
- data/app/assets/javascripts/polymer/src/micro/constructor.html +0 -74
- data/app/assets/javascripts/polymer/src/micro/extends.html +0 -79
- data/app/assets/javascripts/polymer/src/micro/mixins.html +0 -40
- data/app/assets/javascripts/polymer/src/micro/properties.html +0 -96
- data/app/assets/javascripts/polymer/src/micro/tag.html +0 -28
- data/app/assets/javascripts/polymer/src/mini/ready.html +0 -180
- data/app/assets/javascripts/polymer/src/mini/shadow.html +0 -41
- data/app/assets/javascripts/polymer/src/mini/shady.html +0 -365
- data/app/assets/javascripts/polymer/src/mini/template.html +0 -56
- data/app/assets/javascripts/polymer/src/polymer-lib.html +0 -15
- data/app/assets/javascripts/polymer/src/standard/annotations.html +0 -198
- data/app/assets/javascripts/polymer/src/standard/configure.html +0 -160
- data/app/assets/javascripts/polymer/src/standard/effects.html +0 -215
- data/app/assets/javascripts/polymer/src/standard/events.html +0 -127
- data/app/assets/javascripts/polymer/src/standard/notify-path.html +0 -260
- data/app/assets/javascripts/polymer/src/standard/resolveUrl.html +0 -27
- data/app/assets/javascripts/polymer/src/standard/styling.html +0 -157
- data/app/assets/javascripts/polymer/src/standard/utils.html +0 -158
- data/app/assets/javascripts/polymer/src/standard/x-styling.html +0 -300
@@ -1,131 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
|
3
|
-
/*
|
4
|
-
Extremely simple css parser. Intended to be not more than what we need
|
5
|
-
and definitely not necessarly correct =).
|
6
|
-
*/
|
7
|
-
(function() {
|
8
|
-
|
9
|
-
// given a string of css, return a simple rule tree
|
10
|
-
function parse(text) {
|
11
|
-
text = clean(text);
|
12
|
-
return parseCss(lex(text), text);
|
13
|
-
}
|
14
|
-
|
15
|
-
// remove stuff we don't care about that may hinder parsing
|
16
|
-
function clean(cssText) {
|
17
|
-
return cssText.replace(rx.comments, '').replace(rx.port, '');
|
18
|
-
}
|
19
|
-
|
20
|
-
// super simple {...} lexer that returns a node tree
|
21
|
-
function lex(text) {
|
22
|
-
var root = {start: 0, end: text.length};
|
23
|
-
var n = root;
|
24
|
-
for (var i=0, s=0, l=text.length; i < l; i++) {
|
25
|
-
switch (text[i]) {
|
26
|
-
case OPEN_BRACE:
|
27
|
-
//console.group(i);
|
28
|
-
if (!n.rules) {
|
29
|
-
n.rules = [];
|
30
|
-
}
|
31
|
-
var p = n;
|
32
|
-
var previous = p.rules[p.rules.length-1];
|
33
|
-
n = {start: i+1, parent: p, previous: previous};
|
34
|
-
p.rules.push(n);
|
35
|
-
break;
|
36
|
-
case CLOSE_BRACE:
|
37
|
-
//console.groupEnd(n.start);
|
38
|
-
n.end = i+1;
|
39
|
-
n = n.parent || root;
|
40
|
-
break;
|
41
|
-
}
|
42
|
-
}
|
43
|
-
return root;
|
44
|
-
}
|
45
|
-
|
46
|
-
// add selectors/cssText to node tree
|
47
|
-
function parseCss(node, text) {
|
48
|
-
var t = text.substring(node.start, node.end-1);
|
49
|
-
node.cssText = t.trim();
|
50
|
-
if (node.parent) {
|
51
|
-
var ss = node.previous ? node.previous.end : node.parent.start;
|
52
|
-
t = text.substring(ss, node.start-1);
|
53
|
-
// TODO(sorvell): ad hoc; make selector include only after last ;
|
54
|
-
// helps with mixin syntax
|
55
|
-
t = t.substring(t.lastIndexOf(';')+1);
|
56
|
-
node.selector = t.trim();
|
57
|
-
}
|
58
|
-
var r$ = node.rules;
|
59
|
-
if (r$) {
|
60
|
-
for (var i=0, l=r$.length, r; (i<l) && (r=r$[i]); i++) {
|
61
|
-
parseCss(r, text);
|
62
|
-
}
|
63
|
-
}
|
64
|
-
return node;
|
65
|
-
}
|
66
|
-
|
67
|
-
// stringify parsed css.
|
68
|
-
function stringify(node, text) {
|
69
|
-
text = text || '';
|
70
|
-
// calc rule cssText
|
71
|
-
var cssText = '';
|
72
|
-
if (node.cssText || node.rules) {
|
73
|
-
var r$ = node.rules;
|
74
|
-
if (r$ && !hasMixinRules(r$)) {
|
75
|
-
for (var i=0, l=r$.length, r; (i<l) && (r=r$[i]); i++) {
|
76
|
-
cssText = stringify(r, cssText);
|
77
|
-
}
|
78
|
-
} else {
|
79
|
-
cssText = removeCustomProps(node.cssText).trim();
|
80
|
-
if (cssText) {
|
81
|
-
cssText = ' ' + cssText + '\n';
|
82
|
-
}
|
83
|
-
}
|
84
|
-
}
|
85
|
-
// emit rule iff there is cssText
|
86
|
-
if (cssText) {
|
87
|
-
if (node.selector) {
|
88
|
-
text += node.selector + ' ' + OPEN_BRACE + '\n';
|
89
|
-
}
|
90
|
-
text += cssText;
|
91
|
-
if (node.selector) {
|
92
|
-
text += CLOSE_BRACE + '\n\n';
|
93
|
-
}
|
94
|
-
}
|
95
|
-
return text;
|
96
|
-
}
|
97
|
-
|
98
|
-
var OPEN_BRACE = '{';
|
99
|
-
var CLOSE_BRACE = '}';
|
100
|
-
|
101
|
-
function hasMixinRules(rules) {
|
102
|
-
return (rules[0].selector.indexOf(VAR_START) >= 0);
|
103
|
-
}
|
104
|
-
|
105
|
-
function removeCustomProps(cssText) {
|
106
|
-
return cssText
|
107
|
-
.replace(rx.customProp, '')
|
108
|
-
.replace(rx.mixinProp, '')
|
109
|
-
.replace(rx.mixinApply, '');
|
110
|
-
}
|
111
|
-
|
112
|
-
var VAR_START = '--';
|
113
|
-
|
114
|
-
// helper regexp's
|
115
|
-
var rx = {
|
116
|
-
comments: /\/\*[^*]*\*+([^/*][^*]*\*+)*\//gim,
|
117
|
-
port: /@import[^;]*;/gim,
|
118
|
-
customProp: /--[^;{]*?:[^{};]*?;/gim,
|
119
|
-
mixinProp: /--[^;{]*?:[^{;]*?{[^}]*?}/gim,
|
120
|
-
mixinApply: /@mixin[\s]*\([^)]*?\)[\s]*;/gim
|
121
|
-
};
|
122
|
-
|
123
|
-
// exports
|
124
|
-
Polymer.CssParse = {
|
125
|
-
parse: parse,
|
126
|
-
stringify: stringify
|
127
|
-
};
|
128
|
-
|
129
|
-
})();
|
130
|
-
|
131
|
-
</script>
|
@@ -1,69 +0,0 @@
|
|
1
|
-
<!--
|
2
|
-
@license
|
3
|
-
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
4
|
-
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
5
|
-
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
6
|
-
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
7
|
-
Code distributed by Google as part of the polymer project is also
|
8
|
-
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
9
|
-
-->
|
10
|
-
<script>
|
11
|
-
|
12
|
-
Polymer.Debounce = (function() {
|
13
|
-
|
14
|
-
// usage
|
15
|
-
|
16
|
-
// invoke cb.call(this) in 100ms, unless the job is re-registered,
|
17
|
-
// which resets the timer
|
18
|
-
//
|
19
|
-
// this.job = this.debounce(this.job, cb, 100)
|
20
|
-
//
|
21
|
-
// returns a handle which can be used to re-register a job
|
22
|
-
|
23
|
-
var Async = Polymer.Async;
|
24
|
-
|
25
|
-
var Debouncer = function(context) {
|
26
|
-
this.context = context;
|
27
|
-
this.boundComplete = this.complete.bind(this);
|
28
|
-
};
|
29
|
-
|
30
|
-
Debouncer.prototype = {
|
31
|
-
go: function(callback, wait) {
|
32
|
-
var h;
|
33
|
-
this.finish = function() {
|
34
|
-
Async.cancel(h);
|
35
|
-
};
|
36
|
-
h = Async.run(this.boundComplete, wait);
|
37
|
-
this.callback = callback;
|
38
|
-
},
|
39
|
-
stop: function() {
|
40
|
-
if (this.finish) {
|
41
|
-
this.finish();
|
42
|
-
this.finish = null;
|
43
|
-
}
|
44
|
-
},
|
45
|
-
complete: function() {
|
46
|
-
if (this.finish) {
|
47
|
-
this.stop();
|
48
|
-
this.callback.call(this.context);
|
49
|
-
}
|
50
|
-
}
|
51
|
-
};
|
52
|
-
|
53
|
-
function debounce(debouncer, callback, wait) {
|
54
|
-
if (debouncer) {
|
55
|
-
debouncer.stop();
|
56
|
-
} else {
|
57
|
-
debouncer = new Debouncer(this);
|
58
|
-
}
|
59
|
-
debouncer.go(callback, wait);
|
60
|
-
return debouncer;
|
61
|
-
}
|
62
|
-
|
63
|
-
// exports
|
64
|
-
|
65
|
-
return debounce;
|
66
|
-
|
67
|
-
})();
|
68
|
-
|
69
|
-
</script>
|
@@ -1,467 +0,0 @@
|
|
1
|
-
<!--
|
2
|
-
@license
|
3
|
-
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
4
|
-
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
5
|
-
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
6
|
-
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
7
|
-
Code distributed by Google as part of the polymer project is also
|
8
|
-
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
9
|
-
-->
|
10
|
-
<link rel="import" href="settings.html">
|
11
|
-
<link rel="import" href="event-api.html">
|
12
|
-
<script>
|
13
|
-
|
14
|
-
Polymer.DomApi = (function() {
|
15
|
-
|
16
|
-
var Debounce = Polymer.Debounce;
|
17
|
-
var Settings = Polymer.Settings;
|
18
|
-
|
19
|
-
var nativeInsertBefore = Element.prototype.insertBefore;
|
20
|
-
var nativeRemoveChild = Element.prototype.removeChild;
|
21
|
-
var nativeAppendChild = Element.prototype.appendChild;
|
22
|
-
|
23
|
-
var dirtyRoots = [];
|
24
|
-
|
25
|
-
var DomApi = function(node, patch) {
|
26
|
-
this.node = node;
|
27
|
-
if (patch) {
|
28
|
-
this.patch();
|
29
|
-
}
|
30
|
-
};
|
31
|
-
|
32
|
-
DomApi.prototype = {
|
33
|
-
|
34
|
-
// experimental: support patching selected native api.
|
35
|
-
patch: function() {
|
36
|
-
var self = this;
|
37
|
-
this.node.appendChild = function(node) {
|
38
|
-
return self.appendChild(node);
|
39
|
-
};
|
40
|
-
this.node.insertBefore = function(node, ref_node) {
|
41
|
-
return self.insertBefore(node, ref_node);
|
42
|
-
};
|
43
|
-
this.node.removeChild = function(node) {
|
44
|
-
return self.removeChild(node);
|
45
|
-
};
|
46
|
-
},
|
47
|
-
|
48
|
-
get childNodes() {
|
49
|
-
var c$ = getLightChildren(this.node);
|
50
|
-
return Array.isArray(c$) ? c$ : Array.prototype.slice.call(c$);
|
51
|
-
},
|
52
|
-
|
53
|
-
get children() {
|
54
|
-
return Array.prototype.filter.call(this.childNodes, function(n) {
|
55
|
-
return (n.nodeType === Node.ELEMENT_NODE);
|
56
|
-
});
|
57
|
-
},
|
58
|
-
|
59
|
-
get parentNode() {
|
60
|
-
return this.node.lightParent || this.node.parentNode;
|
61
|
-
},
|
62
|
-
|
63
|
-
flush: function() {
|
64
|
-
for (var i=0, host; i<dirtyRoots.length; i++) {
|
65
|
-
host = dirtyRoots[i];
|
66
|
-
if (host.__distribute) {
|
67
|
-
host.__distribute.complete();
|
68
|
-
}
|
69
|
-
}
|
70
|
-
dirtyRoots = [];
|
71
|
-
},
|
72
|
-
|
73
|
-
_lazyDistribute: function(host) {
|
74
|
-
if (host.shadyRoot) {
|
75
|
-
host.shadyRoot._distributionClean = false;
|
76
|
-
}
|
77
|
-
// TODO(sorvell): optimize debounce so it does less work by default
|
78
|
-
// and then remove these checks...
|
79
|
-
// need to dirty distribution once.
|
80
|
-
if (!host.__distribute || !host.__distribute.finish) {
|
81
|
-
host._debounce('__distribute', host._distributeContent);
|
82
|
-
dirtyRoots.push(host);
|
83
|
-
}
|
84
|
-
},
|
85
|
-
|
86
|
-
// cases in which we may not be able to just do standard appendChild
|
87
|
-
// 1. container has a shadyRoot (needsDistribution IFF the shadyRoot
|
88
|
-
// has an insertion point)
|
89
|
-
// 2. container is a shadyRoot (don't distribute, instead set
|
90
|
-
// container to container.host.
|
91
|
-
// 3. node is <content> (host of container needs distribution)
|
92
|
-
appendChild: function(node) {
|
93
|
-
var distributed;
|
94
|
-
if (node.lightParent) {
|
95
|
-
this._removeLogicalInfo(node, node.lightParent);
|
96
|
-
}
|
97
|
-
if (this._nodeIsInLogicalTree(this.node)) {
|
98
|
-
var host = this._hostForNode(this.node);
|
99
|
-
this._addLogicalInfo(node, this.node, host && host.shadyRoot);
|
100
|
-
if (host) {
|
101
|
-
host._elementAdd(node);
|
102
|
-
distributed = this._maybeDistribute(node, this.node, host);
|
103
|
-
}
|
104
|
-
}
|
105
|
-
if (!distributed) {
|
106
|
-
// if adding to a shadyRoot, add to host instead
|
107
|
-
var container = this.node._isShadyRoot ? this.node.host : this.node;
|
108
|
-
nativeAppendChild.call(container, node);
|
109
|
-
}
|
110
|
-
return node;
|
111
|
-
},
|
112
|
-
|
113
|
-
insertBefore: function(node, ref_node) {
|
114
|
-
if (!ref_node) {
|
115
|
-
return this.appendChild(node);
|
116
|
-
}
|
117
|
-
var distributed;
|
118
|
-
if (node.lightParent) {
|
119
|
-
this._removeLogicalInfo(node, node.lightParent);
|
120
|
-
}
|
121
|
-
if (this._nodeIsInLogicalTree(this.node)) {
|
122
|
-
saveLightChildrenIfNeeded(this.node);
|
123
|
-
var children = this.childNodes;
|
124
|
-
var index = children.indexOf(ref_node);
|
125
|
-
if (index < 0) {
|
126
|
-
throw Error('The ref_node to be inserted before is not a child ' +
|
127
|
-
'of this node');
|
128
|
-
}
|
129
|
-
var host = this._hostForNode(this.node);
|
130
|
-
this._addLogicalInfo(node, this.node, host && host.shadyRoot, index);
|
131
|
-
if (host) {
|
132
|
-
host._elementAdd(node);
|
133
|
-
distributed = this._maybeDistribute(node, this.node, host);
|
134
|
-
}
|
135
|
-
}
|
136
|
-
if (!distributed) {
|
137
|
-
// if ref_node is <content> replace with first distributed node
|
138
|
-
ref_node = ref_node.localName === CONTENT ?
|
139
|
-
this._firstComposedNode(ref_node) : ref_node;
|
140
|
-
// if adding to a shadyRoot, add to host instead
|
141
|
-
var container = this.node._isShadyRoot ? this.node.host : this.node;
|
142
|
-
nativeInsertBefore.call(container, node, ref_node);
|
143
|
-
}
|
144
|
-
return node;
|
145
|
-
},
|
146
|
-
|
147
|
-
/**
|
148
|
-
Removes the given `node` from the element's `lightChildren`.
|
149
|
-
This method also performs dom composition.
|
150
|
-
*/
|
151
|
-
removeChild: function(node) {
|
152
|
-
var distributed;
|
153
|
-
if (this._nodeIsInLogicalTree(this.node)) {
|
154
|
-
var host = this._hostForNode(this.node);
|
155
|
-
this._removeLogicalInfo(node, this.node);
|
156
|
-
if (host) {
|
157
|
-
host._elementRemove(node);
|
158
|
-
distributed = this._maybeDistribute(node, this.node, host);
|
159
|
-
}
|
160
|
-
}
|
161
|
-
if (!distributed) {
|
162
|
-
// if removing from a shadyRoot, remove form host instead
|
163
|
-
var container = this.node._isShadyRoot ? this.node.host : this.node;
|
164
|
-
nativeRemoveChild.call(container, node);
|
165
|
-
}
|
166
|
-
},
|
167
|
-
|
168
|
-
replaceChild: function(node, ref_node) {
|
169
|
-
this.insertBefore(node, ref_node);
|
170
|
-
this.removeChild(ref_node);
|
171
|
-
},
|
172
|
-
|
173
|
-
_getOwnerShadyRoot: function() {
|
174
|
-
return this._ownerShadyRootForNode(this.node);
|
175
|
-
},
|
176
|
-
|
177
|
-
getOwnerRoot: function() {
|
178
|
-
return this._getOwnerShadyRoot();
|
179
|
-
},
|
180
|
-
|
181
|
-
_ownerShadyRootForNode: function(node) {
|
182
|
-
if (node._ownerShadyRoot === undefined) {
|
183
|
-
var root;
|
184
|
-
if (node._isShadyRoot) {
|
185
|
-
root = node;
|
186
|
-
} else {
|
187
|
-
var parent = Polymer.dom(node).parentNode;
|
188
|
-
if (parent) {
|
189
|
-
root = parent._isShadyRoot ? parent :
|
190
|
-
this._ownerShadyRootForNode(parent);
|
191
|
-
} else {
|
192
|
-
root = null;
|
193
|
-
}
|
194
|
-
}
|
195
|
-
node._ownerShadyRoot = root;
|
196
|
-
}
|
197
|
-
return node._ownerShadyRoot;
|
198
|
-
|
199
|
-
},
|
200
|
-
|
201
|
-
_maybeDistribute: function(node, parent, host) {
|
202
|
-
var nodeNeedsDistribute = this._nodeNeedsDistribution(node);
|
203
|
-
var distribute = this._parentNeedsDistribution(parent) ||
|
204
|
-
nodeNeedsDistribute;
|
205
|
-
if (nodeNeedsDistribute) {
|
206
|
-
this._updateInsertionPoints(host);
|
207
|
-
}
|
208
|
-
if (distribute) {
|
209
|
-
this._lazyDistribute(host);
|
210
|
-
}
|
211
|
-
return distribute;
|
212
|
-
},
|
213
|
-
|
214
|
-
_updateInsertionPoints: function(host) {
|
215
|
-
host.shadyRoot._insertionPoints =
|
216
|
-
factory(host.shadyRoot).querySelectorAll(CONTENT);
|
217
|
-
},
|
218
|
-
|
219
|
-
_nodeIsInLogicalTree: function(node) {
|
220
|
-
return Boolean(node._isShadyRoot ||
|
221
|
-
this._getOwnerShadyRoot(node) ||
|
222
|
-
node.shadyRoot);
|
223
|
-
},
|
224
|
-
|
225
|
-
_hostForNode: function(node) {
|
226
|
-
var root = node.shadyRoot || (node._isShadyRoot ?
|
227
|
-
node : this._getOwnerShadyRoot(node));
|
228
|
-
return root && root.host;
|
229
|
-
},
|
230
|
-
|
231
|
-
_parentNeedsDistribution: function(parent) {
|
232
|
-
return parent.shadyRoot && hasInsertionPoint(parent.shadyRoot);
|
233
|
-
},
|
234
|
-
|
235
|
-
// TODO(sorvell): technically we should check non-fragment nodes for
|
236
|
-
// <content> children but since this case is assumed to be exceedingly
|
237
|
-
// rare, we avoid the cost and will address with some specific api
|
238
|
-
// when the need arises.
|
239
|
-
_nodeNeedsDistribution: function(node) {
|
240
|
-
return (node.localName === CONTENT) ||
|
241
|
-
((node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) &&
|
242
|
-
node.querySelector(CONTENT));
|
243
|
-
},
|
244
|
-
|
245
|
-
_addLogicalInfo: function(node, container, root, index) {
|
246
|
-
saveLightChildrenIfNeeded(container);
|
247
|
-
var children = factory(container).childNodes;
|
248
|
-
index = index === undefined ? children.length : index;
|
249
|
-
// handle document fragments
|
250
|
-
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
251
|
-
var n = node.firstChild;
|
252
|
-
while (n) {
|
253
|
-
children.splice(index++, 0, n);
|
254
|
-
n.lightParent = container;
|
255
|
-
n = n.nextSibling;
|
256
|
-
}
|
257
|
-
} else {
|
258
|
-
children.splice(index, 0, node);
|
259
|
-
node.lightParent = container;
|
260
|
-
node._ownerShadyRoot = root;
|
261
|
-
}
|
262
|
-
// TODO(sorvell): consider not attaching this to every node and instead
|
263
|
-
// looking up the tree for this info.
|
264
|
-
// add _ownerShadyRoot info
|
265
|
-
var c$ = factory(node).childNodes;
|
266
|
-
if (c$.length) {
|
267
|
-
this._addRootToChildren(node, root);
|
268
|
-
}
|
269
|
-
},
|
270
|
-
|
271
|
-
// NOTE: in general, we expect contents of the lists here to be small-ish
|
272
|
-
// and therefore indexOf to be nbd. Other optimizations can be made
|
273
|
-
// for larger lists (linked list)
|
274
|
-
_removeLogicalInfo: function(node, container) {
|
275
|
-
var children = factory(container).childNodes;
|
276
|
-
var index = children.indexOf(node);
|
277
|
-
if ((index < 0) || (container !== node.lightParent)) {
|
278
|
-
throw Error('The node to be removed is not a child of this node');
|
279
|
-
}
|
280
|
-
children.splice(index, 1);
|
281
|
-
node.lightParent = null;
|
282
|
-
// TODO(sorvell): need to clear any children of element?
|
283
|
-
node._ownerShadyRoot = undefined;
|
284
|
-
},
|
285
|
-
|
286
|
-
_addRootToChildren: function(children, root) {
|
287
|
-
for (var i=0, l=children.length, c, cc; (i<l) && (c=children[i]); i++) {
|
288
|
-
c._ownerShadyRoot = root;
|
289
|
-
cc = factory(c).childNodes;
|
290
|
-
if (cc.length) {
|
291
|
-
this._addRootToChildren(cc, root);
|
292
|
-
}
|
293
|
-
}
|
294
|
-
},
|
295
|
-
|
296
|
-
// TODO(sorvell): This will fail if distribution that affects this
|
297
|
-
// question is pending; this is expected to be exceedingly rare, but if
|
298
|
-
// the issue comes up, we can force a flush in this case.
|
299
|
-
_firstComposedNode: function(content) {
|
300
|
-
var n$ = factory(content).getDistributedNodes();
|
301
|
-
for (var i=0, l=n$.length, n, p$; (i<l) && (n=n$[i]); i++) {
|
302
|
-
p$ = factory(n).getDestinationInsertionPoints();
|
303
|
-
// means that we're composed to this spot.
|
304
|
-
if (p$[p$.length-1] === content) {
|
305
|
-
return n;
|
306
|
-
}
|
307
|
-
}
|
308
|
-
},
|
309
|
-
|
310
|
-
// TODO(sorvell): consider doing native QSA and filtering results.
|
311
|
-
querySelector: function(selector) {
|
312
|
-
return this.querySelectorAll(selector)[0];
|
313
|
-
},
|
314
|
-
|
315
|
-
querySelectorAll: function(selector) {
|
316
|
-
return this._query(function(n) {
|
317
|
-
return matchesSelector.call(n, selector);
|
318
|
-
}, this.node);
|
319
|
-
},
|
320
|
-
|
321
|
-
_query: function(matcher, node) {
|
322
|
-
var list = [];
|
323
|
-
this._queryElements(factory(node).childNodes, matcher, list);
|
324
|
-
return list;
|
325
|
-
},
|
326
|
-
|
327
|
-
_queryElements: function(elements, matcher, list) {
|
328
|
-
for (var i=0, l=elements.length, c; (i<l) && (c=elements[i]); i++) {
|
329
|
-
if (c.nodeType === Node.ELEMENT_NODE) {
|
330
|
-
this._queryElement(c, matcher, list);
|
331
|
-
}
|
332
|
-
}
|
333
|
-
},
|
334
|
-
|
335
|
-
_queryElement: function(node, matcher, list) {
|
336
|
-
if (matcher(node)) {
|
337
|
-
list.push(node);
|
338
|
-
}
|
339
|
-
this._queryElements(factory(node).childNodes, matcher, list);
|
340
|
-
},
|
341
|
-
|
342
|
-
getDestinationInsertionPoints: function() {
|
343
|
-
return this.node._destinationInsertionPoints ||
|
344
|
-
Array.prototype.slice.call(this.node.getDestinationInsertionPoints());
|
345
|
-
},
|
346
|
-
|
347
|
-
getDistributedNodes: function() {
|
348
|
-
return this.node._distributedNodes ||
|
349
|
-
Array.prototype.slice.call(this.node.getDistributedNodes());
|
350
|
-
},
|
351
|
-
|
352
|
-
/*
|
353
|
-
Returns a list of nodes distributed within this element. These can be
|
354
|
-
dom children or elements distributed to children that are insertion
|
355
|
-
points.
|
356
|
-
*/
|
357
|
-
queryDistributedElements: function(selector) {
|
358
|
-
var c$ = this.childNodes;
|
359
|
-
var list = [];
|
360
|
-
this._distributedFilter(selector, c$, list);
|
361
|
-
for (var i=0, l=c$.length, c; (i<l) && (c=c$[i]); i++) {
|
362
|
-
if (c.localName === CONTENT) {
|
363
|
-
this._distributedFilter(selector, factory(c).getDistributedNodes(),
|
364
|
-
list);
|
365
|
-
}
|
366
|
-
}
|
367
|
-
return list;
|
368
|
-
},
|
369
|
-
|
370
|
-
_distributedFilter: function(selector, list, results) {
|
371
|
-
results = results || [];
|
372
|
-
for (var i=0, l=list.length, d; (i<l) && (d=list[i]); i++) {
|
373
|
-
if ((d.nodeType === Node.ELEMENT_NODE) &&
|
374
|
-
(d.localName !== CONTENT) &&
|
375
|
-
matchesSelector.call(d, selector)) {
|
376
|
-
results.push(d);
|
377
|
-
}
|
378
|
-
}
|
379
|
-
return results;
|
380
|
-
}
|
381
|
-
|
382
|
-
};
|
383
|
-
|
384
|
-
if (Settings.useShadow) {
|
385
|
-
|
386
|
-
DomApi.prototype.querySelectorAll = function(selector) {
|
387
|
-
return Array.prototype.slice.call(this.node.querySelectorAll(selector));
|
388
|
-
};
|
389
|
-
|
390
|
-
DomApi.prototype.patch = function() {};
|
391
|
-
|
392
|
-
DomApi.prototype.getOwnerRoot = function() {
|
393
|
-
var n = this.node;
|
394
|
-
while (n) {
|
395
|
-
if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE && n.host) {
|
396
|
-
return n;
|
397
|
-
}
|
398
|
-
n = n.parentNode;
|
399
|
-
}
|
400
|
-
};
|
401
|
-
|
402
|
-
}
|
403
|
-
|
404
|
-
var CONTENT = 'content';
|
405
|
-
|
406
|
-
var factory = function(node, patch) {
|
407
|
-
node = node || document;
|
408
|
-
if (!node.__domApi) {
|
409
|
-
node.__domApi = new DomApi(node, patch);
|
410
|
-
}
|
411
|
-
return node.__domApi;
|
412
|
-
};
|
413
|
-
|
414
|
-
Polymer.dom = function(obj, patch) {
|
415
|
-
if (obj instanceof Event) {
|
416
|
-
return Polymer.EventApi.factory(obj);
|
417
|
-
} else {
|
418
|
-
return factory(obj, patch);
|
419
|
-
}
|
420
|
-
};
|
421
|
-
|
422
|
-
// make flush available directly.
|
423
|
-
Polymer.dom.flush = DomApi.prototype.flush;
|
424
|
-
|
425
|
-
function getLightChildren(node) {
|
426
|
-
var children = node.lightChildren;
|
427
|
-
return children ? children : node.childNodes;
|
428
|
-
}
|
429
|
-
|
430
|
-
function saveLightChildrenIfNeeded(node) {
|
431
|
-
// Capture the list of light children. It's important to do this before we
|
432
|
-
// start transforming the DOM into "rendered" state.
|
433
|
-
//
|
434
|
-
// Children may be added to this list dynamically. It will be treated as the
|
435
|
-
// source of truth for the light children of the element. This element's
|
436
|
-
// actual children will be treated as the rendered state once lightChildren
|
437
|
-
// is populated.
|
438
|
-
if (!node.lightChildren) {
|
439
|
-
var children = [];
|
440
|
-
for (var child = node.firstChild; child; child = child.nextSibling) {
|
441
|
-
children.push(child);
|
442
|
-
child.lightParent = child.lightParent || node;
|
443
|
-
}
|
444
|
-
node.lightChildren = children;
|
445
|
-
}
|
446
|
-
}
|
447
|
-
|
448
|
-
function hasInsertionPoint(root) {
|
449
|
-
return Boolean(root._insertionPoints.length);
|
450
|
-
}
|
451
|
-
|
452
|
-
var p = Element.prototype;
|
453
|
-
var matchesSelector = p.matches || p.matchesSelector ||
|
454
|
-
p.mozMatchesSelector || p.msMatchesSelector ||
|
455
|
-
p.oMatchesSelector || p.webkitMatchesSelector;
|
456
|
-
|
457
|
-
return {
|
458
|
-
getLightChildren: getLightChildren,
|
459
|
-
saveLightChildrenIfNeeded: saveLightChildrenIfNeeded,
|
460
|
-
matchesSelector: matchesSelector,
|
461
|
-
hasInsertionPoint: hasInsertionPoint,
|
462
|
-
factory: factory
|
463
|
-
};
|
464
|
-
|
465
|
-
})();
|
466
|
-
|
467
|
-
</script>
|