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