OSDN Git Service

Version 0.6.25, bugfix.
authoritozyun <itozyun@user.sourceforge.jp>
Sun, 2 Mar 2014 13:44:58 +0000 (22:44 +0900)
committeritozyun <itozyun@user.sourceforge.jp>
Sun, 2 Mar 2014 13:44:58 +0000 (22:44 +0900)
0.6.x/js/core/06_XEventDispatcher.js
0.6.x/js/dom/11_XDomNode.js
0.6.x/js/dom/12_XDomEvent.js
0.6.x/js/dom/14_XDomAttr.js
0.6.x/js/dom/18_XDomQuery.js

index 5c4aac4..29ff847 100644 (file)
@@ -42,30 +42,35 @@ X.EventDispatcher =
                        },\r
                        unlisten : function( type, arg1, arg2, arg3 ){\r
                                var list = this._listeners,\r
-                                       unlistens, i, f;\r
+                                       _list, reservess, unlistens, i, f;\r
                                if( !list ) return this;\r
                                if( type === undefined ){\r
                                        // 全て削除\r
                                        for( type in list ){\r
-                                               this.unlisten( type ); // override されていることがあるので、必ず unlisten を使用\r
+                                               _list = list[ type ];\r
+                                               if( !( i = _list.length ) ) continue;\r
+                                               for( ; i; ){\r
+                                                       this.unlisten( type, _list[ --i ] ); // override されていることがあるので、必ず unlisten を使用\r
+                                               };\r
+                                               // this.unlisten( type ); これは無茶!\r
                                        };\r
                                        return this;\r
                                };\r
                                if( arg1 === undefined ){\r
                                        // 同一タイプを全て削除\r
-                                       if( !( list = list[ type ] ) ) return this;\r
-                                       for( i = list.length; i; ){\r
-                                               this.unisten( type, list[ --i ] ); // override されていることがあるので、必ず unlisten を使用\r
+                                       if( !( list = list[ type ] ) || !( i = list.length ) ) return this;\r
+                                       for( ; i; ){\r
+                                               this.unlisten( type, list[ --i ] ); // override されていることがあるので、必ず unlisten を使用\r
                                        };\r
                                        return this;\r
                                };\r
                                \r
-                               if( this._reserves ){\r
-                                       for( i = this._reserves.length; i; ){\r
-                                               f = this._reserves[ --i ];\r
+                               if( reserves = this._reserves ){\r
+                                       for( i = reserves.length; i; ){\r
+                                               f = reserves[ --i ];\r
                                                if( f[ 0 ] === type && f[ 1 ] === arg1 && f[ 2 ] === arg2 && f[ 3 ] === arg3 ){\r
-                                                       this._reserves.splice( i, 1 );\r
-                                                       if( !this._reserves.legth ) delete this._reserves;\r
+                                                       reserves.splice( i, 1 );\r
+                                                       if( !reserves.legth ) delete this._reserves;\r
                                                        return this;\r
                                                };\r
                                        };\r
index 63d178c..86f6e07 100644 (file)
@@ -336,7 +336,7 @@ Node.prototype.append = function( v ){
                        break;\r
                case Node.IS_HTML_STRING :\r
                case Node.IS_STRING :\r
-                       return this.append( X.Dom.parse( v, true ) );\r
+                       return this.append.apply( this, X.Dom.parse( v, true ) );\r
                case Node.IS_XNODE :\r
                        if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this;\r
                        // 親の xnodes から v を消す\r
@@ -430,9 +430,19 @@ Node.prototype.appendAt = function( start, v ){
 };\r
 \r
 Node.prototype.appendTo = function( parent, opt_index ){\r
-       if( parent.constructor === Node ){\r
-               opt_index === undefined ? parent.append( this ) : parent.appendAt( opt_index, this );\r
+       switch( Node._getType( parent ) ){\r
+               case Node.IS_RAW_HTML :\r
+                       parent = new Node( parent );\r
+                       break;\r
+               case Node.IS_HTML_STRING :\r
+                       parent = X.Dom.parse( parent, true );\r
+                       parent = parent[ 0 ] || parent;\r
+               case Node.IS_XNODE :\r
+                       break;\r
+               default :\r
+                       return this;\r
        };\r
+       opt_index === undefined ? parent.append( this ) : parent.appendAt( opt_index, this );\r
        return this;\r
 };\r
 \r
@@ -502,7 +512,7 @@ Node.prototype.remove = function(){
        parent._xnodes.splice( parent._xnodes.indexOf( this ), 1 );\r
        if( this._root ){\r
                Node._reserveRemoval[ Node._reserveRemoval.length ] = this;\r
-               parent._reserveUpdate();\r
+               this._reserveUpdate();\r
        };\r
        delete this.parent;\r
        delete this._root;\r
@@ -531,10 +541,10 @@ Node.prototype.destroy = function( isChild ){
        elm = this._rawNode || this._ie4getRawNode && this._ie4getRawNode();\r
        \r
        if( xnodes && ( i = xnodes.length ) ){\r
-               for( ; i; ){\r
-                       xnodes[ --i ].destroy( true );\r
-               };\r
-               xnodes.length = 0;\r
+               //for( ; i; ){\r
+               //      xnodes[ --i ].destroy( true );\r
+               //};\r
+               //xnodes.length = 0;\r
        };\r
        elm && this.unlisten(); // イベントの退避\r
 \r
@@ -542,7 +552,7 @@ Node.prototype.destroy = function( isChild ){
        delete this._state;\r
        \r
        if( this._root ){\r
-               this.remove();\r
+               this.remove( isChild );\r
        } else {\r
                this.parent && this.parent._xnodes.splice( this.parent._xnodes.indexOf( this ), 1 );\r
                elm && !isChild && this._actualRemove();\r
@@ -691,7 +701,7 @@ Node.prototype.hasClass = function( v ){
  *  html, text\r
  */\r
 Node.prototype.html = function( html, opt_outer ){\r
-       var xnodes, n, i, l;\r
+       var _ = '', xnodes, n, i, l;\r
        // setter\r
        if( html ){\r
                if( this._xnodeType === 3 ){\r
@@ -714,10 +724,10 @@ Node.prototype.html = function( html, opt_outer ){
        };\r
        html = !opt_outer ? [] : [\r
                '<', this._tag,\r
-               this._id ? ' id=' + this._id : '',\r
-               this._className ? ' class="' + this._className + '"' : '',\r
-               this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),\r
-               this._cssText ? ' style="' + this._cssText + '"' : '',\r
+               this._id ? ' id=' + this._id : _,\r
+               this._className ? ' class="' + this._className + '"' : _,\r
+               this._attrText === _ ? _ : this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),\r
+               this._cssText ? ' style="' + this._cssText + '"' : _,\r
        '>' ];\r
        \r
        n = html.length;\r
@@ -729,7 +739,7 @@ Node.prototype.html = function( html, opt_outer ){
        };\r
        !opt_outer || X.Dom.DTD.EMPTY[ this._tag.toLowerCase() ] || ( html[ n ] = '<\/' + this._tag + '>' );\r
 \r
-       return html.join( '' );\r
+       return html.join( _ );\r
 };\r
 \r
 Node.prototype.text = function( text ){\r
@@ -905,7 +915,11 @@ Node.prototype._updateRawNode =
                                return;\r
                        };\r
                        // id\r
-                       if( this._dirty & X.Dom.Dirty.ID ) elm.id = this._id;\r
+                       if( this._dirty & X.Dom.Dirty.ID ){\r
+                               //this._id ?\r
+                                       ( elm.id = this._id )// :\r
+                                       //elm.removeAttribute( 'id' );\r
+                       };\r
                        // className\r
                        if( this._dirty & X.Dom.Dirty.CLASSNAME ) elm.className = this._className;\r
                        // style\r
@@ -913,7 +927,7 @@ Node.prototype._updateRawNode =
                                if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
                                        elm.style.cssText = this._cssText;\r
                                } else {\r
-                                       elm.style.cssText = '';\r
+                                       elm.style.cssText = ''; // IE5.5以下 Safari3.2 で必要\r
                                        elm.removeAttribute( 'style' );\r
                                        delete this._cssText;\r
                                };\r
@@ -1162,7 +1176,7 @@ Node.prototype._afterActualCreate =
                return this._restoreEvent();// イベントの復帰\r
        }) :\r
        (function(){});\r
-       \r
+\r
 Node.prototype._actualRemove =\r
        document.getElementById ?\r
                ( function( isChild ){\r
@@ -1175,7 +1189,7 @@ Node.prototype._actualRemove =
                                        child._xnodeType === 1 && child._actualRemove( true );\r
                                };\r
                        };\r
-                       //delete this._root;\r
+\r
                        if( !elm ) return;\r
                        this._xnodeType === 1 && this._migrateEvent();// イベントの退避\r
                        // elm.parentNode.tagName check tagName is for ie7\r
@@ -1191,13 +1205,16 @@ Node.prototype._actualRemove =
                                        xnodes[ i ]._actualRemove( true );\r
                                };\r
                        };\r
-                       //delete this._root;\r
+\r
                        if( !elm ) return;\r
                        this._xnodeType === 1 && this._migrateEvent();// イベントの退避\r
                        \r
-                       elm.removeAttribute( 'id', '' ); // ?\r
+                       elm.removeAttribute( 'id' ); // ?\r
                        document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // ?\r
-                       if( !isChild ) elm.outerHTML = '';\r
+                       if( !isChild ){\r
+                               //alert( elm.tagName + this._uid + '\n' + document.all[ this._id || ( 'ie4uid' + this._uid ) ] + '\n' + elm.innerHTML );\r
+                               elm.outerHTML = '';\r
+                       };\r
                        delete this._rawNode;\r
                }) :\r
                (function(){});\r
@@ -1206,3 +1223,5 @@ Node.prototype._actualRemove =
 //})( window, document );\r
 \r
 \r
+\r
+\r
index 85a39e3..f3851a3 100644 (file)
@@ -141,23 +141,26 @@ X.Dom.Event.XDOM_READY          = 2;
 X.Dom.Event.VIEW_ACTIVATE       = 3;
 X.Dom.Event.VIEW_DEACTIVATE     = 4;
 X.Dom.Event.VIEW_RESIZED        = 5;
+X.Dom.Event.BASE_FONT_RESIZED   = 6;
 // on_screen_keyboard_show
 // on_screen_keyboard_hide
-// before_commit_update
-X.Dom.Event.COMMIT_UPDATE       = 6;
+X.Dom.Event.BEFORE_UPDATE       = 7;
+X.Dom.Event.COMMIT_UPDATE       = 8;
 // hash_change
-// before_unload
-// X.Dom.Event.LOAD_BEFORE_STOP    = 7;
-X.Dom.Event.LOAD_ASSET_COMPLETE = 7;
-X.Dom.Event.LOAD_ASSET_ERROR    = 8;
-
-X.Dom.Event.ANIME_BEFORE_START  = 9;
-X.Dom.Event.ANIME_START         = 10;
-X.Dom.Event.ANIME               = 11;
-X.Dom.Event.ANIME_END           = 12;
-X.Dom.Event.ANIME_BEFORE_STOP   = 13; // xnode.stop() のみ、指定時間による停止では呼ばれない
-X.Dom.Event.ANIME_STOP          = 14;
-X.Dom.Event._LAST_EVENT         = 14; // ここに書いてあるイベントの最後の値 X.Dom.Event.ANIME_STOP と同じ値
+X.Dom.Event.BEFORE_UNLOAD       = 9;
+X.Dom.Event.UNLOAD              = 10;
+X.Dom.Event.LOAD_BEFORE_STOP    = 11;
+X.Dom.Event.LOAD_ASSET_STOP     = 12;
+X.Dom.Event.LOAD_ASSET_COMPLETE = 13;
+X.Dom.Event.LOAD_ASSET_ERROR    = 14;
+
+X.Dom.Event.ANIME_BEFORE_START  = 15;
+X.Dom.Event.ANIME_START         = 16;
+X.Dom.Event.ANIME               = 17;
+X.Dom.Event.ANIME_END           = 18;
+X.Dom.Event.ANIME_BEFORE_STOP   = 19; // xnode.stop() のみ、指定時間による停止では呼ばれない
+X.Dom.Event.ANIME_STOP          = 20;
+X.Dom.Event._LAST_EVENT         = 20; // ここに書いてあるイベントの最後の値 X.Dom.Event.ANIME_STOP と同じ値
 
 
 X.Dom.Node.prototype.listen = function( type, arg1, arg2, arg3 /* [ listener || ( context + function ) || function ][ arguments ] */ ){
@@ -204,13 +207,13 @@ X.Dom.Node.prototype.unlisten = function( type /* , arg1, arg2, arg3 */ ){
 X.Dom.Node.prototype._removeEvent =
        document.removeEventListener ?
                (function( type ){
-                       var elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;
+                       var elm = this._rawNode;
                        if( !elm ) return;
                        elm.removeEventListener( type, this, false );
                }) :
        document.detachEvent ?
                (function( type ){
-                       var elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;
+                       var elm = this._rawNode;
                        if( !elm ) return;
                        elm.detachEvent( 'on' + type, this._handleEvent );
                        if( !this._listeners ){
@@ -219,7 +222,7 @@ X.Dom.Node.prototype._removeEvent =
                        };
                }) :
                (function( type ){
-                       var elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;
+                       var elm = this._rawNode || this._ie4getRawNode();
                        if( !elm ) return;
                        elm[ 'on' + type ] = X.emptyFunction;
                        elm[ 'on' + type ] = '';
@@ -386,10 +389,6 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
                };
        })( body );
        
-       
-       
-       
-       
        createTree =
                body.childNodes ?
                        (function( xnode, childNodes, skipCleanup ){
@@ -402,7 +401,8 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
                                for( ; i < l; ++i ){
                                        child = childNodes[ i ];
                                        tag   = child.tagName;
-                                       if( ( child.nodeType !== 1 && child.nodeType !== 3 ) || tag === '!' || tag && tag.charAt( 0 ) === '/' ){
+                                       if( ( child.nodeType !== 1 && child.nodeType !== 3 ) || tag === '!' ||
+                                               ( tag && tag.charAt( 0 ) === '/' ) ){
                                                child.parentNode.removeChild( child );
                                                continue;
                                        };
@@ -428,6 +428,7 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
                                                        } else {
                                                                _xnode._rawNode = child;
                                                                //if( ( doc = child.ownerDocument || child.document ) && ( doc.createElement( 'p' ).tagName === doc.createElement( 'P' ).tagName ) ){
+                                                                       if( tag.charAt( 0 ) === '/' ) tag = tag.slice( 1 );
                                                                        _xnode._tag     = tag; // .toUpperCase()
                                                                //};
                                                                _xnode._root    = xnode._root;
index fb53d4b..0ba8b51 100644 (file)
@@ -244,7 +244,7 @@ X.Dom.Node.prototype.attr = function( nameOrObj /* v */ ){
 X.Dom.Node.prototype._setAttr = function( attrs, newAttrs, name, v ){\r
        if( name === 'UID' ) return;\r
        if( name === 'id' ){\r
-               v = v !== 'ie4uid' + this._uid ? v : undefined;\r
+               v = ( v !== 'ie4uid' + this._uid ) ? v : undefined;\r
                if( v !== this._id ){\r
                        this._id = v;\r
                        this._dirty |= X.Dom.Dirty.ID;\r
index 3d9cdb2..8a6f572 100644 (file)
@@ -206,17 +206,18 @@ X.Dom.Query._parse = function( query, last ){
 \r
        // セレクター\r
        X.Dom.find = X._shortcut = Node.prototype.find = function( queryString ){\r
-               var scope     = this.cnstructor === X.Dom.NodeList && this.length ? this : [ this.cnstructor === Node ? this : Node.root ],\r
+               var HTML      = Node._html,\r
+                       scope     = this.cnstructor === X.Dom.NodeList && this.length ? this : [ this.cnstructor === Node ? this : Node.root ],\r
                        parents   = scope, // 探索元の親要素\r
                        noLower   = 'title id name class for href src',\r
                        ARY_PUSH  = Array.prototype.push,\r
                        ret       = [], // 結果要素\r
                        root      = X.Dom.Node.getRoot( scope[ 0 ] ),\r
                        isXML     = !!X.Dom.Node.isXmlDocument( root ),\r
-                       isMulti   = 1 < scope.length,\r
-                       isStart   = true,// 要素をマージする必要がある\r
+                       isMulti   = 1 < scope.length,// 要素をマージする必要がある\r
+                       isStart   = true,\r
                        _         = ' ',\r
-                       isAll, isNot,\r
+                       isAll, isNot, hasRoot,\r
                        l, i, n, parsed,\r
                        xnodes, // 一時保存用\r
                        merge, // 要素がコメントノードで汚染されている場合使う\r
@@ -254,7 +255,7 @@ X.Dom.Query._parse = function( query, last ){
                                        parents = scope;\r
                                        xnodes && xnodes.length && ARY_PUSH.apply( ret, xnodes );\r
                                        parsed  = null;\r
-                                       xnodes  = null;\r
+                                       xnodes  = [];\r
                                        isStart = true;\r
                                        continue;\r
                                };\r
@@ -364,7 +365,8 @@ X.Dom.Query._parse = function( query, last ){
                                        xnodes = scope; break;\r
                                // root\r
                                case 8 :\r
-                                       xnodes = [ Node._html ]; break;\r
+                                       hasRoot = true;\r
+                                       xnodes = [ HTML ]; break;\r
                                // link\r
                                case 9 :\r
                                        if( links = document.links ){\r
@@ -474,27 +476,53 @@ X.Dom.Query._parse = function( query, last ){
                };\r
                console.log( 'multi:' + ( xnodes && xnodes.length ) );\r
                \r
+               // tree 順に並び替え、同一要素の排除\r
                if( isMulti ){\r
                        xnodes && xnodes.length && ARY_PUSH.apply( ret, xnodes );\r
-                       //for( i = 0, l = xnodes.length, n = ret.length - 1; i < l; ++i ){\r
-                       //      ret[ ++n ] = xnodes[ i ];\r
-                       //};\r
+                       l = ret.length;\r
+                       if( l < 2 ) return ret[ 0 ] || Node.none;\r
+                       \r
                        xnodes = [];\r
                        merge  = {};\r
-                       for( i = 0, n = -1, l = ret.length; i < l; ++i ){\r
+                       for( i = 0, n = -1; i < l; ++i ){\r
                                //alert( 'multi:' + i )\r
                                xnode = ret[ i ];\r
-                               uid   = xnode._uid;\r
-                               if( !merge[ uid ] ){\r
+                               if( !merge[ uid = xnode._uid ] ){\r
                                        merge[ uid ] = true;\r
                                        xnodes[ ++n ] = xnode;\r
                                };\r
                        };\r
+                       X.Dom.Query._sortElementOrder( ret = [], xnodes, hasRoot ? [ HTML ] : HTML._xnodes );\r
+                       xnodes = ret;\r
                };\r
 \r
                return xnodes.length === 1 ? xnodes[ 0 ] : new X.Dom.NodeList( xnodes );\r
        };\r
        \r
+       X.Dom.Query._sortElementOrder = function( newList, list, xnodes ){\r
+               var l = xnodes.length,\r
+                       i = 0,\r
+                       j, child, _xnodes;\r
+               for( ; i < l; ++i ){\r
+                       child = xnodes[ i ];\r
+                       if( child._xnodeType !== 1 ) continue;\r
+                       //console.log( child._tag );\r
+                       if( ( j = list.indexOf( child ) ) !== -1 ){\r
+                               newList[ newList.length ] = child;\r
+                               list.splice( j, 1 );\r
+                               if( list.length === 1 ){\r
+                                       newList[ newList.length ] = list[ 0 ];\r
+                                       list.length = 0;\r
+                                       return true;\r
+                               };\r
+                               if( list.length === 0 ) return true;\r
+                       };\r
+                       if( ( _xnodes = child._xnodes ) && X.Dom.Query._sortElementOrder( newList, list, _xnodes ) ){\r
+                               return true;\r
+                       };\r
+               };\r
+       };\r
+       \r
        X.Dom.Query._fetchElements = function( list, parent, tag ){\r
                var xnodes = parent._xnodes,\r
                        l      = xnodes.length,\r