MCPcopy Index your code
hub / github.com/keepfool/vue-tutorials / nodeToFragment

Function nodeToFragment

01.GettingStarted/js/vue.js:3541–3566  ·  view source on GitHub ↗

* Convert a template node to a DocumentFragment. * * @param {Node} node * @return {DocumentFragment}

(node)

Source from the content-addressed store, hash-verified

3539 */
3540
3541 function nodeToFragment(node) {
3542 // if its a template tag and the browser supports it,
3543 // its content is already a document fragment. However, iOS Safari has
3544 // bug when using directly cloned template content with touch
3545 // events and can cause crashes when the nodes are removed from DOM, so we
3546 // have to treat template elements as string templates. (#2805)
3547 /* istanbul ignore if */
3548 if (isRealTemplate(node)) {
3549 return stringToFragment(node.innerHTML);
3550 }
3551 // script template
3552 if (node.tagName === 'SCRIPT') {
3553 return stringToFragment(node.textContent);
3554 }
3555 // normal node, clone it to avoid mutating the original
3556 var clonedNode = cloneNode(node);
3557 var frag = document.createDocumentFragment();
3558 var child;
3559 /* eslint-disable no-cond-assign */
3560 while (child = clonedNode.firstChild) {
3561 /* eslint-enable no-cond-assign */
3562 frag.appendChild(child);
3563 }
3564 trimNode(frag);
3565 return frag;
3566 }
3567
3568 // Test for the presence of the Safari template cloning bug
3569 // https://bugs.webkit.org/showug.cgi?id=137755

Callers 1

parseTemplateFunction · 0.70

Calls 4

isRealTemplateFunction · 0.70
stringToFragmentFunction · 0.70
cloneNodeFunction · 0.70
trimNodeFunction · 0.70

Tested by

no test coverage detected