From 1d0f175bdfd85ad04995e69a9eb878d8980d9940 Mon Sep 17 00:00:00 2001 From: itozyun Date: Mon, 3 Mar 2014 21:18:30 +0900 Subject: [PATCH] Version 0.6.26, bugfix & BASE_FONT_RESIZED event added. --- 0.6.x/js/dom/10_XDom.js | 6 ++--- 0.6.x/js/dom/11_XDomNode.js | 45 ++++++++++++++++++++++++-------------- 0.6.x/js/dom/12_XDomEvent.js | 52 +++++++++++++++++++++++++++++++++++--------- 0.6.x/js/dom/14_XDomAttr.js | 2 +- 0.6.x/js/dom/15_XDomStyle.js | 1 + 5 files changed, 76 insertions(+), 30 deletions(-) diff --git a/0.6.x/js/dom/10_XDom.js b/0.6.x/js/dom/10_XDom.js index 2e6cbfa..21e77b9 100644 --- a/0.6.x/js/dom/10_XDom.js +++ b/0.6.x/js/dom/10_XDom.js @@ -14,7 +14,7 @@ if( !lock++ ){ size = X.Dom.getSize(); ( w !== size[ 0 ] || h !== size[ 1 ] ) && - X.Dom.dispatch( { type : X.Dom.Event.VIEW_RESIZED, w : w = size[ 0 ], h : h = size[ 1 ] } ); + X.Dom.asyncDispatch( 0, { type : X.Dom.Event.VIEW_RESIZED, w : w = size[ 0 ], h : h = size[ 1 ] } ); X.Timer.once( 1, unlock ); }; }; @@ -26,7 +26,7 @@ delayResize = function(){ var size = X.Dom.getSize(); ( w !== size[ 0 ] || h !== size[ 1 ] ) && - X.Dom.dispatch( { type : X.Dom.Event.VIEW_RESIZED, w : w = size[ 0 ], h : h = size[ 1 ] } ); + X.Dom.asyncDispatch( 0, { type : X.Dom.Event.VIEW_RESIZED, w : w = size[ 0 ], h : h = size[ 1 ] } ); X.Timer.once( 1, unlock ); }; }; @@ -82,7 +82,7 @@ var size = X.Dom.getSize(); X.UA.IE && X.UA.IE < 9 ? - X.Timer.add( 100, resize ) : + X.Timer.add( 200, resize ) : X.Dom.Node._window.listen( 'resize', resize ); X.Dom.readyState = X.Dom.Event.XDOM_READY; X.Dom.asyncDispatch( 0, { type : X.Dom.Event.XDOM_READY, w : size[ 0 ], h : size[ 1 ] } ); diff --git a/0.6.x/js/dom/11_XDomNode.js b/0.6.x/js/dom/11_XDomNode.js index 86f6e07..1ad2852 100644 --- a/0.6.x/js/dom/11_XDomNode.js +++ b/0.6.x/js/dom/11_XDomNode.js @@ -205,9 +205,14 @@ Node._getXNode = function( v ){ }; -Node.create = function( tag, opt_attr, opt_css ){ - Node._newByTag = true; - return new Node( tag, opt_attr, opt_css ); +Node.create = function( tag, opt_attrs, opt_css ){ + switch( Node._getType( tag ) ){ + case Node.IS_STRING : + Node._newByTag = true; + return new Node( tag, opt_attrs, opt_css ); + case Node.IS_HTML_STRING : + return X.Dom.parse( tag, true )[ 0 ]; + }; }; Node.createText = function( text ){ Node._newByText = true; @@ -255,12 +260,11 @@ Node.prototype.create = function( tag, opt_attrs, opt_css ){ if( this._xnodeType !== 1 ) return; if( !this._xnodes ) this._xnodes = []; - Node._newByTag = true; - xnode = new Node( tag, opt_attrs, opt_css ); - xnode.parent = this; + xnode = Node.create( tag, opt_attrs, opt_css ); - this._root && this._reserveUpdate(); + xnode.parent = this; this._xnodes[ this._xnodes.length ] = xnode; + this._root && this._reserveUpdate(); return xnode; }; @@ -836,6 +840,8 @@ Node.prototype._commitUpdate = parentElement.insertBefore( this._actualCreate(), nextElement ) : parentElement.appendChild( this._actualCreate() ); this._afterActualCreate(); + + return elm || this._rawNode; } else if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ) { @@ -916,12 +922,20 @@ Node.prototype._updateRawNode = }; // id if( this._dirty & X.Dom.Dirty.ID ){ - //this._id ? - ( elm.id = this._id )// : - //elm.removeAttribute( 'id' ); + if( X.UA.IE && X.UA.IE < 7 ){ + elm.id = this._id; + } else { + this._id ? ( elm.id = this._id ) : elm.removeAttribute( 'id' ); + }; }; // className - if( this._dirty & X.Dom.Dirty.CLASSNAME ) elm.className = this._className; + if( this._dirty & X.Dom.Dirty.CLASSNAME ){ + if( X.UA.IE && X.UA.IE < 7 ){ + elm.className = this._className; + } else { + this._className ? ( elm.className = this._className ) : elm.removeAttribute( 'class' ); + }; + }; // style if( this._dirty & X.Dom.Dirty.CSS ){ if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){ @@ -977,7 +991,9 @@ Node.prototype._updateRawNode = if( this._dirty & X.Dom.Dirty.CONTENT ) elm.setAttribute( 'id', this._id || ( 'ie4uid' + xnode._uid ) ); // className - if( this._dirty & X.Dom.Dirty.CLASSNAME ) elm.className = this._className; + if( this._dirty & X.Dom.Dirty.CLASSNAME ){ + this._className ? ( elm.className = this._className ) : elm.removeAttribute( 'class' ); + }; // style if( this._dirty & X.Dom.Dirty.CSS ){ if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){ @@ -1211,10 +1227,7 @@ Node.prototype._actualRemove = elm.removeAttribute( 'id' ); // ? document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // ? - if( !isChild ){ - //alert( elm.tagName + this._uid + '\n' + document.all[ this._id || ( 'ie4uid' + this._uid ) ] + '\n' + elm.innerHTML ); - elm.outerHTML = ''; - }; + if( !isChild ) elm.outerHTML = ''; delete this._rawNode; }) : (function(){}); diff --git a/0.6.x/js/dom/12_XDomEvent.js b/0.6.x/js/dom/12_XDomEvent.js index f3851a3..71ee2c1 100644 --- a/0.6.x/js/dom/12_XDomEvent.js +++ b/0.6.x/js/dom/12_XDomEvent.js @@ -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; + }; +}; diff --git a/0.6.x/js/dom/14_XDomAttr.js b/0.6.x/js/dom/14_XDomAttr.js index 0ba8b51..bcbe0d6 100644 --- a/0.6.x/js/dom/14_XDomAttr.js +++ b/0.6.x/js/dom/14_XDomAttr.js @@ -209,7 +209,7 @@ X.Dom.Attr = { * */ X.Dom.Node.prototype.attr = function( nameOrObj /* v */ ){ - var attrs = this._attrs, newAttrs, f; + var attrs = this._attrs, newAttrs, f, p; if( this._xnodeType !== 1 ) return this; diff --git a/0.6.x/js/dom/15_XDomStyle.js b/0.6.x/js/dom/15_XDomStyle.js index f7155de..5fac239 100644 --- a/0.6.x/js/dom/15_XDomStyle.js +++ b/0.6.x/js/dom/15_XDomStyle.js @@ -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 ], -- 2.11.0