This repository has been archived on 2023-08-29. You can view files and clone it, but cannot push or open issues/pull-requests.
yutent
/
anot.js
Archived
1
0
Fork 0

修复svg的支持

master
宇天 2020-07-06 14:38:22 +08:00
parent f795667b5b
commit ccfd33529c
3 changed files with 37 additions and 38 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "anot", "name": "anot",
"version": "2.2.1", "version": "2.2.2",
"description": "Anot - 迷你mvvm框架", "description": "Anot - 迷你mvvm框架",
"main": "dist/anot.js", "main": "dist/anot.js",
"files": ["dist"], "files": ["dist"],

View File

@ -50,7 +50,7 @@ function executeBindings(bindings, vmodels) {
} }
var roneTime = /^\s*::/ var roneTime = /^\s*::/
var rmsAttr = /:(\w+)-?(.*)|@(.*)/ var rmsAttr = /^:(\w+)-?(.*)|@(.*)/
var events = oneObject( var events = oneObject(
'animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit' 'animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit'
@ -372,6 +372,8 @@ function scanText(textNode, vmodels, index) {
anotFragment.appendChild(node) anotFragment.appendChild(node)
} }
textNode.parentNode.replaceChild(anotFragment, textNode) textNode.parentNode.replaceChild(anotFragment, textNode)
if (bindings.length) executeBindings(bindings, vmodels) if (bindings.length) {
executeBindings(bindings, vmodels)
}
} }
} }

View File

@ -48,6 +48,7 @@ var attrDir = Anot.directive('attr', {
update: function(val) { update: function(val) {
var elem = this.element var elem = this.element
var obj = {} var obj = {}
var isSVG = rsvg.test(elem)
val = toJson(val) val = toJson(val)
@ -83,44 +84,40 @@ var attrDir = Anot.directive('attr', {
elem.style.cssText = obj[i] elem.style.cssText = obj[i]
continue continue
} }
if (i === 'href' || i === 'src') { // 修正这些值的显示
if (obj[i] === false || obj[i] === null || obj[i] === undefined) {
obj[i] = ''
}
if (
typeof elem[i] === 'boolean' ||
typeof elem[boolMap[i]] === 'boolean'
) {
var k = i
if (boolMap[i] && k !== boolMap[i]) {
k = boolMap[i]
}
//布尔属性必须使用el.xxx = true|false方式设值
obj[i] = !!obj[i]
elem[k] = obj[i]
if (!obj[i]) {
elem.removeAttribute(k)
continue
}
}
//SVG只能使用setAttribute(xxx, yyy), HTML的固有属性必须elem.xxx = yyy
var isInnate = isSVG ? false : i in elem.cloneNode(false)
if (isInnate) {
elem[i] = obj[i] elem[i] = obj[i]
} else { } else {
// 修正这些值的显示 if (typeof obj[i] === 'object') {
if (obj[i] === false || obj[i] === null || obj[i] === undefined) { obj[i] = Date.isDate(obj[i])
obj[i] = '' ? obj[i].toISOString()
} : JSON.stringify(obj[i])
if (
typeof elem[i] === 'boolean' ||
typeof elem[boolMap[i]] === 'boolean'
) {
var k = i
if (boolMap[i] && k !== boolMap[i]) {
k = boolMap[i]
}
//布尔属性必须使用el.xxx = true|false方式设值
obj[i] = !!obj[i]
elem[k] = obj[i]
if (!obj[i]) {
elem.removeAttribute(k)
continue
}
}
//SVG只能使用setAttribute(xxx, yyy), HTML的固有属性必须elem.xxx = yyy
var isInnate = rsvg.test(elem) ? false : i in elem.cloneNode(false)
if (isInnate) {
elem[i] = obj[i]
} else {
if (typeof obj[i] === 'object') {
obj[i] = Date.isDate(obj[i])
? obj[i].toISOString()
: JSON.stringify(obj[i])
}
elem.setAttribute(i, obj[i])
} }
elem.setAttribute(i, obj[i])
} }
} }
} }