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,40 +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
|
-
/**
|
13
|
-
* Automatically extend using objects referenced in `mixins` array.
|
14
|
-
*
|
15
|
-
* Polymer({
|
16
|
-
*
|
17
|
-
* mixins: [
|
18
|
-
* someMixinObject
|
19
|
-
* ]
|
20
|
-
*
|
21
|
-
* ...
|
22
|
-
*
|
23
|
-
* });
|
24
|
-
*
|
25
|
-
* @class base feature: mixins
|
26
|
-
*/
|
27
|
-
|
28
|
-
Polymer.Base.addFeature({
|
29
|
-
|
30
|
-
_prepMixins: function() {
|
31
|
-
if (this.mixins) {
|
32
|
-
this.mixins.forEach(function(m) {
|
33
|
-
Polymer.Base.extend(this, m);
|
34
|
-
}, this);
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
});
|
39
|
-
|
40
|
-
</script>
|
@@ -1,96 +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
|
-
/**
|
13
|
-
* Define property metadata.
|
14
|
-
*
|
15
|
-
* properties: {
|
16
|
-
* <property>: <Type || Object>,
|
17
|
-
* ...
|
18
|
-
* }
|
19
|
-
*
|
20
|
-
* Example:
|
21
|
-
*
|
22
|
-
* properties: {
|
23
|
-
* // `foo` property can be assigned via attribute, will be deserialized to
|
24
|
-
* // the specified data-type. All `properties` properties have this behavior.
|
25
|
-
* foo: String,
|
26
|
-
*
|
27
|
-
* // `bar` property has additional behavior specifiers.
|
28
|
-
* // type: as above, type for (de-)serialization
|
29
|
-
* // notify: true to send a signal when a value is set to this property
|
30
|
-
* // reflectToAttribute: true to serialize the property to an attribute
|
31
|
-
* // readOnly: if true, the property has no setter
|
32
|
-
* bar: {
|
33
|
-
* type: Boolean,
|
34
|
-
* notify: true
|
35
|
-
* }
|
36
|
-
* }
|
37
|
-
*
|
38
|
-
* By itself the properties feature doesn't do anything but provide property
|
39
|
-
* information. Other features use this information to control behavior.
|
40
|
-
*
|
41
|
-
* The `type` information is used by the `attributes` feature to convert
|
42
|
-
* String values in attributes to typed properties. The `bind` feature uses
|
43
|
-
* property information to control property access.
|
44
|
-
*
|
45
|
-
* Marking a property as `notify` causes a change in the property to
|
46
|
-
* fire a non-bubbling event called `<property>-changed`. Elements that
|
47
|
-
* have enabled two-way binding to the property use this event to
|
48
|
-
* observe changes.
|
49
|
-
*
|
50
|
-
* `readOnly` properties have a getter, but no setter. To set a read-only
|
51
|
-
* property, use the private setter method `_set_<property>(value)`.
|
52
|
-
*
|
53
|
-
* @class base feature: properties
|
54
|
-
*/
|
55
|
-
|
56
|
-
// null object
|
57
|
-
Polymer.nob = Object.create(null);
|
58
|
-
|
59
|
-
Polymer.Base.addFeature({
|
60
|
-
|
61
|
-
properties: {
|
62
|
-
},
|
63
|
-
|
64
|
-
getPropertyInfo: function(property) {
|
65
|
-
return this._getPropertyInfo(property, this.properties);
|
66
|
-
},
|
67
|
-
|
68
|
-
_getPropertyInfo: function(property, properties) {
|
69
|
-
var p = properties[property];
|
70
|
-
if (typeof(p) === 'function') {
|
71
|
-
p = properties[property] = {
|
72
|
-
type: p
|
73
|
-
};
|
74
|
-
}
|
75
|
-
return p || Polymer.nob;
|
76
|
-
},
|
77
|
-
|
78
|
-
getPropertyType: function(property) {
|
79
|
-
return this.getPropertyInfo(property).type;
|
80
|
-
},
|
81
|
-
|
82
|
-
isReadOnlyProperty: function(property) {
|
83
|
-
return this.getPropertyInfo(property).readOnly;
|
84
|
-
},
|
85
|
-
|
86
|
-
isNotifyProperty: function(property) {
|
87
|
-
return this.getPropertyInfo(property).notify;
|
88
|
-
},
|
89
|
-
|
90
|
-
isReflectedProperty: function(property) {
|
91
|
-
return this.getPropertyInfo(property).reflectToAttribute;
|
92
|
-
}
|
93
|
-
|
94
|
-
});
|
95
|
-
|
96
|
-
</script>
|
@@ -1,28 +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.Base.addFeature({
|
13
|
-
|
14
|
-
_prepIs: function() {
|
15
|
-
if (!this.is) {
|
16
|
-
var module =
|
17
|
-
(document._currentScript || document.currentScript).parentNode;
|
18
|
-
if (module.localName === 'dom-module') {
|
19
|
-
var id = module.id || module.getAttribute('name')
|
20
|
-
|| module.getAttribute('is')
|
21
|
-
this.is = id;
|
22
|
-
}
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
});
|
27
|
-
|
28
|
-
</script>
|
@@ -1,180 +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
|
-
/**
|
13
|
-
* Provides `ready` lifecycle callback which is called parent to child.
|
14
|
-
*
|
15
|
-
* This can be useful in a number of cases. Here are some examples:
|
16
|
-
*
|
17
|
-
* Setting a default property value that should have a side effect: To ensure
|
18
|
-
* the side effect, an element must set a default value no sooner than
|
19
|
-
* `created`; however, since `created` flows child to host, this is before the
|
20
|
-
* host has had a chance to set a property value on the child. The `ready`
|
21
|
-
* method solves this problem since it's called host to child.
|
22
|
-
*
|
23
|
-
* Dom distribution: To support reprojection efficiently, it's important to
|
24
|
-
* distribute from host to child in one shot. The `attachedCallback` mostly
|
25
|
-
* goes in the desired order except for elements that are in dom to start; in
|
26
|
-
* this case, all children are attached before the host element. Ready also
|
27
|
-
* addresses this case since it's guaranteed to be called host to child.
|
28
|
-
*
|
29
|
-
* @class standard feature: ready
|
30
|
-
*/
|
31
|
-
|
32
|
-
(function() {
|
33
|
-
|
34
|
-
var baseAttachedCallback = Polymer.Base.attachedCallback;
|
35
|
-
var baseDetachedCallback = Polymer.Base.detachedCallback;
|
36
|
-
|
37
|
-
Polymer.Base.addFeature({
|
38
|
-
|
39
|
-
hostStack: [],
|
40
|
-
_readied: false,
|
41
|
-
_attachedPending: false,
|
42
|
-
|
43
|
-
// for overriding
|
44
|
-
configure: function() {
|
45
|
-
},
|
46
|
-
|
47
|
-
// for overriding
|
48
|
-
ready: function() {
|
49
|
-
},
|
50
|
-
|
51
|
-
/**
|
52
|
-
Returns the host of the local dom in which this element exists.
|
53
|
-
This is a shorthand for Polymer.dom(this).getOwnerRoot().host
|
54
|
-
*/
|
55
|
-
get host() {
|
56
|
-
return this._host || (this._host = this._queryHost());
|
57
|
-
},
|
58
|
-
|
59
|
-
set host(value) {
|
60
|
-
this._host = value;
|
61
|
-
},
|
62
|
-
|
63
|
-
_queryHost: function(node) {
|
64
|
-
var ownerRoot = Polymer.dom(this).getOwnerRoot();
|
65
|
-
return ownerRoot && ownerRoot.host;
|
66
|
-
},
|
67
|
-
|
68
|
-
// NOTE: The concept of 'host' is overloaded. There are two different
|
69
|
-
// notions:
|
70
|
-
// 1. an element hosts the elements in its local dom root.
|
71
|
-
// 2. an element hosts the elements on which it configures data.
|
72
|
-
// Practially, these notions are almost always coincident.
|
73
|
-
// Some special elements like templates may separate them.
|
74
|
-
// In order not to over-emphaisize this technical difference, we expose
|
75
|
-
// one concept to the user and it maps to the dom-related meaning of host.
|
76
|
-
//
|
77
|
-
// 1. set this element's `host` and push this element onto the `host`'s
|
78
|
-
// list of `client` elements
|
79
|
-
// 2. establish this element as the current hosting element (allows
|
80
|
-
// any elements we stamp to easily set host to us).
|
81
|
-
_pushHost: function(host) {
|
82
|
-
this.host = host = host ||
|
83
|
-
Polymer.Base.hostStack[Polymer.Base.hostStack.length-1];
|
84
|
-
if (host && host._clients) {
|
85
|
-
host._clients.push(this);
|
86
|
-
}
|
87
|
-
this._beginHost();
|
88
|
-
},
|
89
|
-
|
90
|
-
_beginHost: function() {
|
91
|
-
Polymer.Base.hostStack.push(this);
|
92
|
-
if (!this._clients) {
|
93
|
-
this._clients = [];
|
94
|
-
}
|
95
|
-
},
|
96
|
-
|
97
|
-
_popHost: function() {
|
98
|
-
// this element is no longer the current hosting element
|
99
|
-
Polymer.Base.hostStack.pop();
|
100
|
-
},
|
101
|
-
|
102
|
-
_readyContent: function() {
|
103
|
-
if (this._canReady()) {
|
104
|
-
this._initializeContent();
|
105
|
-
}
|
106
|
-
},
|
107
|
-
|
108
|
-
_canReady: function() {
|
109
|
-
return !this._readied && (!this.host || this.host._readied);
|
110
|
-
},
|
111
|
-
|
112
|
-
_initializeContent: function() {
|
113
|
-
// prepare root
|
114
|
-
this._setupRoot();
|
115
|
-
// logically distribute self
|
116
|
-
this._beginDistribute();
|
117
|
-
// send data configuration signal
|
118
|
-
this._configure();
|
119
|
-
// now fully prepare localChildren
|
120
|
-
var c$ = this._clients;
|
121
|
-
for (var i=0, l= c$.length, c; (i<l) && (c=c$[i]); i++) {
|
122
|
-
c._initializeContent();
|
123
|
-
}
|
124
|
-
// perform actual dom composition
|
125
|
-
this._finishDistribute();
|
126
|
-
// ensure elements are attached if they are in the dom at ready time
|
127
|
-
// helps normalize attached ordering between native and polyfill ce.
|
128
|
-
// TODO(sorvell): worth perf cost? ~6%
|
129
|
-
// if (!Polymer.Settings.useNativeCustomElements) {
|
130
|
-
// CustomElements.takeRecords();
|
131
|
-
// }
|
132
|
-
// send ready signal
|
133
|
-
this._ready();
|
134
|
-
// reset _host as it needs to be established by local dom after data
|
135
|
-
// configuration
|
136
|
-
this.host = null;
|
137
|
-
this._clients = null;
|
138
|
-
},
|
139
|
-
|
140
|
-
// calls `configure`
|
141
|
-
// note: called host -> localChild
|
142
|
-
_configure: function() {
|
143
|
-
this.configure();
|
144
|
-
},
|
145
|
-
|
146
|
-
// mark readied and call `ready`
|
147
|
-
// note: called localChildren -> host
|
148
|
-
_ready: function() {
|
149
|
-
this._readied = true;
|
150
|
-
this._beforeReady();
|
151
|
-
this.ready();
|
152
|
-
if (this._attachedPending) {
|
153
|
-
this._attachedPending = false;
|
154
|
-
this.attachedCallback();
|
155
|
-
}
|
156
|
-
},
|
157
|
-
|
158
|
-
// for system overriding
|
159
|
-
_beforeReady: function() {},
|
160
|
-
|
161
|
-
// normalize lifecycle: ensure attached occurs only after ready.
|
162
|
-
attachedCallback: function() {
|
163
|
-
if (this._readied) {
|
164
|
-
baseAttachedCallback.call(this);
|
165
|
-
} else {
|
166
|
-
this._attachedPending = true;
|
167
|
-
}
|
168
|
-
},
|
169
|
-
|
170
|
-
detachedCallback: function() {
|
171
|
-
// uncache host so it will be calculated again.
|
172
|
-
this.host = null;
|
173
|
-
baseDetachedCallback.call(this);
|
174
|
-
}
|
175
|
-
|
176
|
-
});
|
177
|
-
|
178
|
-
})();
|
179
|
-
|
180
|
-
</script>
|
@@ -1,41 +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="../lib/settings.html">
|
11
|
-
<script>
|
12
|
-
|
13
|
-
/**
|
14
|
-
Implements `shadyRoot` compatible dom scoping using native ShadowDOM.
|
15
|
-
*/
|
16
|
-
|
17
|
-
// Transform styles if not using ShadowDOM or if flag is set.
|
18
|
-
|
19
|
-
if (Polymer.Settings.useShadow) {
|
20
|
-
|
21
|
-
Polymer.Base.addFeature({
|
22
|
-
|
23
|
-
// no-op's when ShadowDOM is in use
|
24
|
-
_poolContent: function() {},
|
25
|
-
_beginDistribute: function() {},
|
26
|
-
distributeContent: function() {},
|
27
|
-
_distributeContent: function() {},
|
28
|
-
_finishDistribute: function() {},
|
29
|
-
|
30
|
-
// create a shadowRoot
|
31
|
-
_createLocalRoot: function() {
|
32
|
-
this.createShadowRoot();
|
33
|
-
this.shadowRoot.appendChild(this.root);
|
34
|
-
this.root = this.shadowRoot;
|
35
|
-
}
|
36
|
-
|
37
|
-
});
|
38
|
-
|
39
|
-
}
|
40
|
-
|
41
|
-
</script>
|
@@ -1,365 +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="../lib/array-splice.html">
|
11
|
-
<link rel="import" href="../lib/dom-api.html">
|
12
|
-
<script>
|
13
|
-
|
14
|
-
(function() {
|
15
|
-
/**
|
16
|
-
|
17
|
-
Implements a pared down version of ShadowDOM's scoping, which is easy to
|
18
|
-
polyfill across browsers.
|
19
|
-
|
20
|
-
*/
|
21
|
-
Polymer.Base.addFeature({
|
22
|
-
|
23
|
-
_prepContent: function() {
|
24
|
-
// Use this system iff localDom is needed.
|
25
|
-
this._useContent = this._useContent || Boolean(this._template);
|
26
|
-
if (this._useContent) {
|
27
|
-
this._template._hasInsertionPoint =
|
28
|
-
this._template.content.querySelector('content');
|
29
|
-
}
|
30
|
-
},
|
31
|
-
|
32
|
-
// called as part of content initialization, prior to template stamping
|
33
|
-
_poolContent: function() {
|
34
|
-
if (this._useContent) {
|
35
|
-
// capture lightChildren to help reify dom scoping
|
36
|
-
saveLightChildrenIfNeeded(this);
|
37
|
-
}
|
38
|
-
},
|
39
|
-
|
40
|
-
// called as part of content initialization, after template stamping
|
41
|
-
_setupRoot: function() {
|
42
|
-
if (this._useContent) {
|
43
|
-
this._createLocalRoot();
|
44
|
-
}
|
45
|
-
},
|
46
|
-
|
47
|
-
_createLocalRoot: function() {
|
48
|
-
this.shadyRoot = this.root;
|
49
|
-
this.shadyRoot._distributionClean = false;
|
50
|
-
this.shadyRoot._isShadyRoot = true;
|
51
|
-
this.shadyRoot._dirtyRoots = [];
|
52
|
-
// capture insertion point list
|
53
|
-
// TODO(sorvell): it's faster to do this via native qSA than annotator.
|
54
|
-
this.shadyRoot._insertionPoints = this._template._hasInsertionPoint ?
|
55
|
-
this.shadyRoot.querySelectorAll('content') : [];
|
56
|
-
// save logical tree info for shadyRoot.
|
57
|
-
saveLightChildrenIfNeeded(this.shadyRoot);
|
58
|
-
this.shadyRoot.host = this;
|
59
|
-
},
|
60
|
-
|
61
|
-
/**
|
62
|
-
* Force this element to distribute its children to its local dom.
|
63
|
-
* A user should call `distributeContent` if distribution has been
|
64
|
-
* invalidated due to changes to selectors on child elements that
|
65
|
-
* effect distribution. For example, if an element contains an
|
66
|
-
* insertion point with <content select=".foo"> and a `foo` class is
|
67
|
-
* added to a child, then `distributeContent` must be called to update
|
68
|
-
* local dom distribution.
|
69
|
-
*/
|
70
|
-
distributeContent: function() {
|
71
|
-
if (this._useContent) {
|
72
|
-
this.shadyRoot._distributionClean = false;
|
73
|
-
this._distributeContent();
|
74
|
-
}
|
75
|
-
},
|
76
|
-
|
77
|
-
_distributeContent: function() {
|
78
|
-
if (this._useContent && !this.shadyRoot._distributionClean) {
|
79
|
-
// logically distribute self
|
80
|
-
this._beginDistribute();
|
81
|
-
this._distributeDirtyRoots();
|
82
|
-
this._finishDistribute();
|
83
|
-
}
|
84
|
-
},
|
85
|
-
|
86
|
-
_beginDistribute: function() {
|
87
|
-
if (this._useContent && hasInsertionPoint(this.shadyRoot)) {
|
88
|
-
// reset distributions
|
89
|
-
this._resetDistribution(this.shadyRoot);
|
90
|
-
// compute which nodes should be distributed where
|
91
|
-
// TODO(jmesserly): this is simplified because we assume a single
|
92
|
-
// ShadowRoot per host and no `<shadow>`.
|
93
|
-
this._distributePool(this.shadyRoot, this._collectPool());
|
94
|
-
}
|
95
|
-
},
|
96
|
-
|
97
|
-
_distributeDirtyRoots: function() {
|
98
|
-
var c$ = this.shadyRoot._dirtyRoots;
|
99
|
-
for (var i=0, l= c$.length, c; (i<l) && (c=c$[i]); i++) {
|
100
|
-
c._distributeContent();
|
101
|
-
}
|
102
|
-
this.shadyRoot._dirtyRoots = [];
|
103
|
-
},
|
104
|
-
|
105
|
-
_finishDistribute: function() {
|
106
|
-
// compose self
|
107
|
-
if (this._useContent) {
|
108
|
-
if (hasInsertionPoint(this.shadyRoot)) {
|
109
|
-
this._composeTree();
|
110
|
-
} else {
|
111
|
-
if (!this.shadyRoot._hasDistributed) {
|
112
|
-
this.textContent = '';
|
113
|
-
this.appendChild(this.shadyRoot);
|
114
|
-
} else {
|
115
|
-
// simplified non-tree walk composition
|
116
|
-
var children = this._composeNode(this);
|
117
|
-
this._updateChildNodes(this, children);
|
118
|
-
}
|
119
|
-
}
|
120
|
-
this.shadyRoot._hasDistributed = true;
|
121
|
-
this.shadyRoot._distributionClean = true;
|
122
|
-
}
|
123
|
-
},
|
124
|
-
|
125
|
-
// This is a polyfill for Element.prototype.matches, which is sometimes
|
126
|
-
// still prefixed. Alternatively we could just polyfill it somewhere.
|
127
|
-
// Note that the arguments are reversed from what you might expect.
|
128
|
-
elementMatches: function(selector, node) {
|
129
|
-
if (node === undefined) {
|
130
|
-
node = this;
|
131
|
-
}
|
132
|
-
return matchesSelector.call(node, selector);
|
133
|
-
},
|
134
|
-
|
135
|
-
// Many of the following methods are all conceptually static, but they are
|
136
|
-
// included here as "protected" methods to allow overriding.
|
137
|
-
|
138
|
-
_resetDistribution: function(node) {
|
139
|
-
// light children
|
140
|
-
var children = getLightChildren(node);
|
141
|
-
for (var i = 0; i < children.length; i++) {
|
142
|
-
var child = children[i];
|
143
|
-
if (child._destinationInsertionPoints) {
|
144
|
-
child._destinationInsertionPoints = undefined;
|
145
|
-
}
|
146
|
-
}
|
147
|
-
// insertion points
|
148
|
-
var p$ = node._insertionPoints;
|
149
|
-
for (var j = 0; j < p$.length; j++) {
|
150
|
-
p$[j]._distributedNodes = [];
|
151
|
-
}
|
152
|
-
},
|
153
|
-
|
154
|
-
// Gather the pool of nodes that should be distributed. We will combine
|
155
|
-
// these with the "content root" to arrive at the composed tree.
|
156
|
-
_collectPool: function() {
|
157
|
-
var pool = [];
|
158
|
-
var children = getLightChildren(this);
|
159
|
-
for (var i = 0; i < children.length; i++) {
|
160
|
-
var child = children[i];
|
161
|
-
if (isInsertionPoint(child)) {
|
162
|
-
pool.push.apply(pool, child._distributedNodes);
|
163
|
-
} else {
|
164
|
-
pool.push(child);
|
165
|
-
}
|
166
|
-
}
|
167
|
-
return pool;
|
168
|
-
},
|
169
|
-
|
170
|
-
// perform "logical" distribution; note, no actual dom is moved here,
|
171
|
-
// instead elements are distributed into a `content._distributedNodes`
|
172
|
-
// array where applicable.
|
173
|
-
_distributePool: function(node, pool) {
|
174
|
-
var p$ = node._insertionPoints;
|
175
|
-
for (var i=0, l=p$.length, p; (i<l) && (p=p$[i]); i++) {
|
176
|
-
this._distributeInsertionPoint(p, pool);
|
177
|
-
}
|
178
|
-
},
|
179
|
-
|
180
|
-
_distributeInsertionPoint: function(content, pool) {
|
181
|
-
// distribute nodes from the pool that this selector matches
|
182
|
-
var anyDistributed = false;
|
183
|
-
for (var i=0, l=pool.length, node; i < l; i++) {
|
184
|
-
node=pool[i];
|
185
|
-
// skip nodes that were already used
|
186
|
-
if (!node) {
|
187
|
-
continue;
|
188
|
-
}
|
189
|
-
// distribute this node if it matches
|
190
|
-
if (this._matchesContentSelect(node, content)) {
|
191
|
-
distributeNodeInto(node, content);
|
192
|
-
// remove this node from the pool
|
193
|
-
pool[i] = undefined;
|
194
|
-
// since at least one node matched, we won't need fallback content
|
195
|
-
anyDistributed = true;
|
196
|
-
var parent = content.lightParent;
|
197
|
-
// dirty a shadyRoot if a change may trigger reprojection!
|
198
|
-
if (parent && parent.shadyRoot &&
|
199
|
-
hasInsertionPoint(parent.shadyRoot)) {
|
200
|
-
parent.shadyRoot._distributionClean = false;
|
201
|
-
this.shadyRoot._dirtyRoots.push(parent);
|
202
|
-
}
|
203
|
-
}
|
204
|
-
}
|
205
|
-
// Fallback content if nothing was distributed here
|
206
|
-
if (!anyDistributed) {
|
207
|
-
var children = getLightChildren(content);
|
208
|
-
for (var j = 0; j < children.length; j++) {
|
209
|
-
distributeNodeInto(children[j], content);
|
210
|
-
}
|
211
|
-
}
|
212
|
-
},
|
213
|
-
|
214
|
-
// Reify dom such that it is at its correct rendering position
|
215
|
-
// based on logical distribution.
|
216
|
-
_composeTree: function() {
|
217
|
-
this._updateChildNodes(this, this._composeNode(this));
|
218
|
-
var p$ = this.shadyRoot._insertionPoints;
|
219
|
-
for (var i=0, l=p$.length, p, parent; (i<l) && (p=p$[i]); i++) {
|
220
|
-
parent = p.lightParent || p.parentNode;
|
221
|
-
if (!parent._useContent && (parent !== this) &&
|
222
|
-
(parent !== this.shadyRoot)) {
|
223
|
-
this._updateChildNodes(parent, this._composeNode(parent));
|
224
|
-
}
|
225
|
-
}
|
226
|
-
},
|
227
|
-
|
228
|
-
// Returns the list of nodes which should be rendered inside `node`.
|
229
|
-
_composeNode: function(node) {
|
230
|
-
var children = [];
|
231
|
-
var c$ = getLightChildren(node.shadyRoot || node);
|
232
|
-
for (var i = 0; i < c$.length; i++) {
|
233
|
-
var child = c$[i];
|
234
|
-
if (isInsertionPoint(child)) {
|
235
|
-
var distributedNodes = child._distributedNodes;
|
236
|
-
for (var j = 0; j < distributedNodes.length; j++) {
|
237
|
-
var distributedNode = distributedNodes[j];
|
238
|
-
if (isFinalDestination(child, distributedNode)) {
|
239
|
-
children.push(distributedNode);
|
240
|
-
}
|
241
|
-
}
|
242
|
-
} else {
|
243
|
-
children.push(child);
|
244
|
-
}
|
245
|
-
}
|
246
|
-
return children;
|
247
|
-
},
|
248
|
-
|
249
|
-
// Ensures that the rendered node list inside `node` is `children`.
|
250
|
-
_updateChildNodes: function(node, children) {
|
251
|
-
var splices =
|
252
|
-
Polymer.ArraySplice.calculateSplices(children, node.childNodes);
|
253
|
-
for (var i=0; i<splices.length; i++) {
|
254
|
-
var s = splices[i];
|
255
|
-
// remove
|
256
|
-
for (var j=0, c; j < s.removed.length; j++) {
|
257
|
-
c = s.removed[j];
|
258
|
-
if (c.previousSibling == children[s.index-1]) {
|
259
|
-
remove(c);
|
260
|
-
}
|
261
|
-
}
|
262
|
-
// insert
|
263
|
-
for (var idx=s.index, ch, o; idx < s.index + s.addedCount; idx++) {
|
264
|
-
ch = children[idx];
|
265
|
-
o = node.childNodes[idx];
|
266
|
-
while (o && o === ch) {
|
267
|
-
o = o.nextSibling;
|
268
|
-
}
|
269
|
-
insertBefore(node, ch, o);
|
270
|
-
}
|
271
|
-
}
|
272
|
-
},
|
273
|
-
|
274
|
-
_matchesContentSelect: function(node, contentElement) {
|
275
|
-
var select = contentElement.getAttribute('select');
|
276
|
-
// no selector matches all nodes (including text)
|
277
|
-
if (!select) {
|
278
|
-
return true;
|
279
|
-
}
|
280
|
-
select = select.trim();
|
281
|
-
// same thing if it had only whitespace
|
282
|
-
if (!select) {
|
283
|
-
return true;
|
284
|
-
}
|
285
|
-
// selectors can only match Elements
|
286
|
-
if (!(node instanceof Element)) {
|
287
|
-
return false;
|
288
|
-
}
|
289
|
-
// only valid selectors can match:
|
290
|
-
// TypeSelector
|
291
|
-
// *
|
292
|
-
// ClassSelector
|
293
|
-
// IDSelector
|
294
|
-
// AttributeSelector
|
295
|
-
// negation
|
296
|
-
var validSelectors = /^(:not\()?[*.#[a-zA-Z_|]/;
|
297
|
-
if (!validSelectors.test(select)) {
|
298
|
-
return false;
|
299
|
-
}
|
300
|
-
return this.elementMatches(select, node);
|
301
|
-
},
|
302
|
-
|
303
|
-
// system override point
|
304
|
-
_elementAdd: function() {},
|
305
|
-
|
306
|
-
// system override point
|
307
|
-
_elementRemove: function() {}
|
308
|
-
|
309
|
-
});
|
310
|
-
|
311
|
-
var saveLightChildrenIfNeeded = Polymer.DomApi.saveLightChildrenIfNeeded;
|
312
|
-
var getLightChildren = Polymer.DomApi.getLightChildren;
|
313
|
-
var matchesSelector = Polymer.DomApi.matchesSelector;
|
314
|
-
var hasInsertionPoint = Polymer.DomApi.hasInsertionPoint;
|
315
|
-
|
316
|
-
function distributeNodeInto(child, insertionPoint) {
|
317
|
-
insertionPoint._distributedNodes.push(child);
|
318
|
-
var points = child._destinationInsertionPoints;
|
319
|
-
if (!points) {
|
320
|
-
child._destinationInsertionPoints = [insertionPoint];
|
321
|
-
// TODO(sorvell): _destinationInsertionPoints may not be cleared when
|
322
|
-
// nodes are dynamically added/removed, therefore test before adding
|
323
|
-
// insertion points.
|
324
|
-
} else if (points.indexOf(insertionPoint) < 0) {
|
325
|
-
points.push(insertionPoint);
|
326
|
-
}
|
327
|
-
}
|
328
|
-
|
329
|
-
function isFinalDestination(insertionPoint, node) {
|
330
|
-
var points = node._destinationInsertionPoints;
|
331
|
-
return points && points[points.length - 1] === insertionPoint;
|
332
|
-
}
|
333
|
-
|
334
|
-
function isInsertionPoint(node) {
|
335
|
-
// TODO(jmesserly): we could add back 'shadow' support here.
|
336
|
-
return node.localName == 'content';
|
337
|
-
}
|
338
|
-
|
339
|
-
var nativeInsertBefore = Element.prototype.insertBefore;
|
340
|
-
var nativeRemoveChild = Element.prototype.removeChild;
|
341
|
-
|
342
|
-
function insertBefore(parentNode, newChild, refChild) {
|
343
|
-
// remove child from its old parent first
|
344
|
-
remove(newChild);
|
345
|
-
// make sure we never lose logical DOM information:
|
346
|
-
// if the parentNode doesn't have lightChildren, save that information now.
|
347
|
-
saveLightChildrenIfNeeded(parentNode);
|
348
|
-
// insert it into the real DOM
|
349
|
-
nativeInsertBefore.call(parentNode, newChild, refChild || null);
|
350
|
-
}
|
351
|
-
|
352
|
-
function remove(node) {
|
353
|
-
var parentNode = node.parentNode;
|
354
|
-
if (parentNode) {
|
355
|
-
// make sure we never lose logical DOM information:
|
356
|
-
// if the parentNode doesn't have lightChildren, save that information now.
|
357
|
-
saveLightChildrenIfNeeded(parentNode);
|
358
|
-
// remove it from the real DOM
|
359
|
-
nativeRemoveChild.call(parentNode, node);
|
360
|
-
}
|
361
|
-
}
|
362
|
-
|
363
|
-
})();
|
364
|
-
|
365
|
-
</script>
|