修复svg的支持
parent
f795667b5b
commit
ccfd33529c
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "anot",
|
||||
"version": "2.2.1",
|
||||
"version": "2.2.2",
|
||||
"description": "Anot - 迷你mvvm框架",
|
||||
"main": "dist/anot.js",
|
||||
"files": ["dist"],
|
||||
|
|
|
@ -50,7 +50,7 @@ function executeBindings(bindings, vmodels) {
|
|||
}
|
||||
|
||||
var roneTime = /^\s*::/
|
||||
var rmsAttr = /:(\w+)-?(.*)|@(.*)/
|
||||
var rmsAttr = /^:(\w+)-?(.*)|@(.*)/
|
||||
|
||||
var events = oneObject(
|
||||
'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)
|
||||
}
|
||||
textNode.parentNode.replaceChild(anotFragment, textNode)
|
||||
if (bindings.length) executeBindings(bindings, vmodels)
|
||||
if (bindings.length) {
|
||||
executeBindings(bindings, vmodels)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ var attrDir = Anot.directive('attr', {
|
|||
update: function(val) {
|
||||
var elem = this.element
|
||||
var obj = {}
|
||||
var isSVG = rsvg.test(elem)
|
||||
|
||||
val = toJson(val)
|
||||
|
||||
|
@ -83,44 +84,40 @@ var attrDir = Anot.directive('attr', {
|
|||
elem.style.cssText = obj[i]
|
||||
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]
|
||||
} else {
|
||||
// 修正这些值的显示
|
||||
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 = 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])
|
||||
if (typeof obj[i] === 'object') {
|
||||
obj[i] = Date.isDate(obj[i])
|
||||
? obj[i].toISOString()
|
||||
: JSON.stringify(obj[i])
|
||||
}
|
||||
elem.setAttribute(i, obj[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue