OSDN Git Service

Version 0.6.172, bugfix...
[pettanr/clientJs.git] / 0.6.x / js / 02_dom / 20_XNode.js
index aad360f..b7f8ce9 100644 (file)
@@ -1174,10 +1174,20 @@ function X_Node_text( text ){
  * @example node.call( 'focus' );
  */
 function X_Node_call( name /*, opt_args... */ ){
-       var l = arguments.length - 1,
-               v, raw, func, args, params, i;
+       var args = arguments,
+               l    = args.length - 1,
+               v, raw, parent, body,
+               childX, childY, childW, childH,
+               parentW, parentH,
+               parentSX, parentSY, parentSW, parentSH,
+               visibleX, visibleY, visibleW, visibleH,
+               visiblePartX, visiblePartY, func, args, params, i;
 
        switch( name ){
+               case 'isSVG' :
+                       return !!( this[ '_flags' ] & X_NodeFlags_IS_SVG );
+               case 'isVML' :
+                       return !!( this[ '_flags' ] & X_NodeFlags_IS_VML );
                case 'nodeType' :
                        return this[ '_tag' ] ? 1 : 3;
                case 'outerHTML' :
@@ -1196,28 +1206,79 @@ function X_Node_call( name /*, opt_args... */ ){
        X_Node_updateTimerID && X_Node_startUpdate();
        
        raw  = this[ '_rawObject' ] || X_UA_DOM.IE4 && X_Node__ie4getRawNode( this );
+       
        if( !raw ) return;
        
        if( name === 'scrollTo' ){
-               raw.scrollLeft = arguments[ 1 ] || 0;
-               raw.scrollTop  = arguments[ 2 ] || 0;
+               raw.scrollLeft = args[ 1 ] || 0;
+               raw.scrollTop  = args[ 2 ] || 0;
                return;
        };
        
+       if( name === 'inView' ){
+               body   = document.body;
+               child  = raw;
+               visibleX = visibleY = visibleW = visibleH = 0;
+               while( child !== body ){
+                       parent   = child.parentNode || child.parentElement;
+                       parentH  = parent.clientHeight;
+                       parentW  = parent.clientWidth;
+                       parentSW = parent.scrollHeight;
+                       parentSH = parent.scrollWidth;
+                       // 親がスクロール領域を持つ
+                       if( parentH < parentSH || parentW < parentSW ){
+                               childX   = child.offsetLeft + visibleX;
+                               childY   = child.offsetTop  + visibleY;
+                               childW   = visibleW || child.offsetWidth;
+                               childH   = visibleH || child.offsetHeight;
+                               parentSX = parent.scrollLeft;
+                               parentSY = parent.scrollTop;
+                               // 子が表示領域内
+                               if( parentSY < childY   + childH &&
+                           childY   < parentSY + parentH &&
+                           parentSX < childX   + childW  &&
+                           childX   < parentSX + parentW ){
+                               
+                           // right:子の左側が見えている left:子の左側が見えている both:完全に見えている
+                                       visiblePartX =
+                                               childX < parentSX ? 'right' :
+                                               ( parentSX + parentW ) < ( childX + childW ) ? 'left' : 'both';
+                                       visiblePartY = 
+                                               childY < parentSY ? 'bottom' :
+                                               ( parentSY + parentH ) < ( childY + childH ) ? 'top' : 'both';
+
+                                       // 子が見える領域
+                                       visibleX = visiblePartX === 'right'  ? 0 : childX - parentSX;
+                                       visibleY = visiblePartX === 'bottom' ? 0 : childY - parentSY;
+                                       visibleW =
+                                               visiblePartX === 'both'   ? childW :
+                                               visiblePartX === 'right'  ? ( parentSX + parentW - childX ) : ( childX + childW - parentSX );
+                                       visibleH =
+                                               visiblePartY === 'both'   ? childH :
+                                               visiblePartY === 'bottom' ? ( parentSY + parentH - childY ) : ( childY + childH - parentSY );           
+                   } else {
+                       return { 'isInView' : false };
+                   };
+                       };
+                       child = parent;         
+               };
+               return { 'isInView' : true };
+       };
+       
        func = raw[ name ];
        if( X_Type_isFunction( func ) ){
                if( l ){
-                       args = X_Array_copy( arguments );
+                       args = X_Array_copy( args );
                        args.shift();
                        return func.apply( raw, args );
                };
                return raw[ name ]();           
        } else
-       if( X_Type_isUnknown( func ) || ( X_UA[ 'IE' ] < 9 && X_Type_isObject( func ) ) ){
+       if( X_UA[ 'IE' ] < 9 && ( X_Type_isUnknown( func ) || X_Type_isObject( func ) ) ){
                // typeof func === unknown に対策
                // http://la.ma.la/blog/diary_200509031529.htm          
                if( l ){
-                       args = X_Array_copy( arguments );
+                       args = X_Array_copy( args );
                        args.shift();
                        
                params = [];
@@ -1412,7 +1473,7 @@ var X_Node__commitUpdate =
                                                        '>' ].join( '' ) );
                                } else {
                                        if( that[ '_flags' ] & X_NodeFlags_IS_SVG ){
-                                               that[ '_rawObject' ] = elm = document.createElementNS( 'http://www.w3.org/2000/svg', that[ '_tag' ] );
+                                               that[ '_rawObject' ] = elm = document.createElementNS( 'http://www.w3.org/2000/svg', that[ '_tag' ].toLowerCase() );
                                        } else {
                                                that[ '_rawObject' ] = elm = document.createElement( that[ '_tag' ] );
                                        };
@@ -1619,11 +1680,21 @@ var X_Node__updateRawNode =
                        };
                        // id
                        if( that[ '_flags' ] & X_NodeFlags_DIRTY_ID ){
-                               that[ '_id' ] ? ( elm.id = that[ '_id' ] ) : ( elm.id && elm.removeAttribute( 'id' ) );         
+                               that[ '_id' ] ?
+                                       ( ( that[ '_flags' ] & X_NodeFlags_IS_SVG ) ?
+                                               elm.setAttribute( 'id', that[ '_id' ] ) :
+                                               ( elm.id = that[ '_id' ] )
+                                       ) :
+                                       ( elm.id && elm.removeAttribute( 'id' ) );              
                        };
                        // className
                        if( that[ '_flags' ] & X_NodeFlags_DIRTY_CLASSNAME ){
-                               that[ '_className' ] ? ( elm.className = that[ '_className' ] ) : ( elm.className && elm.removeAttribute( X_UA[ 'IE' ] < 8 ? 'className' : 'class' ) ); // className は ie7-                   
+                               that[ '_className' ] ?
+                                       ( ( that[ '_flags' ] & X_NodeFlags_IS_SVG ) ?
+                                               elm.setAttribute( 'class', that[ '_className' ] ) :
+                                               ( elm.className = that[ '_className' ] )
+                                       ) :
+                                       ( elm.className && elm.removeAttribute( X_UA[ 'IE' ] < 8 ? 'className' : 'class' ) ); // className は ie7-                     
                        };
                        
                        // attr
@@ -1665,7 +1736,10 @@ var X_Node__updateRawNode =
                                        // TODO IE では input, なぜか button, object も type, name の変更が出来ない、同値で置き換えようとしても不可
                                        v === undefined ?
                                                elm.removeAttribute( rename[ k ] || k ) :
-                                               ( elm[ rename[ k ] || k ] = X_Node_Attr_noValue[ k ] ? k : v );
+                                       ( ( that[ '_flags' ] & X_NodeFlags_IS_SVG ) ?
+                                               elm.setAttribute( k, v ) :
+                                               ( elm[ rename[ k ] || k ] = X_Node_Attr_noValue[ k ] ? k : v )
+                                       );
                                };
                                delete that[ '_newAttrs' ];
                        };