X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F02_dom%2F05_XNodeAttr.js;h=5a5f16f7a739760f5ba957e6faff733fb9a9bde2;hb=629dcf47fbdb2b56567a1019d22b8a2eeb4f4ed6;hp=2ff418f4912f168412f67f6afc3ecd54865d0dee;hpb=d9cca45398f61025472f2858818519562a746e61;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 2ff418f..5a5f16f 100644 --- a/0.6.x/js/02_dom/05_XNodeAttr.js +++ b/0.6.x/js/02_dom/05_XNodeAttr.js @@ -1,5 +1,4 @@ -var X_Node_Attr = { - noValue : { +var X_Node_Attr_noValue = { checked : 1, compact : 1, declare : 1, @@ -13,8 +12,8 @@ var X_Node_Attr = { nowrap : 1, readonly : 1, selected : 1 - }, - renameForDOM : { +}, +X_Node_Attr_renameForDOM = { 'class' : 'className', accesskey : 'accessKey', 'accept-charset' : 'acceptCharset', @@ -40,22 +39,24 @@ var X_Node_Attr = { usemap : 'useMap', valuetype : 'valueType', checked : 'defaultChecked' - }, - - HAS_VALUE : { +}, + +X_Node_Attr_HAS_VALUE = { INPUT : true, TEXTAREA : true, SELECT : true, - BUTTON : true - }, - - renameForTag : {}, + BUTTON : true, + OBJECT : true, + PARAM : true // FlashVars が flash 側から書き換えられるケースがある +}, + +X_Node_Attr_renameForTag = {}; // http://nanto.asablo.jp/blog/2005/10/29/123294 // checked -> defaultChecked // 動的に生成した input 要素を文書ツリーに挿入する前に設定した checked 属性は反映されず、defaultChecked だと反映される // 先頭にスペース - objToAttrText : function( obj ){ - var noValue = X_Node_Attr.noValue, +function X_Node_Attr_objToAttrText( obj ){ + var noValue = X_Node_Attr_noValue, attrs = [ '' ], n = 0, p, v; if( !obj ) return ''; // Opera7 for( p in obj ){ @@ -66,7 +67,6 @@ var X_Node_Attr = { attrs[ ++n ] = noValue[ p ] ? p : [ p, '="', v, '"' ].join( '' ); }; return 0 < n ? attrs.join( ' ' ) : ''; - } }; (function( renameForDOM, renameForTag ){ @@ -74,19 +74,19 @@ var X_Node_Attr = { for( name in renameForDOM ){ renameForTag[ renameForDOM[ name ] ] = name; }; -})( X_Node_Attr.renameForDOM, X_Node_Attr.renameForTag ); +})( X_Node_Attr_renameForDOM, X_Node_Attr_renameForTag ); /* -------------------------------------- * attribute - * X_Node_Attr.toIndex に定義されている 属性の場合 + * X_Node_Attr_toIndex に定義されている 属性の場合 * * http://nanto.asablo.jp/blog/2005/10/29/123294 * className, onclick等 はここで設定しない * */ -X.Dom.Node.prototype.attr = function( nameOrObj /* v */ ){ +Node.prototype.attr = function( nameOrObj /* v */ ){ var attrs = this._attrs, newAttrs, f, p, elm, v; if( this._xnodeType !== 1 ) return this; @@ -96,21 +96,21 @@ X.Dom.Node.prototype.attr = function( nameOrObj /* v */ ){ newAttrs = this._newAttrs || ( this._newAttrs = {} ); for( p in nameOrObj ){ - if( this._setAttr( attrs, newAttrs, p, nameOrObj[ p ] ) === true ) f = true; + if( X_Node_Attr_setAttr( this, attrs, newAttrs, p, nameOrObj[ p ] ) === true ) f = true; }; if( f ){ this._attrText = false; this._dirty |= X_Node_Dirty.ATTR; - this._root && this._reserveUpdate(); + this._root && X_Node_reserveUpdate(); }; return this; } else if( 1 < arguments.length ){ // setter - if( this._setAttr( attrs || ( this._attrs = {} ), this._newAttrs || ( this._newAttrs = {} ), nameOrObj, arguments[ 1 ] ) === true ){ + 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._root && this._reserveUpdate(); + this._root && X_Node_reserveUpdate(); }; return this; } else @@ -128,24 +128,32 @@ X.Dom.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; case 'value' : case 'checked' : - case 'selected' : case 'disabled' : case 'selectedIndex' : - if( X_Node_Attr.HAS_VALUE[ this._tag ] ){ + if( X_Node_Attr_HAS_VALUE[ this._tag ] ){ if( this._newAttrs && X_Object_inObject( nameOrObj, this._newAttrs ) ) return this._newAttrs[ nameOrObj ]; - if( elm = X_UA_DOM.IE4 ? this._rawObject || this._ie4getRawNode() : this._rawObject ){ + if( elm = X_UA_DOM.IE4 ? this._rawObject || X_Node__ie4getRawNode( this ) : this._rawObject ){ if( !attrs ) attrs = this._attrs = {}; return attrs[ nameOrObj ] = elm[ nameOrObj ]; // getAttribute( nameOrObj )? }; }; break; }; - return attrs && attrs[ X_Node_Attr.renameForTag[ nameOrObj ] || nameOrObj ]; + return attrs && attrs[ X_Node_Attr_renameForTag[ nameOrObj ] || nameOrObj ]; }; }; -X.Dom.Node.prototype._setAttr = function( attrs, newAttrs, name, v ){ +function X_Node_Attr_setAttr( that, attrs, newAttrs, name, v ){ switch( name ){ // case 'type' : TODO IE は input, button, object に対して type の再設定が出来ない _state が要素生成済なら不可 case 'UID' : @@ -153,19 +161,23 @@ X.Dom.Node.prototype._setAttr = function( attrs, newAttrs, name, v ){ case 'tagName' : return; case 'id' : - v = ( v !== 'ie4uid' + this._uid ) ? v : undefined; - if( v !== this._id ){ - this._id = v; - this._dirty |= X_Node_Dirty.ID; - this._root && this._reserveUpdate(); + v = ( v !== 'ie4uid' + that._uid ) ? v : undefined; + if( v !== that._id ){ + that._id = v; + that._dirty |= X_Node_Dirty.ID; + that._root && X_Node_reserveUpdate(); }; return; case 'class' : case 'className' : - return this.className( v ); + return that.className( v ); case 'style' : case 'cssText' : - return this.cssText( v ); + return that.cssText( v ); + case 'text' : + return that.text( v ); + case 'html' : + return that.html( v ); }; // debug if( name.indexOf( 'on' ) === 0 ){ @@ -173,7 +185,7 @@ X.Dom.Node.prototype._setAttr = function( attrs, newAttrs, name, v ){ return; }; - name = X_Node_Attr.renameForTag[ name ] || name; + name = X_Node_Attr_renameForTag[ name ] || name; if( attrs[ name ] === v ) return; if( v == null ){