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
@@ -6,40 +6,1317 @@ The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
6
6
|
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
7
7
|
Code distributed by Google as part of the polymer project is also
|
8
8
|
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
9
|
-
|
9
|
+
--><link rel="import" href="polymer-micro.html">
|
10
10
|
|
11
|
-
<
|
11
|
+
<script>Polymer.Base._addFeature({
|
12
|
+
_prepTemplate: function() {
|
13
|
+
this._template = this._template || Polymer.DomModule.import(this.is, "template");
|
14
|
+
if (!this._template) {
|
15
|
+
var script = document._currentScript || document.currentScript;
|
16
|
+
var prev = script && script.previousElementSibling;
|
17
|
+
if (prev && prev.localName === "template") {
|
18
|
+
this._template = prev;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
if (this._template && this._template.hasAttribute("is")) {
|
22
|
+
this._warn(this._logf("_prepTemplate", "top-level Polymer template " + "must not be a type-extension, found", this._template, "Move inside simple <template>."));
|
23
|
+
}
|
24
|
+
},
|
25
|
+
_stampTemplate: function() {
|
26
|
+
if (this._template) {
|
27
|
+
this.root = this.instanceTemplate(this._template);
|
28
|
+
}
|
29
|
+
},
|
30
|
+
instanceTemplate: function(template) {
|
31
|
+
var dom = document.importNode(template._content || template.content, true);
|
32
|
+
return dom;
|
33
|
+
}
|
34
|
+
});
|
12
35
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
36
|
+
(function() {
|
37
|
+
var baseAttachedCallback = Polymer.Base.attachedCallback;
|
38
|
+
Polymer.Base._addFeature({
|
39
|
+
_hostStack: [],
|
40
|
+
ready: function() {},
|
41
|
+
_pushHost: function(host) {
|
42
|
+
this.dataHost = host = host || Polymer.Base._hostStack[Polymer.Base._hostStack.length - 1];
|
43
|
+
if (host && host._clients) {
|
44
|
+
host._clients.push(this);
|
45
|
+
}
|
46
|
+
this._beginHost();
|
47
|
+
},
|
48
|
+
_beginHost: function() {
|
49
|
+
Polymer.Base._hostStack.push(this);
|
50
|
+
if (!this._clients) {
|
51
|
+
this._clients = [];
|
52
|
+
}
|
53
|
+
},
|
54
|
+
_popHost: function() {
|
55
|
+
Polymer.Base._hostStack.pop();
|
56
|
+
},
|
57
|
+
_tryReady: function() {
|
58
|
+
if (this._canReady()) {
|
59
|
+
this._ready();
|
60
|
+
}
|
61
|
+
},
|
62
|
+
_canReady: function() {
|
63
|
+
return !this.dataHost || this.dataHost._clientsReadied;
|
64
|
+
},
|
65
|
+
_ready: function() {
|
66
|
+
this._beforeClientsReady();
|
67
|
+
this._setupRoot();
|
68
|
+
this._readyClients();
|
69
|
+
this._afterClientsReady();
|
70
|
+
this._readySelf();
|
71
|
+
},
|
72
|
+
_readyClients: function() {
|
73
|
+
this._beginDistribute();
|
74
|
+
var c$ = this._clients;
|
75
|
+
for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
|
76
|
+
c._ready();
|
77
|
+
}
|
78
|
+
this._finishDistribute();
|
79
|
+
this._clientsReadied = true;
|
80
|
+
this._clients = null;
|
81
|
+
},
|
82
|
+
_readySelf: function() {
|
83
|
+
this._doBehavior("ready");
|
84
|
+
this._readied = true;
|
85
|
+
if (this._attachedPending) {
|
86
|
+
this._attachedPending = false;
|
87
|
+
this.attachedCallback();
|
88
|
+
}
|
89
|
+
},
|
90
|
+
_beforeClientsReady: function() {},
|
91
|
+
_afterClientsReady: function() {},
|
92
|
+
_beforeAttached: function() {},
|
93
|
+
attachedCallback: function() {
|
94
|
+
if (this._readied) {
|
95
|
+
this._beforeAttached();
|
96
|
+
baseAttachedCallback.call(this);
|
97
|
+
} else {
|
98
|
+
this._attachedPending = true;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
});
|
102
|
+
})();
|
17
103
|
|
18
|
-
|
104
|
+
Polymer.ArraySplice = function() {
|
105
|
+
function newSplice(index, removed, addedCount) {
|
106
|
+
return {
|
107
|
+
index: index,
|
108
|
+
removed: removed,
|
109
|
+
addedCount: addedCount
|
110
|
+
};
|
111
|
+
}
|
112
|
+
var EDIT_LEAVE = 0;
|
113
|
+
var EDIT_UPDATE = 1;
|
114
|
+
var EDIT_ADD = 2;
|
115
|
+
var EDIT_DELETE = 3;
|
116
|
+
function ArraySplice() {}
|
117
|
+
ArraySplice.prototype = {
|
118
|
+
calcEditDistances: function(current, currentStart, currentEnd, old, oldStart, oldEnd) {
|
119
|
+
var rowCount = oldEnd - oldStart + 1;
|
120
|
+
var columnCount = currentEnd - currentStart + 1;
|
121
|
+
var distances = new Array(rowCount);
|
122
|
+
for (var i = 0; i < rowCount; i++) {
|
123
|
+
distances[i] = new Array(columnCount);
|
124
|
+
distances[i][0] = i;
|
125
|
+
}
|
126
|
+
for (var j = 0; j < columnCount; j++) distances[0][j] = j;
|
127
|
+
for (var i = 1; i < rowCount; i++) {
|
128
|
+
for (var j = 1; j < columnCount; j++) {
|
129
|
+
if (this.equals(current[currentStart + j - 1], old[oldStart + i - 1])) distances[i][j] = distances[i - 1][j - 1]; else {
|
130
|
+
var north = distances[i - 1][j] + 1;
|
131
|
+
var west = distances[i][j - 1] + 1;
|
132
|
+
distances[i][j] = north < west ? north : west;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
return distances;
|
137
|
+
},
|
138
|
+
spliceOperationsFromEditDistances: function(distances) {
|
139
|
+
var i = distances.length - 1;
|
140
|
+
var j = distances[0].length - 1;
|
141
|
+
var current = distances[i][j];
|
142
|
+
var edits = [];
|
143
|
+
while (i > 0 || j > 0) {
|
144
|
+
if (i == 0) {
|
145
|
+
edits.push(EDIT_ADD);
|
146
|
+
j--;
|
147
|
+
continue;
|
148
|
+
}
|
149
|
+
if (j == 0) {
|
150
|
+
edits.push(EDIT_DELETE);
|
151
|
+
i--;
|
152
|
+
continue;
|
153
|
+
}
|
154
|
+
var northWest = distances[i - 1][j - 1];
|
155
|
+
var west = distances[i - 1][j];
|
156
|
+
var north = distances[i][j - 1];
|
157
|
+
var min;
|
158
|
+
if (west < north) min = west < northWest ? west : northWest; else min = north < northWest ? north : northWest;
|
159
|
+
if (min == northWest) {
|
160
|
+
if (northWest == current) {
|
161
|
+
edits.push(EDIT_LEAVE);
|
162
|
+
} else {
|
163
|
+
edits.push(EDIT_UPDATE);
|
164
|
+
current = northWest;
|
165
|
+
}
|
166
|
+
i--;
|
167
|
+
j--;
|
168
|
+
} else if (min == west) {
|
169
|
+
edits.push(EDIT_DELETE);
|
170
|
+
i--;
|
171
|
+
current = west;
|
172
|
+
} else {
|
173
|
+
edits.push(EDIT_ADD);
|
174
|
+
j--;
|
175
|
+
current = north;
|
176
|
+
}
|
177
|
+
}
|
178
|
+
edits.reverse();
|
179
|
+
return edits;
|
180
|
+
},
|
181
|
+
calcSplices: function(current, currentStart, currentEnd, old, oldStart, oldEnd) {
|
182
|
+
var prefixCount = 0;
|
183
|
+
var suffixCount = 0;
|
184
|
+
var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart);
|
185
|
+
if (currentStart == 0 && oldStart == 0) prefixCount = this.sharedPrefix(current, old, minLength);
|
186
|
+
if (currentEnd == current.length && oldEnd == old.length) suffixCount = this.sharedSuffix(current, old, minLength - prefixCount);
|
187
|
+
currentStart += prefixCount;
|
188
|
+
oldStart += prefixCount;
|
189
|
+
currentEnd -= suffixCount;
|
190
|
+
oldEnd -= suffixCount;
|
191
|
+
if (currentEnd - currentStart == 0 && oldEnd - oldStart == 0) return [];
|
192
|
+
if (currentStart == currentEnd) {
|
193
|
+
var splice = newSplice(currentStart, [], 0);
|
194
|
+
while (oldStart < oldEnd) splice.removed.push(old[oldStart++]);
|
195
|
+
return [ splice ];
|
196
|
+
} else if (oldStart == oldEnd) return [ newSplice(currentStart, [], currentEnd - currentStart) ];
|
197
|
+
var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd));
|
198
|
+
var splice = undefined;
|
199
|
+
var splices = [];
|
200
|
+
var index = currentStart;
|
201
|
+
var oldIndex = oldStart;
|
202
|
+
for (var i = 0; i < ops.length; i++) {
|
203
|
+
switch (ops[i]) {
|
204
|
+
case EDIT_LEAVE:
|
205
|
+
if (splice) {
|
206
|
+
splices.push(splice);
|
207
|
+
splice = undefined;
|
208
|
+
}
|
209
|
+
index++;
|
210
|
+
oldIndex++;
|
211
|
+
break;
|
19
212
|
|
20
|
-
|
213
|
+
case EDIT_UPDATE:
|
214
|
+
if (!splice) splice = newSplice(index, [], 0);
|
215
|
+
splice.addedCount++;
|
216
|
+
index++;
|
217
|
+
splice.removed.push(old[oldIndex]);
|
218
|
+
oldIndex++;
|
219
|
+
break;
|
21
220
|
|
22
|
-
|
221
|
+
case EDIT_ADD:
|
222
|
+
if (!splice) splice = newSplice(index, [], 0);
|
223
|
+
splice.addedCount++;
|
224
|
+
index++;
|
225
|
+
break;
|
23
226
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
227
|
+
case EDIT_DELETE:
|
228
|
+
if (!splice) splice = newSplice(index, [], 0);
|
229
|
+
splice.removed.push(old[oldIndex]);
|
230
|
+
oldIndex++;
|
231
|
+
break;
|
232
|
+
}
|
233
|
+
}
|
234
|
+
if (splice) {
|
235
|
+
splices.push(splice);
|
236
|
+
}
|
237
|
+
return splices;
|
238
|
+
},
|
239
|
+
sharedPrefix: function(current, old, searchLength) {
|
240
|
+
for (var i = 0; i < searchLength; i++) if (!this.equals(current[i], old[i])) return i;
|
241
|
+
return searchLength;
|
242
|
+
},
|
243
|
+
sharedSuffix: function(current, old, searchLength) {
|
244
|
+
var index1 = current.length;
|
245
|
+
var index2 = old.length;
|
246
|
+
var count = 0;
|
247
|
+
while (count < searchLength && this.equals(current[--index1], old[--index2])) count++;
|
248
|
+
return count;
|
249
|
+
},
|
250
|
+
calculateSplices: function(current, previous) {
|
251
|
+
return this.calcSplices(current, 0, current.length, previous, 0, previous.length);
|
252
|
+
},
|
253
|
+
equals: function(currentValue, previousValue) {
|
254
|
+
return currentValue === previousValue;
|
255
|
+
}
|
256
|
+
};
|
257
|
+
return new ArraySplice();
|
258
|
+
}();
|
32
259
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
260
|
+
Polymer.EventApi = function() {
|
261
|
+
var Settings = Polymer.Settings;
|
262
|
+
var EventApi = function(event) {
|
263
|
+
this.event = event;
|
264
|
+
};
|
265
|
+
if (Settings.useShadow) {
|
266
|
+
EventApi.prototype = {
|
267
|
+
get rootTarget() {
|
268
|
+
return this.event.path[0];
|
269
|
+
},
|
270
|
+
get localTarget() {
|
271
|
+
return this.event.target;
|
272
|
+
},
|
273
|
+
get path() {
|
274
|
+
return this.event.path;
|
275
|
+
}
|
276
|
+
};
|
277
|
+
} else {
|
278
|
+
EventApi.prototype = {
|
279
|
+
get rootTarget() {
|
280
|
+
return this.event.target;
|
281
|
+
},
|
282
|
+
get localTarget() {
|
283
|
+
var current = this.event.currentTarget;
|
284
|
+
var currentRoot = current && Polymer.dom(current).getOwnerRoot();
|
285
|
+
var p$ = this.path;
|
286
|
+
for (var i = 0; i < p$.length; i++) {
|
287
|
+
if (Polymer.dom(p$[i]).getOwnerRoot() === currentRoot) {
|
288
|
+
return p$[i];
|
289
|
+
}
|
290
|
+
}
|
291
|
+
},
|
292
|
+
get path() {
|
293
|
+
if (!this.event._path) {
|
294
|
+
var path = [];
|
295
|
+
var o = this.rootTarget;
|
296
|
+
while (o) {
|
297
|
+
path.push(o);
|
298
|
+
o = Polymer.dom(o).parentNode || o.host;
|
299
|
+
}
|
300
|
+
path.push(window);
|
301
|
+
this.event._path = path;
|
302
|
+
}
|
303
|
+
return this.event._path;
|
304
|
+
}
|
305
|
+
};
|
306
|
+
}
|
307
|
+
var factory = function(event) {
|
308
|
+
if (!event.__eventApi) {
|
309
|
+
event.__eventApi = new EventApi(event);
|
310
|
+
}
|
311
|
+
return event.__eventApi;
|
312
|
+
};
|
313
|
+
return {
|
314
|
+
factory: factory
|
315
|
+
};
|
316
|
+
}();
|
41
317
|
|
42
|
-
|
318
|
+
Polymer.domInnerHTML = function() {
|
319
|
+
var escapeAttrRegExp = /[&\u00A0"]/g;
|
320
|
+
var escapeDataRegExp = /[&\u00A0<>]/g;
|
321
|
+
function escapeReplace(c) {
|
322
|
+
switch (c) {
|
323
|
+
case "&":
|
324
|
+
return "&";
|
43
325
|
|
44
|
-
|
326
|
+
case "<":
|
327
|
+
return "<";
|
45
328
|
|
329
|
+
case ">":
|
330
|
+
return ">";
|
331
|
+
|
332
|
+
case '"':
|
333
|
+
return """;
|
334
|
+
|
335
|
+
case " ":
|
336
|
+
return " ";
|
337
|
+
}
|
338
|
+
}
|
339
|
+
function escapeAttr(s) {
|
340
|
+
return s.replace(escapeAttrRegExp, escapeReplace);
|
341
|
+
}
|
342
|
+
function escapeData(s) {
|
343
|
+
return s.replace(escapeDataRegExp, escapeReplace);
|
344
|
+
}
|
345
|
+
function makeSet(arr) {
|
346
|
+
var set = {};
|
347
|
+
for (var i = 0; i < arr.length; i++) {
|
348
|
+
set[arr[i]] = true;
|
349
|
+
}
|
350
|
+
return set;
|
351
|
+
}
|
352
|
+
var voidElements = makeSet([ "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr" ]);
|
353
|
+
var plaintextParents = makeSet([ "style", "script", "xmp", "iframe", "noembed", "noframes", "plaintext", "noscript" ]);
|
354
|
+
function getOuterHTML(node, parentNode, composed) {
|
355
|
+
switch (node.nodeType) {
|
356
|
+
case Node.ELEMENT_NODE:
|
357
|
+
var tagName = node.localName;
|
358
|
+
var s = "<" + tagName;
|
359
|
+
var attrs = node.attributes;
|
360
|
+
for (var i = 0, attr; attr = attrs[i]; i++) {
|
361
|
+
s += " " + attr.name + '="' + escapeAttr(attr.value) + '"';
|
362
|
+
}
|
363
|
+
s += ">";
|
364
|
+
if (voidElements[tagName]) {
|
365
|
+
return s;
|
366
|
+
}
|
367
|
+
return s + getInnerHTML(node, composed) + "</" + tagName + ">";
|
368
|
+
|
369
|
+
case Node.TEXT_NODE:
|
370
|
+
var data = node.data;
|
371
|
+
if (parentNode && plaintextParents[parentNode.localName]) {
|
372
|
+
return data;
|
373
|
+
}
|
374
|
+
return escapeData(data);
|
375
|
+
|
376
|
+
case Node.COMMENT_NODE:
|
377
|
+
return "<!--" + node.data + "-->";
|
378
|
+
|
379
|
+
default:
|
380
|
+
console.error(node);
|
381
|
+
throw new Error("not implemented");
|
382
|
+
}
|
383
|
+
}
|
384
|
+
function getInnerHTML(node, composed) {
|
385
|
+
if (node instanceof HTMLTemplateElement) node = node.content;
|
386
|
+
var s = "";
|
387
|
+
var c$ = Polymer.dom(node).childNodes;
|
388
|
+
c$ = composed ? node._composedChildren : c$;
|
389
|
+
for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) {
|
390
|
+
s += getOuterHTML(child, node, composed);
|
391
|
+
}
|
392
|
+
return s;
|
393
|
+
}
|
394
|
+
return {
|
395
|
+
getInnerHTML: getInnerHTML
|
396
|
+
};
|
397
|
+
}();
|
398
|
+
|
399
|
+
Polymer.DomApi = function() {
|
400
|
+
"use strict";
|
401
|
+
var Settings = Polymer.Settings;
|
402
|
+
var getInnerHTML = Polymer.domInnerHTML.getInnerHTML;
|
403
|
+
var nativeInsertBefore = Element.prototype.insertBefore;
|
404
|
+
var nativeRemoveChild = Element.prototype.removeChild;
|
405
|
+
var nativeAppendChild = Element.prototype.appendChild;
|
406
|
+
var dirtyRoots = [];
|
407
|
+
var DomApi = function(node) {
|
408
|
+
this.node = node;
|
409
|
+
if (this.patch) {
|
410
|
+
this.patch();
|
411
|
+
}
|
412
|
+
};
|
413
|
+
DomApi.prototype = {
|
414
|
+
flush: function() {
|
415
|
+
for (var i = 0, host; i < dirtyRoots.length; i++) {
|
416
|
+
host = dirtyRoots[i];
|
417
|
+
host.flushDebouncer("_distribute");
|
418
|
+
}
|
419
|
+
dirtyRoots = [];
|
420
|
+
},
|
421
|
+
_lazyDistribute: function(host) {
|
422
|
+
if (host.shadyRoot && host.shadyRoot._distributionClean) {
|
423
|
+
host.shadyRoot._distributionClean = false;
|
424
|
+
host.debounce("_distribute", host._distributeContent);
|
425
|
+
dirtyRoots.push(host);
|
426
|
+
}
|
427
|
+
},
|
428
|
+
appendChild: function(node) {
|
429
|
+
var distributed;
|
430
|
+
this._removeNodeFromHost(node);
|
431
|
+
if (this._nodeIsInLogicalTree(this.node)) {
|
432
|
+
var host = this._hostForNode(this.node);
|
433
|
+
this._addLogicalInfo(node, this.node, host && host.shadyRoot);
|
434
|
+
this._addNodeToHost(node);
|
435
|
+
if (host) {
|
436
|
+
distributed = this._maybeDistribute(node, this.node, host);
|
437
|
+
}
|
438
|
+
}
|
439
|
+
if (!distributed && !this._tryRemoveUndistributedNode(node)) {
|
440
|
+
var container = this.node._isShadyRoot ? this.node.host : this.node;
|
441
|
+
nativeAppendChild.call(container, node);
|
442
|
+
addToComposedParent(container, node);
|
443
|
+
}
|
444
|
+
return node;
|
445
|
+
},
|
446
|
+
insertBefore: function(node, ref_node) {
|
447
|
+
if (!ref_node) {
|
448
|
+
return this.appendChild(node);
|
449
|
+
}
|
450
|
+
var distributed;
|
451
|
+
this._removeNodeFromHost(node);
|
452
|
+
if (this._nodeIsInLogicalTree(this.node)) {
|
453
|
+
saveLightChildrenIfNeeded(this.node);
|
454
|
+
var children = this.childNodes;
|
455
|
+
var index = children.indexOf(ref_node);
|
456
|
+
if (index < 0) {
|
457
|
+
throw Error("The ref_node to be inserted before is not a child " + "of this node");
|
458
|
+
}
|
459
|
+
var host = this._hostForNode(this.node);
|
460
|
+
this._addLogicalInfo(node, this.node, host && host.shadyRoot, index);
|
461
|
+
this._addNodeToHost(node);
|
462
|
+
if (host) {
|
463
|
+
distributed = this._maybeDistribute(node, this.node, host);
|
464
|
+
}
|
465
|
+
}
|
466
|
+
if (!distributed && !this._tryRemoveUndistributedNode(node)) {
|
467
|
+
ref_node = ref_node.localName === CONTENT ? this._firstComposedNode(ref_node) : ref_node;
|
468
|
+
var container = this.node._isShadyRoot ? this.node.host : this.node;
|
469
|
+
nativeInsertBefore.call(container, node, ref_node);
|
470
|
+
addToComposedParent(container, node, ref_node);
|
471
|
+
}
|
472
|
+
return node;
|
473
|
+
},
|
474
|
+
removeChild: function(node) {
|
475
|
+
if (factory(node).parentNode !== this.node) {
|
476
|
+
console.warn("The node to be removed is not a child of this node", node);
|
477
|
+
}
|
478
|
+
var distributed;
|
479
|
+
if (this._nodeIsInLogicalTree(this.node)) {
|
480
|
+
var host = this._hostForNode(this.node);
|
481
|
+
distributed = this._maybeDistribute(node, this.node, host);
|
482
|
+
this._removeNodeFromHost(node);
|
483
|
+
}
|
484
|
+
if (!distributed) {
|
485
|
+
var container = this.node._isShadyRoot ? this.node.host : this.node;
|
486
|
+
if (container === node.parentNode) {
|
487
|
+
nativeRemoveChild.call(container, node);
|
488
|
+
removeFromComposedParent(container, node);
|
489
|
+
}
|
490
|
+
}
|
491
|
+
return node;
|
492
|
+
},
|
493
|
+
replaceChild: function(node, ref_node) {
|
494
|
+
this.insertBefore(node, ref_node);
|
495
|
+
this.removeChild(ref_node);
|
496
|
+
return node;
|
497
|
+
},
|
498
|
+
getOwnerRoot: function() {
|
499
|
+
return this._ownerShadyRootForNode(this.node);
|
500
|
+
},
|
501
|
+
_ownerShadyRootForNode: function(node) {
|
502
|
+
if (!node) {
|
503
|
+
return;
|
504
|
+
}
|
505
|
+
if (node._ownerShadyRoot === undefined) {
|
506
|
+
var root;
|
507
|
+
if (node._isShadyRoot) {
|
508
|
+
root = node;
|
509
|
+
} else {
|
510
|
+
var parent = Polymer.dom(node).parentNode;
|
511
|
+
if (parent) {
|
512
|
+
root = parent._isShadyRoot ? parent : this._ownerShadyRootForNode(parent);
|
513
|
+
} else {
|
514
|
+
root = null;
|
515
|
+
}
|
516
|
+
}
|
517
|
+
node._ownerShadyRoot = root;
|
518
|
+
}
|
519
|
+
return node._ownerShadyRoot;
|
520
|
+
},
|
521
|
+
_maybeDistribute: function(node, parent, host) {
|
522
|
+
var nodeNeedsDistribute = this._nodeNeedsDistribution(node);
|
523
|
+
var distribute = this._parentNeedsDistribution(parent) || nodeNeedsDistribute;
|
524
|
+
if (nodeNeedsDistribute) {
|
525
|
+
this._updateInsertionPoints(host);
|
526
|
+
}
|
527
|
+
if (distribute) {
|
528
|
+
this._lazyDistribute(host);
|
529
|
+
}
|
530
|
+
return distribute;
|
531
|
+
},
|
532
|
+
_tryRemoveUndistributedNode: function(node) {
|
533
|
+
if (this.node.shadyRoot) {
|
534
|
+
if (node.parentNode) {
|
535
|
+
nativeRemoveChild.call(node.parentNode, node);
|
536
|
+
}
|
537
|
+
return true;
|
538
|
+
}
|
539
|
+
},
|
540
|
+
_updateInsertionPoints: function(host) {
|
541
|
+
host.shadyRoot._insertionPoints = factory(host.shadyRoot).querySelectorAll(CONTENT);
|
542
|
+
},
|
543
|
+
_nodeIsInLogicalTree: function(node) {
|
544
|
+
return Boolean(node._lightParent || node._isShadyRoot || this._ownerShadyRootForNode(node) || node.shadyRoot);
|
545
|
+
},
|
546
|
+
_hostForNode: function(node) {
|
547
|
+
var root = node.shadyRoot || (node._isShadyRoot ? node : this._ownerShadyRootForNode(node));
|
548
|
+
return root && root.host;
|
549
|
+
},
|
550
|
+
_parentNeedsDistribution: function(parent) {
|
551
|
+
return parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot);
|
552
|
+
},
|
553
|
+
_nodeNeedsDistribution: function(node) {
|
554
|
+
return node.localName === CONTENT || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && node.querySelector(CONTENT);
|
555
|
+
},
|
556
|
+
_removeNodeFromHost: function(node) {
|
557
|
+
if (node._lightParent) {
|
558
|
+
var root = this._ownerShadyRootForNode(node);
|
559
|
+
if (root) {
|
560
|
+
root.host._elementRemove(node);
|
561
|
+
}
|
562
|
+
this._removeLogicalInfo(node, node._lightParent);
|
563
|
+
}
|
564
|
+
this._removeOwnerShadyRoot(node);
|
565
|
+
},
|
566
|
+
_addNodeToHost: function(node) {
|
567
|
+
var checkNode = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE ? node.firstChild : node;
|
568
|
+
var root = this._ownerShadyRootForNode(checkNode);
|
569
|
+
if (root) {
|
570
|
+
root.host._elementAdd(node);
|
571
|
+
}
|
572
|
+
},
|
573
|
+
_addLogicalInfo: function(node, container, root, index) {
|
574
|
+
saveLightChildrenIfNeeded(container);
|
575
|
+
var children = factory(container).childNodes;
|
576
|
+
index = index === undefined ? children.length : index;
|
577
|
+
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
578
|
+
var c$ = Array.prototype.slice.call(node.childNodes);
|
579
|
+
for (var i = 0, n; i < c$.length && (n = c$[i]); i++) {
|
580
|
+
children.splice(index++, 0, n);
|
581
|
+
n._lightParent = container;
|
582
|
+
}
|
583
|
+
} else {
|
584
|
+
children.splice(index, 0, node);
|
585
|
+
node._lightParent = container;
|
586
|
+
}
|
587
|
+
},
|
588
|
+
_removeLogicalInfo: function(node, container) {
|
589
|
+
var children = factory(container).childNodes;
|
590
|
+
var index = children.indexOf(node);
|
591
|
+
if (index < 0 || container !== node._lightParent) {
|
592
|
+
throw Error("The node to be removed is not a child of this node");
|
593
|
+
}
|
594
|
+
children.splice(index, 1);
|
595
|
+
node._lightParent = null;
|
596
|
+
},
|
597
|
+
_removeOwnerShadyRoot: function(node) {
|
598
|
+
var hasCachedRoot = factory(node).getOwnerRoot() !== undefined;
|
599
|
+
if (hasCachedRoot) {
|
600
|
+
var c$ = factory(node).childNodes;
|
601
|
+
for (var i = 0, l = c$.length, n; i < l && (n = c$[i]); i++) {
|
602
|
+
this._removeOwnerShadyRoot(n);
|
603
|
+
}
|
604
|
+
}
|
605
|
+
node._ownerShadyRoot = undefined;
|
606
|
+
},
|
607
|
+
_firstComposedNode: function(content) {
|
608
|
+
var n$ = factory(content).getDistributedNodes();
|
609
|
+
for (var i = 0, l = n$.length, n, p$; i < l && (n = n$[i]); i++) {
|
610
|
+
p$ = factory(n).getDestinationInsertionPoints();
|
611
|
+
if (p$[p$.length - 1] === content) {
|
612
|
+
return n;
|
613
|
+
}
|
614
|
+
}
|
615
|
+
},
|
616
|
+
querySelector: function(selector) {
|
617
|
+
return this.querySelectorAll(selector)[0];
|
618
|
+
},
|
619
|
+
querySelectorAll: function(selector) {
|
620
|
+
return this._query(function(n) {
|
621
|
+
return matchesSelector.call(n, selector);
|
622
|
+
}, this.node);
|
623
|
+
},
|
624
|
+
_query: function(matcher, node) {
|
625
|
+
node = node || this.node;
|
626
|
+
var list = [];
|
627
|
+
this._queryElements(factory(node).childNodes, matcher, list);
|
628
|
+
return list;
|
629
|
+
},
|
630
|
+
_queryElements: function(elements, matcher, list) {
|
631
|
+
for (var i = 0, l = elements.length, c; i < l && (c = elements[i]); i++) {
|
632
|
+
if (c.nodeType === Node.ELEMENT_NODE) {
|
633
|
+
this._queryElement(c, matcher, list);
|
634
|
+
}
|
635
|
+
}
|
636
|
+
},
|
637
|
+
_queryElement: function(node, matcher, list) {
|
638
|
+
if (matcher(node)) {
|
639
|
+
list.push(node);
|
640
|
+
}
|
641
|
+
this._queryElements(factory(node).childNodes, matcher, list);
|
642
|
+
},
|
643
|
+
getDestinationInsertionPoints: function() {
|
644
|
+
return this.node._destinationInsertionPoints || [];
|
645
|
+
},
|
646
|
+
getDistributedNodes: function() {
|
647
|
+
return this.node._distributedNodes || [];
|
648
|
+
},
|
649
|
+
queryDistributedElements: function(selector) {
|
650
|
+
var c$ = this.childNodes;
|
651
|
+
var list = [];
|
652
|
+
this._distributedFilter(selector, c$, list);
|
653
|
+
for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
|
654
|
+
if (c.localName === CONTENT) {
|
655
|
+
this._distributedFilter(selector, factory(c).getDistributedNodes(), list);
|
656
|
+
}
|
657
|
+
}
|
658
|
+
return list;
|
659
|
+
},
|
660
|
+
_distributedFilter: function(selector, list, results) {
|
661
|
+
results = results || [];
|
662
|
+
for (var i = 0, l = list.length, d; i < l && (d = list[i]); i++) {
|
663
|
+
if (d.nodeType === Node.ELEMENT_NODE && d.localName !== CONTENT && matchesSelector.call(d, selector)) {
|
664
|
+
results.push(d);
|
665
|
+
}
|
666
|
+
}
|
667
|
+
return results;
|
668
|
+
},
|
669
|
+
_clear: function() {
|
670
|
+
while (this.childNodes.length) {
|
671
|
+
this.removeChild(this.childNodes[0]);
|
672
|
+
}
|
673
|
+
},
|
674
|
+
setAttribute: function(name, value) {
|
675
|
+
this.node.setAttribute(name, value);
|
676
|
+
this._distributeParent();
|
677
|
+
},
|
678
|
+
removeAttribute: function(name) {
|
679
|
+
this.node.removeAttribute(name);
|
680
|
+
this._distributeParent();
|
681
|
+
},
|
682
|
+
_distributeParent: function() {
|
683
|
+
if (this._parentNeedsDistribution(this.parentNode)) {
|
684
|
+
this._lazyDistribute(this.parentNode);
|
685
|
+
}
|
686
|
+
}
|
687
|
+
};
|
688
|
+
Object.defineProperty(DomApi.prototype, "classList", {
|
689
|
+
get: function() {
|
690
|
+
if (!this._classList) {
|
691
|
+
this._classList = new DomApi.ClassList(this);
|
692
|
+
}
|
693
|
+
return this._classList;
|
694
|
+
},
|
695
|
+
configurable: true
|
696
|
+
});
|
697
|
+
DomApi.ClassList = function(host) {
|
698
|
+
this.domApi = host;
|
699
|
+
this.node = host.node;
|
700
|
+
};
|
701
|
+
DomApi.ClassList.prototype = {
|
702
|
+
add: function() {
|
703
|
+
this.node.classList.add.apply(this.node.classList, arguments);
|
704
|
+
this.domApi._distributeParent();
|
705
|
+
},
|
706
|
+
remove: function() {
|
707
|
+
this.node.classList.remove.apply(this.node.classList, arguments);
|
708
|
+
this.domApi._distributeParent();
|
709
|
+
},
|
710
|
+
toggle: function() {
|
711
|
+
this.node.classList.toggle.apply(this.node.classList, arguments);
|
712
|
+
this.domApi._distributeParent();
|
713
|
+
}
|
714
|
+
};
|
715
|
+
if (!Settings.useShadow) {
|
716
|
+
Object.defineProperties(DomApi.prototype, {
|
717
|
+
childNodes: {
|
718
|
+
get: function() {
|
719
|
+
var c$ = getLightChildren(this.node);
|
720
|
+
return Array.isArray(c$) ? c$ : Array.prototype.slice.call(c$);
|
721
|
+
},
|
722
|
+
configurable: true
|
723
|
+
},
|
724
|
+
children: {
|
725
|
+
get: function() {
|
726
|
+
return Array.prototype.filter.call(this.childNodes, function(n) {
|
727
|
+
return n.nodeType === Node.ELEMENT_NODE;
|
728
|
+
});
|
729
|
+
},
|
730
|
+
configurable: true
|
731
|
+
},
|
732
|
+
parentNode: {
|
733
|
+
get: function() {
|
734
|
+
return this.node._lightParent || (this.node.__patched ? this.node._composedParent : this.node.parentNode);
|
735
|
+
},
|
736
|
+
configurable: true
|
737
|
+
},
|
738
|
+
firstChild: {
|
739
|
+
get: function() {
|
740
|
+
return this.childNodes[0];
|
741
|
+
},
|
742
|
+
configurable: true
|
743
|
+
},
|
744
|
+
lastChild: {
|
745
|
+
get: function() {
|
746
|
+
var c$ = this.childNodes;
|
747
|
+
return c$[c$.length - 1];
|
748
|
+
},
|
749
|
+
configurable: true
|
750
|
+
},
|
751
|
+
nextSibling: {
|
752
|
+
get: function() {
|
753
|
+
var c$ = this.parentNode && factory(this.parentNode).childNodes;
|
754
|
+
if (c$) {
|
755
|
+
return c$[Array.prototype.indexOf.call(c$, this.node) + 1];
|
756
|
+
}
|
757
|
+
},
|
758
|
+
configurable: true
|
759
|
+
},
|
760
|
+
previousSibling: {
|
761
|
+
get: function() {
|
762
|
+
var c$ = this.parentNode && factory(this.parentNode).childNodes;
|
763
|
+
if (c$) {
|
764
|
+
return c$[Array.prototype.indexOf.call(c$, this.node) - 1];
|
765
|
+
}
|
766
|
+
},
|
767
|
+
configurable: true
|
768
|
+
},
|
769
|
+
firstElementChild: {
|
770
|
+
get: function() {
|
771
|
+
return this.children[0];
|
772
|
+
},
|
773
|
+
configurable: true
|
774
|
+
},
|
775
|
+
lastElementChild: {
|
776
|
+
get: function() {
|
777
|
+
var c$ = this.children;
|
778
|
+
return c$[c$.length - 1];
|
779
|
+
},
|
780
|
+
configurable: true
|
781
|
+
},
|
782
|
+
nextElementSibling: {
|
783
|
+
get: function() {
|
784
|
+
var c$ = this.parentNode && factory(this.parentNode).children;
|
785
|
+
if (c$) {
|
786
|
+
return c$[Array.prototype.indexOf.call(c$, this.node) + 1];
|
787
|
+
}
|
788
|
+
},
|
789
|
+
configurable: true
|
790
|
+
},
|
791
|
+
previousElementSibling: {
|
792
|
+
get: function() {
|
793
|
+
var c$ = this.parentNode && factory(this.parentNode).children;
|
794
|
+
if (c$) {
|
795
|
+
return c$[Array.prototype.indexOf.call(c$, this.node) - 1];
|
796
|
+
}
|
797
|
+
},
|
798
|
+
configurable: true
|
799
|
+
},
|
800
|
+
textContent: {
|
801
|
+
get: function() {
|
802
|
+
if (this.node.nodeType === Node.TEXT_NODE) {
|
803
|
+
return this.node.textContent;
|
804
|
+
} else {
|
805
|
+
return Array.prototype.map.call(this.childNodes, function(c) {
|
806
|
+
return c.textContent;
|
807
|
+
}).join("");
|
808
|
+
}
|
809
|
+
},
|
810
|
+
set: function(text) {
|
811
|
+
this._clear();
|
812
|
+
if (text) {
|
813
|
+
this.appendChild(document.createTextNode(text));
|
814
|
+
}
|
815
|
+
},
|
816
|
+
configurable: true
|
817
|
+
},
|
818
|
+
innerHTML: {
|
819
|
+
get: function() {
|
820
|
+
if (this.node.nodeType === Node.TEXT_NODE) {
|
821
|
+
return null;
|
822
|
+
} else {
|
823
|
+
return getInnerHTML(this.node);
|
824
|
+
}
|
825
|
+
},
|
826
|
+
set: function(text) {
|
827
|
+
if (this.node.nodeType !== Node.TEXT_NODE) {
|
828
|
+
this._clear();
|
829
|
+
var d = document.createElement("div");
|
830
|
+
d.innerHTML = text;
|
831
|
+
for (var e = d.firstChild; e; e = e.nextSibling) {
|
832
|
+
this.appendChild(e);
|
833
|
+
}
|
834
|
+
}
|
835
|
+
},
|
836
|
+
configurable: true
|
837
|
+
}
|
838
|
+
});
|
839
|
+
DomApi.prototype._getComposedInnerHTML = function() {
|
840
|
+
return getInnerHTML(this.node, true);
|
841
|
+
};
|
842
|
+
} else {
|
843
|
+
DomApi.prototype.querySelectorAll = function(selector) {
|
844
|
+
return Array.prototype.slice.call(this.node.querySelectorAll(selector));
|
845
|
+
};
|
846
|
+
DomApi.prototype.getOwnerRoot = function() {
|
847
|
+
var n = this.node;
|
848
|
+
while (n) {
|
849
|
+
if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE && n.host) {
|
850
|
+
return n;
|
851
|
+
}
|
852
|
+
n = n.parentNode;
|
853
|
+
}
|
854
|
+
};
|
855
|
+
DomApi.prototype.getDestinationInsertionPoints = function() {
|
856
|
+
var n$ = this.node.getDestinationInsertionPoints();
|
857
|
+
return n$ ? Array.prototype.slice.call(n$) : [];
|
858
|
+
};
|
859
|
+
DomApi.prototype.getDistributedNodes = function() {
|
860
|
+
var n$ = this.node.getDistributedNodes();
|
861
|
+
return n$ ? Array.prototype.slice.call(n$) : [];
|
862
|
+
};
|
863
|
+
DomApi.prototype._distributeParent = function() {};
|
864
|
+
Object.defineProperties(DomApi.prototype, {
|
865
|
+
childNodes: {
|
866
|
+
get: function() {
|
867
|
+
return Array.prototype.slice.call(this.node.childNodes);
|
868
|
+
},
|
869
|
+
configurable: true
|
870
|
+
},
|
871
|
+
children: {
|
872
|
+
get: function() {
|
873
|
+
return Array.prototype.slice.call(this.node.children);
|
874
|
+
},
|
875
|
+
configurable: true
|
876
|
+
},
|
877
|
+
textContent: {
|
878
|
+
get: function() {
|
879
|
+
return this.node.textContent;
|
880
|
+
},
|
881
|
+
set: function(value) {
|
882
|
+
return this.node.textContent = value;
|
883
|
+
},
|
884
|
+
configurable: true
|
885
|
+
},
|
886
|
+
innerHTML: {
|
887
|
+
get: function() {
|
888
|
+
return this.node.innerHTML;
|
889
|
+
},
|
890
|
+
set: function(value) {
|
891
|
+
return this.node.innerHTML = value;
|
892
|
+
},
|
893
|
+
configurable: true
|
894
|
+
}
|
895
|
+
});
|
896
|
+
var forwards = [ "parentNode", "firstChild", "lastChild", "nextSibling", "previousSibling", "firstElementChild", "lastElementChild", "nextElementSibling", "previousElementSibling" ];
|
897
|
+
forwards.forEach(function(name) {
|
898
|
+
Object.defineProperty(DomApi.prototype, name, {
|
899
|
+
get: function() {
|
900
|
+
return this.node[name];
|
901
|
+
},
|
902
|
+
configurable: true
|
903
|
+
});
|
904
|
+
});
|
905
|
+
}
|
906
|
+
var CONTENT = "content";
|
907
|
+
var factory = function(node, patch) {
|
908
|
+
node = node || document;
|
909
|
+
if (!node.__domApi) {
|
910
|
+
node.__domApi = new DomApi(node, patch);
|
911
|
+
}
|
912
|
+
return node.__domApi;
|
913
|
+
};
|
914
|
+
Polymer.dom = function(obj, patch) {
|
915
|
+
if (obj instanceof Event) {
|
916
|
+
return Polymer.EventApi.factory(obj);
|
917
|
+
} else {
|
918
|
+
return factory(obj, patch);
|
919
|
+
}
|
920
|
+
};
|
921
|
+
Polymer.dom.flush = DomApi.prototype.flush;
|
922
|
+
function getLightChildren(node) {
|
923
|
+
var children = node._lightChildren;
|
924
|
+
return children ? children : node.childNodes;
|
925
|
+
}
|
926
|
+
function getComposedChildren(node) {
|
927
|
+
if (!node._composedChildren) {
|
928
|
+
node._composedChildren = Array.prototype.slice.call(node.childNodes);
|
929
|
+
}
|
930
|
+
return node._composedChildren;
|
931
|
+
}
|
932
|
+
function addToComposedParent(parent, node, ref_node) {
|
933
|
+
var children = getComposedChildren(parent);
|
934
|
+
var i = ref_node ? children.indexOf(ref_node) : -1;
|
935
|
+
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
936
|
+
var fragChildren = getComposedChildren(node);
|
937
|
+
fragChildren.forEach(function(c) {
|
938
|
+
addNodeToComposedChildren(c, parent, children, i);
|
939
|
+
});
|
940
|
+
} else {
|
941
|
+
addNodeToComposedChildren(node, parent, children, i);
|
942
|
+
}
|
943
|
+
}
|
944
|
+
function addNodeToComposedChildren(node, parent, children, i) {
|
945
|
+
node._composedParent = parent;
|
946
|
+
if (i >= 0) {
|
947
|
+
children.splice(i, 0, node);
|
948
|
+
} else {
|
949
|
+
children.push(node);
|
950
|
+
}
|
951
|
+
}
|
952
|
+
function removeFromComposedParent(parent, node) {
|
953
|
+
node._composedParent = null;
|
954
|
+
if (parent) {
|
955
|
+
var children = getComposedChildren(parent);
|
956
|
+
var i = children.indexOf(node);
|
957
|
+
if (i >= 0) {
|
958
|
+
children.splice(i, 1);
|
959
|
+
}
|
960
|
+
}
|
961
|
+
}
|
962
|
+
function saveLightChildrenIfNeeded(node) {
|
963
|
+
if (!node._lightChildren) {
|
964
|
+
var c$ = Array.prototype.slice.call(node.childNodes);
|
965
|
+
for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) {
|
966
|
+
child._lightParent = child._lightParent || node;
|
967
|
+
}
|
968
|
+
node._lightChildren = c$;
|
969
|
+
}
|
970
|
+
}
|
971
|
+
function hasInsertionPoint(root) {
|
972
|
+
return Boolean(root._insertionPoints.length);
|
973
|
+
}
|
974
|
+
var p = Element.prototype;
|
975
|
+
var matchesSelector = p.matches || p.matchesSelector || p.mozMatchesSelector || p.msMatchesSelector || p.oMatchesSelector || p.webkitMatchesSelector;
|
976
|
+
return {
|
977
|
+
getLightChildren: getLightChildren,
|
978
|
+
getComposedChildren: getComposedChildren,
|
979
|
+
removeFromComposedParent: removeFromComposedParent,
|
980
|
+
saveLightChildrenIfNeeded: saveLightChildrenIfNeeded,
|
981
|
+
matchesSelector: matchesSelector,
|
982
|
+
hasInsertionPoint: hasInsertionPoint,
|
983
|
+
ctor: DomApi,
|
984
|
+
factory: factory
|
985
|
+
};
|
986
|
+
}();
|
987
|
+
|
988
|
+
(function() {
|
989
|
+
Polymer.Base._addFeature({
|
990
|
+
_prepShady: function() {
|
991
|
+
this._useContent = this._useContent || Boolean(this._template);
|
992
|
+
if (this._useContent) {
|
993
|
+
this._template._hasInsertionPoint = this._template.content.querySelector("content");
|
994
|
+
}
|
995
|
+
},
|
996
|
+
_poolContent: function() {
|
997
|
+
if (this._useContent) {
|
998
|
+
saveLightChildrenIfNeeded(this);
|
999
|
+
}
|
1000
|
+
},
|
1001
|
+
_setupRoot: function() {
|
1002
|
+
if (this._useContent) {
|
1003
|
+
this._createLocalRoot();
|
1004
|
+
if (!this.dataHost) {
|
1005
|
+
upgradeLightChildren(this._lightChildren);
|
1006
|
+
}
|
1007
|
+
}
|
1008
|
+
},
|
1009
|
+
_createLocalRoot: function() {
|
1010
|
+
this.shadyRoot = this.root;
|
1011
|
+
this.shadyRoot._distributionClean = false;
|
1012
|
+
this.shadyRoot._isShadyRoot = true;
|
1013
|
+
this.shadyRoot._dirtyRoots = [];
|
1014
|
+
this.shadyRoot._insertionPoints = this._template._hasInsertionPoint ? this.shadyRoot.querySelectorAll("content") : [];
|
1015
|
+
saveLightChildrenIfNeeded(this.shadyRoot);
|
1016
|
+
this.shadyRoot.host = this;
|
1017
|
+
},
|
1018
|
+
get domHost() {
|
1019
|
+
var root = Polymer.dom(this).getOwnerRoot();
|
1020
|
+
return root && root.host;
|
1021
|
+
},
|
1022
|
+
distributeContent: function() {
|
1023
|
+
if (this.shadyRoot) {
|
1024
|
+
var host = getTopDistributingHost(this);
|
1025
|
+
Polymer.dom(this)._lazyDistribute(host);
|
1026
|
+
}
|
1027
|
+
},
|
1028
|
+
_distributeContent: function() {
|
1029
|
+
if (this._useContent && !this.shadyRoot._distributionClean) {
|
1030
|
+
this._beginDistribute();
|
1031
|
+
this._distributeDirtyRoots();
|
1032
|
+
this._finishDistribute();
|
1033
|
+
}
|
1034
|
+
},
|
1035
|
+
_beginDistribute: function() {
|
1036
|
+
if (this._useContent && hasInsertionPoint(this.shadyRoot)) {
|
1037
|
+
this._resetDistribution();
|
1038
|
+
this._distributePool(this.shadyRoot, this._collectPool());
|
1039
|
+
}
|
1040
|
+
},
|
1041
|
+
_distributeDirtyRoots: function() {
|
1042
|
+
var c$ = this.shadyRoot._dirtyRoots;
|
1043
|
+
for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
|
1044
|
+
c._distributeContent();
|
1045
|
+
}
|
1046
|
+
this.shadyRoot._dirtyRoots = [];
|
1047
|
+
},
|
1048
|
+
_finishDistribute: function() {
|
1049
|
+
if (this._useContent) {
|
1050
|
+
if (hasInsertionPoint(this.shadyRoot)) {
|
1051
|
+
this._composeTree();
|
1052
|
+
} else {
|
1053
|
+
if (!this.shadyRoot._hasDistributed) {
|
1054
|
+
this.textContent = "";
|
1055
|
+
this.appendChild(this.shadyRoot);
|
1056
|
+
} else {
|
1057
|
+
var children = this._composeNode(this);
|
1058
|
+
this._updateChildNodes(this, children);
|
1059
|
+
}
|
1060
|
+
}
|
1061
|
+
this.shadyRoot._hasDistributed = true;
|
1062
|
+
this.shadyRoot._distributionClean = true;
|
1063
|
+
}
|
1064
|
+
},
|
1065
|
+
elementMatches: function(selector, node) {
|
1066
|
+
node = node || this;
|
1067
|
+
return matchesSelector.call(node, selector);
|
1068
|
+
},
|
1069
|
+
_resetDistribution: function() {
|
1070
|
+
var children = getLightChildren(this);
|
1071
|
+
for (var i = 0; i < children.length; i++) {
|
1072
|
+
var child = children[i];
|
1073
|
+
if (child._destinationInsertionPoints) {
|
1074
|
+
child._destinationInsertionPoints = undefined;
|
1075
|
+
}
|
1076
|
+
if (isInsertionPoint(child)) {
|
1077
|
+
clearDistributedDestinationInsertionPoints(child);
|
1078
|
+
}
|
1079
|
+
}
|
1080
|
+
var root = this.shadyRoot;
|
1081
|
+
var p$ = root._insertionPoints;
|
1082
|
+
for (var j = 0; j < p$.length; j++) {
|
1083
|
+
p$[j]._distributedNodes = [];
|
1084
|
+
}
|
1085
|
+
},
|
1086
|
+
_collectPool: function() {
|
1087
|
+
var pool = [];
|
1088
|
+
var children = getLightChildren(this);
|
1089
|
+
for (var i = 0; i < children.length; i++) {
|
1090
|
+
var child = children[i];
|
1091
|
+
if (isInsertionPoint(child)) {
|
1092
|
+
pool.push.apply(pool, child._distributedNodes);
|
1093
|
+
} else {
|
1094
|
+
pool.push(child);
|
1095
|
+
}
|
1096
|
+
}
|
1097
|
+
return pool;
|
1098
|
+
},
|
1099
|
+
_distributePool: function(node, pool) {
|
1100
|
+
var p$ = node._insertionPoints;
|
1101
|
+
for (var i = 0, l = p$.length, p; i < l && (p = p$[i]); i++) {
|
1102
|
+
this._distributeInsertionPoint(p, pool);
|
1103
|
+
maybeRedistributeParent(p, this);
|
1104
|
+
}
|
1105
|
+
},
|
1106
|
+
_distributeInsertionPoint: function(content, pool) {
|
1107
|
+
var anyDistributed = false;
|
1108
|
+
for (var i = 0, l = pool.length, node; i < l; i++) {
|
1109
|
+
node = pool[i];
|
1110
|
+
if (!node) {
|
1111
|
+
continue;
|
1112
|
+
}
|
1113
|
+
if (this._matchesContentSelect(node, content)) {
|
1114
|
+
distributeNodeInto(node, content);
|
1115
|
+
pool[i] = undefined;
|
1116
|
+
anyDistributed = true;
|
1117
|
+
}
|
1118
|
+
}
|
1119
|
+
if (!anyDistributed) {
|
1120
|
+
var children = getLightChildren(content);
|
1121
|
+
for (var j = 0; j < children.length; j++) {
|
1122
|
+
distributeNodeInto(children[j], content);
|
1123
|
+
}
|
1124
|
+
}
|
1125
|
+
},
|
1126
|
+
_composeTree: function() {
|
1127
|
+
this._updateChildNodes(this, this._composeNode(this));
|
1128
|
+
var p$ = this.shadyRoot._insertionPoints;
|
1129
|
+
for (var i = 0, l = p$.length, p, parent; i < l && (p = p$[i]); i++) {
|
1130
|
+
parent = p._lightParent || p.parentNode;
|
1131
|
+
if (!parent._useContent && parent !== this && parent !== this.shadyRoot) {
|
1132
|
+
this._updateChildNodes(parent, this._composeNode(parent));
|
1133
|
+
}
|
1134
|
+
}
|
1135
|
+
},
|
1136
|
+
_composeNode: function(node) {
|
1137
|
+
var children = [];
|
1138
|
+
var c$ = getLightChildren(node.shadyRoot || node);
|
1139
|
+
for (var i = 0; i < c$.length; i++) {
|
1140
|
+
var child = c$[i];
|
1141
|
+
if (isInsertionPoint(child)) {
|
1142
|
+
var distributedNodes = child._distributedNodes;
|
1143
|
+
for (var j = 0; j < distributedNodes.length; j++) {
|
1144
|
+
var distributedNode = distributedNodes[j];
|
1145
|
+
if (isFinalDestination(child, distributedNode)) {
|
1146
|
+
children.push(distributedNode);
|
1147
|
+
}
|
1148
|
+
}
|
1149
|
+
} else {
|
1150
|
+
children.push(child);
|
1151
|
+
}
|
1152
|
+
}
|
1153
|
+
return children;
|
1154
|
+
},
|
1155
|
+
_updateChildNodes: function(container, children) {
|
1156
|
+
var composed = getComposedChildren(container);
|
1157
|
+
var splices = Polymer.ArraySplice.calculateSplices(children, composed);
|
1158
|
+
for (var i = 0, d = 0, s; i < splices.length && (s = splices[i]); i++) {
|
1159
|
+
for (var j = 0, n; j < s.removed.length && (n = s.removed[j]); j++) {
|
1160
|
+
remove(n);
|
1161
|
+
composed.splice(s.index + d, 1);
|
1162
|
+
}
|
1163
|
+
d -= s.addedCount;
|
1164
|
+
}
|
1165
|
+
for (var i = 0, s, next; i < splices.length && (s = splices[i]); i++) {
|
1166
|
+
next = composed[s.index];
|
1167
|
+
for (var j = s.index, n; j < s.index + s.addedCount; j++) {
|
1168
|
+
n = children[j];
|
1169
|
+
insertBefore(container, n, next);
|
1170
|
+
composed.splice(j, 0, n);
|
1171
|
+
}
|
1172
|
+
}
|
1173
|
+
},
|
1174
|
+
_matchesContentSelect: function(node, contentElement) {
|
1175
|
+
var select = contentElement.getAttribute("select");
|
1176
|
+
if (!select) {
|
1177
|
+
return true;
|
1178
|
+
}
|
1179
|
+
select = select.trim();
|
1180
|
+
if (!select) {
|
1181
|
+
return true;
|
1182
|
+
}
|
1183
|
+
if (!(node instanceof Element)) {
|
1184
|
+
return false;
|
1185
|
+
}
|
1186
|
+
var validSelectors = /^(:not\()?[*.#[a-zA-Z_|]/;
|
1187
|
+
if (!validSelectors.test(select)) {
|
1188
|
+
return false;
|
1189
|
+
}
|
1190
|
+
return this.elementMatches(select, node);
|
1191
|
+
},
|
1192
|
+
_elementAdd: function() {},
|
1193
|
+
_elementRemove: function() {}
|
1194
|
+
});
|
1195
|
+
var saveLightChildrenIfNeeded = Polymer.DomApi.saveLightChildrenIfNeeded;
|
1196
|
+
var getLightChildren = Polymer.DomApi.getLightChildren;
|
1197
|
+
var matchesSelector = Polymer.DomApi.matchesSelector;
|
1198
|
+
var hasInsertionPoint = Polymer.DomApi.hasInsertionPoint;
|
1199
|
+
var getComposedChildren = Polymer.DomApi.getComposedChildren;
|
1200
|
+
var removeFromComposedParent = Polymer.DomApi.removeFromComposedParent;
|
1201
|
+
function distributeNodeInto(child, insertionPoint) {
|
1202
|
+
insertionPoint._distributedNodes.push(child);
|
1203
|
+
var points = child._destinationInsertionPoints;
|
1204
|
+
if (!points) {
|
1205
|
+
child._destinationInsertionPoints = [ insertionPoint ];
|
1206
|
+
} else {
|
1207
|
+
points.push(insertionPoint);
|
1208
|
+
}
|
1209
|
+
}
|
1210
|
+
function clearDistributedDestinationInsertionPoints(content) {
|
1211
|
+
var e$ = content._distributedNodes;
|
1212
|
+
for (var i = 0; i < e$.length; i++) {
|
1213
|
+
var d = e$[i]._destinationInsertionPoints;
|
1214
|
+
if (d) {
|
1215
|
+
d.splice(d.indexOf(content) + 1, d.length);
|
1216
|
+
}
|
1217
|
+
}
|
1218
|
+
}
|
1219
|
+
function maybeRedistributeParent(content, host) {
|
1220
|
+
var parent = content._lightParent;
|
1221
|
+
if (parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot) && parent.shadyRoot._distributionClean) {
|
1222
|
+
parent.shadyRoot._distributionClean = false;
|
1223
|
+
host.shadyRoot._dirtyRoots.push(parent);
|
1224
|
+
}
|
1225
|
+
}
|
1226
|
+
function isFinalDestination(insertionPoint, node) {
|
1227
|
+
var points = node._destinationInsertionPoints;
|
1228
|
+
return points && points[points.length - 1] === insertionPoint;
|
1229
|
+
}
|
1230
|
+
function isInsertionPoint(node) {
|
1231
|
+
return node.localName == "content";
|
1232
|
+
}
|
1233
|
+
var nativeInsertBefore = Element.prototype.insertBefore;
|
1234
|
+
var nativeRemoveChild = Element.prototype.removeChild;
|
1235
|
+
function insertBefore(parentNode, newChild, refChild) {
|
1236
|
+
var newChildParent = getComposedParent(newChild);
|
1237
|
+
if (newChildParent !== parentNode) {
|
1238
|
+
removeFromComposedParent(newChildParent, newChild);
|
1239
|
+
}
|
1240
|
+
remove(newChild);
|
1241
|
+
saveLightChildrenIfNeeded(parentNode);
|
1242
|
+
nativeInsertBefore.call(parentNode, newChild, refChild || null);
|
1243
|
+
newChild._composedParent = parentNode;
|
1244
|
+
}
|
1245
|
+
function remove(node) {
|
1246
|
+
var parentNode = getComposedParent(node);
|
1247
|
+
if (parentNode) {
|
1248
|
+
saveLightChildrenIfNeeded(parentNode);
|
1249
|
+
node._composedParent = null;
|
1250
|
+
nativeRemoveChild.call(parentNode, node);
|
1251
|
+
}
|
1252
|
+
}
|
1253
|
+
function getComposedParent(node) {
|
1254
|
+
return node.__patched ? node._composedParent : node.parentNode;
|
1255
|
+
}
|
1256
|
+
function getTopDistributingHost(host) {
|
1257
|
+
while (host && hostNeedsRedistribution(host)) {
|
1258
|
+
host = host.domHost;
|
1259
|
+
}
|
1260
|
+
return host;
|
1261
|
+
}
|
1262
|
+
function hostNeedsRedistribution(host) {
|
1263
|
+
var c$ = Polymer.dom(host).children;
|
1264
|
+
for (var i = 0, c; i < c$.length; i++) {
|
1265
|
+
c = c$[i];
|
1266
|
+
if (c.localName === "content") {
|
1267
|
+
return host.domHost;
|
1268
|
+
}
|
1269
|
+
}
|
1270
|
+
}
|
1271
|
+
var needsUpgrade = window.CustomElements && !CustomElements.useNative;
|
1272
|
+
function upgradeLightChildren(children) {
|
1273
|
+
if (needsUpgrade && children) {
|
1274
|
+
for (var i = 0; i < children.length; i++) {
|
1275
|
+
CustomElements.upgrade(children[i]);
|
1276
|
+
}
|
1277
|
+
}
|
1278
|
+
}
|
1279
|
+
})();
|
1280
|
+
|
1281
|
+
if (Polymer.Settings.useShadow) {
|
1282
|
+
Polymer.Base._addFeature({
|
1283
|
+
_poolContent: function() {},
|
1284
|
+
_beginDistribute: function() {},
|
1285
|
+
distributeContent: function() {},
|
1286
|
+
_distributeContent: function() {},
|
1287
|
+
_finishDistribute: function() {},
|
1288
|
+
_createLocalRoot: function() {
|
1289
|
+
this.createShadowRoot();
|
1290
|
+
this.shadowRoot.appendChild(this.root);
|
1291
|
+
this.root = this.shadowRoot;
|
1292
|
+
}
|
1293
|
+
});
|
1294
|
+
}
|
1295
|
+
|
1296
|
+
Polymer.DomModule = document.createElement("dom-module");
|
1297
|
+
|
1298
|
+
Polymer.Base._addFeature({
|
1299
|
+
_registerFeatures: function() {
|
1300
|
+
this._prepIs();
|
1301
|
+
this._prepAttributes();
|
1302
|
+
this._prepBehaviors();
|
1303
|
+
this._prepExtends();
|
1304
|
+
this._prepConstructor();
|
1305
|
+
this._prepTemplate();
|
1306
|
+
this._prepShady();
|
1307
|
+
},
|
1308
|
+
_prepBehavior: function(b) {
|
1309
|
+
this._addHostAttributes(b.hostAttributes);
|
1310
|
+
},
|
1311
|
+
_initFeatures: function() {
|
1312
|
+
this._poolContent();
|
1313
|
+
this._pushHost();
|
1314
|
+
this._stampTemplate();
|
1315
|
+
this._popHost();
|
1316
|
+
this._marshalHostAttributes();
|
1317
|
+
this._setupDebouncers();
|
1318
|
+
this._marshalBehaviors();
|
1319
|
+
this._tryReady();
|
1320
|
+
},
|
1321
|
+
_marshalBehavior: function(b) {}
|
1322
|
+
});</script>
|