From 80baf48679a9d5d59690134c361eb33673029c00 Mon Sep 17 00:00:00 2001 From: itozyun Date: Tue, 20 Jan 2015 22:24:53 +0900 Subject: [PATCH] Version 0.6.123, remove xnode._nodeType. --- 0.6.x/js/02_dom/02_XNode.js | 96 ++++++++++++++++++------------------- 0.6.x/js/02_dom/03_XDomEvent.js | 2 +- 0.6.x/js/02_dom/05_XNodeAttr.js | 14 +----- 0.6.x/js/02_dom/06_XNodeCSS.js | 2 +- 0.6.x/js/02_dom/07_XNodeList.js | 8 ++-- 0.6.x/js/02_dom/08_XNodeSelector.js | 18 +++---- 0.6.x/js/02_dom/22_XTreeBuilder.js | 7 ++- 7 files changed, 67 insertions(+), 80 deletions(-) diff --git a/0.6.x/js/02_dom/02_XNode.js b/0.6.x/js/02_dom/02_XNode.js index d66de3f..9f5fa99 100644 --- a/0.6.x/js/02_dom/02_XNode.js +++ b/0.6.x/js/02_dom/02_XNode.js @@ -8,8 +8,6 @@ var ELM_EXIST : 2 << 1, ELM_IN_TREE : 2 << 2, - IS_TEXTNODE : 2 << 3, - STYLE_IS_DISPLAY_NONE : 2 << 4, // display:none STYLE_IS_HIDDEN : 2 << 5, // visibility:hidden opacity:0 STYLE_IS_POS_ABSOLUTE : 2 << 6, // position:absolute @@ -23,7 +21,7 @@ var IE4_ONLY_TEXT : 2 << 14, IE5_DISPLAY_NONE_FIX : X_UA.IE5 && X_UA.ActiveX ? 2 << 15 : 0, // filterがかかっていると不可ってことかも? MacIE5.2- は ? - UNKNOWN_TAG_FIX : 2 << 16, + UNKNOWN_TAG_FIX : 2 << 16, // 使っていない IE4_TEXTNODE_FIX : 2 << 17, DIRTY_CHILD : 2 << 18, // 使っていない @@ -115,7 +113,6 @@ var if( X_Node_newByTag ){ X_Node_newByTag = false; this._tag = v.toUpperCase(); - this._xnodeType = 1; this._flags |= X_Node_State.EXIST; arguments[ 1 ] && this.attr( arguments[ 1 ] ); css = arguments[ 2 ]; @@ -124,8 +121,7 @@ var if( X_Node_newByText ){ X_Node_newByText = false; this._text = v; - this._xnodeType = 3; - this._flags |= X_Node_State.EXIST | X_Node_State.IS_TEXTNODE; + this._flags |= X_Node_State.EXIST; } else { if( 1 < arguments.length ) return new X_NodeList( arguments ); if( X.Type.isArray( v ) && v.length ) return new X_NodeList( v ); @@ -144,7 +140,6 @@ var this._flags |= X_Node_State.IN_TREE | X_Node_State.ELM_IN_TREE; }; this._rawObject = v; - this._xnodeType = 1; this._flags |= X_Node_State.EXIST | X_Node_State.ELM_EXIST; this._tag = v.tagName.toUpperCase(); this._id = v.id; @@ -167,8 +162,7 @@ var this.parent = X_Node_getXNode( v.parentNode ); if( this.parent && this.parent._root ) this._root = this.parent._root; this._rawObject = v; - this._xnodeType = 3; - this._flags |= X_Node_State.EXIST | X_Node_State.IS_TEXTNODE; + this._flags |= X_Node_State.EXIST; this._text = v.data; v.UID = uid; break; @@ -335,7 +329,7 @@ var X_Node__ie4getRawNode = X_UA_DOM.IE4 && function ( that ){ */ function X_Node_create( tag, opt_attrs, opt_css ){ var xnode; - if( this._xnodeType !== 1 ) return; + if( !this._tag ) return; if( !this._xnodes ) this._xnodes = []; xnode = X_Doc_create( tag, opt_attrs, opt_css ); @@ -356,7 +350,7 @@ function X_Node_createAt( index, tag, opt_attrs, opt_css ){ */ function X_Node_createText( text ){ var xnode; - if( this._xnodeType !== 1 ) return; + if( !this._tag ) return; if( !this._xnodes ) this._xnodes = []; X_Node_newByText = true; @@ -380,27 +374,20 @@ function X_Node_createTextAt( index, text ){ */ function X_Node_clone( opt_clone_children ){ var xnode, xnodes, i, l; - switch( this._xnodeType ){ - case 1 : - X_Node_newByTag = true; - xnode = new Node( this._tag, X_Object_clone( this._attrs ), X_Object_clone( this._css ) ) - .attr( { 'id' : this._id } ) - .className( this._className ); - if( opt_clone_children && ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){ - for( i = 0; i < l; ++i ){ - xnode.append( xnodes[ i ].clone( true ) ); - }; + if( this._tag ){ + X_Node_newByTag = true; + xnode = new Node( this._tag, X_Object_clone( this._attrs ), X_Object_clone( this._css ) ) + .attr( { 'id' : this._id } ) + .className( this._className ); + if( opt_clone_children && ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){ + for( i = 0; i < l; ++i ){ + xnode.append( xnodes[ i ].clone( true ) ); }; - return xnode; - case 3 : - X_Node_newByText = true; - xnode = new Node( this._text ); - return xnode; - - //case 0 : - //case 2 : + }; + return xnode; }; - return this; + X_Node_newByText = true; + return new Node( this._text ); }; /* -------------------------------------- @@ -410,7 +397,7 @@ function X_Node_clone( opt_clone_children ){ */ function X_Node_append( v ){ var i, l, xnodes, frg; - if( this._xnodeType !== 1 ) return; + if( !this._tag ) return; if( 1 < ( l = arguments.length ) ){ for( i = 0; i < l; ++i ){ @@ -430,7 +417,6 @@ function X_Node_append( v ){ case X_Node_TYPE.STRING : return this.append.apply( this, X_HtmlParser_parse( v, true ) ); case X_Node_TYPE.XNODE : - if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this; // 親の xnodes から v を消す if( v.parent ){ v.remove(); @@ -450,7 +436,7 @@ function X_Node_append( v ){ function X_Node_appendAt( start, v ){ var xnodes, l, i; - if( this._xnodeType !== 1 ) return this; + if( !this._tag ) return this; l = arguments.length; if( !( xnodes = this._xnodes ) ) xnodes = this._xnodes = []; @@ -483,7 +469,6 @@ function X_Node_appendAt( start, v ){ }; return this; case X_Node_TYPE.XNODE : - if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this; // 親の xnodes から v を消す if( v.parent ){ v.remove(); @@ -656,7 +641,7 @@ function X_Node_destroy( isChild ){ */ function X_Node_contains( v ){ var elm, type, xnodes, i; - if( !v || this._xnodeType !== 1 || this === v ) return false; + if( !v || !this._tag || this === v ) return false; // contains ie4+ if( ( elm = this._rawObject || X_UA_DOM.IE4 && X_Node__ie4getRawNode( this ) ) && document.contains && ( type = X_Node_getType( v ) ) && ( type === X_Node_TYPE.RAW_HTML || type === X_Node_TYPE.RAW_TEXT ) ){ return elm.contains( v ); @@ -678,7 +663,7 @@ function X_Node_contains( v ){ * getChild */ function X_Node_getChildAt( i ){ - var xnodes = this._xnodeType === 1 && this._xnodes; + var xnodes = this._xnodes; return xnodes && 0 <= i && i < xnodes.length && xnodes[ i ]; }; @@ -803,12 +788,12 @@ function X_Node_html( html ){ var _ = '', q = '"', xnodes, n, i, l; // setter if( html !== undefined ){ // String 以外に Number や false null なども許可 - if( this._xnodeType === 3 ) return this.text( html ); + if( !this._tag ) return this.text( html ); return html ? this.empty().append.apply( this, X_HtmlParser_parse( html, true ) ) : this.empty(); }; // getter - if( this._xnodeType === 3 ){ + if( !this._tag ){ return this._text; }; @@ -846,7 +831,7 @@ function X_Node_text( text ){ if( text === null ) text = ''; text += ''; - if( this._xnodeType === 3 ){ + if( !this._tag ){ if( this._text !== text ){ text ? ( this._text = text ) : delete this.text; this._root && X_Node_reserveUpdate(); @@ -855,7 +840,7 @@ function X_Node_text( text ){ return this; }; if( !text ) return this.empty(); - if( ( xnodes = this._xnodes ) && xnodes.length === 1 && xnodes[ 0 ]._xnodeType === 3 ){ + if( ( xnodes = this._xnodes ) && xnodes.length === 1 && !xnodes[ 0 ]._tag ){ xnodes[ 0 ].text( text ); return this; }; @@ -863,7 +848,7 @@ function X_Node_text( text ){ return this; }; // getter - if( this._xnodeType === 1 ){ + if( this._tag ){ if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){ for( texts = [], i = 0; i < l; ++i ){ texts[ i ] = xnodes[ i ].text(); @@ -884,6 +869,21 @@ function X_Node_call( name /*, opt_args... */ ){ X_Node_updateTimerID && X_Node_startUpdate(); + switch( name ){ + case 'nodeType' : + return this._tag ? 1 : 3; + case 'text' : + return this.text(); + case 'html' : + case 'innerHTML' : + return this.html(); + case 'outerHTML' : + X_Node_outerXNode = this; + v = this.html(); + X_Node_outerXNode = null; + return v; + }; + raw = this._rawObject || X_UA_DOM.IE4 && X_Node__ie4getRawNode( this ); if( !raw ) return; @@ -1042,7 +1042,7 @@ var X_Node__commitUpdate = xnodes = that._xnodes; l = xnodes ? xnodes.length : 0; - if( that._flags & X_Node_State.IE4_TEXTNODE_FIX || ( that._flags & X_Node_State.IE4_ONLY_TEXT && ( l !== 1 || xnodes[ 0 ]._xnodeType !== 3 ) ) ){ // 1 < l && elm.children.length === 0 + if( that._flags & X_Node_State.IE4_TEXTNODE_FIX || ( that._flags & X_Node_State.IE4_ONLY_TEXT && ( l !== 1 || xnodes[ 0 ]._tag ) ) ){ // 1 < l && elm.children.length === 0 html = []; for( i = 0; i < l; ++i ){ html[ i ] = X_Node__actualCreate( xnodes[ i ] ); @@ -1236,7 +1236,7 @@ var X_Node__actualCreate = var elm = that._rawObject, xnodes, frg, i, l; - if( that._xnodeType === 3 ){ + if( !that._tag ){ if( elm ) return elm; //delete that._flags; that._flags &= X_Node_DIRTY_MASK_RESET; @@ -1276,7 +1276,7 @@ var X_Node__actualCreate = var uid = that._uid, html, xnodes, n, i, l; - if( that._xnodeType === 3 ){ + if( !that._tag ){ html = [ '', that._text, '' ];// fake textNode delete that._rawObject; } else { @@ -1295,7 +1295,7 @@ var X_Node__actualCreate = n = html.length; if( ( xnodes = that._xnodes ) && ( l = xnodes.length ) ){ - if( l === 1 && xnodes[ 0 ]._xnodeType === 3 ){ + if( l === 1 && !xnodes[ 0 ]._tag ){ // only textnode html[ n ] = xnodes[ 0 ]._text; ++n; @@ -1322,7 +1322,7 @@ var X_Node__afterActualCreate = that._root = that.parent._root; - if( that._xnodeType === 3 ){ + if( !that._tag ){ // that._flags && X_Node__updateRawNode( that, elm ); that._flags & X_Node_DIRTY_MASK && X_Node__updateRawNode( that, elm ); return that; @@ -1384,7 +1384,7 @@ var X_Node__afterActualCreate = var xnodes, i; that._root = that.parent._root; - if( that._xnodeType !== 1 ) return that; + if( !that._tag ) return that; if( ( xnodes = that._xnodes ) && ( i = xnodes.length ) ){ for( ; i; ){ @@ -1411,7 +1411,7 @@ var X_Node__actualRemove = if( xnodes && ( l = xnodes.length ) ){ for( i = 0; i < l; ++i ){ child = xnodes[ i ]; - child._xnodeType === 1 && X_Node__actualRemove( child, true ); + child._tag && X_Node__actualRemove( child, true ); }; }; diff --git a/0.6.x/js/02_dom/03_XDomEvent.js b/0.6.x/js/02_dom/03_XDomEvent.js index 8708746..3910b6f 100644 --- a/0.6.x/js/02_dom/03_XDomEvent.js +++ b/0.6.x/js/02_dom/03_XDomEvent.js @@ -260,7 +260,7 @@ if( !X_UA.IE || 9 <= X_UA.IE ){ this.type = X_Event_RenameTo[ originalType ] || originalType; this.target = X_Node_getXNode( e.srcElement ); // xnode - if( this.target && this.target._xnodeType === 3 ) this.target = this.target.parent; // ie4 の fake Textnode がヒットしていないか? + if( this.target && !this.target._tag ) this.target = this.target.parent; // ie4 の fake Textnode がヒットしていないか? this.currentTarget = xnode; // xnode this.relatedTarget = X_Node_getXNode( e.formElement || e.toElement ); // xnode this.eventPhase = e.srcElement === element ? 2: 3; diff --git a/0.6.x/js/02_dom/05_XNodeAttr.js b/0.6.x/js/02_dom/05_XNodeAttr.js index a4669c8..cd96a45 100644 --- a/0.6.x/js/02_dom/05_XNodeAttr.js +++ b/0.6.x/js/02_dom/05_XNodeAttr.js @@ -101,7 +101,7 @@ function X_Node_Attr_objToAttrText( obj ){ Node.prototype.attr = function( nameOrObj /* v */ ){ var attrs = this._attrs, newAttrs, f, k, elm, v; - if( this._xnodeType !== 1 ) return this; + if( !this._tag ) return this; if( nameOrObj && X.Type.isObject( nameOrObj ) ){ attrs || ( attrs = this._attrs = {} ); @@ -138,21 +138,9 @@ Node.prototype.attr = function( nameOrObj /* v */ ){ case 'tag' : case 'tagName' : return this._tag; - case 'nodeType' : - return this._tag ? 1 : 3; case 'style' : case 'cssText' : return this.cssText(); - case 'text' : - return this.text(); - case 'html' : - case 'innerHTML' : - return this.html(); - case 'outerHTML' : - X_Node_outerXNode = this; - v = this.html(); - X_Node_outerXNode = null; - return v; case 'selected' : // kquery.js : safariのバグ対策 diff --git a/0.6.x/js/02_dom/06_XNodeCSS.js b/0.6.x/js/02_dom/06_XNodeCSS.js index 09c399b..a3b6db6 100644 --- a/0.6.x/js/02_dom/06_XNodeCSS.js +++ b/0.6.x/js/02_dom/06_XNodeCSS.js @@ -487,7 +487,7 @@ Node.prototype.css = function( nameOrObj /* orUnitID, valuOrUnitOrName */ ){ args = arguments, css = this._css, p, name, v, camelize, unit, ieFix; - if( this._xnodeType !== 1 ) return this; + if( !this._tag ) return this; // setter:object if( X.Type.isObject( nameOrObj ) ){ if( !css ) css = this._css = {}; diff --git a/0.6.x/js/02_dom/07_XNodeList.js b/0.6.x/js/02_dom/07_XNodeList.js index 73f3faf..a1bf749 100644 --- a/0.6.x/js/02_dom/07_XNodeList.js +++ b/0.6.x/js/02_dom/07_XNodeList.js @@ -3,12 +3,12 @@ function X_NodeList( v ){ var args = [], l = arguments.length, i = 0, - indexOf, xnode, j, n = 0, skip; + xnode, j, n = 0, skip; + for( ; i < l; ++i ){ - //args.push( arguments[ i ] ); args.push.apply( args, arguments[ i ] ); }; - //alert( arguments[ 0 ].length + ' , ' + args.length ) + if( ( l = args.length ) === 1 ) return new Node( args[ 0 ] ); if( !this || this.append !== X_NodeList.prototype.append ) return new X_NodeList( args ); @@ -16,7 +16,7 @@ function X_NodeList( v ){ xnode = args[ i ]; //xnode = xnode && xnode.constructor === Node ? xnode : new Node( xnode ); skip = false; - if( xnode._xnodeType === 0 ) continue; + //if( xnode._xnodeType === 0 ) continue; for( j = 0; j < n; ++j ){ if( this[ j ] === xnode ){ skip = true; diff --git a/0.6.x/js/02_dom/08_XNodeSelector.js b/0.6.x/js/02_dom/08_XNodeSelector.js index 793e166..7d18c8b 100644 --- a/0.6.x/js/02_dom/08_XNodeSelector.js +++ b/0.6.x/js/02_dom/08_XNodeSelector.js @@ -320,7 +320,7 @@ function X_Node_Selector__parse( query, last ){ case 2 : for( ; i < l; ++i ){ for( xnode = parents[ i ].firstChild(); xnode; xnode = xnode.nextNode() ){ - if( xnode._xnodeType === 1 && ( isAll || tagName === xnode._tag ) ) xnodes[ ++n ] = xnode; + if( xnode._tag && ( isAll || tagName === xnode._tag ) ) xnodes[ ++n ] = xnode; }; }; break; @@ -328,7 +328,7 @@ function X_Node_Selector__parse( query, last ){ case 3 : for( ; i < l; ++i ){ for( xnode = parents[ i ].nextNode(); xnode; xnode = xnode.nextNode() ){ - if( xnode._xnodeType === 1 ){ + if( xnode._tag ){ if( isAll || tagName === xnode._tag ) xnodes[ ++n ] = xnode; break; }; @@ -340,7 +340,7 @@ function X_Node_Selector__parse( query, last ){ merge = {}; for( ; i < l; ++i ){ for( xnode = parents[ i ].nextNode(); xnode; xnode = xnode.nextNode() ){ - if( xnode._xnodeType === 1 && ( isAll || tagName === xnode._tag ) ){ + if( xnode._tag && ( isAll || tagName === xnode._tag ) ){ uid = xnode._uid; if( merge[ uid ] ){ break; @@ -536,7 +536,7 @@ function X_Node_Selector__parse( query, last ){ j, child, _xnodes; for( ; i < l; ++i ){ child = xnodes[ i ]; - if( child._xnodeType !== 1 ) continue; + if( !child._tag ) continue; //console.log( child._tag ); if( ( j = list.indexOf( child ) ) !== -1 ){ newList[ newList.length ] = child; @@ -561,7 +561,7 @@ function X_Node_Selector__parse( query, last ){ child; for( ; i < l; ++i ){ child = xnodes[ i ]; - if( child._xnodeType === 1 ){ + if( child._tag ){ ( !tag || child._tag === tag ) && ( list[ list.length ] = child ); //console.log( parent._tag + ' > ' + child._tag + ' == ' + tag+ ' l:' + list.length ); child._xnodes && child._xnodes.length && X_Node_Selector__fetchElements( list, child, tag ); @@ -579,7 +579,7 @@ function X_Node_Selector__parse( query, last ){ tmp = null; if( /* tmp === null && */ type <= 0 ){ for( node = xnode.prevNode(); node; node = node.prevNode() ){ - if( node._xnodeType === 1 && ( flag_all || tagName === node._tag ) ){ + if( node._tag && ( flag_all || tagName === node._tag ) ){ tmp = false; break; }; @@ -587,7 +587,7 @@ function X_Node_Selector__parse( query, last ){ }; if( tmp === null && 0 <= type ){ for( node = xnode.nextNode(); node; node = node.nextNode() ){ - if( node._xnodeType === 1 && ( flag_all || tagName === node._tag ) ){ + if( node._tag && ( flag_all || tagName === node._tag ) ){ tmp = false; break; }; @@ -610,7 +610,7 @@ function X_Node_Selector__parse( query, last ){ tmp = checked[ uid ]; if( tmp === void 0 ){ for( c = 0, node = xnode.parent[ pointer ](), tagName = flag_all || xnode._tag; node; node = node[ sibling ]() ){ - if( node._xnodeType === 1 && ( flag_all || tagName === node._tag ) ){ + if( node._tag && ( flag_all || tagName === node._tag ) ){ ++c; checked[ node._uid ] = a === 0 ? c === b : (c - b) % a === 0 && (c - b) / a >= 0; }; @@ -685,7 +685,7 @@ var X_Node_Selector__filter = { for( ; xnode = xnodes[i]; ++i ){ tmp = true; for( node = xnode.firstChild(); node; node = node.nextSibling() ){ - if( node._xnodeType === 1 || ( node._xnodeType === 3 && node._text ) ){ + if( node._tag || ( !node._tag && node._text ) ){ tmp = false; break; }; diff --git a/0.6.x/js/02_dom/22_XTreeBuilder.js b/0.6.x/js/02_dom/22_XTreeBuilder.js index a422d9d..533f6d9 100644 --- a/0.6.x/js/02_dom/22_XTreeBuilder.js +++ b/0.6.x/js/02_dom/22_XTreeBuilder.js @@ -342,7 +342,7 @@ X_TEMP.bindElementToXnode = continue; }; - if( xnode._xnodeType === 1 ){ + if( xnode._tag ){ if( elm.nodeType === 3 ){ if( !( text = elm.data ) || ( text = X_String_cleanupWhiteSpace( text ) ) === ' ' ){ //alert( text.charCodeAt( 0 ) ); @@ -455,7 +455,7 @@ X_TEMP.bindElementToXnode = xnode.parent = parent; - if( xnode._xnodeType === 3 ){ + if( !xnode._tag ){ //alert( X_String_cleanupWhiteSpace( xnode._text ) ); if( !skipCleanup ){ if( !( text = xnode._text ) || ( text = X_String_cleanupWhiteSpace( text ) ) === ' ' ){ @@ -480,8 +480,7 @@ X_TEMP.bindElementToXnode = return; }; - if( xnode._xnodeType !== 1 ){ - //alert( xnode._xnodeType ) + if( !xnode._tag ){ return; }; -- 2.11.0