OSDN Git Service

Version 0.6.87, fix SuperConstructor @ X.Class & force convert to PointerEvent @...
[pettanr/clientJs.git] / 0.6.x / js / 01_dom / 11_XDomNode.js
index e40d14f..ff29163 100644 (file)
@@ -46,7 +46,7 @@ X.Dom.Node = X.EventDispatcher.inherits(
                \r
                _isNew     : false,\r
                \r
-               _rawNode   : null,\r
+               _rawObject : null,\r
                _rect      : null, // \r
                \r
                _root      : null, // xnode が文書ツリーに属しているか?はこれを見る\r
@@ -70,6 +70,9 @@ X.Dom.Node = X.EventDispatcher.inherits(
                \r
                _anime     : null,\r
                \r
+       /*\r
+        * TODO Node の継承ができない!\r
+        */\r
                Constructor : function( v ){\r
                        var css, xnodes, xnode, parent, uid = Node._chashe.length;\r
                        \r
@@ -79,7 +82,7 @@ X.Dom.Node = X.EventDispatcher.inherits(
                                this._xnodeType = 1;\r
                                this._state     = X.Dom.State.DISPLAY_INLINE; // todo\r
                                arguments[ 1 ] && this.attr( arguments[ 1 ] );\r
-                               css = arguments[ 2 ] || arguments[ 1 ];\r
+                               css = arguments[ 2 ];\r
                                css && this[ X.Type.isString( css ) ? 'cssText' : 'css' ]( css );\r
                        } else\r
                        if( Node._newByText ){\r
@@ -102,7 +105,7 @@ X.Dom.Node = X.EventDispatcher.inherits(
                                                // v.parentNode || v.parentElement : dom1 || dom0\r
                                                this.parent     = ( parent = v.parentNode || v.parentElement ) && parent.tagName /* ie7- */ && Node._getXNode( parent );\r
                                                this._root      = this.parent ? this.parent._root : null;\r
-                                               this._rawNode   = v;\r
+                                               this._rawObject = v;\r
                                                this._xnodeType = 1;\r
                                                this._state     = X.Dom.State.DISPLAY_BLOCK; // todo\r
                                                this._tag       = v.tagName.toUpperCase();\r
@@ -123,7 +126,7 @@ X.Dom.Node = X.EventDispatcher.inherits(
                                                if( xnode = Node._getXNode( v ) ) return xnode;\r
                                                this.parent     = Node._getXNode( v.parentNode );\r
                                                this._root      = this.parent ? this.parent._root : null;\r
-                                               this._rawNode   = v;\r
+                                               this._rawObject = v;\r
                                                this._xnodeType = 3;\r
                                                this._state     = X.Dom.State.DISPLAY_INLINE;\r
                                                this._text      = v.data;\r
@@ -136,18 +139,19 @@ X.Dom.Node = X.EventDispatcher.inherits(
                                                return Node.none;\r
                                        case Node.IS_IMAGE :\r
                                                if( xnode = Node._getXNode( v ) ) return xnode;\r
-                                               this._rawNode   = v;\r
+                                               this._rawObject = v;\r
                                                this._xnodeType = 4;\r
                                                v.UID           = uid;\r
                                                this._state     = X.Dom.State.EXIST;\r
                                                break;\r
+                                       /*\r
                                        case Node.IS_WINDOW :\r
                                        case Node.IS_DOCUMENT :\r
                                                if( xnode = Node._getXNode( v ) ) return xnode;\r
-                                               this._rawNode   = v;\r
+                                               this._rawObject = v;\r
                                                this._xnodeType = 2;\r
                                                this._state     = X.Dom.State.DISPLAY_BLOCK;\r
-                                               break;\r
+                                               break; */\r
                                        default :\r
                                                if( Node.none ) return Node.none;\r
                                                return;\r
@@ -177,16 +181,11 @@ Node._getType = function( v ){
        if( !v ) return 0;\r
        if( v === window ) return Node.IS_WINDOW;\r
        if( v === document ) return Node.IS_DOCUMENT;\r
-       if( v.constructor === window.Image ) return Node.IS_IMAGE;\r
-       if( X.UA.WebKit < 525.13 ){ // Safari3-\r
-               if( v.src !== undefined && v.onload !== undefined && X.Type.isNumber( v.height ) && X.Type.isNumber( v.width ) && X.Type.isBoolean( v.complete ) ){\r
-                       return Node.IS_IMAGE;\r
-               };\r
-       };      \r
        if( v.constructor === Node ) return Node.IS_XNODE;\r
        if( v.constructor === X.Dom.NodeList ) return Node.IS_XNODE_LIST;\r
        if( X.Type.isHTMLElement( v ) ) return Node.IS_RAW_HTML;\r
        if( v.nodeType === 3 ) return Node.IS_RAW_TEXT;\r
+       if( X.Type.isImage( v ) ) return Node.IS_IMAGE;\r
        if( typeof v === 'string' ){\r
                return '<' === v.charAt( 0 ) && v.charAt( v.length - 1 ) === '>' ? Node.IS_HTML_STRING : Node.IS_STRING;\r
        };\r
@@ -214,7 +213,7 @@ Node._getXNode = function( v ){
                case Node.IS_RAW_TEXT :\r
                        if( v.UID ) return Node._chashe[ v.UID ];\r
                        for( chashe = Node._chashe, i = chashe.length; i; ){\r
-                               if( ( xnode = Node._chashe[ --i ] ) && ( xnode._rawNode === v ) ) return xnode;\r
+                               if( ( xnode = Node._chashe[ --i ] ) && ( xnode._rawObject === v ) ) return xnode;\r
                        };\r
        };\r
 };\r
@@ -242,7 +241,7 @@ Node.createText = function( text ){
 \r
 Node.getRoot = function( xnode ){\r
        return Node._document;\r
-       //return xNode._body._rawNode.documentElement ? node : node.ownerDocument || node.document;\r
+       //return xNode._body._rawObject.documentElement ? node : node.ownerDocument || node.document;\r
 };\r
        // XMLかどうかを判別する\r
 Node.isXmlDocument =\r
@@ -250,25 +249,25 @@ Node.isXmlDocument =
                X.emptyFunction :\r
                (function( root ){\r
                        if( X.Type.isBoolean( root.isXML ) ) return root.isXML;\r
-                       return root.isXML = root._rawNode.createElement( 'p' ).tagName !== root._rawNode.createElement( 'P' ).tagName;\r
+                       return root.isXML = root._rawObject.createElement( 'p' ).tagName !== root._rawObject.createElement( 'P' ).tagName;\r
                });\r
 \r
 Node._chashe     = [];\r
 Node.none        = Node._chashe[ 0 ] = new Node();\r
-Node._window     = new Node( window ); // Node._chashe[ 1 ]\r
-Node._document   = new Node( document ); // Node._chashe[ 2 ]\r
-Node._html       = null; // Node._chashe[ 3 ]\r
-Node._body       = null;// = Node._chashe[ 4 ] body\r
-Node._systemNode = null;// = Node._chashe[ ? ]\r
+Node._window     = new X.EventDispatcher( window );\r
+Node._document   = new X.EventDispatcher( document );\r
+Node._html       = null; // = Node._chashe[ 1 ] <html>\r
+Node._body       = null; // = Node._chashe[ 2 ] <body>\r
+Node._systemNode = null; // = Node._chashe[ ? ]\r
 \r
 Node._reserveRemoval = [];\r
 \r
 if( X.Dom.DOM_IE4 ){\r
        Node.prototype._ie4getRawNode = function(){\r
-               var elm = this._rawNode;\r
+               var elm = this._rawObject;\r
                return elm ||\r
-                       ( ( elm = document.all[ 'ie4uid' + this._uid ] ) && ( this._rawNode = elm ) ) ||\r
-                       ( this._id && ( elm = document.all[ this._id ] ) ) && ( this._rawNode = elm );\r
+                       ( ( elm = document.all[ 'ie4uid' + this._uid ] ) && ( this._rawObject = elm ) ) ||\r
+                       ( this._id && ( elm = document.all[ this._id ] ) ) && ( this._rawObject = elm );\r
        };\r
 };\r
 \r
@@ -289,7 +288,9 @@ Node.prototype.create = function( tag, opt_attrs, opt_css ){
        return xnode;\r
 };\r
 Node.prototype.createAt = function( index, tag, opt_attrs, opt_css ){\r
-       // TODO\r
+       var xnode = Node.create( tag, opt_attrs, opt_css );\r
+       this.appendAt( index, xnode );\r
+       return xnode;\r
 };\r
 \r
 /* --------------------------------------\r
@@ -309,7 +310,9 @@ Node.prototype.createText = function( text ){
        return xnode;\r
 };\r
 Node.prototype.createTextAt = function( index, text ){\r
-       // TODO\r
+       var xtext = Node.createText( text );\r
+       this.appendAt( index, xtext );\r
+       return xtext;\r
 };\r
 \r
 /* --------------------------------------\r
@@ -589,7 +592,7 @@ Node.prototype.destroy = function( isChild ){
        \r
        if( !this._state ) return;\r
        \r
-       elm = this._rawNode || this._ie4getRawNode && this._ie4getRawNode();\r
+       elm = this._rawObject || this._ie4getRawNode && this._ie4getRawNode();\r
        \r
        if( xnodes && ( i = xnodes.length ) ){\r
                //for( ; i; ){\r
@@ -619,14 +622,15 @@ Node.prototype.contains = function( v ){
        var elm, type, xnodes, i;\r
        if( !v || this._xnodeType !== 1 ) return false;\r
        // contains ie4+\r
-       if( ( elm = this._rawNode || this._ie4getRawNode && this._ie4getRawNode() ) && document.contains && ( type = Node._getType( v ) ) && ( type === Node.IS_RAW_HTML || type === Node.IS_RAW_TEXT ) ){\r
+       if( ( elm = this._rawObject || this._ie4getRawNode && this._ie4getRawNode() ) && document.contains && ( type = Node._getType( v ) ) && ( type === Node.IS_RAW_HTML || type === Node.IS_RAW_TEXT ) ){\r
                return elm.contains( v );       \r
        };\r
        //if( document.compareDocumentPosition ){\r
        //      \r
        //};\r
        xnodes = this._xnodes;\r
-       if( xnodes.indexOf( v ) !== -1 ) return true;\r
+       if( !xnodes || !xnodes.length ) return false;\r
+       if( xnodes.indexOf( v ) !== -1 ) return true; // fast\r
        if( elm === v.parentNode ) return false;\r
        for( i = xnodes.length; i; ){\r
                if( xnodes[ --i ].contains( v ) ) return true;\r
@@ -830,7 +834,7 @@ Node.prototype.text = function( text ){
  * HTML要素に対して name の関数を実行しその戻り値を返す。関数に渡す引数も任意に設定できる。\r
  */\r
 Node.prototype.call = function( name /*, opt_args... */ ){\r
-       var raw  = this._rawNode || this._ie4getRawNode && this._ie4getRawNode(),\r
+       var raw  = this._rawObject || this._ie4getRawNode && this._ie4getRawNode(),\r
                l    = arguments.length - 1,\r
                func, args, params, i;\r
        if( !raw ) return;\r
@@ -885,7 +889,7 @@ Node.prototype.each = function( func /*, opt_args */ ){
  *  Async commit update\r
  * \r
  * state:\r
- *  0 : no_rawnode\r
+ *  0 : no_rawObject\r
  *  1 : no_parent\r
  *  2 : no_root\r
  *  3 : dirty\r
@@ -908,7 +912,7 @@ Node.prototype._startUpdate = function(){
                return;\r
        };\r
        if( this._updateTimerID ){\r
-               //X.Timer.cancelFrame( this._updateTimerID ); // fire 中の cancel が動かない、、、\r
+               X.Timer.cancelFrame( this._updateTimerID );\r
                this._updateTimerID = 0;\r
        } else {\r
                return;\r
@@ -918,8 +922,8 @@ Node.prototype._startUpdate = function(){
 \r
        removal = Node._reserveRemoval;\r
        \r
-       tmp = this._rawNode.style.visibility;\r
-       //this._rawNode.style.visibility = 'hidden';\r
+       tmp = this._rawObject.style.visibility;\r
+       //this._rawObject.style.visibility = 'hidden';\r
 \r
        //console.log( '_actualRemove().' );\r
 \r
@@ -939,17 +943,19 @@ Node.prototype._startUpdate = function(){
        //console.log( 'end of _startUpdate().' );\r
        \r
        X.Dom._listeners && X.Dom._listeners[ X.Dom.Event.AFTER_UPDATE ] && X.Dom.asyncDispatch( 0, { type : X.Dom.Event.AFTER_UPDATE } );\r
-       //this._rawNode.style.visibility = tmp;\r
+       //this._rawObject.style.visibility = tmp;\r
 };\r
 \r
 Node.prototype._commitUpdate =\r
        X.Dom.DOM_W3C ?\r
                ( function( parentElement, nextElement ){\r
-                       var elm = this._rawNode,\r
+                       var elm = this._rawObject,\r
                                xnodes, l, i, frg, next, k, v;\r
 \r
                        if( this._state & X.Dom.State.IE5_DISPLAY_NONE_FIX ){\r
                                //alert( this._tag + ' ' + !!elm );\r
+                               // filter の効いている要素だけdisplay:none が無視される模様。filter を切ればよい?\r
+                               // 親が、display:none の場合は?\r
                                elm && elm.parentNode && this._actualRemove();\r
                                return nextElement;\r
                        };\r
@@ -960,7 +966,7 @@ Node.prototype._commitUpdate =
                                        parentElement.appendChild( this._actualCreate() );\r
                                this._afterActualCreate();\r
 \r
-                               return elm || this._rawNode;\r
+                               return elm || this._rawObject;\r
                        } else\r
                        if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ) {\r
                                \r
@@ -988,7 +994,7 @@ Node.prototype._commitUpdate =
                }) :\r
        X.Dom.DOM_IE4 ? \r
                ( function( parentElement, prevElement ){\r
-                       var elm    = this._rawNode || this._ie4getRawNode(),\r
+                       var elm    = this._rawObject || this._ie4getRawNode(),\r
                                xnodes, l, i, html, text, prev;\r
 \r
                        if( !elm ){\r
@@ -996,7 +1002,7 @@ Node.prototype._commitUpdate =
                                        prevElement.insertAdjacentHTML( 'AfterEnd', this._actualCreate() ) :\r
                                        parentElement.insertAdjacentHTML( 'AfterBegin', this._actualCreate() );\r
                                this._afterActualCreate();\r
-                               return this._rawNode || this._ie4getRawNode();\r
+                               return this._rawObject || this._ie4getRawNode();\r
                        };\r
                        \r
                        xnodes = this._xnodes;\r
@@ -1050,7 +1056,7 @@ Node.prototype._updateRawNode =
                        };\r
                        // className\r
                        if( this._dirty & X.Dom.Dirty.CLASSNAME ){\r
-                               this._className ? ( elm.className = this._className ) : ( elm.className && elm.removeAttribute( X.UA.IE ? 'className' : 'class' ) );                                    \r
+                               this._className ? ( elm.className = this._className ) : ( elm.className && elm.removeAttribute( X.UA.IE5678 ? 'className' : 'class' ) ); // className は ie7-?                         \r
 \r
                                // ie5 only\r
                                if( X.Dom.State.IE5_DISPLAY_NONE_FIX && elm.currentStyle.display === 'none' ){\r
@@ -1060,6 +1066,7 @@ Node.prototype._updateRawNode =
                                };\r
                        };\r
                        // style\r
+                       // TODO display:none の場合、更新をスキップ\r
                        if( this._dirty & X.Dom.Dirty.CSS ){\r
                                if( this._cssText !== null || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
                                        X.UA.Opera78 || X.UA.NN6 ?\r
@@ -1077,6 +1084,7 @@ Node.prototype._updateRawNode =
                        };\r
                        \r
                        // attr\r
+                       // TODO display:none の場合、更新をスキップ\r
                        if( this._dirty & X.Dom.Dirty.ATTR && ( attrs = this._newAttrs || this._attrs ) ){\r
                                rename = X.Dom.Attr.renameForDOM;\r
                                for( k in attrs ){\r
@@ -1088,7 +1096,7 @@ Node.prototype._updateRawNode =
                                                        continue;\r
                                                };\r
                                        };\r
-                                       k = \r
+                                       // TODO IE では input, なぜか buttonも、type の変更が出来ない、k === 'type' && alert( this._dirty + ' ' + elm.outerHTML );\r
                                        ( v = attrs[ k ] ) === undefined ?\r
                                                elm.removeAttribute( rename[ k ] || k ) :\r
                                                ( elm[ rename[ k ] || k ] = X.Dom.Attr.noValue[ k ] ? k : v );                          \r
@@ -1133,7 +1141,7 @@ Node.prototype._updateRawNode =
                        };\r
                        \r
                        if( this._dirty & X.Dom.Dirty.IE_FILTER ){\r
-                               this._rawNode.style.filter = X.Dom.Style.SPECIAL_FIX( this._css );\r
+                               this._rawObject.style.filter = X.Dom.Style.SPECIAL_FIX( this._css );\r
                        };\r
                        \r
                        // attr\r
@@ -1170,13 +1178,13 @@ Node.prototype._updateRawNode =
  */\r
 Node.prototype._actualCreate =\r
        X.Dom.DOM_W3C ? (function( isChild ){\r
-               var elm = this._rawNode,\r
+               var elm = this._rawObject,\r
                        xnodes, frg, i, l;\r
                \r
                if( this._xnodeType === 3 ){\r
                        if( elm ) return elm;\r
                        delete this._dirty;\r
-                       return this._rawNode = document.createTextNode( X.Dom.chrReferanceTo( this._text ) );\r
+                       return this._rawObject = document.createTextNode( X.Dom.chrReferanceTo( this._text ) );\r
                };\r
                \r
                if( !elm ){\r
@@ -1184,7 +1192,7 @@ Node.prototype._actualCreate =
                                delete this._cssText;\r
                        };\r
                        this._isNew = true;\r
-                       this._rawNode = elm =\r
+                       this._rawObject = elm =\r
                                X.Dom._strictElmCreation ?\r
                                        document.createElement( [\r
                                                '<', this._tag,\r
@@ -1214,9 +1222,9 @@ Node.prototype._actualCreate =
                \r
                if( this._xnodeType === 3 ){\r
                        html = [ '<FONT id=ie4uid', uid, ' UID="', uid, '">', this._text, '</FONT>' ];// fake textNode\r
-                       delete this._rawNode;\r
+                       delete this._rawObject;\r
                } else {\r
-                       if( this._rawNode && !isChild ) this._actualRemove( true );\r
+                       if( this._rawObject && !isChild ) this._actualRemove( true );\r
                        \r
                        if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
                                delete this._cssText;\r
@@ -1254,7 +1262,7 @@ Node.prototype._actualCreate =
 \r
 Node.prototype._afterActualCreate =\r
        X.Dom.DOM_W3C ? (function(){\r
-               var elm = this._rawNode, xnodes, l, attrs, k, i;\r
+               var elm = this._rawObject, xnodes, l, attrs, k, i;\r
 \r
                this._root  = this.parent._root;\r
                \r
@@ -1295,7 +1303,7 @@ Node.prototype._afterActualCreate =
                };\r
                // src の onload があるので先ではないか?\r
                // ie の str から要素を作る場合、srcだけ イベント設定後ではないか?\r
-               this._restoreEvent();// イベントの復帰\r
+               X_EventDispatcher_toggleAllEvents( this, true );// イベントの復帰\r
        }) :\r
        X.Dom.DOM_IE4 ? (function(){\r
                var xnodes, i;\r
@@ -1313,7 +1321,7 @@ Node.prototype._afterActualCreate =
                        this._ie4getRawNode().style.filter = X.Dom.Style.SPECIAL_FIX( this._css );\r
                };\r
                delete this._dirty;\r
-               this._restoreEvent();// イベントの復帰\r
+               X_EventDispatcher_toggleAllEvents( this, true );// イベントの復帰\r
        }) :\r
        (function(){});\r
 \r
@@ -1321,7 +1329,7 @@ Node.prototype._actualRemove =
        X.Dom.DOM_W3C ?\r
                ( function( isChild ){\r
                        var xnodes = this._xnodes,\r
-                               elm    = this._rawNode,\r
+                               elm    = this._rawObject,\r
                                child, i, l;\r
                        if( xnodes && ( l = xnodes.length ) ){\r
                                for( i = 0; i < l; ++i ){\r
@@ -1331,7 +1339,7 @@ Node.prototype._actualRemove =
                        };\r
 \r
                        if( !elm ) return;\r
-                       this._xnodeType === 1 && this._migrateEvent();// イベントの退避\r
+                       this._xnodeType === 1 && X_EventDispatcher_toggleAllEvents( this, false );// イベントの退避\r
                        // elm.parentNode.tagName for ie7\r
                        if( !X.UA.MacIE ){\r
                                !isChild && elm.parentNode && elm.parentNode.tagName && elm.parentNode.removeChild( elm );\r
@@ -1342,7 +1350,7 @@ Node.prototype._actualRemove =
        X.Dom.DOM_IE4 ?\r
                ( function( isChild ){\r
                        var xnodes = this._xnodes,\r
-                               elm    = this._rawNode || this._ie4getRawNode(),\r
+                               elm    = this._rawObject || this._ie4getRawNode(),\r
                                i, l, xnode;\r
                        if( xnodes && ( l = xnodes.length ) ){\r
                                for( i = 0; i < l; ++i ){\r
@@ -1351,15 +1359,15 @@ Node.prototype._actualRemove =
                        };\r
 \r
                        if( !elm ) return;\r
-                       this._xnodeType === 1 && this._migrateEvent();// イベントの退避\r
+                       this._xnodeType === 1 && X_EventDispatcher_toggleAllEvents( this, false );// イベントの退避\r
                        \r
                        if( X.Dom.Attr.HAS_VALUE[ this._tag ] && ( !this._newAttrs || !X.inObject( 'value', this._newAttrs ) ) ){\r
                                this._attrs.value = elm.value;\r
                        };\r
                        elm.removeAttribute( 'id' ); // ?\r
-                       document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // MacIE5 でエラー\r
+                       //document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // MacIE5 でエラー\r
                        if( !isChild ) elm.outerHTML = '';\r
-                       delete this._rawNode;\r
+                       delete this._rawObject;\r
                }) :\r
                (function(){});\r
 \r