OSDN Git Service

build SIE3 beta
authordhrname <dhrname@users.sourceforge.jp>
Tue, 31 Jul 2012 10:53:11 +0000 (19:53 +0900)
committerdhrname <dhrname@users.sourceforge.jp>
Tue, 31 Jul 2012 10:53:11 +0000 (19:53 +0900)
org/sie-uncompressed.js

index 633e77c..3826efa 100644 (file)
@@ -324,6 +324,9 @@ Node.prototype = {
 
 
 Array.prototype.item = function( /*long*/ index) {
+  if (!this[index]) {
+    return null;
+  }
   return (this[index]);
 };
 /*ノードリストはArrayで代用。
@@ -893,7 +896,7 @@ Document.prototype._document_ = document
       p;
   attr.namespaceURI = namespaceURI;
   attr.nodeName = attr.name = qualifiedName;
-  if (qualifiedName.indexOf(":") !== -1){
+  if (namespaceURI && (qualifiedName.indexOf(":") !== -1)){
    p = qualifiedName.split(":");
     attr.prefix = p[0];
     attr.localName = p[1];
@@ -1250,9 +1253,10 @@ MutationEvent.prototype = new Event();
 
 /*Node*/ Node.prototype.insertBefore = function( /*Node*/ n, ref) {
   var tp = this.parentNode,
-      np = n.parentNode,
       rp, evt,
       te = this,
+      j = 0,
+      t,
       s, descend, di;
   if (tp) {
     while (!tp) {                              //先祖をたどっていく
@@ -1265,34 +1269,45 @@ MutationEvent.prototype = new Event();
   if (this.ownerDocument !== n.ownerDocument) { //所属Documentの生成元が違うならば
     throw (new DOMException(/*DOMException.WRONG_DOCUMENT_ERR*/ 4));
   }
-  if (np === this) {                  //入力した要素が子要素なら
-    this.removeChild(n);
+  if (n.parentNode) {                  //親要素があれ
+    n.parentNode.removeChild(n);
   }
-  if (np) {
-    (n === np.firstChild) && (np.firstChild = n.nextSibling);
-    (n === np.lastChild ) && (np.lastChild = n.previousSibling);
-  }
-  if (!ref) {                                   //参照要素がNULLの場合、要素を追加する(appendChildと同じ効果)
-    n._num = this.childNodes.length;
-    this.childNodes[n._num] = n;
+  if (!ref) {
+    /*参照要素がNULLの場合、要素を追加する(appendChildと同じ効果)*/
+    if (!this.firstChild) {
+      this.firstChild = n;
+    }
     if (this.lastChild) {
       n.previousSibling = this.lastChild;
       this.lastChild.nextSibling = n;
     }
+    this.lastChild = n;
+    this.childNodes.push(n);
+    n.nextSibling = null;
   } else {
     if (ref.parentNode !== this) {              //参照ノードが子要素でない場合
       throw (new DOMException(/*DOMException.NOT_FOUND_ERR*/ 8));
     }
-    this.childNodes.splice(ref._num,1,n,ref);   //Arrayのspliceを利用して、リストにnノードを追加
+    t = this.firstChild;
+    if (t === ref) {
+      this.firstChild = n;
+    }
+    while (t) {
+      if (t === ref) {
+        this.childNodes.splice(j, 1, n, ref);   //Arrayのspliceを利用して、リストにnノードを追加
+        break;
+      }
+      ++j;
+      t = t.nextSibling;
+    }
     rp = ref.previousSibling;
     if (rp) {
       rp.nextSibling = n;
     }
     ref.previousSibling = n;
+    n.previousSibling = rp;
+    n.nextSibling = ref;
   }
-  n.nextSibling = ref;
-  this.firstChild = this.childNodes[0];
-  this.lastChild = this.childNodes[this.childNodes.length-1];
   n.parentNode = this;
   if ((n.nodeType===/*Node.ENTITY_REFERENCE_NODE*/ 5) || (n.nodeType===/*Node.DOCUMENT_FRAGMENT_NODE*/ 11)) {
     /*実体参照や、文書フラグメントノードだけは子ノードを検索して、
@@ -1317,7 +1332,7 @@ MutationEvent.prototype = new Event();
     te = te.parentNode;
   } while (te);
   if (s !== this.ownerDocument.documentElement) {
-    evt = descend = tp = np = rp = te = s = di = void 0;
+    evt = descend = tp = rp = te = s = di = void 0;
     return n;
   }
   evt = this.ownerDocument.createEvent("MutationEvents");
@@ -1338,7 +1353,7 @@ MutationEvent.prototype = new Event();
       di = null;
     }
   }
-  evt = descend = tp = np = rp = te = s = di = void 0;
+  evt = descend = tp = rp = j = t = te = s = di = void 0;
   return n;
 };
 
@@ -1346,6 +1361,12 @@ MutationEvent.prototype = new Event();
   if (!(ele instanceof Node)) {                   //Nodeでなければ
     throw (new Error());
   }
+  if (ele.parentNode !== this) {                                        //親が違う場合
+    throw (new DOMException(/*DOMException.NOT_FOUND_ERR*/ 8));
+  }
+  if (ele.ownerDocument !== this.ownerDocument) { //所属ドキュメントが違う場合
+    throw (new Error());
+  }
   /*ここから*/
   var evt = this.ownerDocument.createEvent("MutationEvents"),
       descend;
@@ -1373,22 +1394,27 @@ MutationEvent.prototype = new Event();
   ele.dispatchEvent(evt);
   evt = descend = void 0;
   /*ここまで追加*/
-  if (ele.parentNode === this) {
-    this.childNodes.splice(ele._num,1);           //Arrayのspliceを利用して、リストからeleノードを排除
-    if (this.firstChild === ele) {
-      this.firstChild = null;
-    }
-    if (this.lastChild === ele) {
-      this.lastChild = null;
+  ele.parentNode = null;
+  var t = this.firstChild,
+      j = 0;
+  while (t) {
+    if (t === ele) {
+      this.childNodes.splice(j, 1);      //Arrayのspliceを利用して、リストからeleノードを排除
+      break;
     }
-    ele.previousSibling && (ele.previousSibling.nextSibling = ele.nextSibling);
-    ele.nextSibling && (ele.nextSibling.previousSibling = ele.previousSibling);
-  } else {                                        //親が違う場合
-    throw (new DOMException(/*DOMException.NOT_FOUND_ERR*/ 8));
+    ++j;
+    t = t.nextSibling;
   }
-  if (ele.ownerDocument !== this.ownerDocument) { //所属ドキュメントが違う場合
-    throw (new Error());
+  if (this.firstChild === ele) {
+    this.firstChild = ele.nextSibling;
+  }
+  if (this.lastChild === ele) {
+    this.lastChild = ele.previousSibling;
   }
+  ele.previousSibling && (ele.previousSibling.nextSibling = ele.nextSibling);
+  ele.nextSibling && (ele.nextSibling.previousSibling = ele.previousSibling);
+  ele.nextSibling = ele.previousSibling = null;
+  t = j = void 0;
   return ele;
 };