|
| 1 | +<!DOCTYPE html> |
| 2 | +<!-- |
| 3 | +@license |
| 4 | +Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 5 | +This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt |
| 6 | +The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 7 | +The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt |
| 8 | +Code distributed by Google as part of the polymer project is also |
| 9 | +subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt |
| 10 | +--> |
| 11 | +<!DOCTYPE html> |
| 12 | +<html> |
| 13 | + <head> |
| 14 | + <meta charset='utf-8'> |
| 15 | + <script src='../../../webcomponentsjs/webcomponents-lite.js'></script> |
| 16 | + <script src='../../../web-component-tester/browser.js'></script> |
| 17 | + <link rel='import' href='../../polymer.html'> |
| 18 | + </head> |
| 19 | + <body> |
| 20 | + <preservation-templatizer></preservation-templatizer> |
| 21 | + |
| 22 | + <template id='stampable'> |
| 23 | + <h2>Unmodified</h2> |
| 24 | + <span id='html'>{{html}}</span> |
| 25 | + <template preserve-content id='unmodified'> |
| 26 | + <style> |
| 27 | + [attribute] { |
| 28 | + display: none, |
| 29 | + } |
| 30 | + </style> |
| 31 | + <div>style tag present</div> |
| 32 | + </template> |
| 33 | + </template> |
| 34 | + |
| 35 | + <dom-module id='preservation-templatizer'> |
| 36 | + |
| 37 | + <template> |
| 38 | + <h2>Modified</h2> |
| 39 | + <span>{{html}}<span/> |
| 40 | + <template preserve-content id='modified'> |
| 41 | + <style> |
| 42 | + #identifier { |
| 43 | + color: blue; |
| 44 | + } |
| 45 | + </style> |
| 46 | + <div>style tag missing</div> |
| 47 | + </template> |
| 48 | + </template> |
| 49 | + <script> |
| 50 | + HTMLImports.whenReady(function() { |
| 51 | + Polymer({ |
| 52 | + is: 'preservation-templatizer', |
| 53 | + behaviors: [ |
| 54 | + Polymer.Templatizer |
| 55 | + ], |
| 56 | + created: function () { |
| 57 | + this.templatize(document.body.querySelector('#stampable')); |
| 58 | + }, |
| 59 | + ready: function () { |
| 60 | + var div = document.createElement('DIV'); |
| 61 | + var instance = this.stamp({html: 'unresolved'}); |
| 62 | + var unmodified = instance.root.querySelector('#unmodified'); |
| 63 | + |
| 64 | + div.innerHTML = (this.$.modified).innerHTML; |
| 65 | + console.log(div.firstElementChild.localName, div.firstElementChild); |
| 66 | + |
| 67 | + div.innerHTML = (unmodified).innerHTML; |
| 68 | + console.log(div.firstElementChild.localName, div.firstElementChild); |
| 69 | + } |
| 70 | + }); |
| 71 | + }); |
| 72 | + </script> |
| 73 | + </dom-module> |
| 74 | + |
| 75 | + <script> |
| 76 | + suite('polymer: template preserve-content', function() { |
| 77 | + |
| 78 | + test('nested <template preserve-content/> should retain <style/> in a <dom-module/>', function() { |
| 79 | + var element = document.querySelector('preservation-templatizer'); |
| 80 | + assert.ok(element.$.modified.content.querySelector('style')); |
| 81 | + }); |
| 82 | + |
| 83 | + test('nested <template preserve-content/> should retain <style/> in a stamped <template/>', function() { |
| 84 | + var element = document.querySelector('preservation-templatizer'); |
| 85 | + element.templatize(document.querySelector('#stampable')); |
| 86 | + assert.ok(element.stamp().root.querySelector('#unmodified').content.querySelector('style')); |
| 87 | + }); |
| 88 | + |
| 89 | + }); |
| 90 | + </script> |
| 91 | + </body> |
| 92 | +</html> |
0 commit comments