+++ /dev/null
-X.Dom.Attr = {\r
- noValue : {\r
- checked : 1,\r
- compact : 1,\r
- declare : 1,\r
- defer : 1,\r
- disabled : 1,\r
- ismap : 1,\r
- multiple : 1,\r
- nohref : 1,\r
- noresize : 1,\r
- noshade : 1,\r
- nowrap : 1,\r
- readonly : 1,\r
- selected : 1\r
- },\r
- renameForDOM : {\r
- 'class' : 'className',\r
- accesskey : 'accessKey',\r
- 'accept-charset' : 'acceptCharset',\r
- bgcolor : 'bgColor',\r
- cellpadding : 'cellPadding',\r
- cellspacing : 'cellSpacing',\r
- 'char' : 'ch',\r
- charoff : 'chOff',\r
- codebase : 'codeBase',\r
- codetype : 'codeType',\r
- colspan : 'colSpan',\r
- datetime : 'dateTime',\r
- 'for' : 'htmlFor',\r
- frameborder : 'frameBorder',\r
- 'http-equiv' : 'httpEquiv',\r
- ismap : 'isMap',\r
- longdesc : 'longDesc',\r
- maxlength : 'maxLength',\r
- nohref : 'noHref',\r
- readonly : 'readOnly',\r
- rowspan : 'rowSpan',\r
- tabindex : 'tabIndex',\r
- usemap : 'useMap',\r
- valuetype : 'valueType',\r
- checked : 'defaultChecked'\r
- },\r
- \r
- HAS_VALUE : {\r
- INPUT : true,\r
- TEXTAREA : true,\r
- SELECT : true,\r
- BUTTON : true\r
- },\r
- \r
- renameForTag : {},\r
- // http://nanto.asablo.jp/blog/2005/10/29/123294\r
- // checked -> defaultChecked\r
- // 動的に生成した input 要素を文書ツリーに挿入する前に設定した checked 属性は反映されず、defaultChecked だと反映される\r
- // 先頭にスペース\r
- objToAttrText : function( obj ){\r
- var noValue = X.Dom.Attr.noValue,\r
- attrs = [ '' ], n = 0, p, v;\r
- if( !obj ) return ''; // Opera7\r
- for( p in obj ){\r
- v = obj[ p ];\r
- if( p === 'value' ){\r
- v = v.split( '"' ).join( '"' ).split( '>' ).join( '>' ).split( '<' ).join( '<' );\r
- };\r
- attrs[ ++n ] = noValue[ p ] ? p : [ p, '="', v, '"' ].join( '' );\r
- };\r
- return 0 < n ? attrs.join( ' ' ) : '';\r
- }\r
-};\r
-\r
-(function( renameForDOM, renameForTag ){\r
- var name, i;\r
- for( name in renameForDOM ){\r
- renameForTag[ renameForDOM[ name ] ] = name;\r
- };\r
-})( X.Dom.Attr.renameForDOM, X.Dom.Attr.renameForTag );\r
-\r
-\r
-\r
-/* --------------------------------------\r
- * attribute\r
- * X.Dom.Attr.toIndex に定義されている 属性の場合\r
- * \r
- * http://nanto.asablo.jp/blog/2005/10/29/123294\r
- * className, onclick等 はここで設定しない\r
- * \r
- */\r
-X.Dom.Node.prototype.attr = function( nameOrObj /* v */ ){\r
- var attrs = this._attrs, newAttrs, f, p, elm, v;\r
- \r
- if( this._xnodeType !== 1 ) return this;\r
- \r
- if( nameOrObj && X.Type.isObject( nameOrObj ) ){\r
- attrs || ( attrs = this._attrs = {} );\r
- newAttrs = this._newAttrs || ( this._newAttrs = {} );\r
- \r
- for( p in nameOrObj ){\r
- if( this._setAttr( attrs, newAttrs, p, nameOrObj[ p ] ) === true ) f = true;\r
- };\r
- if( f ){\r
- this._attrText = false;\r
- this._dirty |= X.Dom.Dirty.ATTR;\r
- this._root && this._reserveUpdate(); \r
- };\r
- return this;\r
- } else\r
- if( 1 < arguments.length ){\r
- // setter\r
- if( this._setAttr( attrs || ( this._attrs = {} ), this._newAttrs || ( this._newAttrs = {} ), nameOrObj, arguments[ 1 ] ) === true ){\r
- this._attrText = false;\r
- this._dirty |= X.Dom.Dirty.ATTR;\r
- this._root && this._reserveUpdate();\r
- };\r
- return this;\r
- } else\r
- if( typeof nameOrObj === 'string' ){\r
- // getter\r
- switch( nameOrObj ){\r
- case 'id' :\r
- return this._id;\r
- case 'class' :\r
- case 'className' :\r
- return this._className;\r
- case 'tag' :\r
- case 'tagName' :\r
- return this._tag;\r
- case 'style' :\r
- case 'cssText' :\r
- return this.cssText();\r
- case 'value' :\r
- case 'checked' :\r
- case 'selected' :\r
- case 'disabled' : \r
- case 'selectedIndex' :\r
- if( X.Dom.Attr.HAS_VALUE[ this._tag ] ){\r
- if( this._newAttrs && X.inObject( nameOrObj, this._newAttrs ) ) return this._newAttrs[ nameOrObj ];\r
- if( elm = X.Dom.DOM_IE4 ? this._rawObject || this._ie4getRawNode() : this._rawObject ){\r
- if( !attrs ) attrs = this._attrs = {};\r
- return attrs[ nameOrObj ] = elm[ nameOrObj ]; // getAttribute( nameOrObj )?\r
- };\r
- };\r
- break;\r
- };\r
- return attrs && attrs[ X.Dom.Attr.renameForTag[ nameOrObj ] || nameOrObj ];\r
- };\r
-};\r
-X.Dom.Node.prototype._setAttr = function( attrs, newAttrs, name, v ){\r
- switch( name ){\r
- // case 'type' : TODO IE は input, button に対して type の再設定が出来ない _state が要素生成済なら不可\r
- case 'UID' :\r
- case 'tag' :\r
- case 'tagName' :\r
- return;\r
- case 'id' :\r
- v = ( v !== 'ie4uid' + this._uid ) ? v : undefined;\r
- if( v !== this._id ){\r
- this._id = v;\r
- this._dirty |= X.Dom.Dirty.ID;\r
- this._root && this._reserveUpdate();\r
- };\r
- return; \r
- case 'class' :\r
- case 'className' :\r
- return this.className( v );\r
- case 'style' :\r
- case 'cssText' :\r
- return this.cssText( v );\r
- };\r
- // debug\r
- if( name.indexOf( 'on' ) === 0 ){\r
- X.Notification.warn( 'xnode.attr("' + name + '") is wrong, xnode.listen() & xnode.unlisten().' );\r
- return;\r
- };\r
- \r
- name = X.Dom.Attr.renameForTag[ name ] || name;\r
- if( attrs[ name ] === v ) return;\r
- \r
- if( v == null ){\r
- newAttrs[ name ] = undefined;\r
- if( attrs.hasOwnProperty( name ) ) delete attrs[ name ];\r
- } else {\r
- newAttrs[ name ] = attrs[ name ] = v;\r
- };\r
- return true;\r
-};\r
-\r