* Process the template option and normalizes it into a * a DocumentFragment that can be used as a partial or a * instance template. * * @param {*} template * Possible values include: * - DocumentFragment object * - Node object of type Template * -
(template, shouldClone, raw)
| 3660 | */ |
| 3661 | |
| 3662 | function parseTemplate(template, shouldClone, raw) { |
| 3663 | var node, frag; |
| 3664 | |
| 3665 | // if the template is already a document fragment, |
| 3666 | // do nothing |
| 3667 | if (isFragment(template)) { |
| 3668 | trimNode(template); |
| 3669 | return shouldClone ? cloneNode(template) : template; |
| 3670 | } |
| 3671 | |
| 3672 | if (typeof template === 'string') { |
| 3673 | // id selector |
| 3674 | if (!raw && template.charAt(0) === '#') { |
| 3675 | // id selector can be cached too |
| 3676 | frag = idSelectorCache.get(template); |
| 3677 | if (!frag) { |
| 3678 | node = document.getElementById(template.slice(1)); |
| 3679 | if (node) { |
| 3680 | frag = nodeToFragment(node); |
| 3681 | // save selector to cache |
| 3682 | idSelectorCache.put(template, frag); |
| 3683 | } |
| 3684 | } |
| 3685 | } else { |
| 3686 | // normal string template |
| 3687 | frag = stringToFragment(template, raw); |
| 3688 | } |
| 3689 | } else if (template.nodeType) { |
| 3690 | // a direct node |
| 3691 | frag = nodeToFragment(template); |
| 3692 | } |
| 3693 | |
| 3694 | return frag && shouldClone ? cloneNode(frag) : frag; |
| 3695 | } |
| 3696 | |
| 3697 | var template = Object.freeze({ |
| 3698 | cloneNode: cloneNode, |
no test coverage detected