OSDN Git Service

Version 0.6.26, bugfix & BASE_FONT_RESIZED event added.
authoritozyun <itozyun@user.sourceforge.jp>
Mon, 3 Mar 2014 12:18:30 +0000 (21:18 +0900)
committeritozyun <itozyun@user.sourceforge.jp>
Mon, 3 Mar 2014 12:18:30 +0000 (21:18 +0900)
0.6.x/js/dom/10_XDom.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/15_XDomStyle.js

index 2e6cbfa..21e77b9 100644 (file)
@@ -14,7 +14,7 @@
                        if( !lock++ ){\r
                                size = X.Dom.getSize();\r
                                ( w !== size[ 0 ] || h !== size[ 1 ] ) &&\r
-                                       X.Dom.dispatch( { type : X.Dom.Event.VIEW_RESIZED, w : w = size[ 0 ], h : h = size[ 1 ] } );\r
+                                       X.Dom.asyncDispatch( 0, { type : X.Dom.Event.VIEW_RESIZED, w : w = size[ 0 ], h : h = size[ 1 ] } );\r
                                X.Timer.once( 1, unlock );\r
                        };\r
                };\r
@@ -26,7 +26,7 @@
                delayResize = function(){\r
                        var size = X.Dom.getSize();\r
                        ( w !== size[ 0 ] || h !== size[ 1 ] ) &&\r
-                               X.Dom.dispatch( { type : X.Dom.Event.VIEW_RESIZED, w : w = size[ 0 ], h : h = size[ 1 ] } );\r
+                               X.Dom.asyncDispatch( 0, { type : X.Dom.Event.VIEW_RESIZED, w : w = size[ 0 ], h : h = size[ 1 ] } );\r
                        X.Timer.once( 1, unlock );\r
                };\r
        };\r
@@ -82,7 +82,7 @@
                                        var size = X.Dom.getSize();\r
                                        \r
                                        X.UA.IE && X.UA.IE < 9 ?\r
-                                               X.Timer.add( 100, resize ) :\r
+                                               X.Timer.add( 200, resize ) :\r
                                                X.Dom.Node._window.listen( 'resize', resize );  \r
                                        X.Dom.readyState = X.Dom.Event.XDOM_READY;\r
                                        X.Dom.asyncDispatch( 0, { type : X.Dom.Event.XDOM_READY, w : size[ 0 ], h : size[ 1 ] } );\r
index 86f6e07..1ad2852 100644 (file)
@@ -205,9 +205,14 @@ Node._getXNode = function( v ){
 };\r
 \r
 \r
-Node.create = function( tag, opt_attr, opt_css ){\r
-       Node._newByTag = true;\r
-       return new Node( tag, opt_attr, opt_css );\r
+Node.create = function( tag, opt_attrs, opt_css ){\r
+       switch( Node._getType( tag ) ){\r
+               case Node.IS_STRING :\r
+                       Node._newByTag = true;\r
+                       return new Node( tag, opt_attrs, opt_css );\r
+               case Node.IS_HTML_STRING :\r
+                       return X.Dom.parse( tag, true )[ 0 ];\r
+       };\r
 };\r
 Node.createText = function( text ){\r
        Node._newByText = true;\r
@@ -255,12 +260,11 @@ Node.prototype.create = function( tag, opt_attrs, opt_css ){
        if( this._xnodeType !== 1 ) return;\r
        if( !this._xnodes ) this._xnodes = [];\r
        \r
-       Node._newByTag = true;\r
-       xnode = new Node( tag, opt_attrs, opt_css );\r
-       xnode.parent = this;\r
+       xnode = Node.create( tag, opt_attrs, opt_css );\r
        \r
-       this._root && this._reserveUpdate();\r
+       xnode.parent = this;\r
        this._xnodes[ this._xnodes.length ] = xnode;\r
+       this._root && this._reserveUpdate();\r
        return xnode;\r
 };\r
 \r
@@ -836,6 +840,8 @@ Node.prototype._commitUpdate =
                                        parentElement.insertBefore( this._actualCreate(), nextElement ) :\r
                                        parentElement.appendChild( this._actualCreate() );\r
                                this._afterActualCreate();\r
+                               \r
+                               \r
                                return elm || this._rawNode;\r
                        } else\r
                        if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ) {\r
@@ -916,12 +922,20 @@ Node.prototype._updateRawNode =
                        };\r
                        // id\r
                        if( this._dirty & X.Dom.Dirty.ID ){\r
-                               //this._id ?\r
-                                       ( elm.id = this._id )// :\r
-                                       //elm.removeAttribute( 'id' );\r
+                               if( X.UA.IE && X.UA.IE < 7 ){\r
+                                       elm.id = this._id;\r
+                               } else {\r
+                                       this._id ? ( elm.id = this._id ) : elm.removeAttribute( 'id' );                                 \r
+                               };\r
                        };\r
                        // className\r
-                       if( this._dirty & X.Dom.Dirty.CLASSNAME ) elm.className = this._className;\r
+                       if( this._dirty & X.Dom.Dirty.CLASSNAME ){\r
+                               if( X.UA.IE && X.UA.IE < 7 ){\r
+                                       elm.className = this._className;\r
+                               } else {\r
+                                       this._className ? ( elm.className = this._className ) : elm.removeAttribute( 'class' );                                 \r
+                               };\r
+                       };\r
                        // style\r
                        if( this._dirty & X.Dom.Dirty.CSS ){\r
                                if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
@@ -977,7 +991,9 @@ Node.prototype._updateRawNode =
                        if( this._dirty & X.Dom.Dirty.CONTENT ) elm.setAttribute( 'id', this._id || ( 'ie4uid' + xnode._uid ) );\r
 \r
                        // className\r
-                       if( this._dirty & X.Dom.Dirty.CLASSNAME ) elm.className = this._className;\r
+                       if( this._dirty & X.Dom.Dirty.CLASSNAME ){\r
+                               this._className ? ( elm.className = this._className ) : elm.removeAttribute( 'class' );\r
+                       };\r
                        // style\r
                        if( this._dirty & X.Dom.Dirty.CSS ){\r
                                if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
@@ -1211,10 +1227,7 @@ Node.prototype._actualRemove =
                        \r
                        elm.removeAttribute( 'id' ); // ?\r
                        document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // ?\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
+                       if( !isChild ) elm.outerHTML = '';\r
                        delete this._rawNode;\r
                }) :\r
                (function(){});\r
index f3851a3..71ee2c1 100644 (file)
@@ -367,7 +367,7 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
                                                // pre タグ以下はスペースの置換は行わない
                                                node.childNodes && node.childNodes.length &&  me( node, skip || noncleanup.indexOf( tag ) !== -1, head );
                                        };
-                                       textNode = false;                       
+                                       textNode = false;       
                                        break;
                                case 3 :
                                        content = skip ? node.data : X.Dom.cleanupWhiteSpace( node.data );
@@ -391,18 +391,27 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
        
        createTree =
                body.childNodes ?
-                       (function( xnode, childNodes, skipCleanup ){
+                       (function( xnode, childNodes, skipCleanup, textarea ){
                                var i = 0,
                                        j = 0,
                                        l = childNodes.length,
                                        child, _xnode, f, tag, text, _xtext, doc;
                                childNodes = X.copyArray( childNodes );
 
+                               if( textarea ){
+                                       xnode.attr( 'value', xnode.text() );
+                                       for( l = xnode._xnodes.length; i < l; ++i ){
+                                               xnode._xnodes[ i ].destroy();
+                                       };
+                                       xnode._xnodes.length = 0;
+                                       delete xnode._xnodes;
+                                       return;
+                               };
+
                                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;
                                        };
@@ -440,7 +449,7 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
                                                                        continue;
                                                                } else {
                                                                        //alert( '[' +xnode._tag + '>' + _xnode._tag + ' ' + (_xnode._xnodes ? _xnode._xnodes.length : '' ) + '] === ' + tag + ' ' + (child.childNodes ? child.childNodes.length : '' ) + ' Hit\n' + child.outerHTML );
-                                                                       child.childNodes && child.childNodes.length && createTree( _xnode, child.childNodes, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ) );
+                                                                       child.childNodes && child.childNodes.length && createTree( _xnode, child.childNodes, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ), tag === 'TEXTAREA' );
                                                                };
                                                                _xtext = null;
                                                                f = true;
@@ -449,6 +458,7 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
                                                        };
                                                } else
                                                if( _xnode._xnodeType === 3 ){
+                                                       
                                                        if( child.nodeType !== 3 ){
                                                                if( !( text = _xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
                                                                        console.log( '[' +xnode._tag + '>' + _xnode._uid + '] destroy ... ' );
@@ -508,7 +518,7 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
                                };
                        }) :
                body.children ? 
-                       (function( xnode, children, skipCleanup ){
+                       (function( xnode, children, skipCleanup, textarea ){
                                var parent = xnode,
                                        xnodes = parent._xnodes,
                                        l      = xnodes && xnodes.length,
@@ -517,6 +527,16 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
                                        elm, tag, xtext, text;
                                //children = X.copyArray( children );
 
+                               if( textarea ){
+                                       xnode.attr( 'value', xnode.text() );
+                                       for( l = xnode._xnodes.length; i < l; ++i ){
+                                               xnode._xnodes[ i ].destroy();
+                                       };
+                                       xnode._xnodes.length = 0;
+                                       delete xnode._xnodes;
+                                       return;
+                               };
+
                                for( ; i < xnodes.length; ++i ){
                                        xnode = xnodes[ i ];
                                        xnode.parent = parent;
@@ -573,7 +593,7 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
                                                                --i;
                                                                break;
                                                        } else {
-                                                               xnode._xnodes && xnode._xnodes.length && createTree( xnode, elm.children, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ) );
+                                                               xnode._xnodes && xnode._xnodes.length && createTree( xnode, elm.children, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ), tag === 'TEXTAREA' );
                                                                
                                                                !xnode._id && elm.setAttribute( 'id', 'ie4uid' + xnode._uid );//( elm.id = 'ie4uid' + xnode._uid );
                                                                elm.setAttribute( 'UID', xnode._uid );
@@ -615,20 +635,32 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
        xnodes.push.apply( xnodes, X.Dom.parse( body.innerHTML, true ) );
        delete Node.skipCreate;
        
-       //alert(n +  ' ' + body.innerHTML);
-       
        createTree( r, body.childNodes || body.children );
-       //r._dirty = X.Dom.Dirty.IE4_TEXTNODE_FIX;
        
        i = xnodes.length;
        Node._systemNode = s = r.create( 'div' ).className( 'hidden-sysyem-node' );
        //alert( i + ' -> ' + xnodes.length );
        
+       Node._fontSizeNode = r.create( 'div' ).className( 'hidden-sysyem-node' ).cssText( 'line-height:1;height:1em;' ).text( 'X' );
+       
+       r.appendAt( 0, Node._systemNode, Node._fontSizeNode );
+       
        r._startUpdate();
        
        //xnodes.splice( xnodes.indexOf( s ), 1 ); // hide from api user
        
        //alert(n +  ' ' + body.innerHTML);
+       
+       X.Timer.add( 200, X.Dom.Event._detectFontSize );
 } );
 
+Node._fontSizeNode = null;
 
+X.Dom.Event._lastFontSize = 0;
+X.Dom.Event._detectFontSize = function(){
+       var size = Node._fontSizeNode._rawNode.offsetHeight;
+       if( X.Dom.Event._lastFontSize !== size ){
+               X.Dom.Event._lastFontSize && X.Dom.asyncDispatch( 0, { type : X.Dom.Event.BASE_FONT_RESIZED, size : size } );
+               X.Dom.Event._lastFontSize = size;
+       };
+};
index 0ba8b51..bcbe0d6 100644 (file)
@@ -209,7 +209,7 @@ X.Dom.Attr = {
  * \r
  */\r
 X.Dom.Node.prototype.attr = function( nameOrObj /* v */ ){\r
-       var attrs = this._attrs, newAttrs, f;\r
+       var attrs = this._attrs, newAttrs, f, p;\r
        \r
        if( this._xnodeType !== 1 ) return this;\r
        \r
index f7155de..5fac239 100644 (file)
@@ -1036,6 +1036,7 @@ X.Dom.Node.prototype._getCharSize =
                }) :
        X.UA.IE && 5.5 <= X.UA.IE ?
                (function(){
+                       if( this === Node.root && X.Dom.Event._lastFontSize ) return X.Dom.Event._lastFontSize;
                        var font = this._rawNode.currentStyle.fontSize,
                                vu   = X.Dom.Style._Util._splitValueAndUnit( font ),
                                v    = vu[ 0 ],