svnno****@sourc*****
svnno****@sourc*****
2010年 5月 13日 (木) 23:32:20 JST
Revision: 1821 http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1821 Author: dhrname Date: 2010-05-13 23:32:19 +0900 (Thu, 13 May 2010) Log Message: ----------- SVGURIReferenceの埋め込み機能をAjaxを用いて実装 Modified Paths: -------------- branches/ufltima/dom/svg.js Modified: branches/ufltima/dom/svg.js =================================================================== --- branches/ufltima/dom/svg.js 2010-05-13 14:31:41 UTC (rev 1820) +++ branches/ufltima/dom/svg.js 2010-05-13 14:32:19 UTC (rev 1821) @@ -763,6 +763,7 @@ */ function SVGURIReference() { /*readonly SVGAnimatedString*/ this.href = new SVGAnimatedString(); + this._instance = null; //埋め込みの場合に、読み込んだDOMツリーを結び付けておくプロパティ this.addEventListener("DOMAttrModified", function(evt){ if (evt.relatedNode.namespaceURI === "http://www.w3.org/1999/xlink" && evt.attrName === "xlink:href") { evt.target.href.baseVal = evt.newValue; @@ -814,6 +815,55 @@ tar._tar.setAttribute("target", "_blank"); tar._tar.setAttribute("href", uri); } else if (show === "embed") { + var xmlhttp = NAIBU.xmlhttp; + var ui = uri.indexOf("#"); + if (ui > -1) { + var id = uri.substring(ui+1, uri.length); + uri = uri.replace(/#.+$/, ""); + } else { + var id = null; + } + if (ui === 0) { //URIが#で始まるのであれば + var doc = tar.ownerDocument, ele = doc.getElementById(id); + tar._instance = doc.importNode(ele); + var ev = tar.ownerDocument.createEvent("SVGEvents"); + ev.initEvent("SVGLoad", false, false); + ev.target = tar; + tar.dispacthEvent(ev); + ev = null; + ele = null; + } else { + xmlhttp.open("GET", uri, true); + xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + xmlhttp.onreadystatechange = function() { + if (xmlhttp.readyState === 4 && xmlhttp.status === 200) { + var type = xmlhttp.getResponseHeader('Content-Type'); + if (!type) { + tar._tar.src = uri; + } else if (/[text|xml|script]/.test(type)) { //ファイルがtext形式である場合 + /*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; + } else { + tar._tar.src = uri; + } + } + } + } } } }, false); @@ -1221,6 +1271,7 @@ xmlhttp = false; } } + NAIBU.xmlhttp = xmlhttp; if (!document.namespaces["v"]) { document.namespaces.add("v","urn:schemas-microsoft-com:vml"); document.namespaces.add("o","urn:schemas-microsoft-com:office:office");