Просмотр исходного кода

use more thorough cloning to deal with Safari template clone bug (fix #1095)

Evan You 11 лет назад
Родитель
Сommit
eb5c80adcd
2 измененных файлов с 8 добавлено и 4 удалено
  1. 3 2
      src/element-directives/content.js
  2. 5 2
      src/parsers/template.js

+ 3 - 2
src/element-directives/content.js

@@ -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
@@ -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

+ 5 - 2
src/parsers/template.js

@@ -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) {
@@ -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]
         )
       }
@@ -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
   }