Skip to content

Commit

Permalink
use more thorough cloning to deal with Safari template clone bug (fix v…
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jul 29, 2015
1 parent 563b063 commit eb5c80a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/element-directives/content.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var _ = require('../util')
var clone = require('../parsers/template').clone

// This is the elementDirective that handles <content>
// transclusions. It relies on the raw content of an
Expand Down Expand Up @@ -100,10 +101,10 @@ function extractFragment (nodes, parent, main) {
// intact. this ensures proper re-compilation in cases
// where the outlet is inside a conditional block
if (main && !node.__v_selected) {
frag.appendChild(node.cloneNode(true))
frag.appendChild(clone(node))
} else if (!main && node.parentNode === parent) {
node.__v_selected = true
frag.appendChild(node.cloneNode(true))
frag.appendChild(clone(node))
}
}
return frag
Expand Down
7 changes: 5 additions & 2 deletions src/parsers/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ var hasTextareaCloneBug = _.inBrowser

exports.clone = function (node) {
var res = node.cloneNode(true)
if (!node.querySelectorAll) {
return res
}
var i, original, cloned
/* istanbul ignore if */
if (hasBrokenTemplate) {
Expand All @@ -182,7 +185,7 @@ exports.clone = function (node) {
i = cloned.length
while (i--) {
cloned[i].parentNode.replaceChild(
original[i].cloneNode(true),
exports.clone(original[i]),
cloned[i]
)
}
Expand Down Expand Up @@ -229,7 +232,7 @@ exports.parse = function (template, clone, noSelector) {
// do nothing
if (template instanceof DocumentFragment) {
return clone
? template.cloneNode(true)
? exports.clone(template)
: template
}

Expand Down

0 comments on commit eb5c80a

Please sign in to comment.