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 --> |
| 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> |
OLD | NEW |