polymer-rails 0.2.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -3
- data/app/assets/javascripts/polymer/polymer-micro.html +36 -0
- data/app/assets/javascripts/polymer/polymer-mini.html +45 -0
- data/app/assets/javascripts/polymer/polymer.html +59 -11
- data/app/assets/javascripts/polymer/src/lib/annotations/annotations.html +262 -0
- data/app/assets/javascripts/polymer/src/lib/annotations/demo/app-chrome.html +60 -0
- data/app/assets/javascripts/polymer/src/lib/array-observe.html +118 -0
- data/app/assets/javascripts/polymer/src/lib/array-splice.html +262 -0
- data/app/assets/javascripts/polymer/src/lib/async.html +68 -0
- data/app/assets/javascripts/polymer/src/lib/base.html +117 -0
- data/app/assets/javascripts/polymer/src/lib/bind/accessors.html +223 -0
- data/app/assets/javascripts/polymer/src/lib/bind/demo/app-chrome.html +28 -0
- data/app/assets/javascripts/polymer/src/lib/bind/demo/app.html +29 -0
- data/app/assets/javascripts/polymer/src/lib/bind/demo/src/annotations-bind-demo.html +76 -0
- data/app/assets/javascripts/polymer/src/lib/bind/demo/src/bind-demo.html +83 -0
- data/app/assets/javascripts/polymer/src/lib/bind/effects.html +80 -0
- data/app/assets/javascripts/polymer/src/lib/case-map.html +46 -0
- data/app/assets/javascripts/polymer/src/lib/collection.html +179 -0
- data/app/assets/javascripts/polymer/src/lib/css-parse.html +131 -0
- data/app/assets/javascripts/polymer/src/lib/debounce.html +69 -0
- data/app/assets/javascripts/polymer/src/lib/dom-api.html +467 -0
- data/app/assets/javascripts/polymer/src/lib/dom-module.html +68 -0
- data/app/assets/javascripts/polymer/src/lib/event-api.html +92 -0
- data/app/assets/javascripts/polymer/src/lib/expr/focus.html +22 -0
- data/app/assets/javascripts/polymer/src/lib/expr/gestures.html +1 -0
- data/app/assets/javascripts/polymer/src/lib/expr/log.html +21 -0
- data/app/assets/javascripts/polymer/src/lib/expr/sinspect.html +235 -0
- data/app/assets/javascripts/polymer/src/lib/expr/style-auditor.html +123 -0
- data/app/assets/javascripts/polymer/src/lib/expr/style-protector.html +52 -0
- data/app/assets/javascripts/polymer/src/lib/gestures.html +284 -0
- data/app/assets/javascripts/polymer/src/lib/lang.html +21 -0
- data/app/assets/javascripts/polymer/src/lib/module.html +56 -0
- data/app/assets/javascripts/polymer/src/lib/polymer-bootstrap.html +78 -0
- data/app/assets/javascripts/polymer/src/lib/resolve-url.html +82 -0
- data/app/assets/javascripts/polymer/src/lib/settings.html +52 -0
- data/app/assets/javascripts/polymer/src/lib/style-defaults.html +32 -0
- data/app/assets/javascripts/polymer/src/lib/style-transformer.html +185 -0
- data/app/assets/javascripts/polymer/src/lib/style-util.html +77 -0
- data/app/assets/javascripts/polymer/src/lib/template/templatizer.html +132 -0
- data/app/assets/javascripts/polymer/src/lib/template/x-array-selector.html +178 -0
- data/app/assets/javascripts/polymer/src/lib/template/x-autobind.html +80 -0
- data/app/assets/javascripts/polymer/src/lib/template/x-if.html +115 -0
- data/app/assets/javascripts/polymer/src/lib/template/x-repeat.html +510 -0
- data/app/assets/javascripts/polymer/src/lib/template/x-template.html +39 -0
- data/app/assets/javascripts/polymer/src/lib/x-style.html +115 -0
- data/app/assets/javascripts/polymer/src/micro/attributes.html +180 -0
- data/app/assets/javascripts/polymer/src/micro/constructor.html +74 -0
- data/app/assets/javascripts/polymer/src/micro/extends.html +79 -0
- data/app/assets/javascripts/polymer/src/micro/mixins.html +40 -0
- data/app/assets/javascripts/polymer/src/micro/properties.html +96 -0
- data/app/assets/javascripts/polymer/src/micro/tag.html +28 -0
- data/app/assets/javascripts/polymer/src/mini/ready.html +180 -0
- data/app/assets/javascripts/polymer/src/mini/shadow.html +41 -0
- data/app/assets/javascripts/polymer/src/mini/shady.html +365 -0
- data/app/assets/javascripts/polymer/src/mini/template.html +56 -0
- data/app/assets/javascripts/polymer/src/polymer-lib.html +15 -0
- data/app/assets/javascripts/polymer/src/standard/annotations.html +198 -0
- data/app/assets/javascripts/polymer/src/standard/configure.html +160 -0
- data/app/assets/javascripts/polymer/src/standard/effects.html +215 -0
- data/app/assets/javascripts/polymer/src/standard/events.html +127 -0
- data/app/assets/javascripts/polymer/src/standard/notify-path.html +260 -0
- data/app/assets/javascripts/polymer/src/standard/resolveUrl.html +27 -0
- data/app/assets/javascripts/polymer/src/standard/styling.html +157 -0
- data/app/assets/javascripts/polymer/src/standard/utils.html +158 -0
- data/app/assets/javascripts/polymer/src/standard/x-styling.html +300 -0
- data/app/assets/javascripts/webcomponentsjs/webcomponents-lite.js +2270 -0
- data/lib/generators/polymer/component/templates/component.html.erb +3 -3
- data/lib/generators/polymer/install/install_generator.rb +1 -1
- data/lib/polymer-rails/version.rb +1 -1
- metadata +80 -5
- data/app/assets/javascripts/polymer/layout.html +0 -286
- data/app/assets/javascripts/polymer/polymer.js +0 -14
- data/app/assets/javascripts/polymer/webcomponents.js +0 -14
@@ -0,0 +1,56 @@
|
|
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
|
+
* Automatic template management.
|
14
|
+
*
|
15
|
+
* The `template` feature locates and instances a `<template>` element
|
16
|
+
* corresponding to the current Polymer prototype.
|
17
|
+
*
|
18
|
+
* The `<template>` element may be immediately preceeding the script that
|
19
|
+
* invokes `Polymer()`.
|
20
|
+
*
|
21
|
+
* @class standard feature: template
|
22
|
+
*/
|
23
|
+
|
24
|
+
Polymer.Base.addFeature({
|
25
|
+
|
26
|
+
_prepTemplate: function() {
|
27
|
+
// locate template using dom-module
|
28
|
+
this._template =
|
29
|
+
this._template || Polymer.DomModule.import(this.is, 'template');
|
30
|
+
// fallback to look at the node previous to the currentScript.
|
31
|
+
if (!this._template) {
|
32
|
+
var script = document._currentScript || document.currentScript;
|
33
|
+
var prev = script && script.previousElementSibling;
|
34
|
+
if (prev && prev.localName === 'template') {
|
35
|
+
this._template = prev;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
},
|
39
|
+
|
40
|
+
_stampTemplate: function() {
|
41
|
+
if (this._template) {
|
42
|
+
// note: root is now a fragment which can be manipulated
|
43
|
+
// while not attached to the element.
|
44
|
+
this.root = this.instanceTemplate(this._template);
|
45
|
+
}
|
46
|
+
},
|
47
|
+
|
48
|
+
instanceTemplate: function(template) {
|
49
|
+
var dom =
|
50
|
+
document.importNode(template._content || template.content, true);
|
51
|
+
return dom;
|
52
|
+
}
|
53
|
+
|
54
|
+
});
|
55
|
+
|
56
|
+
</script>
|
@@ -0,0 +1,15 @@
|
|
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/settings.html">
|
12
|
+
<link rel="import" href="lib/polymer-bootstrap.html">
|
13
|
+
<link rel="import" href="lib/lang.html">
|
14
|
+
<link rel="import" href="lib/base.html">
|
15
|
+
<link rel="import" href="lib/dom-module.html">
|
@@ -0,0 +1,198 @@
|
|
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
|
+
<!-- employ 'Annotations' module -->
|
12
|
+
|
13
|
+
<link rel="import" href="../lib/annotations/annotations.html">
|
14
|
+
<link rel="import" href="../lib/resolve-url.html">
|
15
|
+
<script>
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Scans a template to produce an annotation object that stores expression
|
19
|
+
* metadata along with information to associate the metadata with nodes in an
|
20
|
+
* instance.
|
21
|
+
*
|
22
|
+
* Elements with `id` in the template are noted and marshaled into an
|
23
|
+
* the `$` hash in an instance.
|
24
|
+
*
|
25
|
+
* Example
|
26
|
+
*
|
27
|
+
* <template>
|
28
|
+
* <div id="foo"></div>
|
29
|
+
* </template>
|
30
|
+
* <script>
|
31
|
+
* Polymer({
|
32
|
+
* task: function() {
|
33
|
+
* this.$.foo.style.color = 'red';
|
34
|
+
* }
|
35
|
+
* });
|
36
|
+
* </script>
|
37
|
+
*
|
38
|
+
* Other expressions that are noted include:
|
39
|
+
*
|
40
|
+
* Double-mustache annotations in text content. The annotation must be the only
|
41
|
+
* content in the tag, compound expressions are not (currently) supported.
|
42
|
+
*
|
43
|
+
* <[tag]>{{path.to.host.property}}<[tag]>
|
44
|
+
*
|
45
|
+
* Double-mustache annotations in an attribute.
|
46
|
+
*
|
47
|
+
* <[tag] someAttribute="{{path.to.host.property}}"><[tag]>
|
48
|
+
*
|
49
|
+
* Only immediate host properties can automatically trigger side-effects.
|
50
|
+
* Setting `host.path` in the example above triggers the binding, setting
|
51
|
+
* `host.path.to.host.property` does not.
|
52
|
+
*
|
53
|
+
* `on-` style event declarations.
|
54
|
+
*
|
55
|
+
* <[tag] on-<event-name>="{{hostMethodName}}"><[tag]>
|
56
|
+
*
|
57
|
+
* Note: **the `annotations` feature does not actually implement the behaviors
|
58
|
+
* associated with these expressions, it only captures the data**.
|
59
|
+
*
|
60
|
+
* Other optional features contain actual data implementations.
|
61
|
+
*
|
62
|
+
* @class standard feature: annotations
|
63
|
+
*/
|
64
|
+
|
65
|
+
/*
|
66
|
+
|
67
|
+
Scans a template to produce an annotation map that stores expression metadata
|
68
|
+
and information that associates the metadata to nodes in a template instance.
|
69
|
+
|
70
|
+
Supported annotations are:
|
71
|
+
|
72
|
+
* id attributes
|
73
|
+
* binding annotations in text nodes
|
74
|
+
* double-mustache expressions: {{expression}}
|
75
|
+
* double-bracket expressions: [[expression]]
|
76
|
+
* binding annotations in attributes
|
77
|
+
* attribute-bind expressions: name="{{expression}} || [[expression]]"
|
78
|
+
* property-bind expressions: name*="{{expression}} || [[expression]]"
|
79
|
+
* property-bind expressions: name:="expression"
|
80
|
+
* event annotations
|
81
|
+
* event delegation directives: on-<eventName>="expression"
|
82
|
+
|
83
|
+
Generated data-structure:
|
84
|
+
|
85
|
+
[
|
86
|
+
{
|
87
|
+
id: '<id>',
|
88
|
+
events: [
|
89
|
+
{
|
90
|
+
mode: ['auto'|''],
|
91
|
+
name: '<name>'
|
92
|
+
value: '<expression>'
|
93
|
+
}, ...
|
94
|
+
],
|
95
|
+
bindings: [
|
96
|
+
{
|
97
|
+
kind: ['text'|'attribute'|'property'],
|
98
|
+
mode: ['auto'|''],
|
99
|
+
name: '<name>'
|
100
|
+
value: '<expression>'
|
101
|
+
}, ...
|
102
|
+
],
|
103
|
+
// TODO(sjmiles): confusingly, this is annotation-parent, not node-parent
|
104
|
+
parent: <reference to parent annotation>,
|
105
|
+
index: <integer index in parent's childNodes collection>
|
106
|
+
},
|
107
|
+
...
|
108
|
+
]
|
109
|
+
|
110
|
+
TODO(sjmiles): this module should produce either syntactic metadata
|
111
|
+
(e.g. double-mustache, double-bracket, star-attr), or semantic metadata
|
112
|
+
(e.g. manual-bind, auto-bind, property-bind). Right now it's half and half.
|
113
|
+
|
114
|
+
*/
|
115
|
+
|
116
|
+
Polymer.Base.addFeature({
|
117
|
+
|
118
|
+
// registration-time
|
119
|
+
|
120
|
+
_prepAnnotations: function() {
|
121
|
+
if (!this._template) {
|
122
|
+
this._annotes = [];
|
123
|
+
} else {
|
124
|
+
// TODO(sorvell): ad hoc method of plugging behavior into Annotations
|
125
|
+
Polymer.Annotations.prepElement = this._prepElement.bind(this);
|
126
|
+
this._annotes = Polymer.Annotations.parseAnnotations(this._template);
|
127
|
+
Polymer.Annotations.prepElement = null;
|
128
|
+
}
|
129
|
+
},
|
130
|
+
|
131
|
+
_prepElement: function(element) {
|
132
|
+
Polymer.ResolveUrl.resolveAttrs(element, this._template.ownerDocument);
|
133
|
+
},
|
134
|
+
|
135
|
+
// instance-time
|
136
|
+
|
137
|
+
findAnnotatedNode: Polymer.Annotations.findAnnotatedNode,
|
138
|
+
|
139
|
+
// marshal all teh things
|
140
|
+
_marshalAnnotationReferences: function() {
|
141
|
+
if (this._template) {
|
142
|
+
this._marshalIdNodes();
|
143
|
+
this._marshalAnnotatedNodes();
|
144
|
+
this._marshalAnnotatedListeners();
|
145
|
+
}
|
146
|
+
},
|
147
|
+
|
148
|
+
// push configuration references at configure time
|
149
|
+
_configureAnnotationReferences: function() {
|
150
|
+
this._configureTemplateContent();
|
151
|
+
},
|
152
|
+
|
153
|
+
// nested template contents have been stored prototypically to avoid
|
154
|
+
// unnecessary duplication, here we put references to the
|
155
|
+
// indirected contents onto the nested template instances
|
156
|
+
_configureTemplateContent: function() {
|
157
|
+
this._annotes.forEach(function(note) {
|
158
|
+
if (note.templateContent) {
|
159
|
+
var template = this.findAnnotatedNode(this.root, note);
|
160
|
+
template._content = note.templateContent;
|
161
|
+
}
|
162
|
+
}, this);
|
163
|
+
},
|
164
|
+
|
165
|
+
// construct `$` map (from id annotations)
|
166
|
+
_marshalIdNodes: function() {
|
167
|
+
this.$ = {};
|
168
|
+
this._annotes.forEach(function(a) {
|
169
|
+
if (a.id) {
|
170
|
+
this.$[a.id] = this.findAnnotatedNode(this.root, a);
|
171
|
+
}
|
172
|
+
}, this);
|
173
|
+
},
|
174
|
+
|
175
|
+
// concretize `_nodes` map (from anonymous annotations)
|
176
|
+
_marshalAnnotatedNodes: function() {
|
177
|
+
if (this._nodes) {
|
178
|
+
this._nodes = this._nodes.map(function(a) {
|
179
|
+
return this.findAnnotatedNode(this.root, a);
|
180
|
+
}, this);
|
181
|
+
}
|
182
|
+
},
|
183
|
+
|
184
|
+
// install event listeners (from event annotations)
|
185
|
+
_marshalAnnotatedListeners: function() {
|
186
|
+
this._annotes.forEach(function(a) {
|
187
|
+
if (a.events && a.events.length) {
|
188
|
+
var node = this.findAnnotatedNode(this.root, a);
|
189
|
+
a.events.forEach(function(e) {
|
190
|
+
this.listen(node, e.name, e.value);
|
191
|
+
}, this);
|
192
|
+
}
|
193
|
+
}, this);
|
194
|
+
}
|
195
|
+
|
196
|
+
});
|
197
|
+
|
198
|
+
</script>
|
@@ -0,0 +1,160 @@
|
|
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
|
+
<script>
|
12
|
+
|
13
|
+
/*
|
14
|
+
Process inputs efficiently via a configure lifecycle callback.
|
15
|
+
Configure is called top-down, host before local dom. Users should
|
16
|
+
implement configure to supply a set of default values for the element by
|
17
|
+
returning an object containing the properties and values to set.
|
18
|
+
|
19
|
+
Configured values are not immediately set, instead they are set when
|
20
|
+
an element becomes ready, after its local dom is ready. This ensures
|
21
|
+
that any user change handlers are not called before ready time.
|
22
|
+
|
23
|
+
*/
|
24
|
+
|
25
|
+
/*
|
26
|
+
Implementation notes:
|
27
|
+
|
28
|
+
Configured values are collected into _config. At ready time, properties
|
29
|
+
are set to the values in _config. This ensures properties are set child
|
30
|
+
before host and change handlers are called only at ready time. The host
|
31
|
+
will reset a value already propagated to a child, but this is not
|
32
|
+
inefficient because of dirty checking at the set point.
|
33
|
+
|
34
|
+
Bind notification events are sent when properties are set at ready time
|
35
|
+
and thus received by the host before it is ready. Since notifications result
|
36
|
+
in property updates and this triggers side effects, handling notifications
|
37
|
+
is deferred until ready time.
|
38
|
+
|
39
|
+
In general, events can be heard before an element is ready. This may occur
|
40
|
+
when a user sends an event in a change handler or listens to a data event
|
41
|
+
directly (on-foo-changed).
|
42
|
+
*/
|
43
|
+
|
44
|
+
Polymer.Base.addFeature({
|
45
|
+
|
46
|
+
// storage for configuration
|
47
|
+
_setupConfigure: function(initialConfig) {
|
48
|
+
this._config = initialConfig || {};
|
49
|
+
this._handlers = [];
|
50
|
+
},
|
51
|
+
|
52
|
+
// static attributes are deserialized into _config
|
53
|
+
_takeAttributes: function() {
|
54
|
+
this._takeAttributesToModel(this._config);
|
55
|
+
},
|
56
|
+
|
57
|
+
// at configure time values are stored in _config
|
58
|
+
_configValue: function(name, value) {
|
59
|
+
this._config[name] = value;
|
60
|
+
},
|
61
|
+
|
62
|
+
// configure: returns user supplied default property values
|
63
|
+
// combines with _config to create final property values
|
64
|
+
_configure: function() {
|
65
|
+
this._configureAnnotationReferences();
|
66
|
+
var i;
|
67
|
+
// get individual default values from property config
|
68
|
+
var config = {};
|
69
|
+
for (i in this.properties) {
|
70
|
+
var c = this.properties[i];
|
71
|
+
if (c.value !== undefined) {
|
72
|
+
if (typeof c.value == 'function') {
|
73
|
+
config[i] = c.value.call(this, this._config);
|
74
|
+
} else {
|
75
|
+
config[i] = c.value;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
// get add'l default values from central configure
|
80
|
+
this.simpleMixin(config, this.configure(this._config));
|
81
|
+
// combine defaults returned from configure with inputs in _config
|
82
|
+
this.simpleMixin(config, this._config);
|
83
|
+
// this is the new _config, which are the final values to be applied
|
84
|
+
this._config = config;
|
85
|
+
// pass configuration data to bindings
|
86
|
+
this._distributeConfig(this._config);
|
87
|
+
},
|
88
|
+
|
89
|
+
simpleMixin: function(a, b) {
|
90
|
+
for (var i in b) {
|
91
|
+
a[i] = b[i];
|
92
|
+
}
|
93
|
+
},
|
94
|
+
|
95
|
+
// distribute config values to bound nodes.
|
96
|
+
_distributeConfig: function(config) {
|
97
|
+
var fx$ = this._propertyEffects;
|
98
|
+
if (fx$) {
|
99
|
+
for (var p in config) {
|
100
|
+
var fx = fx$[p];
|
101
|
+
if (fx) {
|
102
|
+
for (var i=0, l=fx.length, x; (i<l) && (x=fx[i]); i++) {
|
103
|
+
if (x.kind === 'annotation') {
|
104
|
+
var node = this._nodes[x.effect.index];
|
105
|
+
// seeding configuration only
|
106
|
+
if (node._configValue) {
|
107
|
+
var value = (p === x.effect.value) ? config[p] :
|
108
|
+
this.getPathValue(x.effect.value, config);
|
109
|
+
node._configValue(x.effect.name, value);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
},
|
117
|
+
|
118
|
+
_beforeReady: function() {
|
119
|
+
this._applyConfig(this._config);
|
120
|
+
this._flushHandlers();
|
121
|
+
},
|
122
|
+
|
123
|
+
// NOTE: values are already propagated to children via
|
124
|
+
// _distributeConfig so propagation triggered by effects here is
|
125
|
+
// redundant, but safe due to dirty checking
|
126
|
+
_applyConfig: function(config) {
|
127
|
+
for (var n in config) {
|
128
|
+
// Don't stomp on values that may have been set by other side effects
|
129
|
+
if (this[n] === undefined) {
|
130
|
+
this[n] = config[n];
|
131
|
+
}
|
132
|
+
}
|
133
|
+
},
|
134
|
+
|
135
|
+
// NOTE: Notifications can be processed before ready since
|
136
|
+
// they are sent at *child* ready time. Since notifications cause side
|
137
|
+
// effects and side effects must not be processed before ready time,
|
138
|
+
// handling is queue/defered until then.
|
139
|
+
_notifyListener: function(fn, e) {
|
140
|
+
if (!this._readied) {
|
141
|
+
this._queueHandler([fn, e, e.target]);
|
142
|
+
} else {
|
143
|
+
return fn.call(this, e, e.target);
|
144
|
+
}
|
145
|
+
},
|
146
|
+
|
147
|
+
_queueHandler: function(args) {
|
148
|
+
this._handlers.push(args);
|
149
|
+
},
|
150
|
+
|
151
|
+
_flushHandlers: function() {
|
152
|
+
var h$ = this._handlers;
|
153
|
+
for (var i=0, l=h$.length, h; (i<l) && (h=h$[i]); i++) {
|
154
|
+
h[0].call(this, h[1], h[2]);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
});
|
159
|
+
|
160
|
+
</script>
|
@@ -0,0 +1,215 @@
|
|
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/bind/accessors.html">
|
12
|
+
<link rel="import" href="../lib/bind/effects.html">
|
13
|
+
|
14
|
+
<script>
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Support for the declarative property sugaring via mustache `{{ }}`
|
18
|
+
* annotations in templates, and via the `properties` objects on
|
19
|
+
* prototypes.
|
20
|
+
*
|
21
|
+
* Example:
|
22
|
+
*
|
23
|
+
* <template>
|
24
|
+
* <span hidden="{{hideSpan}}">{{name}}</span> is on the hook.
|
25
|
+
* </template>
|
26
|
+
*
|
27
|
+
* The `properties` object syntax is as follows:
|
28
|
+
*
|
29
|
+
* Polymer({
|
30
|
+
*
|
31
|
+
* properties: {
|
32
|
+
* myProp: {
|
33
|
+
* observer: 'myPropChanged',
|
34
|
+
* computed: 'computemyProp(input1, input2)'
|
35
|
+
* }
|
36
|
+
* }
|
37
|
+
*
|
38
|
+
* ...
|
39
|
+
*
|
40
|
+
* });
|
41
|
+
*
|
42
|
+
* The `bind` feature also provides an API for registering effects against
|
43
|
+
* properties.
|
44
|
+
*
|
45
|
+
* Property effects can be created imperatively, by template-annotations
|
46
|
+
* (e.g. mustache notation), or by declaration in the `properties` object.
|
47
|
+
*
|
48
|
+
* The effect data is consumed by the `bind` subsystem (`/src/bind/*`),
|
49
|
+
* which compiles the effects into efficient JavaScript that is triggered,
|
50
|
+
* e.g., when a property is set to a new value.
|
51
|
+
*
|
52
|
+
* @class data feature: bind
|
53
|
+
*/
|
54
|
+
|
55
|
+
Polymer.Base.addFeature({
|
56
|
+
|
57
|
+
_addPropertyEffect: function(property, kind, effect) {
|
58
|
+
// TODO(sjmiles): everything to the right of the first '.' is lost, implies
|
59
|
+
// there is some duplicate information flow (not the only sign)
|
60
|
+
var model = property.split('.').shift();
|
61
|
+
Polymer.Bind.addPropertyEffect(this, model, kind, effect);
|
62
|
+
},
|
63
|
+
|
64
|
+
// prototyping
|
65
|
+
|
66
|
+
_prepEffects: function() {
|
67
|
+
Polymer.Bind.prepareModel(this);
|
68
|
+
this._addPropertyEffects(this.properties);
|
69
|
+
this._addObserverEffects(this.observers);
|
70
|
+
this._addAnnotationEffects(this._annotes);
|
71
|
+
Polymer.Bind.createBindings(this);
|
72
|
+
},
|
73
|
+
|
74
|
+
_addPropertyEffects: function(effects) {
|
75
|
+
if (effects) {
|
76
|
+
for (var n in effects) {
|
77
|
+
var effect = effects[n];
|
78
|
+
if (effect.observer) {
|
79
|
+
this._addObserverEffect(n, effect.observer);
|
80
|
+
}
|
81
|
+
if (effect.computed) {
|
82
|
+
this._addComputedEffect(n, effect.computed);
|
83
|
+
}
|
84
|
+
if (this.isNotifyProperty(n)) {
|
85
|
+
this._addPropertyEffect(n, 'notify');
|
86
|
+
}
|
87
|
+
if (this.isReflectedProperty(n)) {
|
88
|
+
this._addPropertyEffect(n, 'reflect');
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
},
|
93
|
+
|
94
|
+
_addComputedEffect: function(name, expression) {
|
95
|
+
var index = expression.indexOf('(');
|
96
|
+
var method = expression.slice(0, index);
|
97
|
+
var args = expression.slice(index + 1, -1).replace(/ /g, '').split(',');
|
98
|
+
//console.log('%c on [%s] compute [%s] via [%s]', 'color: green', args[0], name, method);
|
99
|
+
var effect = {
|
100
|
+
property: name,
|
101
|
+
args: args,
|
102
|
+
methodName: method
|
103
|
+
};
|
104
|
+
for (var i=0; i<args.length; i++) {
|
105
|
+
this._addPropertyEffect(args[i], 'compute', effect);
|
106
|
+
}
|
107
|
+
},
|
108
|
+
|
109
|
+
_addObserverEffects: function(effects) {
|
110
|
+
for (var n in effects) {
|
111
|
+
this._addObserverEffect(n, effects[n]);
|
112
|
+
}
|
113
|
+
},
|
114
|
+
|
115
|
+
_addObserverEffect: function(property, observer) {
|
116
|
+
var effect = {
|
117
|
+
method: observer
|
118
|
+
};
|
119
|
+
var props = property.split(' ');
|
120
|
+
if (props.length == 1) {
|
121
|
+
// Single property synchronous observer (supports paths)
|
122
|
+
var model = property.split('.').shift();
|
123
|
+
if (model != property) {
|
124
|
+
// TODO(kschaaf): path observers won't get the right `new` argument
|
125
|
+
this.addPathObserver(property, observer);
|
126
|
+
}
|
127
|
+
effect.property = model;
|
128
|
+
this._addPropertyEffect(model, 'observer', effect);
|
129
|
+
} else {
|
130
|
+
// Multiple-property observer
|
131
|
+
effect.properties = props;
|
132
|
+
for (var i=0, l=props.length; i<l; i++) {
|
133
|
+
this._addPropertyEffect(props[i], 'observer', effect);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
},
|
137
|
+
|
138
|
+
_addAnnotationEffects: function(effects) {
|
139
|
+
// create a virtual annotation list, must be concretized at instance time
|
140
|
+
this._nodes = [];
|
141
|
+
// process annotations that have been parsed from template
|
142
|
+
effects.forEach(function(note) {
|
143
|
+
// where to find the node in the concretized list
|
144
|
+
var index = this._nodes.push(note) - 1;
|
145
|
+
note.bindings.forEach(function(effect) {
|
146
|
+
this._addAnnotationEffect(effect, index);
|
147
|
+
}, this);
|
148
|
+
}, this);
|
149
|
+
},
|
150
|
+
|
151
|
+
_addAnnotationEffect: function(effect, index) {
|
152
|
+
// TODO(sjmiles): annotations have 'effects' proper and 'listener'
|
153
|
+
if (Polymer.Bind._shouldAddListener(effect)) {
|
154
|
+
// <node>.on.<dash-case-property>-changed: <path> = e.detail.value
|
155
|
+
Polymer.Bind._addAnnotatedListener(this, index,
|
156
|
+
effect.name, effect.value, effect.event);
|
157
|
+
}
|
158
|
+
var computed = effect.value.match(/(\w*)\((.*)\)/);
|
159
|
+
if (computed) {
|
160
|
+
var method = computed[1];
|
161
|
+
var args = computed[2].split(/[^\w]+/);
|
162
|
+
this._addAnnotatedComputationEffect(method, args, effect, index);
|
163
|
+
} else {
|
164
|
+
// capture the node index
|
165
|
+
effect.index = index;
|
166
|
+
// discover top-level property (model) from path
|
167
|
+
var model = effect.value.split('.').shift();
|
168
|
+
// add 'annotation' binding effect for property 'model'
|
169
|
+
this._addPropertyEffect(model, 'annotation', effect);
|
170
|
+
}
|
171
|
+
},
|
172
|
+
|
173
|
+
_addAnnotatedComputationEffect: function(method, args, info, index) {
|
174
|
+
var effect = {
|
175
|
+
kind: info.kind,
|
176
|
+
property: info.name,
|
177
|
+
index: index,
|
178
|
+
args: args,
|
179
|
+
methodName: method
|
180
|
+
};
|
181
|
+
for (var i=0, l=args.length; i<l; i++) {
|
182
|
+
this._addPropertyEffect(args[i], 'annotatedComputation', effect);
|
183
|
+
}
|
184
|
+
},
|
185
|
+
|
186
|
+
// instancing
|
187
|
+
|
188
|
+
_marshalInstanceEffects: function() {
|
189
|
+
Polymer.Bind.prepareInstance(this);
|
190
|
+
Polymer.Bind.setupBindListeners(this);
|
191
|
+
},
|
192
|
+
|
193
|
+
_applyEffectValue: function(value, info) {
|
194
|
+
var node = this._nodes[info.index];
|
195
|
+
// TODO(sorvell): ideally, the info object is normalized for easy
|
196
|
+
// lookup here.
|
197
|
+
var property = info.property || info.name || 'textContent';
|
198
|
+
// TODO(sorvell): consider pre-processing this step so we don't need
|
199
|
+
// this lookup.
|
200
|
+
// if (info._class === undefined) {
|
201
|
+
// info._class = (property === 'class' || property === 'className');
|
202
|
+
// }
|
203
|
+
// if (info._class) {
|
204
|
+
// value = this._scopeElementClass(node, value);
|
205
|
+
// }
|
206
|
+
if (info.kind == 'attribute') {
|
207
|
+
this.serializeValueToAttribute(value, property, node);
|
208
|
+
} else {
|
209
|
+
return node[property] = value;
|
210
|
+
}
|
211
|
+
}
|
212
|
+
|
213
|
+
});
|
214
|
+
|
215
|
+
</script>
|