OSDN Git Service

Version 0.6.221, Update the X.TextRange.
[pettanr/clientJs.git] / 0.6.x / js / 02_dom / 20_XNode.js
index d80b855..bb392e3 100644 (file)
@@ -155,7 +155,8 @@ var Node = X[ 'Node' ] = X_EventDispatcher[ 'inherits' ](
                        var uid = X_Node_CHASHE.length,
                                css, xnodes, xnode, parent;
                        
-                       if( X_Node_newByTag ){
+                       // TODO 継承クラスで this.Super('DIV') ができない! -> サブクラスから呼ばれた場合も
+                       if( X_Node_newByTag || this.constructor !== Node ){
                                X_Node_newByTag = false;
                                this[ '_tag' ]  = v.toUpperCase();
                                arguments[ 1 ] && this[ 'attr' ]( arguments[ 1 ] );
@@ -223,6 +224,7 @@ var Node = X[ 'Node' ] = X_EventDispatcher[ 'inherits' ](
                        X_Node_CHASHE[ this[ '_uid' ] = uid ] = this;
                },
                
+               // TODO .mesure() -> X.Event.MESURED
                'width'          : X_Node_width,
                'height'         : X_Node_height,
                'clientWidth'    : X_Node_clientWidth,
@@ -253,6 +255,8 @@ var Node = X[ 'Node' ] = X_EventDispatcher[ 'inherits' ](
                
                'createTextAt'   : X_Node_createTextAt,
                
+               'createRange'    : X_Node_createRange,
+               
                'clone'          : X_Node_clone,
                
                'append'         : X_Node_append,
@@ -289,7 +293,7 @@ var Node = X[ 'Node' ] = X_EventDispatcher[ 'inherits' ](
                'toggleClass'    : X_Node_toggleClass,
                'hasClass'       : X_Node_hasClass,
                
-               'html'           : X_Node_html,
+               'html'           : X_Node__html,
                'text'           : X_Node_text,
                'call'           : X_Node_call,
                'each'           : X_Node_each
@@ -360,6 +364,7 @@ function X_Node_getType( v ){
        if( X_Type_isString( v ) ){
                return '<' === v.charAt( 0 ) && v.charAt( v.length - 1 ) === '>' ? X_NodeType_HTML_STRING : X_NodeType_STRING;
        };
+       // Node サブクラスのインスタンス
        if( v[ 'instanceOf' ] && v[ 'instanceOf' ]( Node ) ) return X_NodeType_XNODE;
        return 0;
 };
@@ -494,6 +499,15 @@ function X_Node_createTextAt( index, text ){
 };
 
 /**
+ * 選択されたテキストへの参照やテキスト座標情報
+ * @alias Node.prototype.createRange
+ * @return {TextRange} 新規作成されたテキストレンジ
+ */
+function X_Node_createRange( a, b, c ){
+       return X_TextRange( this, a, b, c );
+};
+
+/**
  * Node のクローンを作成し返す。id もクローンされる点に注意。イベントリスナはクローンされない。
  * http://d.hatena.ne.jp/think49/20110724/1311472811
  * http://d.hatena.ne.jp/uupaa/20100508/1273299874
@@ -1103,7 +1117,7 @@ function X_Node_hasClass( v ){
  * @return {string|Node} 
  * @example node.html( '<img>' );
  */
-function X_Node_html( html ){
+function X_Node__html( html ){
        var _ = '', q = '"', xnodes, n, i, l;
        // setter
        if( html !== undefined ){ // String 以外に Number や false null なども許可
@@ -1368,7 +1382,7 @@ function X_Node_reserveUpdate(){
 var X_Node_updateReservedByReleaseGPU = false;
 
 function X_Node_startUpdate( time ){
-       var removal, i, xnodeOrElm, xnodesIEFilterFixAfter, xnode;
+       var removal, i, xnodeOrElm, xnodesIEFilterFixAfter, xnode, active;
        
        if( !X_Node_updateTimerID || X_ViewPort_readyState < X_EVENT_INIT ){
                return;
@@ -1408,17 +1422,24 @@ function X_Node_startUpdate( time ){
                removal.length = 0;
        };
        
-       
-       X_UA[ 'IE5' ] && ( X_elmBody.style.visibility = 'hidden' );
-       
+       // 強制的に再描画を起こす, 但し activeElement からフォーカスが外れるため復帰する
+       // IE5mode win10 で 確認
+       if( X_UA[ 'IE5' ] ){
+               active = document.activeElement;
+               X_elmBody.style.visibility = 'hidden';
+       };
+
        if( X_Node_html[ '_flags' ] & X_Node_BitMask_IS_DIRTY ){
                X_Node__commitUpdate( X_Node_html, X_Node_html[ '_rawObject' ].parentNode, null, X_Node_html[ '_flags' ], 1, xnodesIEFilterFixAfter = [] );
        } else {
                X_Node__commitUpdate( X_Node_head, X_Node_head[ '_rawObject' ].parentNode, null, X_Node_head[ '_flags' ], 1, xnodesIEFilterFixAfter = [] );
                X_Node__commitUpdate( X_Node_body, X_Node_body[ '_rawObject' ].parentNode, null, X_Node_body[ '_flags' ], 1, xnodesIEFilterFixAfter = [] );
        };
-       
-       X_UA[ 'IE5' ] && ( X_elmBody.style.visibility = '' );
+
+       if( X_UA[ 'IE5' ] ){
+               X_elmBody.style.visibility = '';
+               active && active.parentNode && active.focus();
+       };
        
        if( X_Node_updateReservedByReleaseGPU ){
                X_Node_reserveUpdate();
@@ -1508,7 +1529,12 @@ var X_Node__commitUpdate =
                        if( !elm ){
                                if( !that[ '_tag' ] ){
                                        that[ '_flags' ] &= X_Node_BitMask_RESET_DIRTY;
-                                       elm = document.createTextNode( X_String_chrReferanceTo( that[ '_text' ] ) );
+                                       if( X_UA[ 'IE' ] < 8 ){
+                                               // \n -> \r\n に変換しないと pre タグで開業されない  win10ie7(ie11 emu) で確認
+                                               elm = document.createTextNode( X_String_chrReferanceTo( that[ '_text' ] ).split( '\n' ).join( X_String_CRLF ) );
+                                       } else {
+                                               elm = document.createTextNode( X_String_chrReferanceTo( that[ '_text' ] ) );
+                                       };
                                        if( !X_UA[ 'IE' ] ){
                                                elm[ 'UID' ] = that[ '_uid' ];
                                        };
@@ -1784,7 +1810,12 @@ var X_Node__updateRawNode =
 
                        // textNode
                        if( !that[ '_tag' ] ){
-                               elm.data = X_String_chrReferanceTo( that[ '_text' ] );
+                               if( X_UA[ 'IE' ] < 8 ){
+                                       // \n -> \r\n に変換しないと pre タグで開業されない  win10ie7(ie11 emu) で確認
+                                       elm.data = X_String_chrReferanceTo( that[ '_text' ] ).split( '\n' ).join( X_String_CRLF );
+                               } else {
+                                       elm.data = X_String_chrReferanceTo( that[ '_text' ] );
+                               };
                                that[ '_flags' ] &= X_Node_BitMask_RESET_DIRTY;
                                return;
                        };
@@ -1805,7 +1836,7 @@ var X_Node__updateRawNode =
                                                elm.setAttribute( 'class', that[ '_className' ] ) :
                                                ( elm.className = that[ '_className' ] )
                                        ) :
-                                       ( elm.className && elm.removeAttribute( X_UA[ 'IE' ] < 8 ? 'className' : 'class' ) ); // className は ie7-                     
+                                       ( elm.className && elm.removeAttribute( X_UA[ 'IE' ] < 8 ? 'className' : 'class' ) ); // className は ie7-             
                        };
                        
                        // attr