|
107 | 107 | </script>
|
108 | 108 | </dom-module>
|
109 | 109 |
|
| 110 | +<dom-module id="x-dynamic-content-redist-element"> |
| 111 | + <template> |
| 112 | + <template is="dom-if" id="redistDomif"> |
| 113 | + <x-dist id="redistContainer"> |
| 114 | + <content select=".insert" id="redistContent"></content> |
| 115 | + </x-dist> |
| 116 | + </template> |
| 117 | + </template> |
| 118 | + <script> |
| 119 | + HTMLImports.whenReady(function() { |
| 120 | + Polymer({is: 'x-dynamic-content-redist-element'}); |
| 121 | + }); |
| 122 | + </script> |
| 123 | +</dom-module> |
| 124 | + |
110 | 125 | <dom-module id="x-multi-dist">
|
111 | 126 | <template>
|
112 | 127 | <x-dist id="dist1"><content id="content1"></content></x-dist>
|
|
138 | 153 | </script>
|
139 | 154 | </dom-module>
|
140 | 155 |
|
| 156 | +<dom-module id="x-toggle-if"> |
| 157 | + <template> |
| 158 | + <div id="container1"> |
| 159 | + <template id="foo" is="dom-if" if="{{foo}}" restamp> |
| 160 | + <span>foo</span> |
| 161 | + <content select="#one"></content> |
| 162 | + <content select="#two"></content> |
| 163 | + </template> |
| 164 | + </div> |
| 165 | + <div id="container2"> |
| 166 | + <template id="notFoo" is="dom-if" if="{{!foo}}" restamp> |
| 167 | + <span>Not foo</span> |
| 168 | + <content select="#one"></content> |
| 169 | + <content select="#two"></content> |
| 170 | + </template> |
| 171 | + </div> |
| 172 | + </template> |
| 173 | + <script> |
| 174 | + HTMLImports.whenReady(function() { |
| 175 | + Polymer({ |
| 176 | + is: 'x-toggle-if', |
| 177 | + properties: { |
| 178 | + foo: { |
| 179 | + type: Boolean, |
| 180 | + value: true |
| 181 | + } |
| 182 | + } |
| 183 | + }); |
| 184 | + }); |
| 185 | + </script> |
| 186 | +</dom-module> |
| 187 | + |
141 | 188 | <x-compose-lazy-no-dist><span>Child</span></x-compose-lazy-no-dist>
|
142 | 189 |
|
143 | 190 |
|
|
901 | 948 | document.body.removeChild(el);
|
902 | 949 | });
|
903 | 950 |
|
| 951 | + test('x-dynamic-content-redist-element', function() { |
| 952 | + var el = document.createElement('x-dynamic-content-redist-element'); |
| 953 | + document.body.appendChild(el); |
| 954 | + var div = document.createElement('div'); |
| 955 | + div.classList.add('insert'); |
| 956 | + Polymer.dom(el).appendChild(div); |
| 957 | + assert(!el.querySelector('#redistContainer .insert')); |
| 958 | + el.$.redistDomif.if = true; |
| 959 | + el.$.redistDomif.render(); |
| 960 | + Polymer.dom.flush(); |
| 961 | + assert.ok(el.querySelector('#redistContainer .insert')); |
| 962 | + document.body.removeChild(el); |
| 963 | + }); |
| 964 | + |
| 965 | + test('x-toggle-if', function() { |
| 966 | + var el = document.createElement('x-toggle-if'); |
| 967 | + document.body.appendChild(el); |
| 968 | + var c1 = document.createElement('div'); |
| 969 | + c1.id = 'one'; |
| 970 | + Polymer.dom(el).appendChild(c1); |
| 971 | + var c2 = document.createElement('div'); |
| 972 | + c2.id = 'two'; |
| 973 | + Polymer.dom(el).appendChild(c2); |
| 974 | + el.$.foo.render(); |
| 975 | + el.$.notFoo.render(); |
| 976 | + Polymer.dom.flush(); |
| 977 | + assert.equal(c1.parentNode, el.$.container1); |
| 978 | + assert.equal(c2.parentNode, el.$.container1); |
| 979 | + el.foo = !el.foo; |
| 980 | + el.$.foo.render(); |
| 981 | + el.$.notFoo.render(); |
| 982 | + Polymer.dom.flush(); |
| 983 | + assert.equal(c1.parentNode, el.$.container2); |
| 984 | + assert.equal(c2.parentNode, el.$.container2); |
| 985 | + el.foo = !el.foo; |
| 986 | + el.$.foo.render(); |
| 987 | + el.$.notFoo.render(); |
| 988 | + Polymer.dom.flush(); |
| 989 | + assert.equal(c1.parentNode, el.$.container1); |
| 990 | + assert.equal(c2.parentNode, el.$.container1); |
| 991 | + el.foo = !el.foo; |
| 992 | + el.$.foo.render(); |
| 993 | + el.$.notFoo.render(); |
| 994 | + Polymer.dom.flush(); |
| 995 | + assert.equal(c1.parentNode, el.$.container2); |
| 996 | + assert.equal(c2.parentNode, el.$.container2); |
| 997 | + el.foo = !el.foo; |
| 998 | + el.$.foo.render(); |
| 999 | + el.$.notFoo.render(); |
| 1000 | + Polymer.dom.flush(); |
| 1001 | + assert.equal(c1.parentNode, el.$.container1); |
| 1002 | + assert.equal(c2.parentNode, el.$.container1); |
| 1003 | + document.body.removeChild(el); |
| 1004 | + }); |
| 1005 | + |
904 | 1006 | });
|
905 | 1007 |
|
906 | 1008 | </script>
|
|
0 commit comments