OSDN Git Service

add enter home button.
[pettanr/pettanr.git] / app / assets / javascripts / peta.apps.js
index f11646b..b531283 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * pettanR peta.apps.js
- *   version 0.5.15
+ *   version 0.5.17
  *   
  * author:
  *   itozyun
@@ -505,7 +505,7 @@ var Cabinet = gOS.registerApplication( function(){
        this.onOpen = function( _w, _h ){
                headerH = Util.getElementSize( document.getElementById( 'cabinet-header' ) ).height;
                
-               self.addMouseEventListener( document.getElementById( 'cabinet-close-button' ), 'click', Cabinet.shutdown );
+               self.addEventListener( document.getElementById( 'cabinet-close-button' ), 'click', Cabinet.shutdown );
                
                finder = self.createFinder( self.rootElement, tree );
                self.onPaneResize( _w, _h );
@@ -550,7 +550,7 @@ var Gallery = gOS.registerApplication( function(){
        this.onOpen = function( _w, _h ){
                headerH = Util.getElementSize( document.getElementById( 'gallery-header' ) ).height;
                
-               self.addMouseEventListener( document.getElementById( 'gallery-close-button' ), 'click', Gallery.shutdown );
+               self.addEventListener( document.getElementById( 'gallery-close-button' ), 'click', Gallery.shutdown );
                
                finder = self.createFinder( self.rootElement, tree );
                self.onPaneResize( _w, _h );
@@ -686,7 +686,7 @@ var PremiumSatge = gOS.registerApplication( function(){
                                'margin:', MATH_FLOOR( itemH / 2 - h / 2 ), 'px ', MATH_FLOOR( itemW / 2 - w / 2 ), 'px 0'
                        ].join('');
                        reversibleImage.resize( w, h );
-                       self.addMouseEventListener( elmIconWrap, 'click', onClick );
+                       self.addEventListener( elmIconWrap, 'click', onClick );
                };
                
                function onClick(){
@@ -817,8 +817,8 @@ var PremiumSatge = gOS.registerApplication( function(){
                
                buttonW       = Util.getElementSize( elmButton ).width;
                
-               self.addMouseEventListener( elmContainer, 'mousewheel', onMouseWheel );
-               self.addMouseEventListener( elmButton, 'click', clickClose );
+               self.addEventListener( elmContainer, 'mousewheel', onMouseWheel );
+               self.addEventListener( elmButton, 'click', clickClose );
                tree.addTreeEventListener( Const.TREE.EVENT.UPDATE, drawIcons );
                
                if( Driver.isPettanrFileInstance( _ARTISTIDorFILE ) === true ){
@@ -925,13 +925,13 @@ var TextEditor = gOS.registerApplication( function(){
        function clickOK(){
                textElement && textElement.text( elmTextarea.value );
                self.addAsyncCall( asyncCallback );
-       }
+       };
        
        function asyncCallback(){
                onUpdate && onUpdate( textElement );
                onUpdate = textElement = null;
                TextEditor.shutdown();
-       }
+       };
        
 
        function textareaFitHeight(){
@@ -939,9 +939,9 @@ var TextEditor = gOS.registerApplication( function(){
                while( elmTextarea.offsetHeight < textElement.h ){
                        rows++;
                        elmTextarea.rows = rows;
-               }
+               };
                if( rows > 1 ) elmTextarea.rows = --rows;
-       }
+       };
        
        /* grobal method */
        
@@ -956,7 +956,7 @@ var TextEditor = gOS.registerApplication( function(){
                elmButton   = document.getElementById( 'speach-edit-complete-button' );
                
                self.addKeyEventListener( 'keydown', new Function( 'return false' ), 69, false, true );
-               self.addMouseEventListener( elmButton, 'click', clickOK );
+               self.addEventListener( elmButton, 'click', clickOK );
                
                panelX = _panelX;
                panelY = _panelY;
@@ -1098,8 +1098,8 @@ var Reader = gOS.registerApplication( function(){
 
                bindWorker = pettanr.bind.createBindWorker( elmContainer, null, false, false );
                
-               self.addMouseEventListener( elmBackButton, 'click', onBackClick );
-               self.addMouseEventListener( elmNextButton, 'click', onNextClick );
+               self.addEventListener( elmBackButton, 'click', onBackClick );
+               self.addEventListener( elmNextButton, 'click', onNextClick );
                
                numPanel = currentIndex = 0;
                
@@ -1286,14 +1286,14 @@ var Editor = gOS.registerApplication( function(){
                                if( this.visible === true ) return;
                                elmRoot.appendChild( this.elm );
                                this.elm.className = ELM_ITEM_CLASSNAME + '-focus';
-                               this.onShow && app.addAsyncCall( this.onShow );
+                               this.onShow && app.addAsyncCall( this.onShow, null, this );
                                this.visible = true;
                        },
                        hide: function(){
                                if( this.visible === false ) return;
                                elmBar.appendChild( this.elm );
                                this.elm.className = ELM_ITEM_CLASSNAME;
-                               this.onHide && app.addAsyncCall( this.onHide );
+                               this.onHide && app.addAsyncCall( this.onHide, null, this );
                                this.visible = false;
                        },
                        createOption: function( title, shortcut, callback, visible, separateBefore, separateAfter ){
@@ -1309,7 +1309,7 @@ var Editor = gOS.registerApplication( function(){
                        },
                        _open: function(){
                                for( var lis = this.optionList, i = lis.length; i; ){
-                                       app.addMouseEventListener( lis[ --i ].elm, 'click', this.onClick );
+                                       app.addEventListener( lis[ --i ].elm, 'click', this.onClick );
                                };
                        },                      
                        _close: function(){
@@ -1449,7 +1449,7 @@ var Editor = gOS.registerApplication( function(){
                        if( stackBack.length === 0 ) return;
 
                        var s = stackBack.pop();
-                       s.fn( s.argBack );
+                       s.fn.apply( {}, s.argBack );
                        menubarBack.visible( stackBack.length !== 0 );
                        SAVE_CONTROL.panelUpdated( stackBack.length !== 0 );
                        
@@ -1460,20 +1460,20 @@ var Editor = gOS.registerApplication( function(){
                        if( stackForward.length === 0 ) return;
                        
                        var s = stackForward.pop();
-                       s.fn( s.argForword );
+                       s.fn.apply( {}, s.argForword );
                        menubarForward.visible( stackForward.length !== 0 );
                        
                        stackBack.push( s );
                        menubarBack.visible( true );
                        SAVE_CONTROL.panelUpdated( true );
                };
-               var StackClass = function( _function, _argBack, _argForword, _destroy ){
+               var RecordClass = function( _function, _argBack, _argForword, _destroy ){
                        this.fn         = _function;
                        this.argBack    = _argBack;
                        this.argForword = _argForword;
                        this.destroy    = _destroy;
                };
-               StackClass.prototype.kill = function( _callDestroy ){
+               RecordClass.prototype.kill = function( _callDestroy ){
                        var     _argBack    = this.argBack,
                                _argForword = this.argForword,
                                v;
@@ -1513,8 +1513,8 @@ var Editor = gOS.registerApplication( function(){
                        while( s = stackForward.shift() ) s.kill( true );
                        menubarBack = menubarForward = stackBack = stackForward = null;
                        },
-                   saveState: function( _function, _argBack, _argForword, _destroy ){
-                       stackBack.push( new StackClass( _function, _argBack, _argForword, _destroy ));
+                   saveState: function( _function, _argBack, _argForword, _onRecordDestroy ){
+                       stackBack.push( new RecordClass( _function, _argBack, _argForword, _onRecordDestroy ));
                        menubarBack.visible( true );
                                SAVE_CONTROL.panelUpdated( true );
                                
@@ -1729,7 +1729,7 @@ var Editor = gOS.registerApplication( function(){
                        };
                        this.onFadeOut = function(){
                                self.elm.parentNode.removeChild( self.elm );
-                               self.onClose &&  app.addAsyncCall( self.onClose );
+                               self.onClose && app.addAsyncCall( self.onClose, null, self );
                        };
                        this.close = function(){
                                if( visible === false) return;
@@ -1948,11 +1948,11 @@ var Editor = gOS.registerApplication( function(){
                                        delete TOOL_BOX_WINDOW.onInit;
                                },
                                onFirstOpen: function(){
-                                       app.addMouseEventListener( document.getElementById( 'toolbox-add-image-button'), 'click', addImage );
-                                       app.addMouseEventListener( document.getElementById( 'toolbox-add-text-button'), 'click', addText );
-                                       app.addMouseEventListener( document.getElementById( 'toolbox-edit-bg-button'), 'click', editBG );
-                                       app.addMouseEventListener( document.getElementById( 'toolbox-switch-grid'), 'click', switchGrid );
-                                       app.addMouseEventListener( document.getElementById( 'toolbox-popup-help-button'), 'click', popupHelp );
+                                       app.addEventListener( document.getElementById( 'toolbox-add-image-button'), 'click', addImage );
+                                       app.addEventListener( document.getElementById( 'toolbox-add-text-button'), 'click', addText );
+                                       app.addEventListener( document.getElementById( 'toolbox-edit-bg-button'), 'click', editBG );
+                                       app.addEventListener( document.getElementById( 'toolbox-switch-grid'), 'click', switchGrid );
+                                       app.addEventListener( document.getElementById( 'toolbox-popup-help-button'), 'click', popupHelp );
                                        
                                        // postButton = $( '#toolbox-post-button');
                                        
@@ -2199,13 +2199,13 @@ var Editor = gOS.registerApplication( function(){
                function jumpPage( _index ){
                        if( Type.isNumber( _index ) === true && 0 <= _index && _index < numPage && currentPageIndex !== _index ){
                                currentPageIndex = _index;
-                       }
-                       jqNaviItems.removeClass( 'current' ).eq( currentPageIndex).addClass( 'current' );
+                       };
+                       jqNaviItems.removeClass( 'current' ).eq( currentPageIndex ).addClass( 'current' );
                        jqPages.hide().eq( currentPageIndex ).show();
                }
                function onNaviClick( e ){
                        // this は <a>
-                       jumpPage( Util.getChildIndex( this.parentNode, this ));
+                       jumpPage( Util.getChildIndex( this.parentNode, this ) );
                        return false;
                }
                function onInnerLinkClick( e ){
@@ -2339,10 +2339,10 @@ var Editor = gOS.registerApplication( function(){
                        panelX, panelY, panelW, panelH,
                        offsetY, startY, startH,
                        isDragging = false;
-                       
-               function restoreState( arg ){
-                       if( arg && arg.length > 3){
-                               PANEL_CONTROL.resize( isTop, arg[ 0 ] || panelX, arg[ 1 ] || panelY, arg[ 2 ] || panelW, arg[ 3 ] || panelH );
+               /* history */
+               function restoreState( x, y, w, h ){
+                       if( arguments.length > 3){
+                               PANEL_CONTROL.resize( isTop, x || panelX, y || panelY, w || panelW, h || panelH );
                        };
                };
                        
@@ -2538,27 +2538,27 @@ var Editor = gOS.registerApplication( function(){
                };
                function layerBack(){
                        if( currentElement === null) return;
-                       if( PANEL_ELEMENT_CONTROL.replace( currentElement, false) === false ) return;
+                       if( PANEL_ELEMENT_CONTROL.replace( currentElement, false ) === false ) return;
                        INFOMATION_WINDOW.update( currentElement );
-                       HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.restoreReplace, [ currentElement, true ], [ currentElement, false ]);
+                       HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.resplace, [ currentElement, true ], [ currentElement, false ] );
                        var _z = currentElement.z;
                        LAYER_BACK_BUTTON.visible( _z > 0 );
                        LAYER_FORWARD_BUTTON.visible( _z < PANEL_ELEMENT_ARRAY.length -1 );
                };
                function layerForward(){
                        if( currentElement === null) return;
-                       if( PANEL_ELEMENT_CONTROL.replace( currentElement, true) === false) return;
+                       if( PANEL_ELEMENT_CONTROL.replace( currentElement, true ) === false) return;
                        INFOMATION_WINDOW.update( currentElement);
-                       HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.restoreReplace, [ currentElement, false], [ currentElement, true]);
+                       HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.replace, [ currentElement, false], [ currentElement, true ] );
                        var _z = currentElement.z;
-                       LAYER_BACK_BUTTON.visible( _z > 0);
+                       LAYER_BACK_BUTTON.visible( _z > 0 );
                        LAYER_FORWARD_BUTTON.visible( _z < PANEL_ELEMENT_ARRAY.length -1);
                };
                function del(){
                        if( currentElement === null) return;
-                       buttonBackOrForward( true);
-                       PANEL_ELEMENT_CONTROL.remove( currentElement);
-                       HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.restore, [ true, currentElement], [ false, currentElement], true);
+                       buttonBackOrForward( true );
+                       HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.restore, [ true, currentElement ], [ false, currentElement ], false ); // true
+                       PANEL_ELEMENT_CONTROL.remove( currentElement );
                        PANEL_ELEMENT_OPERATION_MANAGER.hide();
                };
                function edit(){
@@ -2568,7 +2568,7 @@ var Editor = gOS.registerApplication( function(){
                };
                function change(){
                        if( currentElement === null) return;
-                       buttonBackOrForward( true);
+                       buttonBackOrForward( true );
                        PremiumSatge.boot( currentElement.getArtistID(), currentElement.resourcePicture );
                };
                function onImageSelect( resourcePicture ){
@@ -2605,14 +2605,14 @@ var Editor = gOS.registerApplication( function(){
                                elmConsoleParent    = elmConsoleWrapper.parentNode;
                                styleConsoleWrapper.display = 'none';
                                
-                               app.addMouseEventListener( document.getElementById( 'edit-text-button' ),     'click', edit );
-                               app.addMouseEventListener( document.getElementById( 'delete-image-button' ),  'click', del );
-                               app.addMouseEventListener( document.getElementById( 'delete-text-button' ),   'click', del );
-                               app.addMouseEventListener( document.getElementById( 'change-image-button' ),  'click', change );
-                               app.addMouseEventListener( document.getElementById( 'layer-forward-button' ), 'click', layerForward );
-                               app.addMouseEventListener( document.getElementById( 'forward-text-button' ),  'click', layerForward );
-                               app.addMouseEventListener( document.getElementById( 'layer-back-button' ),    'click', layerBack );
-                               app.addMouseEventListener( document.getElementById( 'back-text-button' ),     'click', layerBack );
+                               app.addEventListener( document.getElementById( 'edit-text-button' ),     'click', edit );
+                               app.addEventListener( document.getElementById( 'delete-image-button' ),  'click', del );
+                               app.addEventListener( document.getElementById( 'delete-text-button' ),   'click', del );
+                               app.addEventListener( document.getElementById( 'change-image-button' ),  'click', change );
+                               app.addEventListener( document.getElementById( 'layer-forward-button' ), 'click', layerForward );
+                               app.addEventListener( document.getElementById( 'forward-text-button' ),  'click', layerForward );
+                               app.addEventListener( document.getElementById( 'layer-back-button' ),    'click', layerBack );
+                               app.addEventListener( document.getElementById( 'back-text-button' ),     'click', layerBack );
                                                                                        
                                delete CONSOLE_CONTROLER.init;
                        },
@@ -3050,14 +3050,14 @@ var Editor = gOS.registerApplication( function(){
                        },
                        onFinish: function(){
                                updateMouseCursor( '');
-                               if( w === startW && h === startH && x === startX && y === startY) return;
-                               PANEL_ELEMENT_OPERATION_MANAGER.resize( x, y, w, h);
+                               if( w === startW && h === startH && x === startX && y === startY ) return;
+                               PANEL_ELEMENT_OPERATION_MANAGER.resize( x, y, w, h );
                                currentElement.resize( x, y, w, h);
-                               PANEL_ELEMENT_OPERATION_MANAGER.saveStatus( startX, startY, startW, startH, undefined, startFilpV, startFilpH);
+                               PANEL_ELEMENT_OPERATION_MANAGER.saveStatus( startX, startY, startW, startH, undefined, startFilpV, startFilpH );
                        },
                        onCancel: function(){
                                updateMouseCursor( '');
-                               PANEL_ELEMENT_OPERATION_MANAGER.resize( startX, startY, startW, startH);
+                               PANEL_ELEMENT_OPERATION_MANAGER.resize( startX, startY, startW, startH );
                                currentElement.type === PANEL_ELEMENT_TYPE_IMAGE ?
                                        currentElement.animate( startX, startY, startW, startH, startFilpV, startFilpH) :
                                        currentElement.animate( startX, startY, startW, startH, angle);
@@ -3135,18 +3135,6 @@ var Editor = gOS.registerApplication( function(){
                        currentElement       = null,
                        currentX, currentY, currentW, currentH, angle, flipV, flipH;
 
-                       function resize( _x, _y, _w, _h, _angle ){
-                               currentX = _x = _x !== undefined ? _x : currentX;
-                               currentY = _y = _y !== undefined ? _y : currentY;
-                               currentW = _w = _w !== undefined ? _w : currentW;
-                               currentH = _h = _h !== undefined ? _h : currentH;
-                               angle = _angle = _angle !== undefined ? _angle : angle;
-
-                               RESIZE_OPERATOR.update( _x, _y, _w, _h );
-                               currentIsTextElement === true && TAIL_OPERATOR.update( _w, _h, angle );
-                               CONSOLE_CONTROLER.show( currentElement, _w, _h );
-                               INFOMATION_WINDOW.update( currentElement );
-                       };
                        function show( _currentElement ){
                                currentElement === null && RESIZE_OPERATOR.show( _currentElement );
                                if( currentElement !== _currentElement ){
@@ -3158,7 +3146,7 @@ var Editor = gOS.registerApplication( function(){
                                        flipV = currentIsTextElement === false ? _currentElement.flipV() : 0;
                                        flipH = currentIsTextElement === false ? _currentElement.flipH() : 0;
                                        
-                                       resize(
+                                       PANEL_ELEMENT_OPERATION_MANAGER.resize(
                                                _currentElement.x, _currentElement.y, _currentElement.w, _currentElement.h,
                                                currentIsTextElement === true ? _currentElement.angle() : 0
                                        );
@@ -3203,20 +3191,28 @@ var Editor = gOS.registerApplication( function(){
                                CONSOLE_CONTROLER.hide();
                                INFOMATION_WINDOW.update( null );
                        },
-                       resize: resize,
-                       restoreState: function( arg ){
-                               if( arg && arg.length !== 8 ) return;
-                               var _currentElement = arg[ 0 ],
-                                       _x = arg[ 1 ], _y = arg[ 2 ], _w = arg[ 3 ], _h = arg[ 4 ],
-                                       _a = arg[ 5 ],
-                                       _flipV = arg[ 6 ], _flipH = arg[ 7 ];
+                       resize: function( _x, _y, _w, _h, _angle ){
+                               currentX = _x = _x !== undefined ? _x : currentX;
+                               currentY = _y = _y !== undefined ? _y : currentY;
+                               currentW = _w = _w !== undefined ? _w : currentW;
+                               currentH = _h = _h !== undefined ? _h : currentH;
+                               angle = _angle = _angle !== undefined ? _angle : angle;
+
+                               RESIZE_OPERATOR.update( _x, _y, _w, _h );
+                               currentIsTextElement === true && TAIL_OPERATOR.update( _w, _h, angle );
+                               CONSOLE_CONTROLER.show( currentElement, _w, _h );
+                               INFOMATION_WINDOW.update( currentElement );
+                       },
+                       /* history */
+                       restoreState: function( _currentElement, _x, _y, _w, _h, _a, _flipV, _flipH ){
+                               if( arguments.length !== 8 ) return;
                                if( !_currentElement && !currentOperator ) return;
                                _currentElement.type === PANEL_ELEMENT_TYPE_IMAGE ?
                                        _currentElement.animate( _x, _y, _w, _h, _flipV, _flipH ) :
                                        _currentElement.animate( _x, _y, _w, _h, _a );
                                currentOperator !== null && currentOperator.onCancel && currentOperator.onCancel();
                                currentOperator = null;
-                               currentElement === _currentElement ? resize( _x, _y, _w, _h, _a ) : show( _currentElement );
+                               currentElement === _currentElement ? PANEL_ELEMENT_OPERATION_MANAGER.resize( _x, _y, _w, _h, _a ) : show( _currentElement );
                        },
                        saveStatus: function( startX, startY, startW, startH, startA, startFilpV, startFilpH ){
                                startX = startX !== undefined ? startX : currentX;
@@ -3327,6 +3323,7 @@ var Editor = gOS.registerApplication( function(){
                function flipReversibleImage(){
                        reversibleImage && reversibleImage.resize( flipH * w, flipV * h );
                };
+               /* history */
                function updateResourcePicture( _resourcePicture ){
                        resourcePicture = _resourcePicture;
                        
@@ -3460,6 +3457,7 @@ var Editor = gOS.registerApplication( function(){
                                balloon.angle( a );
                        }
                }
+               /* history */
                function updateText( _text ){
                        text = _text || text || '';
                        elmText.firstChild.data = text;
@@ -3622,14 +3620,13 @@ var Editor = gOS.registerApplication( function(){
                                                        filter:         '',
                                                        opacity:        ''
                                                }).fadeOut( onFadeOut );
-                                               currentElement = currentElement === _panelElement ? null : currentElement;
+                                               if( currentElement === _panelElement ) currentElement = null;
                                                return;
                                        };
                                };
                        },
-                       restore: function( arg ){
-                               var isAppend = arg[ 0 ],
-                                       panelElement = arg[ 1 ];
+                       /* history */
+                       restore: function( isAppend, panelElement ){
                                isAppend === true ? appendPanelElement( panelElement ) :  PANEL_ELEMENT_CONTROL.remove( panelElement );
                        },
                        replace: function( _panelElement, goForward ){
@@ -3655,14 +3652,11 @@ var Editor = gOS.registerApplication( function(){
                                renumber( true );
                                return true;
                        },
-                       restoreReplace: function( arg ){
-                               PANEL_ELEMENT_CONTROL.replace( arg[ 0 ], arg[ 1 ] );
-                       },
                        onPanelResize : function ( _panelX, _panelY, _panelW, _panelH, isResizerTopAction ){
                        /*
                         * リサイズが、ResizerTopによって行われた場合、panelElementのyを動かして見かけ上動かないようにする。
                         */                                     
-                               if( isResizerTopAction === true){
+                               if( isResizerTopAction === true ){
                                        var     _shiftX = _panelW - panelW,
                                                _shiftY = _panelH - panelH;
                                        for( var i = PANEL_ELEMENT_ARRAY.length; i; ){
@@ -3787,14 +3781,14 @@ var Editor = gOS.registerApplication( function(){
        function updateMouseCursor( _cursor ){
                if( currentCursor !== _cursor ){
                        currentCursor = _cursor;
-                       self.addAsyncCall( update );
+                       app.addAsyncCall( update );
                };
                function update(){
                        elmMouseEventChatcher.style.cursor = currentCursor;
                };
        };
        function centering(){
-               self.onPaneResize( windowW, windowH );
+               app.onPaneResize( windowW, windowH );
        };
        function mouseEventRellay( e ){
                var _mouseX = e.clientX,
@@ -4072,10 +4066,10 @@ var Editor = gOS.registerApplication( function(){
         * マウスイベントをcurrentElement(currentElement)に伝えるのが仕事
         * このような実装になるのは、ここの表示オブジェクトにイベントを設定した場合、表示が追いつかずマウスカーソルが外れたタイミングでイベントが終わってしまうため。
         */
-               self.addMouseEventListener( elmMouseEventChatcher, 'mousemove', mouseEventRellay );
-               self.addMouseEventListener( elmMouseEventChatcher, 'mousedown', mouseEventRellay );
-               self.addMouseEventListener( elmMouseEventChatcher, 'mouseup',   mouseEventRellay );
-               //self.addMouseEventListener( elmMouseEventChatcher, 'mouseout',  mouseEventRellay );
+               self.addEventListener( elmMouseEventChatcher, 'mousemove', mouseEventRellay );
+               self.addEventListener( elmMouseEventChatcher, 'mousedown', mouseEventRellay );
+               self.addEventListener( elmMouseEventChatcher, 'mouseup',   mouseEventRellay );
+               //self.addEventListener( elmMouseEventChatcher, 'mouseout',  mouseEventRellay );
                
                phase   = 1;