From a6fb58886573a29de68e283853deb4044be82cb1 Mon Sep 17 00:00:00 2001 From: dhrname Date: Wed, 13 Apr 2016 21:34:37 +0900 Subject: [PATCH] Add an isCSS property to the object --- org/w3c/dom/smil.js | 24 +++++++++++++++--------- tool/Spec/spec/SvgDomSpec.js | 3 +++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/org/w3c/dom/smil.js b/org/w3c/dom/smil.js index 3ffd06e..040685e 100644 --- a/org/w3c/dom/smil.js +++ b/org/w3c/dom/smil.js @@ -814,19 +814,21 @@ base("$calcMode").up("$attribute").mix( { /*アニメーションするために、対象の属性やプロパティを変化させるメソッド*/ setAttribute: function (value) { - if (!this.attrName) { + var attrName = this.attrName; + if (!attrName) { return; } var ele = this.element; - ele.setAttributeNS(this.attrNameSpace, this.attrName, value); + ele.setAttributeNS(this.attrNameSpace, attrName, value); /*スタイルシートのプロパティも上書きしておく*/ - ele.style.setProperty(this.attrName, value, ""); + this.isCSS && ele.style.setProperty(attrName, value, ""); value = ele = void 0; }, /*setAttributeメソッドとは逆の効果で、無効化させるメソッド*/ removeAttribute: function () { - if (!this.attrName) { + var attrName = this.attrName; + if (!attrName) { return; } var ele = this.element; @@ -835,9 +837,9 @@ base("$calcMode").up("$attribute").mix( { } else { /*初期段階でターゲットの要素に属性が指定されていない場合は、 * 現在の属性値を削除するだけでよい*/ - ele.removeAttributeNS(this.attrNameSpace, this.attrName); + ele.removeAttributeNS(this.attrNameSpace, attrName); /*スタイルシートのプロパティも削除しておく。removePropertyでないことに注意*/ - this.isCSS && ele.style.setProperty(this.attrName, this.defaultValue, ""); + this.isCSS && ele.style.setProperty(attrName, this.defaultValue, ""); } value = ele = void 0; }, @@ -868,6 +870,10 @@ base("$calcMode").up("$attribute").mix( { */ return null; } + + /*属性値の設定*/ + this.attrName = this.getAttr("attributeName", ""); + /*属性タイプの設定*/ var attrType = this.getAttr("attributeType", "auto"); var computedStyle = this.element && this.element.ownerDocument.defaultView.getComputedStyle(this.element, ""); @@ -875,11 +881,11 @@ base("$calcMode").up("$attribute").mix( { this.isCSS = true; } else if ((attrType === "auto") && this.element) { if ( computedStyle.getPropertyValue(this.attrName) ) { - this.isCSS = true; + this.isCSS = true; } } - /*属性値の設定*/ - this.attrName = this.getAttr("attributeName", ""); + + /*xlink関連の属性のときは名前空間を変更しておく*/ if (this.attrName.indexOf("xlink") > -1) { this.attrNameSpace = "http://www.w3.org/1999/xlink"; } diff --git a/tool/Spec/spec/SvgDomSpec.js b/tool/Spec/spec/SvgDomSpec.js index d101d80..ace16db 100644 --- a/tool/Spec/spec/SvgDomSpec.js +++ b/tool/Spec/spec/SvgDomSpec.js @@ -1718,10 +1718,13 @@ describe("SMIL Animation Spec", function() { expect(attr.setAttribute()).toBeUndefined(); expect(attr.setAttribute("block")).toBeUndefined(); expect(p4.hasAttributeNS(null, "display")).toBeFalsy(); + expect(attr.isCSS).toBeFalsy(); + s.setAttributeNS(null, "attributeName", "display"); attr.push(s); expect(attr.setAttribute("block")).toBeUndefined(); expect(p4.hasAttributeNS(null, "display")).toBeTruthy(); + expect(attr.isCSS).toBeTruthy(); expect(p4.style.getPropertyValue("display")).toBe("block"); p4 = document.createElementNS("http://www.w3.org/2000/svg", "g"); -- 2.11.0