Array.prototype.item = function( /*long*/ index) {
+ if (!this[index]) {
+ return null;
+ }
return (this[index]);
};
/*ノードリストはArrayで代用。
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];
/*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) { //先祖をたどっていく
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)) {
/*実体参照や、文書フラグメントノードだけは子ノードを検索して、
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");
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;
};
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;
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;
};