diff --git a/src/browser/auto-close-tags.js b/src/browser/auto-close-tags.js index ec6241da..43ed9eff 100644 --- a/src/browser/auto-close-tags.js +++ b/src/browser/auto-close-tags.js @@ -7,13 +7,26 @@ * @file 自闭合标签表 */ -var splitStr2Obj = require('../util/split-str-2-obj'); - /** * 自闭合标签列表 * * @type {Object} */ -var autoCloseTags = splitStr2Obj('area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr'); +var autoCloseTags = { + area: 1, + base: 1, + br: 1, + col: 1, + embed: 1, + hr: 1, + img: 1, + input: 1, + link: 1, + meta: 1, + param: 1, + source: 1, + track: 1, + wbr: 1 +}; exports = module.exports = autoCloseTags; diff --git a/src/browser/bool-attrs.js b/src/browser/bool-attrs.js index 775e34c2..d1e64d8d 100644 --- a/src/browser/bool-attrs.js +++ b/src/browser/bool-attrs.js @@ -7,19 +7,36 @@ * @file bool属性表 */ - -var splitStr2Obj = require('../util/split-str-2-obj'); - /** * bool属性表 * * @type {Object} */ -var boolAttrs = splitStr2Obj( - 'allowpaymentrequest,async,autofocus,autoplay,' - + 'checked,controls,default,defer,disabled,formnovalidate,' - + 'hidden,ismap,itemscope,loop,multiple,muted,nomodule,novalidate,' - + 'open,readonly,required,reversed,selected,typemustmatch' -); +var boolAttrs = { + allowpaymentrequest: 1, + async: 1, + autofocus: 1, + autoplay: 1, + checked: 1, + controls: 1, + default: 1, + defer: 1, + disabled: 1, + formnovalidate: 1, + hidden: 1, + ismap: 1, + itemscope: 1, + loop: 1, + multiple: 1, + muted: 1, + nomodule: 1, + novalidate: 1, + open: 1, + readonly: 1, + required: 1, + reversed: 1, + selected: 1, + typemustmatch: 1 +}; exports = module.exports = boolAttrs; diff --git a/src/browser/create-el.js b/src/browser/create-el.js deleted file mode 100644 index a9c49765..00000000 --- a/src/browser/create-el.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) Baidu Inc. All rights reserved. - * - * This source code is licensed under the MIT license. - * See LICENSE file in the project root for license information. - * - * @file DOM创建 - */ - -var svgTags = require('./svg-tags'); - -/** - * 创建 DOM 元素 - * - * @param {string} tagName tagName - * @return {HTMLElement} - */ -function createEl(tagName) { - if (svgTags[tagName] && document.createElementNS) { - return document.createElementNS('http://www.w3.org/2000/svg', tagName); - } - - return document.createElement(tagName); -} - -exports = module.exports = createEl; diff --git a/src/browser/hot-tags.js b/src/browser/hot-tags.js index 51d3dfea..2fe1cbf6 100644 --- a/src/browser/hot-tags.js +++ b/src/browser/hot-tags.js @@ -7,17 +7,44 @@ * @file 常用标签表,用于 element 创建优化 */ -var splitStr2Obj = require('../util/split-str-2-obj'); - /** * 常用标签表 * * @type {Object} */ -var hotTags = splitStr2Obj( - 'div,span,img,ul,ol,li,dl,dt,dd,a,b,u,hr,' - + 'form,input,textarea,button,label,select,option,' - + 'table,tbody,th,tr,td,thead,main,aside,header,footer,nav' -); +var hotTags = { + div: 1, + span: 1, + img: 1, + ul: 1, + ol: 1, + li: 1, + dl: 1, + dt: 1, + dd: 1, + a: 1, + b: 1, + u: 1, + hr: 1, + form: 1, + input: 1, + textarea: 1, + button: 1, + label: 1, + select: 1, + option: 1, + table: 1, + tbody: 1, + th: 1, + tr: 1, + td: 1, + thead: 1, + main: 1, + aside: 1, + header: 1, + footer: 1, + nav: 1 + +}; exports = module.exports = hotTags; diff --git a/src/browser/svg-tags.js b/src/browser/svg-tags.js index 9b633230..d3b4089c 100644 --- a/src/browser/svg-tags.js +++ b/src/browser/svg-tags.js @@ -7,7 +7,6 @@ * @file SVG标签表 */ -var splitStr2Obj = require('../util/split-str-2-obj'); /** * svgTags @@ -15,34 +14,62 @@ var splitStr2Obj = require('../util/split-str-2-obj'); * @see https://www.w3.org/TR/SVG/svgdtd.html 只取常用 * @type {Object} */ -var svgTags = splitStr2Obj('' +var svgTags = { // Animation elements - + 'animate,animateMotion,animateTransform,' + animate: 1, + animateMotion: 1, + animateTransform: 1, // Basic shapes - + 'circle,ellipse,line,polygon,polyline,rect,' + circle: 1, + ellipse: 1, + line: 1, + polygon: 1, + polyline: 1, + rect: 1, // Container elements - + 'defs,g,marker,mask,missing-glyph,pattern,svg,symbol,' + defs: 1, + g: 1, + marker: 1, + mask: 1, + 'missing-glyph': 1, + pattern: 1, + svg: 1, + 'symbol': 1, // Descriptive elements - + 'desc,metadata,' + desc: 1, + metadata: 1, // Font elements - + 'font,font-face,' + font: 1, + 'font-face': 1, // Gradient elements - + 'linearGradient,radialGradient,stop,' + linearGradient: 1, + radialGradient: 1, + stop: 1, // Graphics elements - + 'image,path,use,' + image: 1, + path: 1, + use: 1, // Text elements - + 'glyph,textPath,text,tref,tspan,' + glyph: 1, + textPath: 1, + text: 1, + tref: 1, + tspan: 1, // Others - + 'clipPath,cursor,filter,foreignObject,view' -); + clipPath: 1, + cursor: 1, + filter: 1, + foreignObject: 1, + view: 1 +}; exports = module.exports = svgTags; diff --git a/src/main.js b/src/main.js index 395f9b54..8dc18f36 100644 --- a/src/main.js +++ b/src/main.js @@ -18,7 +18,6 @@ // require('./browser/on'); // require('./browser/un'); // require('./browser/svg-tags'); - // require('./browser/create-el'); // require('./browser/remove-el'); // require('./util/next-tick'); // require('./browser/ie'); diff --git a/src/util/split-str-2-obj.js b/src/util/split-str-2-obj.js deleted file mode 100644 index 5a09a274..00000000 --- a/src/util/split-str-2-obj.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) Baidu Inc. All rights reserved. - * - * This source code is licensed under the MIT license. - * See LICENSE file in the project root for license information. - * - * @file 将字符串逗号切分返回对象 - */ - -var each = require('../util/each'); - -/** - * 将字符串逗号切分返回对象 - * - * @param {string} source 源字符串 - * @return {Object} - */ -function splitStr2Obj(source) { - var result = {}; - each( - source.split(','), - function (key) { - result[key] = key; - } - ); - return result; -} - -exports = module.exports = splitStr2Obj; diff --git a/src/view/component.js b/src/view/component.js index 5b14115c..8f802bd4 100644 --- a/src/view/component.js +++ b/src/view/component.js @@ -22,6 +22,7 @@ var Data = require('../runtime/data'); var evalExpr = require('../runtime/eval-expr'); var changeExprCompare = require('../runtime/change-expr-compare'); var DataChangeType = require('../runtime/data-change-type'); +var svgTags = require('../browser/svg-tags'); var insertBefore = require('../browser/insert-before'); var un = require('../browser/un'); var preprocessComponents = require('./preprocess-components'); @@ -1033,7 +1034,9 @@ Component.prototype.attach = function (parentEl, beforeEl) { } else { props = aNode.props; - this.el = createEl(this.tagName); + this.el = svgTags[this.tagName] && document.createElementNS + ? document.createElementNS('http://www.w3.org/2000/svg', this.tagName) + : document.createElement(this.tagName); } if (this._sbindData) { diff --git a/src/view/element.js b/src/view/element.js index c7a732ca..7b410350 100644 --- a/src/view/element.js +++ b/src/view/element.js @@ -11,6 +11,7 @@ var changeExprCompare = require('../runtime/change-expr-compare'); var changesIsInDataRef = require('../runtime/changes-is-in-data-ref'); var evalExpr = require('../runtime/eval-expr'); +var svgTags = require('../browser/svg-tags'); var insertBefore = require('../browser/insert-before'); var LifeCycle = require('./life-cycle'); var NodeType = require('./node-type'); @@ -125,7 +126,9 @@ Element.prototype.attach = function (parentEl, beforeEl) { } else { props = aNode.props; - this.el = createEl(this.tagName); + this.el = svgTags[this.tagName] && document.createElementNS + ? document.createElementNS('http://www.w3.org/2000/svg', this.tagName) + : document.createElement(this.tagName); } if (this._sbindData) { diff --git a/src/view/preheat-el.js b/src/view/preheat-el.js index 2f922ef6..0ffff2d9 100644 --- a/src/view/preheat-el.js +++ b/src/view/preheat-el.js @@ -7,6 +7,8 @@ * @file ANode预热 */ +var svgTags = require('../browser/svg-tags'); + /** * ANode预热HTML元素,用于循环创建时clone * @@ -14,7 +16,9 @@ * @return {HTMLElement} */ function preheatEl(aNode) { - var el = createEl(aNode.tagName); + var el = svgTags[aNode.tagName] && document.createElementNS + ? document.createElementNS('http://www.w3.org/2000/svg', aNode.tagName) + : document.createElement(aNode.tagName); aNode._el = el; for (var i = 0, l = aNode.props.length; i < l; i++) { diff --git a/src/view/style-props.js b/src/view/style-props.js index 34961285..97d3cab9 100644 --- a/src/view/style-props.js +++ b/src/view/style-props.js @@ -7,13 +7,14 @@ * @file 样式的基本属性 */ -var splitStr2Obj = require('../util/split-str-2-obj'); - /** * 元素的基本属性 * * @type {Object} */ -var styleProps = splitStr2Obj('class,style'); +var styleProps = { + 'class': 1, + style: 1 +}; exports = module.exports = styleProps; diff --git a/src/view/template-component.js b/src/view/template-component.js index c04902a2..5541416a 100644 --- a/src/view/template-component.js +++ b/src/view/template-component.js @@ -22,6 +22,7 @@ var Data = require('../runtime/data'); var evalExpr = require('../runtime/eval-expr'); var changeExprCompare = require('../runtime/change-expr-compare'); var DataChangeType = require('../runtime/data-change-type'); +var svgTags = require('../browser/svg-tags'); var insertBefore = require('../browser/insert-before'); var createNode = require('./create-node'); var preheatEl = require('./preheat-el'); @@ -252,7 +253,9 @@ TemplateComponent.prototype.attach = function (parentEl, beforeEl) { } else { props = aNode.props; - this.el = createEl(this.tagName); + this.el = svgTags[this.tagName] && document.createElementNS + ? document.createElementNS('http://www.w3.org/2000/svg', this.tagName) + : document.createElement(this.tagName); } if (this._sbindData) {