svnno****@sourc*****
svnno****@sourc*****
2010年 2月 4日 (木) 22:57:21 JST
Revision: 1634 http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1634 Author: dhrname Date: 2010-02-04 22:57:21 +0900 (Thu, 04 Feb 2010) Log Message: ----------- DOMNodexxxイベントとDOMCharacterDataModifiedを発火させるようにした Modified Paths: -------------- branches/ufltima/dom/events.js Modified: branches/ufltima/dom/events.js =================================================================== --- branches/ufltima/dom/events.js 2010-02-04 12:43:48 UTC (rev 1633) +++ branches/ufltima/dom/events.js 2010-02-04 13:57:21 UTC (rev 1634) @@ -252,7 +252,7 @@ if (tgans) { //ノードがすでにあるならば、 var s = this[this._num]; this[this._num] = node; - evt.initMutationEvent("DOMAttrModified", true, true, node, null, node.nodeName, node.nodeName, MutationEvent.MODIFICATION); + evt.initMutationEvent("DOMAttrModified", true, false, node, null, node.nodeName, node.nodeName, MutationEvent.MODIFICATION); node.ownerElement.dispatchEvent(evt); //このとき、MutationEventsが発動 return s; } else { @@ -261,9 +261,107 @@ } this[this.length] = arg; //新たに、argを項目として追加する this.length += 1; - evt.initMutationEvent("DOMAttrModified", true, true, node, null, node.nodeName, node.nodeName, MutationEvent.ADDITION); + evt.initMutationEvent("DOMAttrModified", true, false, node, null, node.nodeName, node.nodeName, MutationEvent.ADDITION); node.ownerElement.dispatchEvent(evt); return null; } + evt = null; }; + +/*Node*/ Node.prototype.insertBefore = function( /*Node*/ n, ref) { + var tp = this.parentNode; + if (tp) { + while (!tp) { //先祖をたどっていく + if (tp === n) { //先祖要素が追加ノードならばエラー + throw (new DOMException(DOMException.HIERARCHY_REQUEST_ERR)); + } + tp = tp.parentNode; + } + } + if (this.ownerDocument !== n.ownerDocument) { //所属Documentの生成元が違うならば + throw (new DOMException(DOMException.WRONG_DOCUMENT_ERR)); + } + if (n.parentNode === this) { //入力した要素が子要素ならば + this.removeChild(n); + } + if (!ref) { //参照要素がNULLの場合、要素を追加する(appendChildと同じ効果) + this.childNodes[this.childNodes.length] = n; + n.previousSibling = this.lastChild; + } else { + if (ref.parentNode !== this) { //参照ノードが子要素でない場合 + throw (new DOMException(DOMException.NOT_FOUND_ERR)); + } + this.childNodes.splice(ref._num,1,n,ref); //Arrayのspliceを利用して、リストにnノードを追加 + ref.previousSibling = n; + } + n.nextSibling = ref; + this.firstChild = this.childNodes[0]; + this.lastChild = this.childNodes[this.childNodes.length-1]; + n.parentNode = this; + var evt = this.ownerDocument.createEvent("MutationEvents"); + evt.target = n; + evt.initMutationEvent("DOMNodeInserted", true, false, this, null, null, null, null); + n.dispatchEvent(evt); + evt = null; + return n; +}; + +/*Node*/ Node.prototype.removeChild = function( /*Node*/ ele) { + if (!(ele instanceof Node)) { //Nodeでなければ + throw (new Error()); + } + var evt = this.ownerDocument.createEvent("MutationEvents"); + evt.target = ele; + evt.initMutationEvent("DOMNodeRemoved", true, false, this, null, null, null, null); + ele.dispatchEvent(evt); + evt = null; + if (ele.parentNode === this) { + this.childNodes.splice(ele._num,1); //Arrayのspliceを利用して、リストからeleノードを排除 + } else { //親が違う場合 + throw (new DOMException(DOMException.NOT_FOUND_ERR)); + } + if (ele.ownerDocument !== this.ownerDocument) { //所属ドキュメントが違う場合 + throw (new Error()); + } + return ele; +}; + +/*void*/ CharacterData.prototype.appendData = function( /*string*/ arg) { + var pd = this.data; + this.data += arg; + this.length = this.data.length; + var evt = this.ownerDocument.createEvent("MutationEvents"); + evt.target = this.parentNode; + evt.initMutationEvent("DOMCharacterDataModified", true, false, null, pd, this.data, null, null); + ele.dispatchEvent(evt); + evt = arg = pd = null; +}; +/*void*/ CharacterData.prototype.insertData = function( /*long*/ offset, /*string*/ arg) { + var pd = this.data; + var pre = this.substring(0, offset - 1); //文字列を二つに分けた、前半部分 + var next = this.substring(offset, this.length - offset); //後半部分 + this.data = pre + this.data + next; + this.length = this.data.length; + var evt = this.ownerDocument.createEvent("MutationEvents"); + evt.target = this.parentNode; + evt.initMutationEvent("DOMCharacterDataModified", true, false, null, pd, this.data, null, null); + ele.dispatchEvent(evt); + evt = arg = pd = null; +}; +/*void*/ CharacterData.prototype.deleteData = function( /*long*/ offset, /*long*/ count) { + var pd = this.data; + var pre = this.substring(0, offset - 1); //残すべき前半部分 + var next = this.substring(offset + count, this.length - 1); //後半部分 + if (offset + count > this.length) { //offsetとcountの和が文字全体の長さを超える場合、offsetから最後までのを削除 + next = ""; + } + this.data = pre + next; + this.length = this.data.length; + var evt = this.ownerDocument.createEvent("MutationEvents"); + evt.target = this.parentNode; + evt.initMutationEvent("DOMCharacterDataModified", true, false, null, pd, this.data, null, null); + ele.dispatchEvent(evt); + evt = pd = null; +}; + // _EVENTS_IDL_