From: dhrname Date: Mon, 7 Oct 2013 14:04:24 +0000 (+0900) Subject: file.readメソッドの変数を整理して軽量化 X-Git-Tag: v16beta~200 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=dcfddf836c61345c54c3f8a12c2fcbeeb670919e;p=sie%2Fsie.git file.readメソッドの変数を整理して軽量化 --- diff --git a/tool/funcproto/openfile.js b/tool/funcproto/openfile.js index 6ac415f..2aa476a 100644 --- a/tool/funcproto/openfile.js +++ b/tool/funcproto/openfile.js @@ -16,24 +16,23 @@ if (!Function.prototype.open) { handle.read = function () { var data = this.join(""), xml, - doc; + doc = document; if (arguments[0] && (arguments[0] === "element")) { - doc = document; - try { - xml = (new DOMParser()).parseFromString( data , "text/xml" ); - } catch( e ) { - xml = null; - } - if ( !xml || !xml.documentElement - || xml.getElementsByTagName( "parsererror" ).length ) { - throw new Error( "Invalid XML: " + data ); - } if (doc.importNode) { + try { + xml = (new DOMParser()).parseFromString( data , "text/xml" ); + } catch( e ) { + xml = null; + } + if ( !xml || !xml.documentElement + || xml.getElementsByTagName( "parsererror" ).length ) { + throw new Error( "Invalid XML: " + data ); + } var s = doc.importNode(xml.documentElement); doc.documentElement.appendChild(s); return s; } else { - doc.documentElement.lastChild.insertAdjacentHTML("afterend", xml.documentElement.xml); + doc.documentElement.lastChild.insertAdjacentHTML("afterend", data); return doc.documentElement.lastChild; } } else {