OSDN Git Service

client is version0.4.27, added timer for appendChild, but still clash at ie7-.
[pettanr/pettanr.git] / public / assets / system.js
index f7010b8..448f1e8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * pettanR system.js
- *   version 0.4.26
+ *   version 0.4.27
  *   
  * author:
  *   itozyun
@@ -1782,38 +1782,31 @@ pettanr.premiumSatge = pettanr.view.registerApplication( function(){
                THUMB_PATH = BASE_PATH, // + 'thumbnail/',
                LIMIT_FILESIZE = 1024 * 10; // 10KB
 
-       var ImageGroupIconClass = function( INDEX, file ){
-               var elmIconWrap = elmIconOrigin.cloneNode( true ),
-                       elmIconTitle = pettanr.util.getElementsByClassName( elmIconWrap, 'image-group-item-title' )[ 0 ],
-                       data = pettanr.driver._getAPI().getFileData( file ),
-                       SRC = [ BASE_PATH, data.id, '.', data.ext ].join( ''),
-                       LOW_SRC = data.filesize && data.filesize > LIMIT_FILESIZE ? [ THUMB_PATH, data.id, '.', data.ext ].join( '') : null,
+       var ImageGroupIconClass = function( INDEX, data ){
+               var elmIconWrap     = elmIconOrigin.cloneNode( true ),
+                       elmIconTitle    = pettanr.util.getElementsByClassName( elmIconWrap, 'image-group-item-title' )[ 0 ],
+                       SRC             = [ BASE_PATH, data.id, '.', data.ext ].join( ''),
+                       LOW_SRC         = data.filesize && data.filesize > LIMIT_FILESIZE ? [ THUMB_PATH, data.id, '.', data.ext ].join( '') : null,
                        reversibleImage = null,
-                       onEnterFlag = false,
-                       imgW, imgH;
+                       timer           = null,
+                       onEnterFlag     = false,
+                       instance        = this;
                elmContainer.appendChild( elmIconWrap );
                elmIconWrap.style.left = ( INDEX * itemW ) + 'px';
                elmIconTitle.appendChild( document.createTextNode( data.filesize + 'bytes' ) );
                
-               file.destroy();
-               file = null;
-               
                function onImageLoad( url, _imgW, _imgH ){
-                       if( reversibleImage === null) {
-                               alert( url);
-                               return;
-                       }
-                       data.width = imgW = _imgW || data.width || 64;
-                       data.height = imgH = _imgH || data.height || 64;
-                       elmIconTitle.firstChild.data = imgW + 'x' + imgH;
-                       var zoom = 128 /( imgW > imgH ? imgW : imgH),
-                               MATH_FLOOR = Math.floor
-                               h = MATH_FLOOR( imgH *zoom ),
-                               w = MATH_FLOOR( imgW *zoom );
+                       data.width = _imgW = _imgW || data.width || 64;
+                       data.height = _imgH = _imgH || data.height || 64;
+                       elmIconTitle.firstChild.data = _imgW + 'x' + _imgH;
+                       var zoom = 128 /( _imgW > _imgH ? _imgW : _imgH ),
+                               MATH_FLOOR = Math.floor,
+                               h = MATH_FLOOR( _imgH * zoom ),
+                               w = MATH_FLOOR( _imgW * zoom );
                        reversibleImage.elm.style.cssText = [
-                               'width:', w, 'px;',
-                               'height:', h +'px;',
-                               'margin:', MATH_FLOOR( itemH /2 -h /2 ), 'px ', MATH_FLOOR( itemW /2 -w /2 ), 'px 0'
+                               'width:',  w, 'px;',
+                               'height:', h'px;',
+                               'margin:', MATH_FLOOR( itemH / 2 - h / 2 ), 'px ', MATH_FLOOR( itemW / 2 - w / 2 ), 'px 0'
                        ].join('');
                        reversibleImage.resize( w, h );
                        elmIconWrap.onclick = onClick;
@@ -1823,30 +1816,40 @@ pettanr.premiumSatge = pettanr.view.registerApplication( function(){
                        onUpdateData = data;
                        pettanr.premiumSatge.shutdown();
                }
-               return {
-                       onEnter: function(){
-                               if( onEnterFlag === true || data === null ) return; // data === null : destroyed
-                               reversibleImage = pettanr.image.createReversibleImage( LOW_SRC || SRC, itemW, itemH, onImageLoad );
-                               elmIconWrap.appendChild( reversibleImage.elm );
-                               onEnterFlag = true;
-                       },
-                       destroy: function(){
-                               reversibleImage && reversibleImage.destroy();
-                               // pettanr.util.removeAllChildren( elmIconWrap );
-                               elmContainer.removeChild( elmIconWrap );
-                               elmIconWrap.onclick = null;
-                               reversibleImage = elmIconWrap = elmIconTitle = data  = null;
-                               delete this.destroy;
-                       }
+               
+               function asyncDraw(){
+                       reversibleImage = pettanr.image.createReversibleImage( LOW_SRC || SRC, itemW, itemH, onImageLoad );
+                       elmIconWrap.appendChild( reversibleImage.elm );
+                       onEnterFlag = true;
+                       timer = null;
+               }
+               
+               this.onEnter = function( delay ){
+                       timer = window.setTimeout( asyncDraw, delay );
+                       delete instance.onEnter;
+               }
+               this.destroy = function(){
+                       delete instance.destroy;
+                       timer && window.clearTimeout( timer );
+                       reversibleImage && reversibleImage.destroy();
+                       pettanr.util.removeAllChildren( elmIconWrap );
+                       elmContainer.removeChild( elmIconWrap );
+                       elmIconWrap.onclick = '';
+                       reversibleImage = elmIconWrap = elmIconTitle = data = timer = null;
                }
        }
        
        function onEnterShowImage(){
                var l = ICON_ARRAY.length,
                        _start = -wrapX /itemW -1,
-                       _end = _start + winW /itemW +1;
-               for( var i=0; i<l; ++i){
-                       _start < i && i < _end && ICON_ARRAY[ i ].onEnter();
+                       _end = _start + winW /itemW +1,
+                       _icon;
+               for( var i=0, c = 0; i<l; ++i){
+                       _icon = ICON_ARRAY[ i ];
+                       if( _start < i && i < _end && _icon.onEnter ){
+                               _icon.onEnter( c * 100 );
+                               c++;
+                       }
                }
                onEnterInterval !== null && window.clearTimeout( onEnterInterval );
                onEnterInterval = null;
@@ -1876,10 +1879,13 @@ pettanr.premiumSatge = pettanr.view.registerApplication( function(){
                                id:   artistID,
                                type: pettanr.driver.FILE_TYPE.ARTIST
                        })[ 0 ],
-                       _artistFile = ARTIST_ROOT_FILE.getChildFileByIndex( _index );
+                       _artistFile = ARTIST_ROOT_FILE.getChildFileByIndex( _index ),
+                       _file;
                if( _artistFile !== null ){
                        for(var i=0, l=_artistFile.getChildFileLength(); i<l; ++i ){
-                               ICON_ARRAY.push( new ImageGroupIconClass( i, _artistFile.getChildFileByIndex( i ) ));
+                               _file = _artistFile.getChildFileByIndex( i );
+                               ICON_ARRAY.push( new ImageGroupIconClass( i, pettanr.driver._getAPI().getFileData( _file ) ));
+                               _file.destroy();
                        }
                        elmName.firstChild.data = _artistFile.getName();
                        _artistFile.destroy();
@@ -2009,7 +2015,11 @@ pettanr.textEditor = pettanr.view.registerApplication( function(){
        
        function clickOK(){
                textElement && textElement.text( jqTextarea.val() );
-               onUpdateFunction && onUpdateFunction( textElement );
+               onUpdateFunction ? window.setTimeout( asyncCallback, 50 ) : pettanr.textEditor.shutdown();
+       }
+       
+       function asyncCallback(){
+               onUpdateFunction( textElement );
                pettanr.textEditor.shutdown();
        }
        
@@ -2023,6 +2033,14 @@ pettanr.textEditor = pettanr.view.registerApplication( function(){
                        return false;
                }       
        }
+       function textareaFitHeight(){
+               var rows = 0;
+               while( jqTextarea.height() < textElement.h ){
+                       rows++;
+                       jqTextarea.attr( 'rows', rows );
+               }
+               rows > 1 && jqTextarea.attr( 'rows', --rows );
+       }
        
        /* grobal method */
        // this.rootElement = elmWrap;
@@ -2032,12 +2050,11 @@ pettanr.textEditor = pettanr.view.registerApplication( function(){
        this.MIN_WIDTH   = 320;
        this.MIN_HEIGHT  = 320;
        this.init = function(){
-               instance.jqWrap = jqWrap = $( '#speach-editor-wrapper' ).hide();
+               jqWrap     = $( '#speach-editor-wrapper' ).hide();
                jqTextarea = $( '#speach-editor' ).keydown( keyCancel );
-               jqButton = $( '#speach-edit-complete-button').click( clickOK );
+               jqButton   = $( '#speach-edit-complete-button').click( clickOK );
                delete instance.init;
        }
-       this.jqWrap = null;
        this.onOpen = function( _w, _h, _panelX, _panelY, _textElement, _onUpdateFunction ){
                instance.init && instance.init();
                
@@ -2046,25 +2063,17 @@ pettanr.textEditor = pettanr.view.registerApplication( function(){
                textElement = _textElement;
                onUpdateFunction = _onUpdateFunction || null;
                
-               var h = _textElement.h;
-               
+               jqWrap.show();
                instance.onPaneResize( _w, _h );
                jqTextarea.val( _textElement.text() ).focus();
                
                /*
                 * ie6,7は、textarea { width:100%}でも高さが変わらない。rowsを設定。
                 */
-               pettanr.ua.isIE === true && pettanr.ua.ieVersion <= 7 && setTimeout( function(){
-                       var rows = 0;
-                       while( jqTextarea.height() < h){
-                               rows++;
-                               jqTextarea.attr( 'rows', rows);
-                       }
-                       rows > 1 && jqTextarea.attr( 'rows', rows -1 );
-               }, 0);
+               pettanr.ua.isIE === true && pettanr.ua.ieVersion <= 7 && setTimeout( textareaFitHeight, 0);
        }
        this.onPaneResize = function( _w, _h ){
-               jqWrap.show().css( {
+               jqWrap.css( {
                        left:                   textElement.x + panelX,
                        top:                    textElement.y + panelY,
                        width:                  textElement.w,
@@ -2073,7 +2082,7 @@ pettanr.textEditor = pettanr.view.registerApplication( function(){
        }
        this.onClose = function(){
                jqWrap.hide();
-               textElement = onUpdateFunction = null;          
+               textElement = onUpdateFunction = null;
        }
 });