svnno****@sourc*****
svnno****@sourc*****
2010年 6月 2日 (水) 23:40:23 JST
Revision: 1876 http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1876 Author: dhrname Date: 2010-06-02 23:40:23 +0900 (Wed, 02 Jun 2010) Log Message: ----------- SVGScriptElementの実装開始 Modified Paths: -------------- branches/06x/061/org/w3c/dom/svg.js Modified: branches/06x/061/org/w3c/dom/svg.js =================================================================== --- branches/06x/061/org/w3c/dom/svg.js 2010-06-02 14:40:02 UTC (rev 1875) +++ branches/06x/061/org/w3c/dom/svg.js 2010-06-02 14:40:23 UTC (rev 1876) @@ -869,23 +869,31 @@ /*responseXMLを使うと、時々、空のデータを返すことがあるため(原因は不明)、 *ここでは、responseTextを用いる */ - var doc = new ActiveXObject("MSXML2.DomDocument"); - str = xmlhttp.responseText.replace(/!DOCTYPE/,"!--").replace(/(dtd">|\]>)/,"-->"); - doc.loadXML(str); - if (id) { - var ele = doc.getElementById(id); - } else { - var ele = doc.documentElement; - } - tar._instance = tar.ownerDocument.importNode(ele); - var ev = tar.ownerDocument.createEvent("SVGEvents"); - ev.initEvent("SVGLoad", false, false); - ev.target = tar; - tar.dispacthEvent(ev); - ev = null; + /*script要素とstyle要素は、 + *_textプロパティに読み込んだテキストを格納しておく + *それら以外は、_instanceプロパティにDOMツリーを格納しておく + */ + if (tar.localName !== "script" && tar.localName !== "style") { + var doc = new ActiveXObject("MSXML2.DomDocument"); + str = xmlhttp.responseText.replace(/!DOCTYPE/,"!--").replace(/(dtd">|\]>)/,"-->"); + doc.loadXML(str); + if (id) { + var ele = doc.getElementById(id); + } else { + var ele = doc.documentElement; + } + tar._instance = tar.ownerDocument.importNode(ele); + } else { + tar._text = xmlhttp.responseText; + } } else { tar._tar.src = uri; } + var ev = tar.ownerDocument.createEvent("SVGEvents"); + ev.initEvent("SVGLoad", false, false); + ev.target = tar; + tar.dispacthEvent(ev); + ev = null; } } } @@ -3567,9 +3575,39 @@ SVGViewElement.prototype = new SVGElement(); function SVGScriptElement() { - SVGElement.apply(this, arguments); + SVGElement.apply(this); /*DOMString*/ this.type; SVGURIReference.apply(this, arguments); + this.addEventListener("DOMAttrModified", function(evt){ + if (evt.attrName === "type") { + evt.target.type = evt.newValue; + } + }, false); + this.addEventListener("SVGLoad", function(evt){ + var tar = evt.target; + var evtt = this.ownerDocument.createEvent("MutationEvents"); + evtt.initMutationEvent("DOMNodeInsertedIntoDocument", false, false, null, null, null, null, null); + tar.dispatchEvent(evt); + }, false); + this.addEventListener("DOMNodeInserted", function(evt){ + var tar = evt.target; + if (evt.eventPhase === Event.BUBBLING_PHASE) { + if (tar.nodeType === Node.CDATA_SECTION_NODE) { + evt.currentTarget._text = tar.nodeValue; + } + return; + } + tar.addEventListener("DOMNodeInsertedIntoDocument", function(evt){ + var tar = evt.target, script = tar._text; + script = "(function(window, document){" +script; + script += "})(Document.prototype.defaultView, window._document)"; + /*_documentに該当する文書ノードをグローバル変数に入れておいて、後で渡しておく*/ + window._document = tar.ownerDocument; + eval(script); + tar = evt = script = null; + }, false); + tar = evt = null; + }, false); return this; }; SVGScriptElement.constructor = SVGElement;