react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / vendor / core / getMarkupWrap.js
81158 views/**1* Copyright 2013-2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @providesModule getMarkupWrap9*/1011var ExecutionEnvironment = require('ExecutionEnvironment');1213var invariant = require('invariant');1415/**16* Dummy container used to detect which wraps are necessary.17*/18var dummyNode =19ExecutionEnvironment.canUseDOM ? document.createElement('div') : null;2021/**22* Some browsers cannot use `innerHTML` to render certain elements standalone,23* so we wrap them, render the wrapped nodes, then extract the desired node.24*25* In IE8, certain elements cannot render alone, so wrap all elements ('*').26*/27var shouldWrap = {28// Force wrapping for SVG elements because if they get created inside a <div>,29// they will be initialized in the wrong namespace (and will not display).30'circle': true,31'defs': true,32'ellipse': true,33'g': true,34'line': true,35'linearGradient': true,36'path': true,37'polygon': true,38'polyline': true,39'radialGradient': true,40'rect': true,41'stop': true,42'text': true43};4445var selectWrap = [1, '<select multiple="true">', '</select>'];46var tableWrap = [1, '<table>', '</table>'];47var trWrap = [3, '<table><tbody><tr>', '</tr></tbody></table>'];4849var svgWrap = [1, '<svg>', '</svg>'];5051var markupWrap = {52'*': [1, '?<div>', '</div>'],5354'area': [1, '<map>', '</map>'],55'col': [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],56'legend': [1, '<fieldset>', '</fieldset>'],57'param': [1, '<object>', '</object>'],58'tr': [2, '<table><tbody>', '</tbody></table>'],5960'optgroup': selectWrap,61'option': selectWrap,6263'caption': tableWrap,64'colgroup': tableWrap,65'tbody': tableWrap,66'tfoot': tableWrap,67'thead': tableWrap,6869'td': trWrap,70'th': trWrap,7172'circle': svgWrap,73'defs': svgWrap,74'ellipse': svgWrap,75'g': svgWrap,76'line': svgWrap,77'linearGradient': svgWrap,78'path': svgWrap,79'polygon': svgWrap,80'polyline': svgWrap,81'radialGradient': svgWrap,82'rect': svgWrap,83'stop': svgWrap,84'text': svgWrap85};8687/**88* Gets the markup wrap configuration for the supplied `nodeName`.89*90* NOTE: This lazily detects which wraps are necessary for the current browser.91*92* @param {string} nodeName Lowercase `nodeName`.93* @return {?array} Markup wrap configuration, if applicable.94*/95function getMarkupWrap(nodeName) {96invariant(!!dummyNode, 'Markup wrapping node not initialized');97if (!markupWrap.hasOwnProperty(nodeName)) {98nodeName = '*';99}100if (!shouldWrap.hasOwnProperty(nodeName)) {101if (nodeName === '*') {102dummyNode.innerHTML = '<link />';103} else {104dummyNode.innerHTML = '<' + nodeName + '></' + nodeName + '>';105}106shouldWrap[nodeName] = !dummyNode.firstChild;107}108return shouldWrap[nodeName] ? markupWrap[nodeName] : null;109}110111112module.exports = getMarkupWrap;113114115