OSDN Git Service

bug-fix
[pettanr/pettanr.git] / public / assets / system.js
index e0b9406..22c8c97 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * pettanR system.js
- *   version 0.4.19
+ *   version 0.4.20
  *   
  * author:
  *   itozyun
@@ -101,6 +101,18 @@ pettanr.file = ( function(){
                        TREE_ARRAY.push( _tree);
                        return _tree;
                },
+               getFileUID: function( FILEDATAorFILE ){
+                       if( FILEDATAorFILE instanceof FileClass ){
+                               return FILEDATAorFILE.getUID();
+                       }
+                       
+                       var uid = pettanr.util.getIndex( FILEDATA_RESITER, FILEDATAorFILE );
+                       if( uid === -1){
+                               uid = FILEDATA_RESITER.length;
+                               FILEDATA_RESITER.push( FILEDATAorFILE );
+                       }
+                       return uid;
+               },
                getFileDataAccess: function( UIDorFILEorFILEDATA){
                        var _uid, _data, _access;
                        
@@ -120,7 +132,7 @@ pettanr.file = ( function(){
                                if( _access.DATA === _data) return _access;
                        }
                        return null;
-               },              
+               },      
                getFileData: function( UIDorFILEorFILEDATA){
                        var _access = FILE_CONTROLER.getFileDataAccess( UIDorFILEorFILEDATA);
                        return _access !== null ? _access.DATA : null;
@@ -318,27 +330,24 @@ pettanr.file = ( function(){
  * fileの変更、それに付随して追加されたイベントは、TreeClassで管理される。
  * treeがdestryされると、fileのイベントリスナーも全て削除される。
  * 他の tree も data の共通する currentFile に対してのみは、file の変更イベントを受け取って流す.
+ * 
+ * parentData のほうがいい!
  */
        
-       var FileClass = function( tree, parentFile, data ){
-               var uid = pettanr.util.getIndex( FILEDATA_RESITER, data ),
+       var FileClass = function( tree, parentData, data ){
+               var uid = FILE_CONTROLER.getFileUID( data ),
                        instance = this;
                
-               if( uid === -1){
-                       uid = FILEDATA_RESITER.length;
-                       FILEDATA_RESITER.push( data );
-               }
-               
                FILEDATA_ACCESS.push(
                        {
                                TREE:                           tree,
-                               parentFile:                     parentFile,
+                               parentData:                     parentData,
                                DATA:                           data,
                                dispatchFileEvent:      dispatchEvent
                        }
                );
                
-               tree = parentFile = data = null;
+               tree = parentData = data = null;
                
                function dispatchEvent( e ){
                        FILE_CONTROLER.fileEventRellay( uid, e );
@@ -468,17 +477,17 @@ pettanr.file = ( function(){
                        var _access = FILE_CONTROLER.getFileDataAccess( this ),
                                _children = FILE_CONTROLER.getChildren( this );
                        if( typeof _index !== 'number' || _index < 0 || Type.isArray( _children ) === false || _index >= _children.length) return null;
-                       var _file = new FileClass( _access.TREE, this, _children[ _index ]);
+                       var _file = new FileClass( _access.TREE, _access.data, _children[ _index ]);
                        // _file.init();
                        return _file;
                },
                move: function( _newFolder, _newIndex, opt_callback ){
                        var _access = FILE_CONTROLER.getFileDataAccess( this );
-                       _access.TREE.move( _access.parentFile, this.getUID(), _newFolder, _newIndex, opt_callback );
+                       _access.TREE.move( _access.parentData, this.getUID(), _newFolder, _newIndex, opt_callback );
                },
                replace: function( _newIndex, opt_callback ){
                        var _access = FILE_CONTROLER.getFileDataAccess( this );
-                       _access.TREE.replace( _access.parentFile, this.getUID(), _newIndex, opt_callback);
+                       _access.TREE.replace( _access.parentData, this.getUID(), _newIndex, opt_callback);
                },
                /**
                 * サーチ
@@ -517,7 +526,7 @@ pettanr.file = ( function(){
                        FILEDATA_ACCESS.splice( _index, 1 );
                        delete _access.DATA;
                        delete _access.TREE;
-                       delete _access.parentFile;
+                       delete _access.parentData;
                        delete _access.dispatchFileEvent;
                }
        }
@@ -797,18 +806,22 @@ pettanr.finder = ( function(){
                ELM_WRAPPER.onclick = onDownClick;
                function onDownClick(){
                        onDownCallback( index);
+                       return false;
                }
                ELM_EDITOR_BUTTON.onclick = onEditorClick;
                function onEditorClick(){
                        onEditorCallback( file, editorList[ 0 ] );
+                       return false;
                }
                ELM_VIEWER_BUTTON.onclick = onViwerClick;
                function onViwerClick(){
                        onViewerCallback( file, viewerList[ 0 ] );
+                       return false;
                }
                ELM_ACTION_BUTTON.onclick = onActionClick;
                function onActionClick(){
                        onActionCallback( file );
+                       return false;
                }
                function draw(){
                        var _thumb = file.getThumbnail();
@@ -1030,7 +1043,7 @@ pettanr.finder = ( function(){
                        _app.boot( _file );
                }
                function onViwer( _file, _app ){
-                       _app.boot( _file );
+                       _app.bootInOverlay( _file );
                }
                function onAction( _file ){
 
@@ -1229,6 +1242,13 @@ pettanr.driver = ( function(){
                        viewerApplicationList: function( _file ){
                                var _data = FileAPI.getFileData( _file ),
                                        _type = _data !== null ? _data.type : null;
+                                       
+                               if( _data === FILE_DATA_MY_PICTURES_ROOT ){
+                                       return [ pettanr.premiumSatge ];
+                               }
+                               if( _type === pettanr.driver.FILE_TYPE.ARTIST ){
+                                       return [ pettanr.premiumSatge ];
+                               }
                                return [];
                        },
                        editorApplicationList: function( _file ){
@@ -1597,7 +1617,7 @@ pettanr.gallery = pettanr.view.registerApplication( function(){
        this.onClose = function(){
                finder.close();
        }
-       this.onWindowResize = function( _w, _h){
+       this.onPaneResize = function( _w, _h){
                finder.resize( _w, _h - pageHeaderH );
        }
 });
@@ -1611,7 +1631,7 @@ pettanr.backyard = pettanr.view.registerApplication( function(){
        }
        this.onClose = function(){
        }
-       this.onWindowResize = function( _w, _h){
+       this.onPaneResize = function( _w, _h){
        }
 });
 pettanr.backyard.addToLancher();
@@ -1689,29 +1709,49 @@ pettanr.premiumSatge = pettanr.view.registerApplication( function(){
                ARTIST_ROOT_FILE = ARTIST_TREE.getRootFile(),
                instance = this,
                winW, winH,
-               containerW, containerH, wrapX,
-               jqWrap, jqContainer, jqItemOrigin,
-               itemW, itemH,
-               jqName, jqButton, buttonW,
+               wrapX,
+               elmWrap = document.getElementById( 'image-gruop-wrapper' ),
+               elmContainer = document.getElementById( 'image-icon-container' ),
+               containerW,
+               containerH = pettanr.util.getElementSize( elmContainer ).height,                
+               elmIconOrigin = ( function(){
+                       var ret = document.createElement( 'div' ),
+                               data = document.createElement( 'div' );
+                       ret.appendChild( data );
+                       ret.className = 'image-gruop-item';
+                       data.className = 'image-gruop-item-title';
+                       return ret;
+               })(),
+               jqContainer,
+               size = pettanr.util.getElementSize( elmIconOrigin ),
+               itemW = size.width,
+               itemH = size.height,
+               elmName = document.getElementById( 'gruop-name-display' ),
+               elmButton = document.getElementById( 'image-gruop-button' ),
+               buttonW = pettanr.util.getElementSize( elmButton ).width,
                //onUpdateFunction,
                _g_onUpdateFunction,
                onEnterInterval = null;
+
+       elmButton.onclick = clickOK;
        
        var BASE_PATH = pettanr.LOCAL === true ? 'resource_pictures\/' : pettanr.CONST.PETTANR_ROOT_PATH + 'resource_pictures\/',
                THUMB_PATH = BASE_PATH, // + 'thumbnail/',
                LIMIT_FILESIZE = 1024 * 10; // 10KB
 
        var ImageGroupIconClass = function( INDEX, file ){
-               var JQ_ICON_WRAP = jqItemOrigin.clone( true),
+               var elmIconWrap = elmIconOrigin.cloneNode( true ),
+                       elmIconTitle = pettanr.util.getElementsByClassName( elmIconWrap, 'image-gruop-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,
                        reversibleImage = null,
                        onEnterFlag = false,
                        imgW, imgH;
-               JQ_ICON_WRAP.children( 'div').eq( 0 ).html( data.filesize + 'bytes' );
-               jqContainer.append( JQ_ICON_WRAP.css( { left: INDEX * itemW}));
-               
+               elmContainer.appendChild( elmIconWrap );
+               elmIconWrap.style.left = ( INDEX * itemW ) + 'px';
+               elmIconTitle.appendChild( document.createTextNode( data.filesize + 'bytes' ));
+
                function onImageLoad( url, _imgW, _imgH ){
                        if( reversibleImage === null) {
                                alert( url);
@@ -1719,15 +1759,18 @@ pettanr.premiumSatge = pettanr.view.registerApplication( function(){
                        }
                        data.width = imgW = _imgW || data.width || 64;
                        data.height = imgH = _imgH || data.height || 64;
-                       JQ_ICON_WRAP.children( 'div').eq( 1).html( imgW +'x' +imgH);
+                       elmIconTitle.firstChild.data = imgW + 'x' + imgH;
                        var zoom = 128 /( imgW > imgH ? imgW : imgH),
-                               h = Math.floor( imgH *zoom ),
-                               w = Math.floor( imgW *zoom );
-                       reversibleImage.elm.style.width = w +'px';
-                       reversibleImage.elm.style.height = h +'px';
-                       reversibleImage.elm.style.margin = Math.floor( itemH /2 -h /2)+'px 0 0';
-                       reversibleImage.resize( w, h);
-                       JQ_ICON_WRAP.click( onClick );
+                               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'
+                       ].join('');
+                       reversibleImage.resize( w, h );
+                       elmIconWrap.onclick = onClick;
                }
                
                function onClick( e ){
@@ -1759,14 +1802,15 @@ pettanr.premiumSatge = pettanr.view.registerApplication( function(){
                this.onEnter = function(){
                        if( onEnterFlag === true ) return;
                        reversibleImage = pettanr.image.createReversibleImage( LOW_SRC || SRC, itemW, itemH, onImageLoad );
-                       JQ_ICON_WRAP.children( 'img' ).replaceWith( reversibleImage.elm );
-                       onEnterFlag = true;                                             
+                       elmIconWrap.appendChild( reversibleImage.elm );
+                       onEnterFlag = true;
                }
                this.destroy = function(){
                        reversibleImage && reversibleImage.destroy();
-                       JQ_ICON_WRAP.remove();
+                       pettanr.util.removeAllChildren( elmIconWrap );
+                       elmContainer.removeChild( elmIconWrap );
                        file.destroy();
-                       reversibleImage = JQ_ICON_WRAP = data = null;
+                       reversibleImage = elmIconWrap = elmIconTitle = data = file = null;
                        delete this.destroy;
                }
        }
@@ -1801,28 +1845,30 @@ pettanr.premiumSatge = pettanr.view.registerApplication( function(){
        // this.rootElement = elmWrap;
        this.displayName = 'premiumStage';
        this.ID          = 'premiumStage';
-       this.rootElement = document.getElementById( 'image-gruop-wrapper' );
+       this.rootElement = elmWrap;
        this.MIN_WIDTH   = 320;
        this.MIN_HEIGHT  = 320;
        this.init = function(){
-               instance.jqWrap = jqWrap = $( '#image-gruop-wrapper').hide();
-               jqContainer = $( '#image-icon-container').mousewheel( onMouseWheel);
-               containerH = pettanr.util.getElementSize( jqContainer.get( 0)).height;
-               jqItemOrigin = $( $( '#imageGruopItemTemplete').remove().html());
-               var itemSize = pettanr.util.getElementSize( jqItemOrigin.get( 0));
-               itemW = itemSize.width;
-               itemH = itemSize.height;
-               jqName = $( '#gruop-name-display');
-               jqButton = $( '#image-gruop-button').click( clickOK);
-               buttonW = pettanr.util.getElementSize( jqButton.get( 0)).width;
-               
+               jqContainer = $( elmContainer ).mousewheel( onMouseWheel );
                delete instance.init;
        }
-       this.jqWrap = null;
-       this.onOpen = function( _windowW, _windowH, _artistID, _onUpdateFunction ){
+       this.onOpen = function( _windowW, _windowH, _ARTISTIDorFILE, _onUpdateFunction ){
                instance.init && instance.init();
+               
+               var _data, _artistID = -1;
+               
+               if( pettanr.driver.isPettanrFileInstance( _ARTISTIDorFILE ) === true ){
+                       if( _ARTISTIDorFILE.getType() === pettanr.driver.FILE_TYPE.ARTIST ){
+                               _data = pettanr.driver._getAPI().getFileData( _ARTISTIDorFILE );
+                               _artistID = _data !== null ? _data.id || 0 : -1;
+                       }
+               } else
+               if( Type.isNumber( _ARTISTIDorFILE ) === true ){
+                       _artistID = _ARTISTIDorFILE;
+               }
+               
                //onUpdateFunction = _onUpdateFunction;
-               if( _onUpdateFunction){
+               if( _onUpdateFunction ){
                        _g_onUpdateFunction = pettanr.util.createGlobalFunction( _onUpdateFunction);
                } else {
                        _g_onUpdateFunction = null;
@@ -1837,39 +1883,43 @@ pettanr.premiumSatge = pettanr.view.registerApplication( function(){
                if( _artistFile !== null ){
                        for( i=0, l=_artistFile.getChildFileLength(); i<l; ++i ){
                                ICON_ARRAY.push( new ImageGroupIconClass( i, _artistFile.getChildFileByIndex( i ) ));
-                       }                       
+                       }
+                       elmName.firstChild.data = _artistFile.getName() + l;
+                       _artistFile.destroy();
                }
-
+               
                wrapX = 0;
                containerW = l * itemW;
                
                winW = _windowW;
                winH = _windowH;
                var w = winW > containerW ? winW : containerW,
-                       h = _windowH > containerH ? containerH : _windowH;
+                       h = _windowH > containerH ? containerH : _windowH,
+                       MATH_FLOOR = Math.floor;
+               
+               onEnterShowImage();
                
-               jqWrap.show();
                jqContainer.css( {
                        width:          w,
                        height:         0,
                        left:           0,
-                       top:            Math.floor( _windowH /2)
+                       top:            MATH_FLOOR( _windowH /2)
                }).stop().animate( {
                        height:         h,
-                       top:            Math.floor( _windowH /2 -h /2)
+                       top:            MATH_FLOOR( _windowH /2 -h /2)
                });
                
-               jqButton.css( {
-                       left:           Math.floor( winW /2 - buttonW /2),
-                       top:            Math.floor( _windowH /2 + containerH /2 +10)
-               });
-               
-               onEnterShowImage();
+               elmButton.style.cssText = [
+                       'left:', MATH_FLOOR( winW /2 - buttonW /2), 'px;',
+                       'top:', MATH_FLOOR( _windowH /2 + containerH /2 +10), 'px'
+               ].join('');
        }
        this.onPaneResize = function( _windowW, _windowH ){
                var w = _windowW > containerW ? _windowW : containerW,
                        h = _windowH > containerH ? containerH : _windowH,
-                       offsetW = Math.floor( _windowW /2 -winW /2);
+                       MATH_FLOOR = Math.floor,
+                       offsetW = MATH_FLOOR( _windowW /2 -winW /2);
+                       
                winW = _windowW;
                winH = _windowH;
                if( offsetW <= 0){ // smaller
@@ -1878,7 +1928,7 @@ pettanr.premiumSatge = pettanr.view.registerApplication( function(){
                                width:                          w
                        }).animate( {
                                left:                           0,
-                               top:                            Math.floor( _windowH /2 -h /2)
+                               top:                            MATH_FLOOR( _windowH /2 -h /2)
                        });                                     
                } else {
                        jqContainer.css( { // bigger
@@ -1886,22 +1936,20 @@ pettanr.premiumSatge = pettanr.view.registerApplication( function(){
                                width:                          w,
                                borderLeftWidth:        offsetW
                        }).animate( {
-                               top:                            Math.floor( _windowH /2 -h /2),
+                               top:                            MATH_FLOOR( _windowH /2 -h /2),
                                borderLeftWidth:        0
                        });
                }
-               jqButton.css( {
-                       left:           Math.floor( _windowW /2 -buttonW /2),
-                       top:            Math.floor( _windowH /2 +containerH /2 +10)
-               });
+               elmButton.style.cssText = [
+                       'left:', MATH_FLOOR( _windowW /2 -buttonW /2), 'px;',
+                       'top:', MATH_FLOOR( _windowH /2 +containerH /2 +10), 'px'
+               ].join('');
                onEnterShowImage();
        }
        this.onClose = function(){
                jqContainer.stop().animate( {
                                height: 0,
                                top:    Math.floor( winH /2 )
-                       }, function(){
-                               jqWrap.hide();
                        });
                while( ICON_ARRAY.length > 0 ){
                        ICON_ARRAY.shift().destroy();