[Sie-announce] SIEコード [1670] 1, DOMNodeInsertedIntoDocumentイベントの実装

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 2月 19日 (金) 23:46:48 JST


Revision: 1670
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1670
Author:   dhrname
Date:     2010-02-19 23:46:48 +0900 (Fri, 19 Feb 2010)

Log Message:
-----------
1, DOMNodeInsertedIntoDocumentイベントの実装
2, dispatchEventメソッドの修正

Modified Paths:
--------------
    branches/ufltima/dom/events.js

Modified: branches/ufltima/dom/events.js
===================================================================
--- branches/ufltima/dom/events.js	2010-02-19 14:45:15 UTC (rev 1669)
+++ branches/ufltima/dom/events.js	2010-02-19 14:46:48 UTC (rev 1670)
@@ -110,7 +110,8 @@
     throw new EventException(EventException.UNSPECIFIED_EVENT_TYPE_ERR);
   }
   evt.target = this;
-  var te = this, s = []; //配列sに、このノードからドキュメントノードにいたるまでの、DOMツリーのリストを作成しておく
+  var te = this, s = [];
+  //配列sに、このノードからドキュメントノードにいたるまでの、DOMツリーのリストを作成しておく
   do {
     s[s.length] = te;
     te = te.parentNode;
@@ -123,9 +124,11 @@
     var d = sli - i;
     if (d === 0){ //イベントのターゲットに到着(折り返し地点)
       n = -1;
-      evt.eventPhase = Event.AT_TARGET;      
+      evt.eventPhase = Event.AT_TARGET;
+      evt.currentTarget = evt.target;
+    } else {
+      evt.currentTarget = s[d*n-1];
     }
-    evt.currentTarget = s[d*n-1];
     var tce = evt.currentTarget._capter; //tceは登録しておいたリスナーのリスト
     for (var j=0,tcli=tce.length;j<tcli;++j){
       if (tce[j]) {
@@ -133,22 +136,27 @@
       }
     }
     if (d === 0) {
+      if (!evt.bubbles) {
+        break; //浮上フェーズに移行せず、停止する
+      }
       evt.eventPhase = Event.BUBBLING_PHASE;
-    } 
+    }
   }
   evt = null;
   return true;
 };
 
 function EventListener(cap,type,listener) {
-  this._cap = cap; this._type = type; this._listener = listener;
+  this._cap = cap;
+  this._type = type;
+  this._listener = listener;
   return this;
 };
 EventListener.prototype = {
 /*void*/ handleEvent : function( /*Event*/ evt) {
     var ph = evt.eventPhase, cap = this._cap;
     if (ph === Event.CAPTURING_PHASE) { //イベントフェーズが捕獲段階であることを示し
-      cap = cap ? false : true;         //このオブジェクト(EventListenr)が捕獲を指定するならば、リスナーを作動させる。指定しなければ、作動しない。
+      cap = cap ? false : true;         //このオブジェクト(EventListenr)が捕獲フェーズを指定するならば、リスナーを作動させる。指定しなければ、作動しない。
     }
     if (!cap && evt.type === this._type) {
       this._listener(evt);
@@ -315,11 +323,17 @@
   evt.target = n;
   evt.initMutationEvent("DOMNodeInserted", true, false, this, null, null, null, null);
   n.dispatchEvent(evt);
-  var descendantElements = this.getElementsByTagNameNS("*", "*");
+  /*以下のDOMNodeInsertedIntoDocumentイベントは、間接的、あるいは直接ノードが
+   *挿入されたときに発火する。間接的な挿入とは、サブツリーを作っておいて、それをいっぺんに挿入する場合など。
+   *このイベントは浮上しないことに注意を要する
+   */
+  evt.initMutationEvent("DOMNodeInsertedIntoDocument", false, false, null, null, null, null, null);
+  n.dispatchEvent(evt);
+  var descendantElements = this.getElementsByTagNameNS("*", "*"); //全子孫要素を取得
   for (var i=0,dli=descendantElements.length;i<dli;++i) {
     var di = descendantElements[i];
     evt.target = di;
-    evt.initMutationEvent("DOMNodeInsertedIntoDocument", true, false, null, null, null, null, null);
+    evt.initMutationEvent("DOMNodeInsertedIntoDocument", false, false, null, null, null, null, null);
     di.dispatchEvent(evt);
     di = null;
   }




Sie-announce メーリングリストの案内
Back to archive index