OLD | NEW |
| (Empty) |
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.g
ithub.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/CONTRI
BUTORS.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/PATEN
TS.txt | |
9 --><script>(function () { | |
10 function resolve() { | |
11 document.body.removeAttribute('unresolved'); | |
12 } | |
13 if (window.WebComponents) { | |
14 addEventListener('WebComponentsReady', resolve); | |
15 } else { | |
16 if (document.readyState === 'interactive' || document.readyState === 'complete')
{ | |
17 resolve(); | |
18 } else { | |
19 addEventListener('DOMContentLoaded', resolve); | |
20 } | |
21 } | |
22 }()); | |
23 Polymer = { | |
24 Settings: function () { | |
25 var user = window.Polymer || {}; | |
26 location.search.slice(1).split('&').forEach(function (o) { | |
27 o = o.split('='); | |
28 o[0] && (user[o[0]] = o[1] || true); | |
29 }); | |
30 var wantShadow = user.dom === 'shadow'; | |
31 var hasShadow = Boolean(Element.prototype.createShadowRoot); | |
32 var nativeShadow = hasShadow && !window.ShadowDOMPolyfill; | |
33 var useShadow = wantShadow && hasShadow; | |
34 var hasNativeImports = Boolean('import' in document.createElement('link')); | |
35 var useNativeImports = hasNativeImports; | |
36 var useNativeCustomElements = !window.CustomElements || window.CustomElements.us
eNative; | |
37 return { | |
38 wantShadow: wantShadow, | |
39 hasShadow: hasShadow, | |
40 nativeShadow: nativeShadow, | |
41 useShadow: useShadow, | |
42 useNativeShadow: useShadow && nativeShadow, | |
43 useNativeImports: useNativeImports, | |
44 useNativeCustomElements: useNativeCustomElements | |
45 }; | |
46 }() | |
47 }; | |
48 (function () { | |
49 var userPolymer = window.Polymer; | |
50 window.Polymer = function (prototype) { | |
51 var ctor = desugar(prototype); | |
52 prototype = ctor.prototype; | |
53 var options = { prototype: prototype }; | |
54 if (prototype.extends) { | |
55 options.extends = prototype.extends; | |
56 } | |
57 Polymer.telemetry._registrate(prototype); | |
58 document.registerElement(prototype.is, options); | |
59 return ctor; | |
60 }; | |
61 var desugar = function (prototype) { | |
62 var base = Polymer.Base; | |
63 if (prototype.extends) { | |
64 base = Polymer.Base._getExtendedPrototype(prototype.extends); | |
65 } | |
66 prototype = Polymer.Base.chainObject(prototype, base); | |
67 prototype.registerCallback(); | |
68 return prototype.constructor; | |
69 }; | |
70 window.Polymer = Polymer; | |
71 if (userPolymer) { | |
72 for (var i in userPolymer) { | |
73 Polymer[i] = userPolymer[i]; | |
74 } | |
75 } | |
76 Polymer.Class = desugar; | |
77 }()); | |
78 Polymer.telemetry = { | |
79 registrations: [], | |
80 _regLog: function (prototype) { | |
81 console.log('[' + prototype.is + ']: registered'); | |
82 }, | |
83 _registrate: function (prototype) { | |
84 this.registrations.push(prototype); | |
85 Polymer.log && this._regLog(prototype); | |
86 }, | |
87 dumpRegistrations: function () { | |
88 this.registrations.forEach(this._regLog); | |
89 } | |
90 }; | |
91 Object.defineProperty(window, 'currentImport', { | |
92 enumerable: true, | |
93 configurable: true, | |
94 get: function () { | |
95 return (document._currentScript || document.currentScript).ownerDocument; | |
96 } | |
97 }); | |
98 Polymer.Base = { | |
99 __isPolymerInstance__: true, | |
100 _addFeature: function (feature) { | |
101 this.extend(this, feature); | |
102 }, | |
103 registerCallback: function () { | |
104 this._registerFeatures(); | |
105 this._doBehavior('registered'); | |
106 }, | |
107 createdCallback: function () { | |
108 Polymer.telemetry.instanceCount++; | |
109 this.root = this; | |
110 this._doBehavior('created'); | |
111 this._initFeatures(); | |
112 }, | |
113 attachedCallback: function () { | |
114 this.isAttached = true; | |
115 this._doBehavior('attached'); | |
116 }, | |
117 detachedCallback: function () { | |
118 this.isAttached = false; | |
119 this._doBehavior('detached'); | |
120 }, | |
121 attributeChangedCallback: function (name) { | |
122 this._setAttributeToProperty(this, name); | |
123 this._doBehavior('attributeChanged', arguments); | |
124 }, | |
125 extend: function (prototype, api) { | |
126 if (prototype && api) { | |
127 Object.getOwnPropertyNames(api).forEach(function (n) { | |
128 this.copyOwnProperty(n, api, prototype); | |
129 }, this); | |
130 } | |
131 return prototype || api; | |
132 }, | |
133 mixin: function (target, source) { | |
134 for (var i in source) { | |
135 target[i] = source[i]; | |
136 } | |
137 return target; | |
138 }, | |
139 copyOwnProperty: function (name, source, target) { | |
140 var pd = Object.getOwnPropertyDescriptor(source, name); | |
141 if (pd) { | |
142 Object.defineProperty(target, name, pd); | |
143 } | |
144 }, | |
145 _log: console.log.apply.bind(console.log, console), | |
146 _warn: console.warn.apply.bind(console.warn, console), | |
147 _error: console.error.apply.bind(console.error, console), | |
148 _logf: function () { | |
149 return this._logPrefix.concat([this.is]).concat(Array.prototype.slice.call(argum
ents, 0)); | |
150 } | |
151 }; | |
152 Polymer.Base._logPrefix = function () { | |
153 var color = window.chrome || /firefox/i.test(navigator.userAgent); | |
154 return color ? [ | |
155 '%c[%s::%s]:', | |
156 'font-weight: bold; background-color:#EEEE00;' | |
157 ] : ['[%s::%s]:']; | |
158 }(); | |
159 Polymer.Base.chainObject = function (object, inherited) { | |
160 if (object && inherited && object !== inherited) { | |
161 if (!Object.__proto__) { | |
162 object = Polymer.Base.extend(Object.create(inherited), object); | |
163 } | |
164 object.__proto__ = inherited; | |
165 } | |
166 return object; | |
167 }; | |
168 Polymer.Base = Polymer.Base.chainObject(Polymer.Base, HTMLElement.prototype); | |
169 if (window.CustomElements) { | |
170 Polymer.instanceof = CustomElements.instanceof; | |
171 } else { | |
172 Polymer.instanceof = function (obj, ctor) { | |
173 return obj instanceof ctor; | |
174 }; | |
175 } | |
176 Polymer.isInstance = function (obj) { | |
177 return Boolean(obj && obj.__isPolymerInstance__); | |
178 }; | |
179 Polymer.telemetry.instanceCount = 0; | |
180 (function () { | |
181 var modules = {}; | |
182 var DomModule = function () { | |
183 return document.createElement('dom-module'); | |
184 }; | |
185 DomModule.prototype = Object.create(HTMLElement.prototype); | |
186 DomModule.prototype.constructor = DomModule; | |
187 DomModule.prototype.createdCallback = function () { | |
188 var id = this.id || this.getAttribute('name') || this.getAttribute('is'); | |
189 if (id) { | |
190 this.id = id; | |
191 modules[id] = this; | |
192 } | |
193 }; | |
194 DomModule.prototype.import = function (id, slctr) { | |
195 var m = modules[id]; | |
196 if (!m) { | |
197 forceDocumentUpgrade(); | |
198 m = modules[id]; | |
199 } | |
200 if (m && slctr) { | |
201 m = m.querySelector(slctr); | |
202 } | |
203 return m; | |
204 }; | |
205 var cePolyfill = window.CustomElements && !CustomElements.useNative; | |
206 if (cePolyfill) { | |
207 var ready = CustomElements.ready; | |
208 CustomElements.ready = true; | |
209 } | |
210 document.registerElement('dom-module', DomModule); | |
211 if (cePolyfill) { | |
212 CustomElements.ready = ready; | |
213 } | |
214 function forceDocumentUpgrade() { | |
215 if (cePolyfill) { | |
216 var script = document._currentScript || document.currentScript; | |
217 if (script) { | |
218 CustomElements.upgradeAll(script.ownerDocument); | |
219 } | |
220 } | |
221 } | |
222 }()); | |
223 Polymer.Base._addFeature({ | |
224 _prepIs: function () { | |
225 if (!this.is) { | |
226 var module = (document._currentScript || document.currentScript).parentNode; | |
227 if (module.localName === 'dom-module') { | |
228 var id = module.id || module.getAttribute('name') || module.getAttribute('is'); | |
229 this.is = id; | |
230 } | |
231 } | |
232 } | |
233 }); | |
234 Polymer.Base._addFeature({ | |
235 behaviors: [], | |
236 _prepBehaviors: function () { | |
237 if (this.behaviors.length) { | |
238 this.behaviors = this._flattenBehaviorsList(this.behaviors); | |
239 } | |
240 this._prepAllBehaviors(this.behaviors); | |
241 }, | |
242 _flattenBehaviorsList: function (behaviors) { | |
243 var flat = []; | |
244 behaviors.forEach(function (b) { | |
245 if (b instanceof Array) { | |
246 flat = flat.concat(this._flattenBehaviorsList(b)); | |
247 } else if (b) { | |
248 flat.push(b); | |
249 } else { | |
250 this._warn(this._logf('_flattenBehaviorsList', 'behavior is null, check for miss
ing or 404 import')); | |
251 } | |
252 }, this); | |
253 return flat; | |
254 }, | |
255 _prepAllBehaviors: function (behaviors) { | |
256 for (var i = behaviors.length - 1; i >= 0; i--) { | |
257 this._mixinBehavior(behaviors[i]); | |
258 } | |
259 for (var i = 0, l = behaviors.length; i < l; i++) { | |
260 this._prepBehavior(behaviors[i]); | |
261 } | |
262 this._prepBehavior(this); | |
263 }, | |
264 _mixinBehavior: function (b) { | |
265 Object.getOwnPropertyNames(b).forEach(function (n) { | |
266 switch (n) { | |
267 case 'hostAttributes': | |
268 case 'registered': | |
269 case 'properties': | |
270 case 'observers': | |
271 case 'listeners': | |
272 case 'created': | |
273 case 'attached': | |
274 case 'detached': | |
275 case 'attributeChanged': | |
276 case 'configure': | |
277 case 'ready': | |
278 break; | |
279 default: | |
280 if (!this.hasOwnProperty(n)) { | |
281 this.copyOwnProperty(n, b, this); | |
282 } | |
283 break; | |
284 } | |
285 }, this); | |
286 }, | |
287 _doBehavior: function (name, args) { | |
288 this.behaviors.forEach(function (b) { | |
289 this._invokeBehavior(b, name, args); | |
290 }, this); | |
291 this._invokeBehavior(this, name, args); | |
292 }, | |
293 _invokeBehavior: function (b, name, args) { | |
294 var fn = b[name]; | |
295 if (fn) { | |
296 fn.apply(this, args || Polymer.nar); | |
297 } | |
298 }, | |
299 _marshalBehaviors: function () { | |
300 this.behaviors.forEach(function (b) { | |
301 this._marshalBehavior(b); | |
302 }, this); | |
303 this._marshalBehavior(this); | |
304 } | |
305 }); | |
306 Polymer.Base._addFeature({ | |
307 _getExtendedPrototype: function (tag) { | |
308 return this._getExtendedNativePrototype(tag); | |
309 }, | |
310 _nativePrototypes: {}, | |
311 _getExtendedNativePrototype: function (tag) { | |
312 var p = this._nativePrototypes[tag]; | |
313 if (!p) { | |
314 var np = this.getNativePrototype(tag); | |
315 p = this.extend(Object.create(np), Polymer.Base); | |
316 this._nativePrototypes[tag] = p; | |
317 } | |
318 return p; | |
319 }, | |
320 getNativePrototype: function (tag) { | |
321 return Object.getPrototypeOf(document.createElement(tag)); | |
322 } | |
323 }); | |
324 Polymer.Base._addFeature({ | |
325 _prepConstructor: function () { | |
326 this._factoryArgs = this.extends ? [ | |
327 this.extends, | |
328 this.is | |
329 ] : [this.is]; | |
330 var ctor = function () { | |
331 return this._factory(arguments); | |
332 }; | |
333 if (this.hasOwnProperty('extends')) { | |
334 ctor.extends = this.extends; | |
335 } | |
336 Object.defineProperty(this, 'constructor', { | |
337 value: ctor, | |
338 writable: true, | |
339 configurable: true | |
340 }); | |
341 ctor.prototype = this; | |
342 }, | |
343 _factory: function (args) { | |
344 var elt = document.createElement.apply(document, this._factoryArgs); | |
345 if (this.factoryImpl) { | |
346 this.factoryImpl.apply(elt, args); | |
347 } | |
348 return elt; | |
349 } | |
350 }); | |
351 Polymer.nob = Object.create(null); | |
352 Polymer.Base._addFeature({ | |
353 properties: {}, | |
354 getPropertyInfo: function (property) { | |
355 var info = this._getPropertyInfo(property, this.properties); | |
356 if (!info) { | |
357 this.behaviors.some(function (b) { | |
358 return info = this._getPropertyInfo(property, b.properties); | |
359 }, this); | |
360 } | |
361 return info || Polymer.nob; | |
362 }, | |
363 _getPropertyInfo: function (property, properties) { | |
364 var p = properties && properties[property]; | |
365 if (typeof p === 'function') { | |
366 p = properties[property] = { type: p }; | |
367 } | |
368 if (p) { | |
369 p.defined = true; | |
370 } | |
371 return p; | |
372 } | |
373 }); | |
374 Polymer.CaseMap = { | |
375 _caseMap: {}, | |
376 dashToCamelCase: function (dash) { | |
377 var mapped = Polymer.CaseMap._caseMap[dash]; | |
378 if (mapped) { | |
379 return mapped; | |
380 } | |
381 if (dash.indexOf('-') < 0) { | |
382 return Polymer.CaseMap._caseMap[dash] = dash; | |
383 } | |
384 return Polymer.CaseMap._caseMap[dash] = dash.replace(/-([a-z])/g, function (m) { | |
385 return m[1].toUpperCase(); | |
386 }); | |
387 }, | |
388 camelToDashCase: function (camel) { | |
389 var mapped = Polymer.CaseMap._caseMap[camel]; | |
390 if (mapped) { | |
391 return mapped; | |
392 } | |
393 return Polymer.CaseMap._caseMap[camel] = camel.replace(/([a-z][A-Z])/g, function
(g) { | |
394 return g[0] + '-' + g[1].toLowerCase(); | |
395 }); | |
396 } | |
397 }; | |
398 Polymer.Base._addFeature({ | |
399 _prepAttributes: function () { | |
400 this._aggregatedAttributes = {}; | |
401 }, | |
402 _addHostAttributes: function (attributes) { | |
403 if (attributes) { | |
404 this.mixin(this._aggregatedAttributes, attributes); | |
405 } | |
406 }, | |
407 _marshalHostAttributes: function () { | |
408 this._applyAttributes(this, this._aggregatedAttributes); | |
409 }, | |
410 _applyAttributes: function (node, attr$) { | |
411 for (var n in attr$) { | |
412 if (!this.hasAttribute(n) && n !== 'class') { | |
413 this.serializeValueToAttribute(attr$[n], n, this); | |
414 } | |
415 } | |
416 }, | |
417 _marshalAttributes: function () { | |
418 this._takeAttributesToModel(this); | |
419 }, | |
420 _takeAttributesToModel: function (model) { | |
421 for (var i = 0, l = this.attributes.length; i < l; i++) { | |
422 this._setAttributeToProperty(model, this.attributes[i].name); | |
423 } | |
424 }, | |
425 _setAttributeToProperty: function (model, attrName) { | |
426 if (!this._serializing) { | |
427 var propName = Polymer.CaseMap.dashToCamelCase(attrName); | |
428 var info = this.getPropertyInfo(propName); | |
429 if (info.defined || this._propertyEffects && this._propertyEffects[propName]) { | |
430 var val = this.getAttribute(attrName); | |
431 model[propName] = this.deserialize(val, info.type); | |
432 } | |
433 } | |
434 }, | |
435 _serializing: false, | |
436 reflectPropertyToAttribute: function (name) { | |
437 this._serializing = true; | |
438 this.serializeValueToAttribute(this[name], Polymer.CaseMap.camelToDashCase(name)
); | |
439 this._serializing = false; | |
440 }, | |
441 serializeValueToAttribute: function (value, attribute, node) { | |
442 var str = this.serialize(value); | |
443 (node || this)[str === undefined ? 'removeAttribute' : 'setAttribute'](attribute
, str); | |
444 }, | |
445 deserialize: function (value, type) { | |
446 switch (type) { | |
447 case Number: | |
448 value = Number(value); | |
449 break; | |
450 case Boolean: | |
451 value = value !== null; | |
452 break; | |
453 case Object: | |
454 try { | |
455 value = JSON.parse(value); | |
456 } catch (x) { | |
457 } | |
458 break; | |
459 case Array: | |
460 try { | |
461 value = JSON.parse(value); | |
462 } catch (x) { | |
463 value = null; | |
464 console.warn('Polymer::Attributes: couldn`t decode Array as JSON'); | |
465 } | |
466 break; | |
467 case Date: | |
468 value = new Date(value); | |
469 break; | |
470 case String: | |
471 default: | |
472 break; | |
473 } | |
474 return value; | |
475 }, | |
476 serialize: function (value) { | |
477 switch (typeof value) { | |
478 case 'boolean': | |
479 return value ? '' : undefined; | |
480 case 'object': | |
481 if (value instanceof Date) { | |
482 return value; | |
483 } else if (value) { | |
484 try { | |
485 return JSON.stringify(value); | |
486 } catch (x) { | |
487 return ''; | |
488 } | |
489 } | |
490 default: | |
491 return value != null ? value : undefined; | |
492 } | |
493 } | |
494 }); | |
495 Polymer.Base._addFeature({ | |
496 _setupDebouncers: function () { | |
497 this._debouncers = {}; | |
498 }, | |
499 debounce: function (jobName, callback, wait) { | |
500 this._debouncers[jobName] = Polymer.Debounce.call(this, this._debouncers[jobName
], callback, wait); | |
501 }, | |
502 isDebouncerActive: function (jobName) { | |
503 var debouncer = this._debouncers[jobName]; | |
504 return debouncer && debouncer.finish; | |
505 }, | |
506 flushDebouncer: function (jobName) { | |
507 var debouncer = this._debouncers[jobName]; | |
508 if (debouncer) { | |
509 debouncer.complete(); | |
510 } | |
511 }, | |
512 cancelDebouncer: function (jobName) { | |
513 var debouncer = this._debouncers[jobName]; | |
514 if (debouncer) { | |
515 debouncer.stop(); | |
516 } | |
517 } | |
518 }); | |
519 Polymer.version = '1.0.7'; | |
520 Polymer.Base._addFeature({ | |
521 _registerFeatures: function () { | |
522 this._prepIs(); | |
523 this._prepAttributes(); | |
524 this._prepBehaviors(); | |
525 this._prepConstructor(); | |
526 }, | |
527 _prepBehavior: function (b) { | |
528 this._addHostAttributes(b.hostAttributes); | |
529 }, | |
530 _marshalBehavior: function (b) { | |
531 }, | |
532 _initFeatures: function () { | |
533 this._marshalHostAttributes(); | |
534 this._setupDebouncers(); | |
535 this._marshalBehaviors(); | |
536 } | |
537 });</script> | |
538 | |
OLD | NEW |