File tree 2 files changed +29
-7
lines changed
Filter options
2 files changed +29
-7
lines changed
Original file line number Diff line number Diff line change @@ -56,6 +56,19 @@ map.rect = [
56
56
'</svg>'
57
57
]
58
58
59
+ /**
60
+ * Check if a node is a supported template node with a
61
+ * DocumentFragment content.
62
+ *
63
+ * @param {Node } node
64
+ * @return {Boolean }
65
+ */
66
+
67
+ function isRealTemplate ( node ) {
68
+ return _ . isTemplate ( node ) &&
69
+ node . content instanceof DocumentFragment
70
+ }
71
+
59
72
var tagRE = / < ( [ \w : ] + ) /
60
73
var entityRE = / & \w + ; /
61
74
@@ -120,10 +133,7 @@ function stringToFragment (templateString) {
120
133
function nodeToFragment ( node ) {
121
134
// if its a template tag and the browser supports it,
122
135
// its content is already a document fragment.
123
- if (
124
- _ . isTemplate ( node ) &&
125
- node . content instanceof DocumentFragment
126
- ) {
136
+ if ( isRealTemplate ( node ) ) {
127
137
_ . trimNode ( node . content )
128
138
return node . content
129
139
}
@@ -174,16 +184,21 @@ var hasTextareaCloneBug = _.inBrowser
174
184
*/
175
185
176
186
exports . clone = function ( node ) {
177
- var res = node . cloneNode ( true )
178
187
if ( ! node . querySelectorAll ) {
179
- return res
188
+ return node . cloneNode ( )
180
189
}
190
+ var res = node . cloneNode ( true )
181
191
var i , original , cloned
182
192
/* istanbul ignore if */
183
193
if ( hasBrokenTemplate ) {
194
+ var clone = res
195
+ if ( isRealTemplate ( node ) ) {
196
+ node = node . content
197
+ clone = res . content
198
+ }
184
199
original = node . querySelectorAll ( 'template' )
185
200
if ( original . length ) {
186
- cloned = res . querySelectorAll ( 'template' )
201
+ cloned = clone . querySelectorAll ( 'template' )
187
202
i = cloned . length
188
203
while ( i -- ) {
189
204
cloned [ i ] . parentNode . replaceChild (
Original file line number Diff line number Diff line change @@ -137,6 +137,13 @@ if (_.inBrowser) {
137
137
expect ( c . firstChild . innerHTML ) . toBe ( '1' )
138
138
} )
139
139
140
+ it ( 'should deal with Safari template clone bug even when nested' , function ( ) {
141
+ var a = document . createElement ( 'div' )
142
+ a . innerHTML = '<template><div>1</div><template>2</template></template>'
143
+ var c = templateParser . clone ( a )
144
+ expect ( c . firstChild . innerHTML ) . toBe ( '<div>1</div><template>2</template>' )
145
+ } )
146
+
140
147
it ( 'should deal with IE textarea clone bug' , function ( ) {
141
148
var t = document . createElement ( 'textarea' )
142
149
t . placeholder = 't'
You can’t perform that action at this time.
0 commit comments