Sha256: c6cbc7d6c19bd94a543ac3209dd5027582b2d91f7cf64378d0ec23ae163d4422
Contents?: true
Size: 1.63 KB
Versions: 7
Compression:
Stored size: 1.63 KB
Contents
// string -> DOM conversion // wrappers originally from jQuery, scooped from component/domify var map = { legend : [1, '<fieldset>', '</fieldset>'], tr : [2, '<table><tbody>', '</tbody></table>'], col : [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'], _default : [0, '', ''] } map.td = map.th = [3, '<table><tbody><tr>', '</tr></tbody></table>'] map.option = map.optgroup = [1, '<select multiple="multiple">', '</select>'] map.thead = map.tbody = map.colgroup = map.caption = map.tfoot = [1, '<table>', '</table>'] map.text = map.circle = map.ellipse = map.line = map.path = map.polygon = map.polyline = map.rect = [1, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">','</svg>'] var TAG_RE = /<([\w:]+)/ module.exports = function (templateString) { var frag = document.createDocumentFragment(), m = TAG_RE.exec(templateString) // text only if (!m) { frag.appendChild(document.createTextNode(templateString)) return frag } var tag = m[1], wrap = map[tag] || map._default, depth = wrap[0], prefix = wrap[1], suffix = wrap[2], node = document.createElement('div') node.innerHTML = prefix + templateString.trim() + suffix while (depth--) node = node.lastChild // one element if (node.firstChild === node.lastChild) { frag.appendChild(node.firstChild) return frag } // multiple nodes, return a fragment var child /* jshint boss: true */ while (child = node.firstChild) { if (node.nodeType === 1) { frag.appendChild(child) } } return frag }
Version data entries
7 entries across 7 versions & 1 rubygems