X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F02_dom%2F05_XNodeAttr.js;h=cd96a459c077d53b36f7ae6d97a15415199a56b9;hb=80baf48679a9d5d59690134c361eb33673029c00;hp=6c23b0b22d1d9f1e63e6f86b80bb4c85e1e8d446;hpb=db532e067114718c69d226d08979d236416ae73d;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/02_dom/05_XNodeAttr.js b/0.6.x/js/02_dom/05_XNodeAttr.js index 6c23b0b..cd96a45 100644 --- a/0.6.x/js/02_dom/05_XNodeAttr.js +++ b/0.6.x/js/02_dom/05_XNodeAttr.js @@ -45,7 +45,20 @@ X_Node_Attr_HAS_VALUE = { INPUT : true, TEXTAREA : true, SELECT : true, - BUTTON : true + BUTTON : true, + OBJECT : true, + PARAM : true // FlashVars が flash 側から書き換えられるケースがある?? +}, + +// の場合、value の値はユーザーで変えることはない +// はユーザーによって常に変更される HTML5 ではこれにさらにいろいろ加わる +X_Node_Attr_STATIC_VALUE_TYPES = { + button : true, + hidden : true, + submit : true, + reset : true, + radio : true, + checkbox : true }, X_Node_Attr_renameForTag = {}; @@ -55,22 +68,24 @@ X_Node_Attr_renameForTag = {}; // 先頭にスペース function X_Node_Attr_objToAttrText( obj ){ var noValue = X_Node_Attr_noValue, - attrs = [ '' ], n = 0, p, v; + attrs = [ '' ], n = 0, k, v; if( !obj ) return ''; // Opera7 - for( p in obj ){ - v = obj[ p ]; - if( p === 'value' ){ + for( k in obj ){ + //if( X_EMPTY_OBJECT[ k ] ) continue; + v = obj[ k ]; + if( k === 'value' ){ v = v.split( '"' ).join( '"' ).split( '>' ).join( '>' ).split( '<' ).join( '<' ); }; - attrs[ ++n ] = noValue[ p ] ? p : [ p, '="', v, '"' ].join( '' ); + attrs[ ++n ] = noValue[ k ] ? k : [ k, '="', v, '"' ].join( '' ); }; return 0 < n ? attrs.join( ' ' ) : ''; }; (function( renameForDOM, renameForTag ){ - var name, i; - for( name in renameForDOM ){ - renameForTag[ renameForDOM[ name ] ] = name; + var k, i; + for( k in renameForDOM ){ + //if( X_EMPTY_OBJECT[ k ] ) continue; + renameForTag[ renameForDOM[ k ] ] = k; }; })( X_Node_Attr_renameForDOM, X_Node_Attr_renameForTag ); @@ -78,28 +93,28 @@ function X_Node_Attr_objToAttrText( obj ){ /* -------------------------------------- * attribute - * X_Node_Attr_toIndex に定義されている 属性の場合 * * http://nanto.asablo.jp/blog/2005/10/29/123294 * className, onclick等 はここで設定しない * */ Node.prototype.attr = function( nameOrObj /* v */ ){ - var attrs = this._attrs, newAttrs, f, p, elm, 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 = {} ); newAttrs = this._newAttrs || ( this._newAttrs = {} ); - for( p in nameOrObj ){ - if( X_Node_Attr_setAttr( this, attrs, newAttrs, p, nameOrObj[ p ] ) === true ) f = true; + for( k in nameOrObj ){ + //if( X_EMPTY_OBJECT[ k ] ) continue; + if( X_Node_Attr_setAttr( this, attrs, newAttrs, k, nameOrObj[ k ] ) === true ) f = true; }; if( f ){ this._attrText = false; - this._dirty |= X_Node_Dirty.ATTR; - this._root && X_Node_reserveUpdate(); + this._flags |= X_Node_State.DIRTY_ATTR; + this._root && X_Node_reserveUpdate(); }; return this; } else @@ -107,7 +122,7 @@ Node.prototype.attr = function( nameOrObj /* v */ ){ // setter if( X_Node_Attr_setAttr( this, attrs || ( this._attrs = {} ), this._newAttrs || ( this._newAttrs = {} ), nameOrObj, arguments[ 1 ] ) === true ){ this._attrText = false; - this._dirty |= X_Node_Dirty.ATTR; + this._flags |= X_Node_State.DIRTY_ATTR; this._root && X_Node_reserveUpdate(); }; return this; @@ -126,16 +141,14 @@ Node.prototype.attr = function( nameOrObj /* v */ ){ case 'style' : case 'cssText' : return this.cssText(); - case 'text' : - return this.text(); - case 'html' : - return this.html(); + case 'selected' : // kquery.js : safariのバグ対策 // if ($.browser.safari && key === "selected" && tmp) tmp.selectedIndex; // 親ノードの selectedIndex の getter を呼んでおくと値が正しくなる、ということ?( by itozyun ) - if( X_UA.WebKit ) this._rawObject.parentNode.selectedIndex; + if( X_UA.WebKit ) this._rawObject.parentNode && this._rawObject.parentNode.selectedIndex; case 'value' : + if( this._tag === 'INPUT' && X_Node_Attr_STATIC_VALUE_TYPES[ attrs[ 'type' ] ] ) break; case 'checked' : case 'disabled' : case 'selectedIndex' : @@ -160,9 +173,10 @@ function X_Node_Attr_setAttr( that, attrs, newAttrs, name, v ){ return; case 'id' : v = ( v !== 'ie4uid' + that._uid ) ? v : undefined; + // TODO unique の check if( v !== that._id ){ that._id = v; - that._dirty |= X_Node_Dirty.ID; + that._flags |= X_Node_State.DIRTY_ID; that._root && X_Node_reserveUpdate(); }; return;