@@ -2,19 +2,6 @@ var _ = require('../util')
2
2
var Cache = require ( '../cache' )
3
3
var templateCache = new Cache ( 100 )
4
4
5
- /**
6
- * Test for the presence of the Safari template cloning bug
7
- * https://bugs.webkit.org/show_bug.cgi?id=137755
8
- */
9
-
10
- var hasBrokenTemplate = _ . inBrowser
11
- ? ( function ( ) {
12
- var a = document . createElement ( 'div' )
13
- a . innerHTML = '<template>1</template>'
14
- return ! a . cloneNode ( true ) . firstChild . innerHTML
15
- } ) ( )
16
- : false
17
-
18
5
var map = {
19
6
_default : [ 0 , '' , '' ] ,
20
7
legend : [ 1 , '<fieldset>' , '</fieldset>' ] ,
@@ -141,30 +128,67 @@ function nodeToFragment (node) {
141
128
: stringToFragment ( node . innerHTML )
142
129
}
143
130
131
+ // Test for the presence of the Safari template cloning bug
132
+ // https://bugs.webkit.org/show_bug.cgi?id=137755
133
+ var hasBrokenTemplate = _ . inBrowser
134
+ ? ( function ( ) {
135
+ var a = document . createElement ( 'div' )
136
+ a . innerHTML = '<template>1</template>'
137
+ return ! a . cloneNode ( true ) . firstChild . innerHTML
138
+ } ) ( )
139
+ : false
140
+
141
+ // Test for IE10/11 textarea placeholder clone bug
142
+ var hasTextareaCloneBug = _ . inBrowser
143
+ ? ( function ( ) {
144
+ var t = document . createElement ( 'textarea' )
145
+ t . placeholder = 't'
146
+ return t . cloneNode ( true ) . value === 't'
147
+ } ) ( )
148
+ : false
149
+
144
150
/**
145
- * Deal with Safari cloning nested <template> bug by
146
- * manually cloning all template instances.
151
+ * 1. Deal with Safari cloning nested <template> bug by
152
+ * manually cloning all template instances.
153
+ * 2. Deal with IE10/11 textarea placeholder bug by setting
154
+ * the correct value after cloning.
147
155
*
148
156
* @param {Element|DocumentFragment } node
149
157
* @return {Element|DocumentFragment }
150
158
*/
151
159
152
160
exports . clone = function ( node ) {
153
161
var res = node . cloneNode ( true )
162
+ var i , original , cloned
154
163
/* istanbul ignore if */
155
164
if ( hasBrokenTemplate ) {
156
- var templates = node . querySelectorAll ( 'template' )
157
- if ( templates . length ) {
158
- var cloned = res . querySelectorAll ( 'template' )
159
- var i = cloned . length
165
+ original = node . querySelectorAll ( 'template' )
166
+ if ( original . length ) {
167
+ cloned = res . querySelectorAll ( 'template' )
168
+ i = cloned . length
160
169
while ( i -- ) {
161
170
cloned [ i ] . parentNode . replaceChild (
162
- templates [ i ] . cloneNode ( true ) ,
171
+ original [ i ] . cloneNode ( true ) ,
163
172
cloned [ i ]
164
173
)
165
174
}
166
175
}
167
176
}
177
+ /* istanbul ignore if */
178
+ if ( hasTextareaCloneBug ) {
179
+ if ( node . tagName === 'TEXTAREA' ) {
180
+ res . value = node . value
181
+ } else {
182
+ original = node . querySelectorAll ( 'textarea' )
183
+ if ( original . length ) {
184
+ cloned = res . querySelectorAll ( 'textarea' )
185
+ i = cloned . length
186
+ while ( i -- ) {
187
+ cloned [ i ] . value = original [ i ] . value
188
+ }
189
+ }
190
+ }
191
+ }
168
192
return res
169
193
}
170
194
0 commit comments