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,127 +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
|
-
|
11
|
-
<link rel="import" href="../lib/gestures.html">
|
12
|
-
|
13
|
-
<script>
|
14
|
-
|
15
|
-
/**
|
16
|
-
* Supports `listeners` and `keyPresses` objects.
|
17
|
-
*
|
18
|
-
* Example:
|
19
|
-
*
|
20
|
-
* using('Base', function(Base) {
|
21
|
-
*
|
22
|
-
* Polymer({
|
23
|
-
*
|
24
|
-
* listeners: {
|
25
|
-
* // `click` events on the host are delegated to `clickHandler`
|
26
|
-
* 'click': 'clickHandler'
|
27
|
-
* },
|
28
|
-
*
|
29
|
-
* keyPresses: {
|
30
|
-
* // 'ESC' key presses are delegated to `escHandler`
|
31
|
-
* Base.ESC_KEY: 'escHandler'
|
32
|
-
* },
|
33
|
-
*
|
34
|
-
* ...
|
35
|
-
*
|
36
|
-
* });
|
37
|
-
*
|
38
|
-
* });
|
39
|
-
*
|
40
|
-
* @class standard feature: events
|
41
|
-
*
|
42
|
-
*/
|
43
|
-
|
44
|
-
Polymer.Base.addFeature({
|
45
|
-
|
46
|
-
listeners: {},
|
47
|
-
|
48
|
-
_marshalListeners: function() {
|
49
|
-
this._listenListeners(this.listeners);
|
50
|
-
this._listenKeyPresses(this.keyPresses);
|
51
|
-
},
|
52
|
-
|
53
|
-
_listenListeners: function(listeners) {
|
54
|
-
var node, name, key;
|
55
|
-
for (key in listeners) {
|
56
|
-
if (key.indexOf('.') < 0) {
|
57
|
-
node = this;
|
58
|
-
name = key;
|
59
|
-
} else {
|
60
|
-
name = key.split('.');
|
61
|
-
node = this.$[name[0]];
|
62
|
-
name = name[1];
|
63
|
-
}
|
64
|
-
this.listen(node, name, listeners[key]);
|
65
|
-
}
|
66
|
-
},
|
67
|
-
|
68
|
-
listen: function(node, eventName, methodName) {
|
69
|
-
var host = this;
|
70
|
-
var handler = function(e) {
|
71
|
-
if (host[methodName]) {
|
72
|
-
host[methodName](e, e.detail);
|
73
|
-
} else {
|
74
|
-
console.warn('[%s].[%s]: event handler [%s] is null in scope (%o)',
|
75
|
-
node.localName, eventName, methodName, host);
|
76
|
-
}
|
77
|
-
};
|
78
|
-
switch (eventName) {
|
79
|
-
case 'tap':
|
80
|
-
case 'track':
|
81
|
-
Polymer.Gestures.add(eventName, node, handler);
|
82
|
-
break;
|
83
|
-
|
84
|
-
default:
|
85
|
-
node.addEventListener(eventName, handler);
|
86
|
-
break;
|
87
|
-
}
|
88
|
-
},
|
89
|
-
|
90
|
-
keyPresses: {},
|
91
|
-
|
92
|
-
_listenKeyPresses: function(keyPresses) {
|
93
|
-
// for..in here to gate empty keyPresses object (iterates once or never)
|
94
|
-
for (var n in keyPresses) {
|
95
|
-
// only get here if there is something in keyPresses
|
96
|
-
// TODO(sjmiles): _keyPressesFeatureHandler uses `this.keyPresses`
|
97
|
-
// to look up keycodes, it's not agnostic like this method is
|
98
|
-
this.addEventListener('keydown', this._keyPressesFeatureHandler);
|
99
|
-
// map string keys to numeric codes
|
100
|
-
for (n in keyPresses) {
|
101
|
-
if (typeof n === 'string') {
|
102
|
-
keyPresses[this.eventKeyCodes[n]] = keyPresses[n];
|
103
|
-
}
|
104
|
-
}
|
105
|
-
break;
|
106
|
-
}
|
107
|
-
},
|
108
|
-
|
109
|
-
_keyPressesFeatureHandler: function(e) {
|
110
|
-
var method = this.keyPresses[e.keyCode];
|
111
|
-
if (method && this[method]) {
|
112
|
-
return this[method](e.keyCode, e);
|
113
|
-
}
|
114
|
-
},
|
115
|
-
|
116
|
-
eventKeyCodes: {
|
117
|
-
ESC_KEY: 27,
|
118
|
-
ENTER_KEY: 13,
|
119
|
-
LEFT: 37,
|
120
|
-
UP: 38,
|
121
|
-
RIGHT: 39,
|
122
|
-
DOWN: 40
|
123
|
-
}
|
124
|
-
|
125
|
-
});
|
126
|
-
|
127
|
-
</script>
|
@@ -1,260 +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/case-map.html">
|
11
|
-
<script>
|
12
|
-
|
13
|
-
/**
|
14
|
-
* Changes to an object sub-field (aka "path") via a binding
|
15
|
-
* (e.g. `<x-foo value="{{item.subfield}}"`) will notify other elements bound to
|
16
|
-
* the same object automatically.
|
17
|
-
*
|
18
|
-
* When modifying a sub-field of an object imperatively
|
19
|
-
* (e.g. `this.item.subfield = 42`), in order to have the new value propagated
|
20
|
-
* to other elements, a special `setPathValue(path, value)` API is provided.
|
21
|
-
* `setPathValue` sets the object field at the path specified, and then notifies the
|
22
|
-
* binding system so that other elements bound to the same path will update.
|
23
|
-
*
|
24
|
-
* Example:
|
25
|
-
*
|
26
|
-
* Polymer({
|
27
|
-
*
|
28
|
-
* is: 'x-date',
|
29
|
-
*
|
30
|
-
* properties: {
|
31
|
-
* date: {
|
32
|
-
* type: Object,
|
33
|
-
* notify: true
|
34
|
-
* }
|
35
|
-
* },
|
36
|
-
*
|
37
|
-
* attached: function() {
|
38
|
-
* this.date = {};
|
39
|
-
* setInterval(function() {
|
40
|
-
* var d = new Date();
|
41
|
-
* // Required to notify elements bound to date of changes to sub-fields
|
42
|
-
* // this.date.seconds = d.getSeconds(); <-- Will not notify
|
43
|
-
* this.setPathValue('date.seconds', d.getSeconds());
|
44
|
-
* this.setPathValue('date.minutes', d.getMinutes());
|
45
|
-
* this.setPathValue('date.hours', d.getHours() % 12);
|
46
|
-
* }.bind(this), 1000);
|
47
|
-
* }
|
48
|
-
*
|
49
|
-
* });
|
50
|
-
*
|
51
|
-
* Allows bindings to `date` sub-fields to update on changes:
|
52
|
-
*
|
53
|
-
* <x-date date="{{date}}"></x-date>
|
54
|
-
*
|
55
|
-
* Hour: <span>{{date.hours}}</span>
|
56
|
-
* Min: <span>{{date.minutes}}</span>
|
57
|
-
* Sec: <span>{{date.seconds}}</span>
|
58
|
-
*
|
59
|
-
* @class data feature: path notification
|
60
|
-
*/
|
61
|
-
|
62
|
-
Polymer.Base.addFeature({
|
63
|
-
/**
|
64
|
-
Notify that a path has changed. For example:
|
65
|
-
|
66
|
-
this.item.user.name = 'Bob';
|
67
|
-
this.notifyPath('item.user.name', this.item.user.name);
|
68
|
-
|
69
|
-
Returns true if notification actually took place, based on
|
70
|
-
a dirty check of whether the new value was already known
|
71
|
-
*/
|
72
|
-
notifyPath: function(path, value, fromAbove) {
|
73
|
-
var old = this._propertySet(path, value);
|
74
|
-
// manual dirty checking for now...
|
75
|
-
if (old !== value) {
|
76
|
-
//console.group(this.localName + '#' + this.id + ' ' + path);
|
77
|
-
// Take path effects at this level for exact path matches,
|
78
|
-
// and notify down for any bindings to a subset of this path
|
79
|
-
this._pathEffector(path, value);
|
80
|
-
// Send event to notify the path change upwards
|
81
|
-
// Optimization: don't notify up if we know the notification
|
82
|
-
// is coming from above already (avoid wasted event dispatch)
|
83
|
-
if (!fromAbove) {
|
84
|
-
// TODO(sorvell): should only notify if notify: true?
|
85
|
-
this._notifyPath(path, value);
|
86
|
-
}
|
87
|
-
//console.groupEnd(this.localName + '#' + this.id + ' ' + path);
|
88
|
-
}
|
89
|
-
},
|
90
|
-
|
91
|
-
/**
|
92
|
-
Convienence method for setting a value to a path and calling
|
93
|
-
notify path
|
94
|
-
*/
|
95
|
-
setPathValue: function(path, value) {
|
96
|
-
var parts = path.split('.');
|
97
|
-
if (parts.length > 1) {
|
98
|
-
var last = parts.pop();
|
99
|
-
var prop = this;
|
100
|
-
while (parts.length) {
|
101
|
-
prop = prop[parts.shift()];
|
102
|
-
if (!prop) {
|
103
|
-
return;
|
104
|
-
}
|
105
|
-
}
|
106
|
-
// TODO(kschaaf): want dirty-check here?
|
107
|
-
// if (prop[last] !== value) {
|
108
|
-
prop[last] = value;
|
109
|
-
this.notifyPath(path, value);
|
110
|
-
// }
|
111
|
-
} else {
|
112
|
-
this[path] = value;
|
113
|
-
}
|
114
|
-
},
|
115
|
-
|
116
|
-
getPathValue: function(path, root) {
|
117
|
-
var parts = path.split('.');
|
118
|
-
var last = parts.pop();
|
119
|
-
var prop = root || this;
|
120
|
-
while (parts.length) {
|
121
|
-
prop = prop[parts.shift()];
|
122
|
-
if (!prop) {
|
123
|
-
return;
|
124
|
-
}
|
125
|
-
}
|
126
|
-
return prop[last];
|
127
|
-
},
|
128
|
-
|
129
|
-
addPathObserver: function(path, method) {
|
130
|
-
var fx$ = this._pathEffects || (this._pathEffects = []);
|
131
|
-
var match = path.indexOf('.*') == (path.length-2);
|
132
|
-
if (match) {
|
133
|
-
path = path.slice(0, -2);
|
134
|
-
}
|
135
|
-
fx$.push({path: path, match: match, method: method});
|
136
|
-
},
|
137
|
-
|
138
|
-
// TODO(kschaaf): This machine can be optimized to memoize compiled path
|
139
|
-
// effectors as new paths are notified for performance, since it involves
|
140
|
-
// a fair amount of runtime lookup
|
141
|
-
_pathEffector: function(path, value) {
|
142
|
-
// get root property
|
143
|
-
var model = this._modelForPath(path);
|
144
|
-
// search property effects of the root property for 'annotation' effects
|
145
|
-
var fx$ = this._propertyEffects[model];
|
146
|
-
if (fx$) {
|
147
|
-
fx$.forEach(function(fx) {
|
148
|
-
if (fx.kind === 'annotation') {
|
149
|
-
// locate the bound node
|
150
|
-
var n = this._nodeForBinding(fx.effect);
|
151
|
-
if (n) {
|
152
|
-
// perform the effect
|
153
|
-
this._performAnnotationPathEffect(n, path, value, fx.effect);
|
154
|
-
}
|
155
|
-
}
|
156
|
-
}, this);
|
157
|
-
}
|
158
|
-
// iterate and perform _pathEffects matching path
|
159
|
-
if (this._pathEffects) {
|
160
|
-
this._pathEffects.forEach(function(fx) {
|
161
|
-
this._performPathEffect(path, value, fx);
|
162
|
-
}, this);
|
163
|
-
}
|
164
|
-
// notify runtime-bound paths
|
165
|
-
if (this._boundPaths) {
|
166
|
-
this._notifyBoundPaths(path, value);
|
167
|
-
}
|
168
|
-
},
|
169
|
-
|
170
|
-
_nodeForBinding: function(info) {
|
171
|
-
return info.id ? this.$[info.id] : this._nodes[info.index];
|
172
|
-
},
|
173
|
-
|
174
|
-
_performAnnotationPathEffect: function(node, path, value, effect) {
|
175
|
-
if (effect.value === path || effect.value.indexOf(path + '.') === 0) {
|
176
|
-
// TODO(sorvell): ideally the effect function is on this prototype
|
177
|
-
// so we don't have to call it like this.
|
178
|
-
Polymer.Bind.annotationEffect.call(this, path, value, effect);
|
179
|
-
// path == item.stuff.count
|
180
|
-
// value == item.stuff
|
181
|
-
// name == zizz
|
182
|
-
// calls effect n.notifyPath for zizz.count
|
183
|
-
} else if ((path.indexOf(effect.value + '.') === 0) &&
|
184
|
-
node.notifyPath && !effect.negate) {
|
185
|
-
var p = this._fixPath(effect.name , effect.value, path);
|
186
|
-
node.notifyPath(p, value, true);
|
187
|
-
}
|
188
|
-
},
|
189
|
-
|
190
|
-
_performPathEffect: function(path, value, fx) {
|
191
|
-
if (fx.path == path || (fx.match && path.indexOf(fx.path) === 0)) {
|
192
|
-
var fn = this[fx.method];
|
193
|
-
if (fn) {
|
194
|
-
// TODO(kschaaf): sending null for old; no good way to get it?
|
195
|
-
fn.call(this, value, null, path);
|
196
|
-
}
|
197
|
-
}
|
198
|
-
},
|
199
|
-
|
200
|
-
bindPaths: function(to, from) {
|
201
|
-
this._boundPaths = this._boundPaths || {};
|
202
|
-
if (from) {
|
203
|
-
this._boundPaths[to] = from;
|
204
|
-
// this.setPathValue(to, this.getPathValue(from));
|
205
|
-
} else {
|
206
|
-
this.unbindPath(to);
|
207
|
-
// this.setPathValue(to, from);
|
208
|
-
}
|
209
|
-
},
|
210
|
-
|
211
|
-
unbindPaths: function(path) {
|
212
|
-
if (this._boundPaths) {
|
213
|
-
delete this._boundPaths[path];
|
214
|
-
}
|
215
|
-
},
|
216
|
-
|
217
|
-
_notifyBoundPaths: function(path, value) {
|
218
|
-
var from, to;
|
219
|
-
for (var a in this._boundPaths) {
|
220
|
-
var b = this._boundPaths[a];
|
221
|
-
if (path.indexOf(a + '.') == 0) {
|
222
|
-
from = a;
|
223
|
-
to = b;
|
224
|
-
break;
|
225
|
-
}
|
226
|
-
if (path.indexOf(b + '.') == 0) {
|
227
|
-
from = b;
|
228
|
-
to = a;
|
229
|
-
break;
|
230
|
-
}
|
231
|
-
}
|
232
|
-
if (from && to) {
|
233
|
-
var p = this._fixPath(to, from, path);
|
234
|
-
this.notifyPath(p, value);
|
235
|
-
}
|
236
|
-
},
|
237
|
-
|
238
|
-
_fixPath: function(property, root, path) {
|
239
|
-
return property + path.slice(root.length);
|
240
|
-
},
|
241
|
-
|
242
|
-
_notifyPath: function(path, value) {
|
243
|
-
var rootName = this._modelForPath(path);
|
244
|
-
var dashCaseName = Polymer.CaseMap.camelToDashCase(rootName);
|
245
|
-
var eventName = dashCaseName + this._EVENT_CHANGED;
|
246
|
-
this.fire(eventName, {
|
247
|
-
path: path,
|
248
|
-
value: value
|
249
|
-
}, null, false);
|
250
|
-
},
|
251
|
-
|
252
|
-
_modelForPath: function(path) {
|
253
|
-
return path.split('.').shift();
|
254
|
-
},
|
255
|
-
|
256
|
-
_EVENT_CHANGED: '-changed',
|
257
|
-
|
258
|
-
});
|
259
|
-
|
260
|
-
</script>
|
@@ -1,27 +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
|
-
resolveUrl: function(url) {
|
15
|
-
// TODO(sorvell): do we want to put the module reference on the prototype?
|
16
|
-
var module = Polymer.DomModule.import(this.is);
|
17
|
-
var root = '';
|
18
|
-
if (module) {
|
19
|
-
var assetPath = module.getAttribute('assetpath') || '';
|
20
|
-
root = Polymer.ResolveUrl.resolveUrl(assetPath, module.ownerDocument.baseURI);
|
21
|
-
}
|
22
|
-
return Polymer.ResolveUrl.resolveUrl(url, root);
|
23
|
-
}
|
24
|
-
|
25
|
-
});
|
26
|
-
|
27
|
-
</script>
|
@@ -1,157 +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
|
-
|
11
|
-
<link rel="import" href="../lib/style-util.html">
|
12
|
-
<link rel="import" href="../lib/resolve-url.html">
|
13
|
-
<link rel="import" href="../lib/style-transformer.html">
|
14
|
-
<link rel="import" href="../lib/settings.html">
|
15
|
-
|
16
|
-
<script>
|
17
|
-
|
18
|
-
(function() {
|
19
|
-
|
20
|
-
var prepTemplate = Polymer.Base._prepTemplate;
|
21
|
-
var prepElement = Polymer.Base._prepElement;
|
22
|
-
var baseStampTemplate = Polymer.Base._stampTemplate;
|
23
|
-
|
24
|
-
Polymer.Base.addFeature({
|
25
|
-
|
26
|
-
// declaration-y
|
27
|
-
_prepTemplate: function() {
|
28
|
-
prepTemplate.call(this);
|
29
|
-
var port = Polymer.DomModule.import(this.is);
|
30
|
-
if (this._encapsulateStyle === undefined) {
|
31
|
-
this._encapsulateStyle =
|
32
|
-
Boolean(port && !Polymer.Settings.useNativeShadow);
|
33
|
-
}
|
34
|
-
// scope css
|
35
|
-
// NOTE: dom scoped via annotations
|
36
|
-
if (Polymer.Settings.useNativeShadow || this._encapsulateStyle) {
|
37
|
-
this._scopeCss();
|
38
|
-
}
|
39
|
-
},
|
40
|
-
|
41
|
-
_prepElement: function(element) {
|
42
|
-
if (this._encapsulateStyle) {
|
43
|
-
Polymer.StyleTransformer.element(element, this.is);
|
44
|
-
}
|
45
|
-
prepElement.call(this, element);
|
46
|
-
},
|
47
|
-
|
48
|
-
_scopeCss: function() {
|
49
|
-
this._styles = this._prepareStyles();
|
50
|
-
this._scopeStyles(this._styles);
|
51
|
-
},
|
52
|
-
|
53
|
-
// search for extra style modules via `styleModules`
|
54
|
-
_prepareStyles: function() {
|
55
|
-
var cssText = '', m$ = this.styleModules;
|
56
|
-
if (m$) {
|
57
|
-
for (var i=0, l=m$.length, m; (i<l) && (m=m$[i]); i++) {
|
58
|
-
cssText += this._cssFromModule(m);
|
59
|
-
}
|
60
|
-
}
|
61
|
-
cssText += this._cssFromModule(this.is);
|
62
|
-
var styles = [];
|
63
|
-
if (cssText) {
|
64
|
-
var s = document.createElement('style');
|
65
|
-
s.textContent = cssText;
|
66
|
-
styles.push(s);
|
67
|
-
}
|
68
|
-
return styles;
|
69
|
-
},
|
70
|
-
|
71
|
-
// returns cssText of styles in a given module; also un-applies any
|
72
|
-
// styles that apply to the document.
|
73
|
-
_cssFromModule: function(moduleId) {
|
74
|
-
var m = Polymer.DomModule.import(moduleId);
|
75
|
-
if (m && !m._cssText) {
|
76
|
-
var cssText = '';
|
77
|
-
var e$ = Array.prototype.slice.call(m.querySelectorAll('style'));
|
78
|
-
this._unapplyStyles(e$);
|
79
|
-
e$ = e$.concat(Array.prototype.map.call(
|
80
|
-
m.querySelectorAll(REMOTE_SHEET_SELECTOR), function(l) {
|
81
|
-
return l.import.body;
|
82
|
-
}));
|
83
|
-
m._cssText = this._cssFromStyles(e$);
|
84
|
-
}
|
85
|
-
return m && m._cssText || '';
|
86
|
-
},
|
87
|
-
|
88
|
-
_cssFromStyles: function(styles) {
|
89
|
-
var cssText = '';
|
90
|
-
for (var i=0, l=styles.length, s; (i<l) && (s = styles[i]); i++) {
|
91
|
-
if (s && s.textContent) {
|
92
|
-
cssText +=
|
93
|
-
Polymer.ResolveUrl.resolveCss(s.textContent, s.ownerDocument);
|
94
|
-
}
|
95
|
-
}
|
96
|
-
return cssText;
|
97
|
-
},
|
98
|
-
|
99
|
-
_unapplyStyles: function(styles) {
|
100
|
-
for (var i=0, l=styles.length, s; (i<l) && (s = styles[i]); i++) {
|
101
|
-
s = s.__appliedElement || s;
|
102
|
-
s.parentNode.removeChild(s);
|
103
|
-
}
|
104
|
-
},
|
105
|
-
|
106
|
-
_scopeStyles: function(styles) {
|
107
|
-
for (var i=0, l=styles.length, s; (i<l) && (s=styles[i]); i++) {
|
108
|
-
// transform style if necessary and place in correct place
|
109
|
-
if (Polymer.Settings.useNativeShadow) {
|
110
|
-
if (this._template) {
|
111
|
-
this._template.content.appendChild(s);
|
112
|
-
}
|
113
|
-
} else {
|
114
|
-
var rules = this._rulesForStyle(s);
|
115
|
-
Polymer.StyleUtil.applyCss(
|
116
|
-
Polymer.StyleTransformer.css(rules, this.is, this.extends),
|
117
|
-
this.is, null, true);
|
118
|
-
}
|
119
|
-
}
|
120
|
-
},
|
121
|
-
|
122
|
-
_rulesForStyle: function(style) {
|
123
|
-
if (!style.__cssRules) {
|
124
|
-
style.__cssRules = Polymer.StyleUtil.parser.parse(style.textContent);
|
125
|
-
}
|
126
|
-
return style.__cssRules;
|
127
|
-
},
|
128
|
-
|
129
|
-
// instance-y
|
130
|
-
_stampTemplate: function() {
|
131
|
-
if (this._encapsulateStyle) {
|
132
|
-
Polymer.StyleTransformer.host(this, this.is);
|
133
|
-
}
|
134
|
-
baseStampTemplate.call(this);
|
135
|
-
},
|
136
|
-
|
137
|
-
// add scoping class whenever an element is added to localDOM
|
138
|
-
_elementAdd: function(node) {
|
139
|
-
if (this._encapsulateStyle && !node.__styleScoped) {
|
140
|
-
Polymer.StyleTransformer.dom(node, this.is);
|
141
|
-
}
|
142
|
-
},
|
143
|
-
|
144
|
-
// remove scoping class whenever an element is removed from localDOM
|
145
|
-
_elementRemove: function(node) {
|
146
|
-
if (this._encapsulateStyle) {
|
147
|
-
Polymer.StyleTransformer.dom(node, '');
|
148
|
-
}
|
149
|
-
}
|
150
|
-
|
151
|
-
});
|
152
|
-
|
153
|
-
var REMOTE_SHEET_SELECTOR = 'link[rel=import][type~=css]';
|
154
|
-
|
155
|
-
})();
|
156
|
-
|
157
|
-
</script>
|