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
13
<script>(function () {
15
document.body.removeAttribute('unresolved');
17
if (window.WebComponents) {
18
addEventListener('WebComponentsReady', resolve);
20
if (document.readyState === 'interactive' || document.readyState === 'complete') {
23
addEventListener('DOMContentLoaded', resolve);
28
Settings: function () {
29
var settings = window.Polymer || {};
30
var parts = location.search.slice(1).split('&');
31
for (var i = 0, o; i < parts.length && (o = parts[i]); i++) {
33
o[0] && (settings[o[0]] = o[1] || true);
35
settings.wantShadow = settings.dom === 'shadow';
36
settings.hasShadow = Boolean(Element.prototype.createShadowRoot);
37
settings.nativeShadow = settings.hasShadow && !window.ShadowDOMPolyfill;
38
settings.useShadow = settings.wantShadow && settings.hasShadow;
39
settings.hasNativeImports = Boolean('import' in document.createElement('link'));
40
settings.useNativeImports = settings.hasNativeImports;
41
settings.useNativeCustomElements = !window.CustomElements || window.CustomElements.useNative;
42
settings.useNativeShadow = settings.useShadow && settings.nativeShadow;
43
settings.usePolyfillProto = !settings.useNativeCustomElements && !Object.__proto__;
48
var userPolymer = window.Polymer;
49
window.Polymer = function (prototype) {
50
if (typeof prototype === 'function') {
51
prototype = prototype.prototype;
56
var factory = desugar(prototype);
57
prototype = factory.prototype;
58
var options = { prototype: prototype };
59
if (prototype.extends) {
60
options.extends = prototype.extends;
62
Polymer.telemetry._registrate(prototype);
63
document.registerElement(prototype.is, options);
66
var desugar = function (prototype) {
67
var base = Polymer.Base;
68
if (prototype.extends) {
69
base = Polymer.Base._getExtendedPrototype(prototype.extends);
71
prototype = Polymer.Base.chainObject(prototype, base);
72
prototype.registerCallback();
73
return prototype.constructor;
76
for (var i in userPolymer) {
77
Polymer[i] = userPolymer[i];
80
Polymer.Class = desugar;
84
_regLog: function (prototype) {
85
console.log('[' + prototype.is + ']: registered');
87
_registrate: function (prototype) {
88
this.registrations.push(prototype);
89
Polymer.log && this._regLog(prototype);
91
dumpRegistrations: function () {
92
this.registrations.forEach(this._regLog);
95
Object.defineProperty(window, 'currentImport', {
99
return (document._currentScript || document.currentScript).ownerDocument;
102
Polymer.RenderStatus = {
105
whenReady: function (cb) {
109
this._callbacks.push(cb);
112
_makeReady: function () {
114
for (var i = 0; i < this._callbacks.length; i++) {
115
this._callbacks[i]();
117
this._callbacks = [];
119
_catchFirstRender: function () {
120
requestAnimationFrame(function () {
121
Polymer.RenderStatus._makeReady();
124
_afterNextRenderQueue: [],
125
_waitingNextRender: false,
126
afterNextRender: function (element, fn, args) {
127
this._watchNextRender();
128
this._afterNextRenderQueue.push([
134
_watchNextRender: function () {
135
if (!this._waitingNextRender) {
136
this._waitingNextRender = true;
137
var fn = function () {
138
Polymer.RenderStatus._flushNextRender();
143
requestAnimationFrame(fn);
147
_flushNextRender: function () {
149
setTimeout(function () {
150
self._flushRenderCallbacks(self._afterNextRenderQueue);
151
self._afterNextRenderQueue = [];
152
self._waitingNextRender = false;
155
_flushRenderCallbacks: function (callbacks) {
156
for (var i = 0, h; i < callbacks.length; i++) {
158
h[1].apply(h[0], h[2] || Polymer.nar);
162
if (window.HTMLImports) {
163
HTMLImports.whenReady(function () {
164
Polymer.RenderStatus._catchFirstRender();
167
Polymer.RenderStatus._catchFirstRender();
169
Polymer.ImportStatus = Polymer.RenderStatus;
170
Polymer.ImportStatus.whenLoaded = Polymer.ImportStatus.whenReady;
173
var settings = Polymer.Settings;
175
__isPolymerInstance__: true,
176
_addFeature: function (feature) {
177
this.extend(this, feature);
179
registerCallback: function () {
180
this._desugarBehaviors();
181
this._doBehavior('beforeRegister');
182
this._registerFeatures();
183
if (!settings.lazyRegister) {
184
this.ensureRegisterFinished();
187
createdCallback: function () {
188
if (!this.__hasRegisterFinished) {
189
this._ensureRegisterFinished(this.__proto__);
191
Polymer.telemetry.instanceCount++;
193
this._doBehavior('created');
194
this._initFeatures();
196
ensureRegisterFinished: function () {
197
this._ensureRegisterFinished(this);
199
_ensureRegisterFinished: function (proto) {
200
if (proto.__hasRegisterFinished !== proto.is) {
201
proto.__hasRegisterFinished = proto.is;
202
if (proto._finishRegisterFeatures) {
203
proto._finishRegisterFeatures();
205
proto._doBehavior('registered');
208
attachedCallback: function () {
210
Polymer.RenderStatus.whenReady(function () {
211
self.isAttached = true;
212
self._doBehavior('attached');
215
detachedCallback: function () {
216
this.isAttached = false;
217
this._doBehavior('detached');
219
attributeChangedCallback: function (name, oldValue, newValue) {
220
this._attributeChangedImpl(name);
221
this._doBehavior('attributeChanged', [
227
_attributeChangedImpl: function (name) {
228
this._setAttributeToProperty(this, name);
230
extend: function (prototype, api) {
231
if (prototype && api) {
232
var n$ = Object.getOwnPropertyNames(api);
233
for (var i = 0, n; i < n$.length && (n = n$[i]); i++) {
234
this.copyOwnProperty(n, api, prototype);
237
return prototype || api;
239
mixin: function (target, source) {
240
for (var i in source) {
241
target[i] = source[i];
245
copyOwnProperty: function (name, source, target) {
246
var pd = Object.getOwnPropertyDescriptor(source, name);
248
Object.defineProperty(target, name, pd);
251
_log: console.log.apply.bind(console.log, console),
252
_warn: console.warn.apply.bind(console.warn, console),
253
_error: console.error.apply.bind(console.error, console),
255
return this._logPrefix.concat([this.is]).concat(Array.prototype.slice.call(arguments, 0));
258
Polymer.Base._logPrefix = function () {
259
var color = window.chrome || /firefox/i.test(navigator.userAgent);
262
'font-weight: bold; background-color:#EEEE00;'
265
Polymer.Base.chainObject = function (object, inherited) {
266
if (object && inherited && object !== inherited) {
267
if (!Object.__proto__) {
268
object = Polymer.Base.extend(Object.create(inherited), object);
270
object.__proto__ = inherited;
274
Polymer.Base = Polymer.Base.chainObject(Polymer.Base, HTMLElement.prototype);
275
if (window.CustomElements) {
276
Polymer.instanceof = CustomElements.instanceof;
278
Polymer.instanceof = function (obj, ctor) {
279
return obj instanceof ctor;
282
Polymer.isInstance = function (obj) {
283
return Boolean(obj && obj.__isPolymerInstance__);
285
Polymer.telemetry.instanceCount = 0;
290
var findModule = function (id) {
291
return modules[id] || lcModules[id.toLowerCase()];
293
var DomModule = function () {
294
return document.createElement('dom-module');
296
DomModule.prototype = Object.create(HTMLElement.prototype);
297
Polymer.Base.extend(DomModule.prototype, {
298
constructor: DomModule,
299
createdCallback: function () {
302
register: function (id) {
303
id = id || this.id || this.getAttribute('name') || this.getAttribute('is');
307
lcModules[id.toLowerCase()] = this;
310
import: function (id, selector) {
312
var m = findModule(id);
314
forceDomModulesUpgrade();
318
m = m.querySelector(selector);
324
var cePolyfill = window.CustomElements && !CustomElements.useNative;
325
document.registerElement('dom-module', DomModule);
326
function forceDomModulesUpgrade() {
328
var script = document._currentScript || document.currentScript;
329
var doc = script && script.ownerDocument || document;
330
var modules = doc.querySelectorAll('dom-module');
331
for (var i = modules.length - 1, m; i >= 0 && (m = modules[i]); i--) {
332
if (m.__upgraded__) {
335
CustomElements.upgrade(m);
341
Polymer.Base._addFeature({
342
_prepIs: function () {
344
var module = (document._currentScript || document.currentScript).parentNode;
345
if (module.localName === 'dom-module') {
346
var id = module.id || module.getAttribute('name') || module.getAttribute('is');
351
this.is = this.is.toLowerCase();
355
Polymer.Base._addFeature({
357
_desugarBehaviors: function () {
358
if (this.behaviors.length) {
359
this.behaviors = this._desugarSomeBehaviors(this.behaviors);
362
_desugarSomeBehaviors: function (behaviors) {
363
var behaviorSet = [];
364
behaviors = this._flattenBehaviorsList(behaviors);
365
for (var i = behaviors.length - 1; i >= 0; i--) {
366
var b = behaviors[i];
367
if (behaviorSet.indexOf(b) === -1) {
368
this._mixinBehavior(b);
369
behaviorSet.unshift(b);
374
_flattenBehaviorsList: function (behaviors) {
376
for (var i = 0; i < behaviors.length; i++) {
377
var b = behaviors[i];
378
if (b instanceof Array) {
379
flat = flat.concat(this._flattenBehaviorsList(b));
383
this._warn(this._logf('_flattenBehaviorsList', 'behavior is null, check for missing or 404 import'));
388
_mixinBehavior: function (b) {
389
var n$ = Object.getOwnPropertyNames(b);
390
for (var i = 0, n; i < n$.length && (n = n$[i]); i++) {
391
if (!Polymer.Base._behaviorProperties[n] && !this.hasOwnProperty(n)) {
392
this.copyOwnProperty(n, b, this);
396
_prepBehaviors: function () {
397
this._prepFlattenedBehaviors(this.behaviors);
399
_prepFlattenedBehaviors: function (behaviors) {
400
for (var i = 0, l = behaviors.length; i < l; i++) {
401
this._prepBehavior(behaviors[i]);
403
this._prepBehavior(this);
405
_doBehavior: function (name, args) {
406
for (var i = 0; i < this.behaviors.length; i++) {
407
this._invokeBehavior(this.behaviors[i], name, args);
409
this._invokeBehavior(this, name, args);
411
_invokeBehavior: function (b, name, args) {
414
fn.apply(this, args || Polymer.nar);
417
_marshalBehaviors: function () {
418
for (var i = 0; i < this.behaviors.length; i++) {
419
this._marshalBehavior(this.behaviors[i]);
421
this._marshalBehavior(this);
424
Polymer.Base._behaviorProperties = {
425
hostAttributes: true,
426
beforeRegister: true,
434
attributeChanged: true,
437
Polymer.Base._addFeature({
438
_getExtendedPrototype: function (tag) {
439
return this._getExtendedNativePrototype(tag);
441
_nativePrototypes: {},
442
_getExtendedNativePrototype: function (tag) {
443
var p = this._nativePrototypes[tag];
445
var np = this.getNativePrototype(tag);
446
p = this.extend(Object.create(np), Polymer.Base);
447
this._nativePrototypes[tag] = p;
451
getNativePrototype: function (tag) {
452
return Object.getPrototypeOf(document.createElement(tag));
455
Polymer.Base._addFeature({
456
_prepConstructor: function () {
457
this._factoryArgs = this.extends ? [
461
var ctor = function () {
462
return this._factory(arguments);
464
if (this.hasOwnProperty('extends')) {
465
ctor.extends = this.extends;
467
Object.defineProperty(this, 'constructor', {
472
ctor.prototype = this;
474
_factory: function (args) {
475
var elt = document.createElement.apply(document, this._factoryArgs);
476
if (this.factoryImpl) {
477
this.factoryImpl.apply(elt, args);
482
Polymer.nob = Object.create(null);
483
Polymer.Base._addFeature({
485
getPropertyInfo: function (property) {
486
var info = this._getPropertyInfo(property, this.properties);
488
for (var i = 0; i < this.behaviors.length; i++) {
489
info = this._getPropertyInfo(property, this.behaviors[i].properties);
495
return info || Polymer.nob;
497
_getPropertyInfo: function (property, properties) {
498
var p = properties && properties[property];
499
if (typeof p === 'function') {
500
p = properties[property] = { type: p };
507
_prepPropertyInfo: function () {
508
this._propertyInfo = {};
509
for (var i = 0; i < this.behaviors.length; i++) {
510
this._addPropertyInfo(this._propertyInfo, this.behaviors[i].properties);
512
this._addPropertyInfo(this._propertyInfo, this.properties);
513
this._addPropertyInfo(this._propertyInfo, this._propertyEffects);
515
_addPropertyInfo: function (target, source) {
518
for (var i in source) {
521
if (i[0] === '_' && !s.readOnly) {
526
type: typeof s === 'function' ? s : s.type,
527
readOnly: s.readOnly,
528
attribute: Polymer.CaseMap.camelToDashCase(i)
535
t.readOnly = s.readOnly;
545
dashToCamel: /-[a-z]/g,
546
camelToDash: /([A-Z])/g
548
dashToCamelCase: function (dash) {
549
return this._caseMap[dash] || (this._caseMap[dash] = dash.indexOf('-') < 0 ? dash : dash.replace(this._rx.dashToCamel, function (m) {
550
return m[1].toUpperCase();
553
camelToDashCase: function (camel) {
554
return this._caseMap[camel] || (this._caseMap[camel] = camel.replace(this._rx.camelToDash, '-$1').toLowerCase());
557
Polymer.Base._addFeature({
558
_addHostAttributes: function (attributes) {
559
if (!this._aggregatedAttributes) {
560
this._aggregatedAttributes = {};
563
this.mixin(this._aggregatedAttributes, attributes);
566
_marshalHostAttributes: function () {
567
if (this._aggregatedAttributes) {
568
this._applyAttributes(this, this._aggregatedAttributes);
571
_applyAttributes: function (node, attr$) {
572
for (var n in attr$) {
573
if (!this.hasAttribute(n) && n !== 'class') {
575
this.serializeValueToAttribute(v, n, this);
579
_marshalAttributes: function () {
580
this._takeAttributesToModel(this);
582
_takeAttributesToModel: function (model) {
583
if (this.hasAttributes()) {
584
for (var i in this._propertyInfo) {
585
var info = this._propertyInfo[i];
586
if (this.hasAttribute(info.attribute)) {
587
this._setAttributeToProperty(model, info.attribute, i, info);
592
_setAttributeToProperty: function (model, attribute, property, info) {
593
if (!this._serializing) {
594
property = property || Polymer.CaseMap.dashToCamelCase(attribute);
595
info = info || this._propertyInfo && this._propertyInfo[property];
596
if (info && !info.readOnly) {
597
var v = this.getAttribute(attribute);
598
model[property] = this.deserialize(v, info.type);
603
reflectPropertyToAttribute: function (property, attribute, value) {
604
this._serializing = true;
605
value = value === undefined ? this[property] : value;
606
this.serializeValueToAttribute(value, attribute || Polymer.CaseMap.camelToDashCase(property));
607
this._serializing = false;
609
serializeValueToAttribute: function (value, attribute, node) {
610
var str = this.serialize(value);
612
if (str === undefined) {
613
node.removeAttribute(attribute);
615
node.setAttribute(attribute, str);
618
deserialize: function (value, type) {
621
value = Number(value);
624
value = value != null;
628
value = JSON.parse(value);
634
value = JSON.parse(value);
637
console.warn('Polymer::Attributes: couldn`t decode Array as JSON');
641
value = new Date(value);
649
serialize: function (value) {
650
switch (typeof value) {
652
return value ? '' : undefined;
654
if (value instanceof Date) {
655
return value.toString();
658
return JSON.stringify(value);
664
return value != null ? value : undefined;
668
Polymer.version = '1.4.0';
669
Polymer.Base._addFeature({
670
_registerFeatures: function () {
672
this._prepBehaviors();
673
this._prepConstructor();
674
this._prepPropertyInfo();
676
_prepBehavior: function (b) {
677
this._addHostAttributes(b.hostAttributes);
679
_marshalBehavior: function (b) {
681
_initFeatures: function () {
682
this._marshalHostAttributes();
683
this._marshalBehaviors();
b'\\ No newline at end of file'