polymer-core-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +82 -0
- data/Rakefile +2 -0
- data/app/assets/components/core-ajax/core-ajax.html.erb +320 -0
- data/app/assets/components/core-ajax/core-xhr.html.erb +112 -0
- data/app/assets/components/core-animated-pages/core-animated-pages.css +18 -0
- data/app/assets/components/core-animated-pages/core-animated-pages.html.erb +413 -0
- data/app/assets/components/core-animated-pages/transitions/cascade-transition.html +138 -0
- data/app/assets/components/core-animated-pages/transitions/core-transition-pages.html.erb +173 -0
- data/app/assets/components/core-animated-pages/transitions/cross-fade.html.erb +173 -0
- data/app/assets/components/core-animated-pages/transitions/hero-transition.css +12 -0
- data/app/assets/components/core-animated-pages/transitions/hero-transition.html.erb +267 -0
- data/app/assets/components/core-animated-pages/transitions/list-cascade.html +58 -0
- data/app/assets/components/core-animated-pages/transitions/scale-up.html +37 -0
- data/app/assets/components/core-animated-pages/transitions/slide-down.html +55 -0
- data/app/assets/components/core-animated-pages/transitions/slide-from-bottom.html +31 -0
- data/app/assets/components/core-animated-pages/transitions/slide-from-right.html +35 -0
- data/app/assets/components/core-animated-pages/transitions/slide-up.html +82 -0
- data/app/assets/components/core-animated-pages/transitions/tile-cascade.html +101 -0
- data/app/assets/components/core-animation/core-animation-group.html.erb +168 -0
- data/app/assets/components/core-animation/core-animation.html.erb +523 -0
- data/app/assets/components/core-animation/web-animations.html.erb +1 -0
- data/app/assets/components/core-collapse/core-collapse.css +16 -0
- data/app/assets/components/core-collapse/core-collapse.html.erb +247 -0
- data/app/assets/components/core-drag-drop/core-drag-drop.html +109 -0
- data/app/assets/components/core-drawer-panel/core-drawer-panel.css +162 -0
- data/app/assets/components/core-drawer-panel/core-drawer-panel.html.erb +150 -0
- data/app/assets/components/core-field/core-field.css +38 -0
- data/app/assets/components/core-field/core-field.html.erb +32 -0
- data/app/assets/components/core-header-panel/core-header-panel.css +75 -0
- data/app/assets/components/core-header-panel/core-header-panel.html.erb +196 -0
- data/app/assets/components/core-icon/core-icon.css +25 -0
- data/app/assets/components/core-icon/core-icon.html.erb +126 -0
- data/app/assets/components/core-icon-button/core-icon-button.css +70 -0
- data/app/assets/components/core-icon-button/core-icon-button.html.erb +83 -0
- data/app/assets/components/core-icons/core-icons.html +14 -0
- data/app/assets/components/core-iconset/core-iconset.html.erb +236 -0
- data/app/assets/components/core-iconset-svg/core-iconset-svg.html +170 -0
- data/app/assets/components/core-input/core-input.css +35 -0
- data/app/assets/components/core-input/core-input.html.erb +311 -0
- data/app/assets/components/core-item/core-item.css +31 -0
- data/app/assets/components/core-item/core-item.html.erb +80 -0
- data/app/assets/components/core-list/core-list.css +20 -0
- data/app/assets/components/core-list/core-list.html.erb +403 -0
- data/app/assets/components/core-localstorage/core-localstorage.html +126 -0
- data/app/assets/components/core-media-query/core-media-query.html +86 -0
- data/app/assets/components/core-menu/core-menu.css +18 -0
- data/app/assets/components/core-menu/core-menu.html.erb +62 -0
- data/app/assets/components/core-menu/core-submenu.css +29 -0
- data/app/assets/components/core-menu/core-submenu.html.erb +106 -0
- data/app/assets/components/core-menu-button/core-menu-button.css +10 -0
- data/app/assets/components/core-menu-button/core-menu-button.html.erb +139 -0
- data/app/assets/components/core-meta/core-meta.html +143 -0
- data/app/assets/components/core-overlay/core-key-helper.html +17 -0
- data/app/assets/components/core-overlay/core-overlay-layer.html +112 -0
- data/app/assets/components/core-overlay/core-overlay.html.erb +661 -0
- data/app/assets/components/core-pages/core-pages.css +30 -0
- data/app/assets/components/core-pages/core-pages.html.erb +43 -0
- data/app/assets/components/core-range/core-range.html +107 -0
- data/app/assets/components/core-scaffold/core-scaffold.html.erb +147 -0
- data/app/assets/components/core-scroll-header-panel/core-scroll-header-panel.css +57 -0
- data/app/assets/components/core-scroll-header-panel/core-scroll-header-panel.html.erb +257 -0
- data/app/assets/components/core-selection/core-selection.html +148 -0
- data/app/assets/components/core-selector/core-selector.html.erb +423 -0
- data/app/assets/components/core-shared-lib/core-shared-lib.html +150 -0
- data/app/assets/components/core-signals/core-signals.html +83 -0
- data/app/assets/components/core-splitter/core-splitter.css.erb +27 -0
- data/app/assets/components/core-splitter/core-splitter.html.erb +159 -0
- data/app/assets/components/core-splitter/handle-h.svg +4 -0
- data/app/assets/components/core-splitter/handle.svg +4 -0
- data/app/assets/components/core-style/core-style.html +385 -0
- data/app/assets/components/core-toolbar/core-toolbar.css +126 -0
- data/app/assets/components/core-toolbar/core-toolbar.html.erb +73 -0
- data/app/assets/components/core-tooltip/core-tooltip.css +103 -0
- data/app/assets/components/core-tooltip/core-tooltip.html.erb +144 -0
- data/app/assets/components/core-transition/core-transition-css.html.erb +76 -0
- data/app/assets/components/core-transition/core-transition-overlay.css +46 -0
- data/app/assets/components/core-transition/core-transition.html.erb +44 -0
- data/app/assets/components/web-animations-js/web-animations.js +5666 -0
- data/lib/polymer-core-rails/engine.rb +4 -0
- data/lib/polymer-core-rails/version.rb +3 -0
- data/lib/polymer-core-rails.rb +2 -0
- metadata +167 -0
@@ -0,0 +1,403 @@
|
|
1
|
+
<!--
|
2
|
+
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
3
|
+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
4
|
+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
5
|
+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
6
|
+
Code distributed by Google as part of the polymer project is also
|
7
|
+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
8
|
+
-->
|
9
|
+
|
10
|
+
<!--
|
11
|
+
`core-list` displays a virtual, 'infinite' list. The template inside the
|
12
|
+
`core-list` element represents the dom to create for each list item. The
|
13
|
+
`data` property specifies an array of list item data. The `height` property
|
14
|
+
represents the height of a list item.
|
15
|
+
|
16
|
+
By default, the list supports selection via tapping. Styling the selection
|
17
|
+
should be done via binding. The `selectedProperty` property is set on the
|
18
|
+
list view data for each selected item.
|
19
|
+
|
20
|
+
`core-list` manages a viewport of data based on the current scroll position.
|
21
|
+
For performance reasons, not every item in the list is rendered at once.
|
22
|
+
|
23
|
+
<core-list data="{{data}}" height="80">
|
24
|
+
<template>
|
25
|
+
<div class="{{ {selected: selected} | tokenList }}">List row: {{index}}</div>
|
26
|
+
</template>
|
27
|
+
</core-list>
|
28
|
+
|
29
|
+
@group Polymer Core Elements
|
30
|
+
@element core-list
|
31
|
+
-->
|
32
|
+
|
33
|
+
<%= html_import_tag "core-selection/core-selection" %>
|
34
|
+
|
35
|
+
<polymer-element name="core-list" on-tap="{{tapHandler}}">
|
36
|
+
<template>
|
37
|
+
<core-selection id="selection" multi="{{multi}}" on-core-select="{{selectedHandler}}"></core-selection>
|
38
|
+
<%= stylesheet_link_tag "core-list/core-list"%>
|
39
|
+
<div id="viewport" class="core-list-viewport"><content></content></div>
|
40
|
+
</template>
|
41
|
+
<script>
|
42
|
+
(function() {
|
43
|
+
|
44
|
+
Polymer('core-list', {
|
45
|
+
|
46
|
+
publish: {
|
47
|
+
/**
|
48
|
+
* Fired when an item element is tapped.
|
49
|
+
*
|
50
|
+
* @event core-activate
|
51
|
+
* @param {Object} detail
|
52
|
+
* @param {Object} detail.item the item element
|
53
|
+
*/
|
54
|
+
|
55
|
+
/**
|
56
|
+
*
|
57
|
+
* An array of source data for the list to display.
|
58
|
+
*
|
59
|
+
* @attribute data
|
60
|
+
* @type array
|
61
|
+
* @default null
|
62
|
+
*/
|
63
|
+
data: null,
|
64
|
+
|
65
|
+
/**
|
66
|
+
*
|
67
|
+
* An optional element on which to listen for scroll events.
|
68
|
+
*
|
69
|
+
* @attribute scrollTarget
|
70
|
+
* @type Element
|
71
|
+
* @default core-list
|
72
|
+
*/
|
73
|
+
scrollTarget: null,
|
74
|
+
|
75
|
+
/**
|
76
|
+
*
|
77
|
+
* The height of a list item. `core-list` currently supports only fixed-height
|
78
|
+
* list items. This height must be specified via the height property.
|
79
|
+
*
|
80
|
+
* @attribute height
|
81
|
+
* @type number
|
82
|
+
* @default 80
|
83
|
+
*/
|
84
|
+
height: 80,
|
85
|
+
|
86
|
+
/**
|
87
|
+
*
|
88
|
+
* The number of extra items rendered above the minimum set required to
|
89
|
+
* fill the list's height.
|
90
|
+
*
|
91
|
+
* @attribute extraItems
|
92
|
+
* @type number
|
93
|
+
* @default 30
|
94
|
+
*/
|
95
|
+
extraItems: 30,
|
96
|
+
|
97
|
+
/**
|
98
|
+
*
|
99
|
+
* The property set on the list view data to represent selection state.
|
100
|
+
* This should set so that it does not conflict with other data properties.
|
101
|
+
* Note, selection data is not stored on the data in given in the data property.
|
102
|
+
*
|
103
|
+
* @attribute selectedProperty
|
104
|
+
* @type string
|
105
|
+
* @default 'selected'
|
106
|
+
*/
|
107
|
+
selectedProperty: 'selected',
|
108
|
+
|
109
|
+
// TODO(sorvell): experimental
|
110
|
+
/**
|
111
|
+
*
|
112
|
+
* If true, data is sync'd from the list back to the list's data.
|
113
|
+
*
|
114
|
+
* @attribute sync
|
115
|
+
* @type boolean
|
116
|
+
* @default false
|
117
|
+
*/
|
118
|
+
sync: false,
|
119
|
+
|
120
|
+
/**
|
121
|
+
*
|
122
|
+
* Set to true to support multiple selection.
|
123
|
+
*
|
124
|
+
* @attribute multi
|
125
|
+
* @type boolean
|
126
|
+
* @default false
|
127
|
+
*/
|
128
|
+
multi: false
|
129
|
+
|
130
|
+
},
|
131
|
+
|
132
|
+
observe: {
|
133
|
+
'data template scrollTarget': 'initialize'
|
134
|
+
},
|
135
|
+
|
136
|
+
ready: function() {
|
137
|
+
this.clearSelection();
|
138
|
+
this._boundScrollHandler = this.scrollHandler.bind(this);
|
139
|
+
},
|
140
|
+
|
141
|
+
attached: function() {
|
142
|
+
this.template = this.querySelector('template');
|
143
|
+
},
|
144
|
+
|
145
|
+
// TODO(sorvell): it'd be nice to dispense with 'data' and just use
|
146
|
+
// template repeat's model. However, we need tighter integration
|
147
|
+
// with TemplateBinding for this.
|
148
|
+
initialize: function() {
|
149
|
+
if (!this.data || !this.template) {
|
150
|
+
return;
|
151
|
+
}
|
152
|
+
var target = this.scrollTarget || this;
|
153
|
+
if (this._target !== target) {
|
154
|
+
if (this._target) {
|
155
|
+
this._target.removeEventListener('scroll', this._boundScrollHandler, false);
|
156
|
+
}
|
157
|
+
this._target = target;
|
158
|
+
this._target.addEventListener('scroll', this._boundScrollHandler, false);
|
159
|
+
}
|
160
|
+
|
161
|
+
this.initializeViewport();
|
162
|
+
this.initalizeData();
|
163
|
+
this.onMutation(this, this.initializeItems);
|
164
|
+
},
|
165
|
+
|
166
|
+
// TODO(sorvell): need to handle resizing
|
167
|
+
initializeViewport: function() {
|
168
|
+
this.$.viewport.style.height = this.height * this.data.length + 'px';
|
169
|
+
this._visibleCount = Math.ceil(this._target.offsetHeight / this.height);
|
170
|
+
this._physicalCount = Math.min(this._visibleCount + this.extraItems,
|
171
|
+
this.data.length);
|
172
|
+
this._physicalHeight = this.height * this._physicalCount;
|
173
|
+
},
|
174
|
+
|
175
|
+
// TODO(sorvell): selection currently cannot be maintained when
|
176
|
+
// items are added or deleted.
|
177
|
+
initalizeData: function() {
|
178
|
+
var exampleDatum = this.data[0] || {};
|
179
|
+
this._propertyNames = Object.getOwnPropertyNames(exampleDatum);
|
180
|
+
this._physicalData = new Array(this._physicalCount);
|
181
|
+
for (var i = 0; i < this._physicalCount; ++i) {
|
182
|
+
this._physicalData[i] = {};
|
183
|
+
this.updateItem(i, i);
|
184
|
+
}
|
185
|
+
this.template.model = this._physicalData;
|
186
|
+
this.template.setAttribute('repeat', '');
|
187
|
+
},
|
188
|
+
|
189
|
+
initializeItems: function() {
|
190
|
+
this._physicalItems = new Array(this._physicalCount);
|
191
|
+
for (var i = 0, item = this.template.nextElementSibling;
|
192
|
+
item && i < this._physicalCount;
|
193
|
+
++i, item = item.nextElementSibling) {
|
194
|
+
this._physicalItems[i] = item;
|
195
|
+
item._transformValue = 0;
|
196
|
+
}
|
197
|
+
this.refresh(false);
|
198
|
+
},
|
199
|
+
|
200
|
+
updateItem: function(virtualIndex, physicalIndex) {
|
201
|
+
var virtualDatum = this.data[virtualIndex];
|
202
|
+
var physicalDatum = this._physicalData[physicalIndex];
|
203
|
+
this.pushItemData(virtualDatum, physicalDatum);
|
204
|
+
physicalDatum._physicalIndex = physicalIndex;
|
205
|
+
physicalDatum._virtualIndex = virtualIndex;
|
206
|
+
if (this.selectedProperty) {
|
207
|
+
physicalDatum[this.selectedProperty] = this._selectedData.get(virtualDatum);
|
208
|
+
}
|
209
|
+
},
|
210
|
+
|
211
|
+
pushItemData: function(source, dest) {
|
212
|
+
for (var i = 0; i < this._propertyNames.length; ++i) {
|
213
|
+
var propertyName = this._propertyNames[i];
|
214
|
+
dest[propertyName] = source[propertyName];
|
215
|
+
}
|
216
|
+
},
|
217
|
+
|
218
|
+
// experimental: push physical data back to this.data.
|
219
|
+
// this is optional when scrolling and needs to be called at other times.
|
220
|
+
syncData: function() {
|
221
|
+
if (this.firstPhysicalIndex === undefined ||
|
222
|
+
this.baseVirtualIndex === undefined) {
|
223
|
+
return;
|
224
|
+
}
|
225
|
+
var p, v;
|
226
|
+
for (var i = 0; i < this.firstPhysicalIndex; ++i) {
|
227
|
+
p = this._physicalData[i];
|
228
|
+
v = this.data[this.baseVirtualIndex + this._physicalCount + i];
|
229
|
+
this.pushItemData(p, v);
|
230
|
+
}
|
231
|
+
for (var i = this.firstPhysicalIndex; i < this._physicalCount; ++i) {
|
232
|
+
p = this._physicalData[i];
|
233
|
+
v = this.data[this.baseVirtualIndex + i];
|
234
|
+
this.pushItemData(p, v);
|
235
|
+
}
|
236
|
+
},
|
237
|
+
|
238
|
+
scrollHandler: function(e, detail) {
|
239
|
+
this._scrollTop = e.detail ? e.detail.target.scrollTop : e.target.scrollTop;
|
240
|
+
this.refresh(false);
|
241
|
+
},
|
242
|
+
|
243
|
+
/**
|
244
|
+
* Refresh the list at the current scroll position.
|
245
|
+
*
|
246
|
+
* @method refresh
|
247
|
+
*/
|
248
|
+
refresh: function(force) {
|
249
|
+
var firstVisibleIndex = Math.floor(this._scrollTop / this.height);
|
250
|
+
var visibleMidpoint = firstVisibleIndex + this._visibleCount / 2;
|
251
|
+
|
252
|
+
var firstReifiedIndex = Math.max(0, Math.floor(visibleMidpoint -
|
253
|
+
this._physicalCount / 2));
|
254
|
+
firstReifiedIndex = Math.min(firstReifiedIndex, this.data.length -
|
255
|
+
this._physicalCount);
|
256
|
+
|
257
|
+
var firstPhysicalIndex = firstReifiedIndex % this._physicalCount;
|
258
|
+
var baseVirtualIndex = firstReifiedIndex - firstPhysicalIndex;
|
259
|
+
|
260
|
+
var baseTransformValue = Math.floor(this.height * baseVirtualIndex);
|
261
|
+
var nextTransformValue = Math.floor(baseTransformValue +
|
262
|
+
this._physicalHeight);
|
263
|
+
|
264
|
+
var baseTransformString = 'translate3d(0,' + baseTransformValue + 'px,0)';
|
265
|
+
var nextTransformString = 'translate3d(0,' + nextTransformValue + 'px,0)';
|
266
|
+
// TODO(sorvell): experiemental for sync'ing back to virtual data.
|
267
|
+
if (this.sync) {
|
268
|
+
this.syncData();
|
269
|
+
}
|
270
|
+
this.firstPhysicalIndex = firstPhysicalIndex;
|
271
|
+
this.baseVirtualIndex = baseVirtualIndex;
|
272
|
+
|
273
|
+
for (var i = 0; i < firstPhysicalIndex; ++i) {
|
274
|
+
var item = this._physicalItems[i];
|
275
|
+
if (force || item._transformValue != nextTransformValue) {
|
276
|
+
this.updateItem(baseVirtualIndex + this._physicalCount + i, i);
|
277
|
+
setTransform(item, nextTransformString, nextTransformValue);
|
278
|
+
}
|
279
|
+
}
|
280
|
+
for (var i = firstPhysicalIndex; i < this._physicalCount; ++i) {
|
281
|
+
var item = this._physicalItems[i];
|
282
|
+
if (force || item._transformValue != baseTransformValue) {
|
283
|
+
this.updateItem(baseVirtualIndex + i, i);
|
284
|
+
setTransform(item, baseTransformString, baseTransformValue);
|
285
|
+
}
|
286
|
+
}
|
287
|
+
},
|
288
|
+
|
289
|
+
// list selection
|
290
|
+
tapHandler: function(e) {
|
291
|
+
if (e.target === this) {
|
292
|
+
return;
|
293
|
+
}
|
294
|
+
if (this.sync) {
|
295
|
+
this.syncData();
|
296
|
+
}
|
297
|
+
var n = e.target;
|
298
|
+
var model = n.templateInstance && n.templateInstance.model;
|
299
|
+
if (model) {
|
300
|
+
var vi = model._virtualIndex, pi = model._physicalIndex;
|
301
|
+
var data = this.data[vi], item = this._physicalItems[pi];
|
302
|
+
this.$.selection.select(data);
|
303
|
+
this.asyncFire('core-activate', {data: data, item: item});
|
304
|
+
}
|
305
|
+
},
|
306
|
+
|
307
|
+
selectedHandler: function(e, detail) {
|
308
|
+
if (this.selectedProperty) {
|
309
|
+
var i$ = this.indexesForData(detail.item);
|
310
|
+
// TODO(sorvell): we should be relying on selection to store the
|
311
|
+
// selected data but we want to optimize for lookup.
|
312
|
+
this._selectedData.set(detail.item, detail.isSelected);
|
313
|
+
if (i$.physical >= 0) {
|
314
|
+
this.updateItem(i$.virtual, i$.physical);
|
315
|
+
}
|
316
|
+
}
|
317
|
+
},
|
318
|
+
|
319
|
+
/**
|
320
|
+
* Select the list item at the given index.
|
321
|
+
*
|
322
|
+
* @method selectItem
|
323
|
+
* @param {number} index
|
324
|
+
*/
|
325
|
+
selectItem: function(index) {
|
326
|
+
var data = this.data[index];
|
327
|
+
if (data) {
|
328
|
+
this.$.selection.select(data);
|
329
|
+
}
|
330
|
+
},
|
331
|
+
|
332
|
+
/**
|
333
|
+
* Set the selected state of the list item at the given index.
|
334
|
+
*
|
335
|
+
* @method setItemSelected
|
336
|
+
* @param {number} index
|
337
|
+
* @param {boolean} isSelected
|
338
|
+
*/
|
339
|
+
setItemSelected: function(index, isSelected) {
|
340
|
+
var data = this.data[index];
|
341
|
+
if (data) {
|
342
|
+
this.$.selection.setItemSelected(data, isSelected);
|
343
|
+
}
|
344
|
+
},
|
345
|
+
|
346
|
+
indexesForData: function(data) {
|
347
|
+
var virtual = this.data.indexOf(data);
|
348
|
+
var physical = this.virtualToPhysicalIndex(virtual);
|
349
|
+
return { virtual: virtual, physical: physical };
|
350
|
+
},
|
351
|
+
|
352
|
+
virtualToPhysicalIndex: function(index) {
|
353
|
+
for (var i=0, l=this._physicalData.length; i<l; i++) {
|
354
|
+
if (this._physicalData[i]._virtualIndex === index) {
|
355
|
+
return i;
|
356
|
+
}
|
357
|
+
}
|
358
|
+
return -1;
|
359
|
+
},
|
360
|
+
|
361
|
+
get selection() {
|
362
|
+
return this.$.selection.getSelection();
|
363
|
+
},
|
364
|
+
|
365
|
+
selectedChanged: function() {
|
366
|
+
this.$.selection.select(this.selected);
|
367
|
+
},
|
368
|
+
|
369
|
+
clearSelection: function() {
|
370
|
+
this._selectedData = new WeakMap();
|
371
|
+
if (this.multi) {
|
372
|
+
var s$ = this.selection;
|
373
|
+
for (var i=0, l=s$.length, s; (i<l) && (s=s$[i]); i++) {
|
374
|
+
this.$.selection.setItemSelected(s, false);
|
375
|
+
}
|
376
|
+
} else {
|
377
|
+
this.$.selection.setItemSelected(this.selection, false);
|
378
|
+
}
|
379
|
+
this.$.selection.clear();
|
380
|
+
},
|
381
|
+
|
382
|
+
scrollToItem: function(index) {
|
383
|
+
this.scrollTop = index * this.height;
|
384
|
+
}
|
385
|
+
|
386
|
+
});
|
387
|
+
|
388
|
+
// determine proper transform mechanizm
|
389
|
+
if (document.documentElement.style.transform !== undefined) {
|
390
|
+
function setTransform(element, string, value) {
|
391
|
+
element.style.transform = string;
|
392
|
+
element._transformValue = value;
|
393
|
+
}
|
394
|
+
} else {
|
395
|
+
function setTransform(element, string, value) {
|
396
|
+
element.style.webkitTransform = string;
|
397
|
+
element._transformValue = value;
|
398
|
+
}
|
399
|
+
}
|
400
|
+
|
401
|
+
})();
|
402
|
+
</script>
|
403
|
+
</polymer-element>
|
@@ -0,0 +1,126 @@
|
|
1
|
+
<!--
|
2
|
+
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
3
|
+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
4
|
+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
5
|
+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
6
|
+
Code distributed by Google as part of the polymer project is also
|
7
|
+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
8
|
+
-->
|
9
|
+
|
10
|
+
<!--
|
11
|
+
Element access to localStorage. The "name" property
|
12
|
+
is the key to the data ("value" property) stored in localStorage.
|
13
|
+
|
14
|
+
`core-localstorage` automatically saves the value to localStorage when
|
15
|
+
value is changed. Note that if value is an object auto-save will be
|
16
|
+
triggered only when value is a different instance.
|
17
|
+
|
18
|
+
<core-localstorage name="my-app-storage" value="{{value}}"></core-localstorage>
|
19
|
+
|
20
|
+
@group Polymer Core Elements
|
21
|
+
@element core-localstorage
|
22
|
+
@blurb Element access to localStorage.
|
23
|
+
@url github.io
|
24
|
+
@categories Data
|
25
|
+
-->
|
26
|
+
|
27
|
+
<polymer-element name="core-localstorage" attributes="name value useRaw autoSaveDisabled" hidden>
|
28
|
+
<script>
|
29
|
+
|
30
|
+
Polymer('core-localstorage', {
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Fired when a value is loaded from localStorage.
|
34
|
+
* @event core-localstorage-load
|
35
|
+
*/
|
36
|
+
|
37
|
+
/**
|
38
|
+
* The key to the data stored in localStorage.
|
39
|
+
*
|
40
|
+
* @attribute name
|
41
|
+
* @type string
|
42
|
+
* @default null
|
43
|
+
*/
|
44
|
+
name: '',
|
45
|
+
|
46
|
+
/**
|
47
|
+
* The data associated with the specified name.
|
48
|
+
*
|
49
|
+
* @attribute value
|
50
|
+
* @type object
|
51
|
+
* @default null
|
52
|
+
*/
|
53
|
+
value: null,
|
54
|
+
|
55
|
+
/**
|
56
|
+
* If true, the value is stored and retrieved without JSON processing.
|
57
|
+
*
|
58
|
+
* @attribute useRaw
|
59
|
+
* @type boolean
|
60
|
+
* @default false
|
61
|
+
*/
|
62
|
+
useRaw: false,
|
63
|
+
|
64
|
+
/**
|
65
|
+
* If true, auto save is disabled.
|
66
|
+
*
|
67
|
+
* @attribute autoSaveDisabled
|
68
|
+
* @type boolean
|
69
|
+
* @default false
|
70
|
+
*/
|
71
|
+
autoSaveDisabled: false,
|
72
|
+
|
73
|
+
attached: function() {
|
74
|
+
// wait for bindings are all setup
|
75
|
+
this.async('load');
|
76
|
+
},
|
77
|
+
|
78
|
+
valueChanged: function() {
|
79
|
+
if (this.loaded && !this.autoSaveDisabled) {
|
80
|
+
this.save();
|
81
|
+
}
|
82
|
+
},
|
83
|
+
|
84
|
+
load: function() {
|
85
|
+
var v = localStorage.getItem(this.name);
|
86
|
+
if (this.useRaw) {
|
87
|
+
this.value = v;
|
88
|
+
} else {
|
89
|
+
// localStorage has a flaw that makes it difficult to determine
|
90
|
+
// if a key actually exists or not (getItem returns null if the
|
91
|
+
// key doesn't exist, which is not distinguishable from a stored
|
92
|
+
// null value)
|
93
|
+
// however, if not `useRaw`, an (unparsed) null value unambiguously
|
94
|
+
// signals that there is no value in storage (a stored null value would
|
95
|
+
// be escaped, i.e. "null")
|
96
|
+
// in this case we save any non-null current (default) value
|
97
|
+
if (v === null) {
|
98
|
+
if (this.value !== null) {
|
99
|
+
this.save();
|
100
|
+
}
|
101
|
+
} else {
|
102
|
+
try {
|
103
|
+
v = JSON.parse(v);
|
104
|
+
} catch(x) {
|
105
|
+
}
|
106
|
+
this.value = v;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
this.loaded = true;
|
110
|
+
this.asyncFire('core-localstorage-load');
|
111
|
+
},
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Saves the value to localStorage.
|
115
|
+
*
|
116
|
+
* @method save
|
117
|
+
*/
|
118
|
+
save: function() {
|
119
|
+
var v = this.useRaw ? this.value : JSON.stringify(this.value);
|
120
|
+
localStorage.setItem(this.name, v);
|
121
|
+
}
|
122
|
+
|
123
|
+
});
|
124
|
+
|
125
|
+
</script>
|
126
|
+
</polymer-element>
|
@@ -0,0 +1,86 @@
|
|
1
|
+
<!--
|
2
|
+
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
3
|
+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
4
|
+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
5
|
+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
6
|
+
Code distributed by Google as part of the polymer project is also
|
7
|
+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
8
|
+
-->
|
9
|
+
<!--
|
10
|
+
/**
|
11
|
+
* @group Polymer Core Elements
|
12
|
+
* @element core-media-query
|
13
|
+
* @status beta
|
14
|
+
* @homepage github.io
|
15
|
+
*
|
16
|
+
* core-media-query can be used to data bind to a CSS media query.
|
17
|
+
* The "query" property is a bare CSS media query.
|
18
|
+
* The "queryMatches" property will be a boolean representing if the page matches that media query.
|
19
|
+
*
|
20
|
+
* core-media-query uses media query listeners to dynamically update the "queryMatches" property.
|
21
|
+
* A "core-media-change" event also fires when queryMatches changes.
|
22
|
+
*
|
23
|
+
* Example:
|
24
|
+
*
|
25
|
+
* <core-media-query query="max-width: 640px" queryMatches="{{phoneScreen}}"></core-media-query>
|
26
|
+
*
|
27
|
+
*/
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Fired when the media query state changes
|
31
|
+
*
|
32
|
+
* @event core-media-change
|
33
|
+
*/
|
34
|
+
-->
|
35
|
+
|
36
|
+
<polymer-element name="core-media-query" attributes="query queryMatches">
|
37
|
+
<template>
|
38
|
+
<style>
|
39
|
+
:host {
|
40
|
+
display: none;
|
41
|
+
}
|
42
|
+
</style>
|
43
|
+
</template>
|
44
|
+
<script>
|
45
|
+
Polymer('core-media-query', {
|
46
|
+
|
47
|
+
/**
|
48
|
+
* The Boolean return value of the media query
|
49
|
+
*
|
50
|
+
* @attribute queryMatches
|
51
|
+
* @type Boolean
|
52
|
+
* @default false
|
53
|
+
*/
|
54
|
+
queryMatches: false,
|
55
|
+
|
56
|
+
/**
|
57
|
+
* The CSS media query to evaulate
|
58
|
+
*
|
59
|
+
* @attribute query
|
60
|
+
* @type string
|
61
|
+
* @default ''
|
62
|
+
*/
|
63
|
+
query: '',
|
64
|
+
ready: function() {
|
65
|
+
this._mqHandler = this.queryHandler.bind(this);
|
66
|
+
this._mq = null;
|
67
|
+
},
|
68
|
+
queryChanged: function() {
|
69
|
+
if (this._mq) {
|
70
|
+
this._mq.removeListener(this._mqHandler);
|
71
|
+
}
|
72
|
+
var query = this.query;
|
73
|
+
if (query[0] !== '(') {
|
74
|
+
query = '(' + this.query + ')';
|
75
|
+
}
|
76
|
+
this._mq = window.matchMedia(query);
|
77
|
+
this._mq.addListener(this._mqHandler);
|
78
|
+
this.queryHandler(this._mq);
|
79
|
+
},
|
80
|
+
queryHandler: function(mq) {
|
81
|
+
this.queryMatches = mq.matches;
|
82
|
+
this.asyncFire('core-media-change', mq);
|
83
|
+
}
|
84
|
+
});
|
85
|
+
</script>
|
86
|
+
</polymer-element>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
3
|
+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
4
|
+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
5
|
+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
6
|
+
Code distributed by Google as part of the polymer project is also
|
7
|
+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
8
|
+
*/
|
9
|
+
|
10
|
+
html /deep/ core-menu {
|
11
|
+
display: block;
|
12
|
+
margin: 12px;
|
13
|
+
}
|
14
|
+
|
15
|
+
polyfill-next-selector { content: 'core-menu > core-item'; }
|
16
|
+
html /deep/ core-menu::shadow ::content > core-item {
|
17
|
+
cursor: default;
|
18
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
<!--
|
2
|
+
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
3
|
+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
4
|
+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
5
|
+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
6
|
+
Code distributed by Google as part of the polymer project is also
|
7
|
+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
8
|
+
-->
|
9
|
+
|
10
|
+
<!--
|
11
|
+
`core-menu` is a selector which styles to looks like a menu.
|
12
|
+
|
13
|
+
<core-menu selected="0">
|
14
|
+
<core-item icon="settings" label="Settings"></core-item>
|
15
|
+
<core-item icon="dialog" label="Dialog"></core-item>
|
16
|
+
<core-item icon="search" label="Search"></core-item>
|
17
|
+
</core-menu>
|
18
|
+
|
19
|
+
When an item is selected the `core-selected` class is added to it. The user can
|
20
|
+
use the class to add more stylings to the selected item.
|
21
|
+
|
22
|
+
core-item.core-selected {
|
23
|
+
color: red;
|
24
|
+
}
|
25
|
+
|
26
|
+
The `selectedItem` property references the selected item.
|
27
|
+
|
28
|
+
<core-menu selected="0" selectedItem="{{item}}">
|
29
|
+
<core-item icon="settings" label="Settings"></core-item>
|
30
|
+
<core-item icon="dialog" label="Dialog"></core-item>
|
31
|
+
<core-item icon="search" label="Search"></core-item>
|
32
|
+
</core-menu>
|
33
|
+
|
34
|
+
<div>selected label: {{item.label}}</div>
|
35
|
+
|
36
|
+
The `core-select` event signals selection change.
|
37
|
+
|
38
|
+
<core-menu selected="0" on-core-select="{{selectAction}}">
|
39
|
+
<core-item icon="settings" label="Settings"></core-item>
|
40
|
+
<core-item icon="dialog" label="Dialog"></core-item>
|
41
|
+
<core-item icon="search" label="Search"></core-item>
|
42
|
+
</core-menu>
|
43
|
+
|
44
|
+
...
|
45
|
+
|
46
|
+
selectAction: function(e, detail) {
|
47
|
+
if (detail.isSelected) {
|
48
|
+
var selectedItem = detail.item;
|
49
|
+
...
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
@group Polymer Core Elements
|
54
|
+
@element core-menu
|
55
|
+
@extends core-selector
|
56
|
+
-->
|
57
|
+
|
58
|
+
<%= html_import_tag "core-selector/core-selector" %>
|
59
|
+
|
60
|
+
<%= stylesheet_link_tag "core-list/core-list", "shim-shadowdom" => true %>
|
61
|
+
|
62
|
+
<polymer-element name="core-menu" extends="core-selector" noscript></polymer-element>
|