From 75a2db7eb468f6df4338f8a7545f4c7dbc19b841 Mon Sep 17 00:00:00 2001 From: itozyun Date: Tue, 2 Oct 2012 09:04:33 +0900 Subject: [PATCH] add enter home button. --- Gemfile.lock | 2 +- app/assets/javascripts/peta.apps.js | 176 +++++++++++---------- app/assets/javascripts/pongame.js | 6 +- app/assets/javascripts/system.js | 270 +++++++++++++++++++++++++++------ app/views/layouts/application.html.erb | 3 +- 5 files changed, 316 insertions(+), 141 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e1009875..ed342776 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -79,7 +79,7 @@ GEM multi_json (~> 1.0) factory_girl (4.0.0) activesupport (>= 3.0.0) - ffi (1.1.5) + ffi (1.1.5-x86-mingw32) gherkin (2.11.2-x86-mingw32) json (>= 1.4.6) hike (1.2.1) diff --git a/app/assets/javascripts/peta.apps.js b/app/assets/javascripts/peta.apps.js index f11646bb..b531283f 100644 --- a/app/assets/javascripts/peta.apps.js +++ b/app/assets/javascripts/peta.apps.js @@ -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 は - 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; diff --git a/app/assets/javascripts/pongame.js b/app/assets/javascripts/pongame.js index 60b4e0bf..c2b27b90 100644 --- a/app/assets/javascripts/pongame.js +++ b/app/assets/javascripts/pongame.js @@ -69,7 +69,7 @@ // Attach a function to onmousemove event of the box // box.onmousemove = MovePaddle; - self.addMouseEventListener( box, 'mousemove', MovePaddle ); + self.addEventListener( box, 'mousemove', MovePaddle ); // Call 'GameLoop()' function every 10 milliseconds //iID = setInterval( GameLoop , 10 ); @@ -191,8 +191,8 @@ Init(); self.onPaneResize( _w, _h ); - self.addMouseEventListener( paddle1, 'click', Start ); - self.addMouseEventListener( close, 'click', self.close ); + self.addEventListener( paddle1, 'click', Start ); + self.addEventListener( close, 'click', self.close ); }; this.onPaneResize = function( _w, _h ){ var h = Util.getElementSize( self.rootElement ).height; diff --git a/app/assets/javascripts/system.js b/app/assets/javascripts/system.js index adb6ac04..995ce3d4 100644 --- a/app/assets/javascripts/system.js +++ b/app/assets/javascripts/system.js @@ -1,6 +1,6 @@ /* * pettanR system.js - * version 0.5.16 + * version 0.5.18 * * * Type @@ -55,7 +55,7 @@ return false; } var r; - if(v && v.nodeType === 1){ + if(v && v.nodeType === 1 ){ try{ r = v.cloneNode(false); } catch(n) { @@ -207,7 +207,7 @@ } document.createStyleSheet().cssText = "v\:shape,v\:image{behavior:url(#default#VML);display:block;};"; } - } + }; })(); @@ -295,6 +295,25 @@ }; }, 0 ); + function clone( src ) { + var ret; + if( Type.isArray(src) === true ){ + ret = []; + } else + if( Type.isObject(src) === true ){ + ret = {}; + } else + if( Type.isNumber(src) === true || Type.isString(src) === true || Type.isBoolean( src ) === true ){ + return src; + } else { + return null; + }; + for( var key in src ){ + ret[ key ] = clone( src[ key ]); + }; + return ret; + }; + return { parse: function( v ){ if( Type.isString( v ) === true ){ @@ -322,7 +341,10 @@ }; }; return baseInstance; - }, + }, + copy: function( objOrArray ){ + return clone( objOrArray ); + }, cleanCommnetNode: function ( _targetElm ){ search( _targetElm || body ); @@ -1718,21 +1740,23 @@ var SystemTimer = ( function(){ var AsyncCall = ( function(){ var CALLBACK_LIST = []; - var CallbackTicketClass = function( _apiuser, _callback, _argments ){ - this.apiuser = _apiuser; - this.callback = _callback; - this.argments = _argments; - _apiuser = _callback = _argments = null; - } + var CallbackTicketClass = function( _apiuser, _callback, _argments, _thisObject ){ + this.apiuser = _apiuser; + this.callback = _callback; + this.argments = _argments; + this.thisObject = _thisObject; + }; CallbackTicketClass.prototype = new TicketBase(); CallbackTicketClass.prototype.call = function(){ var f = this.callback, - a = this.argments; + a = this.argments, + t = this.thisObject; + this.destroy(); if( Type.isArray( a ) === true ){ - f.apply( this.apiuser, a ); + f.apply( t, a ); } else { - f( a ); - } + f.call( t, a ); + }; }; CallbackTicketClass.prototype.destroy = function( _apiuser, _callback ){ if( _apiuser && _apiuser !== this.apiuser ) return false; @@ -1746,15 +1770,14 @@ var AsyncCall = ( function(){ var _ticket = CALLBACK_LIST.shift(); if( _ticket ){ _ticket.call(); - _ticket.destroy(); CALLBACK_LIST.length !== 0 && SystemTimer.add( SUPER_USER_KEY, dispatch, 1, true ); - } - } + }; + }; return { - add: function( _apiuser, _callback, _argments ){ + add: function( _apiuser, _callback, _argments, _thisObject ){ CALLBACK_LIST.length === 0 && SystemTimer.add( SUPER_USER_KEY, dispatch, 1, true ); - CALLBACK_LIST.push( new CallbackTicketClass( _apiuser, _callback, _argments ) ); + CALLBACK_LIST.push( new CallbackTicketClass( _apiuser, _callback, _argments, _thisObject || _apiuser ) ); }, remove: function( _apiuser, _callback ){ var _ticket, @@ -1764,10 +1787,10 @@ var AsyncCall = ( function(){ CALLBACK_LIST.splice( i, 1 ); } else { ++i; - } - } + }; + }; } - } + }; })(); /* ----------------------------------------------------------- @@ -1832,20 +1855,20 @@ var File = ( function(){ success: onSuccess, error: onError }); - } + }; function onSuccess( _data ){ currentTicket.load( _data ); currentTicket.kill(); currentTicket = null; request(); - } + }; function onError(){ ++numError; currentTicket.error(); currentTicket.kill(); // retry currentTicket = null; request(); - } + }; return { getNumTask: function(){ @@ -1858,7 +1881,7 @@ var File = ( function(){ REQUEST_TICKET_RESISTER.push( new RequestTicketClass( _apiuser, DATA_IS_JSON, _data, _url, _onLoad, _onError )); currentTicket === null && request(); } - } + }; })(); var FILE_CONTROLER = { @@ -1993,11 +2016,11 @@ var File = ( function(){ _type = _ticket.eventType; _callback = _ticket.callBack; if( _eventType === _type && _uid === _ticket.fileUID ){ - AsyncCall.add( apiuser, _callback, [ _eventType, _targetFile, e.key, e.value ] ); + AsyncCall.add( apiuser, _callback, [ _eventType, _targetFile, e.key, e.value ], _targetFile ); } else if( _type === Const.TREE.EVENT.UPDATE && _eventType === Const.FILE.EVENT.GET_SEQENTIAL_FILES ){ //_callback( _eventType, _targetFile ); - AsyncCall.add( apiuser, _callback, [ _eventType, _targetFile ] ); + AsyncCall.add( apiuser, _callback, [ _eventType, _targetFile ], instance ); }; }; }; @@ -2590,7 +2613,7 @@ var AbstractApplication = function( displayName, appClass, isOverlay ){ KeyEvent.remove( self ); SystemTimer.remove( self ); AsyncCall.remove( self ); - Css.unload( self ); + StyleSheet.unload( self ); while( uiList.length > 0 ){ uiList.shift().destroy(); @@ -2632,7 +2655,7 @@ var AbstractApplication = function( displayName, appClass, isOverlay ){ this.fetchCSS = function( _url, opt_onload, opt_onerror ){ if( phase === 1 ){ ++fetchResource; - Css.load( self, _url, fetchResourceComplete, fetchResourceComplete ); + StyleSheet.load( self, _url, fetchResourceComplete, fetchResourceComplete ); }; }; @@ -2652,7 +2675,7 @@ AbstractApplication.prototype.onClose = function(){ // overrride return true; }; // false の場合、close の拒否 -AbstractApplication.prototype.addMouseEventListener = function( _element, _eventType, _handler ){ +AbstractApplication.prototype.addEventListener = function( _element, _eventType, _handler ){ MouseEvent.add( this, _element, _eventType, _handler ); }; AbstractApplication.prototype.removeMouseEventListener = function( _element, _eventType, _handler ){ @@ -2676,8 +2699,8 @@ AbstractApplication.prototype.addTimer = function( handler, time, once ){ AbstractApplication.prototype.removeTimer = function( handler ){ SystemTimer.remove( this, handler ); }; -AbstractApplication.prototype.addAsyncCall = function( _callback, _argments ){ - AsyncCall.add( this, _callback, _argments ); +AbstractApplication.prototype.addAsyncCall = function( _callback, _argments, _thisObject ){ + AsyncCall.add( this, _callback, _argments, _thisObject ); }; AbstractApplication.prototype.removeAsyncCall = function( _callback ){ AsyncCall.remove( this, _callback ); @@ -2783,7 +2806,7 @@ var Application = ( function(){ } else { Application.onCurrentApplicationChange( coveredApplication ); coveredApplication = null; - } + }; }, onCurrentApplicationChange: function( _application ){ if( Application.isApplicationInstance( _application ) === false ) return; @@ -2850,7 +2873,7 @@ var Application = ( function(){ tailList.push( tail ); elm = tail.elm; elmContainer.appendChild( elm ); - self.addMouseEventListener( elm, 'click', onTailClick ); + self.addEventListener( elm, 'click', onTailClick ); }; }; @@ -2973,7 +2996,7 @@ var Application = ( function(){ if( pageNodes.length !== 0 ){ if( Type.isFunction( gOS.PageApplicationClass ) === true ){ Page.appClass = gOS.PageApplicationClass; - Page.appClass.bgColor = Page.appClass.bgColor || '#ffffff'; + Page.appClass.bgColor = Page.appClass.bgColor; Page.appClass.MIN_WIDTH = Page.appClass.MIN_WIDTH || 240; Page.appClass.MIN_HEIGHT = Page.appClass.MIN_HEIGHT || 240; } else { @@ -2992,6 +3015,9 @@ var Application = ( function(){ }; }; ref = Application.register( Page.appClass, false, true, document.title, 'page', null, Page.appClass.tailColor || '#999999' ); + if( Type.isFunction( gOS.PageApplicationClass ) === true ){ + gOS.PageApplicationRef = ref; + }; }; delete Page.onReady; }, @@ -3807,7 +3833,7 @@ var KeyEvent = ( function(){ * http://thudjs.tumblr.com/post/637855087/stylesheet-onload-or-lack-thereof */ -var Css = ( function(){ +var StyleSheet = ( function(){ var head = doc.getElementsByTagName( 'head' )[ 0 ]; var TICKET_LIST = []; @@ -3861,9 +3887,9 @@ var Css = ( function(){ }; }, error: function(){ - for( var i = this.onerror.length, c; i; ){ - c = this.onerror[ --i ]; - Type.isFunction( c ) === true && AsyncCall.add( t.apiusers[ i ], c, t.url ); + for( var i = this.onerror.length, f; i; ){ + f = this.onerror[ --i ]; + Type.isFunction( f ) === true && AsyncCall.add( this.apiusers[ i ], f, this.url ); this.onload[ i ] = this.onerror[ i ] = null; }; }, @@ -3967,6 +3993,141 @@ var Css = ( function(){ } })(); +/* + * AssetLoader + * fetchCSS + * fetchJson + * fetchHtml + * fetchImage + * fetchLocalFile + * fetchLocalStorage + */ + +var Image = ( function(){ + var TASK_LIST = []; + /* + * FetchClass original is + * + * LICENSE: MIT? + * URL: http://d.hatena.ne.jp/uupaa/20080413/1208067631 + * AUTHOR: uupaa.js@gmail.com + * + */ + function detect(){ + for( var i=0, t; i < TASK_LIST.length; ){ + t = TASK_LIST[ i ]; + if( t.complete() === true ){ + TASK_LIST.splice( i, 1 ); + } else { + ++i; + }; + }; + TASK_LIST.length === 0 && SystemTimer.remove( SUPER_USER_KEY, detect ); + }; + function getTask( img ){ + for( var i = TASK_LIST.length; i; ){ + if( TASK_LIST[ --i ].img === img ) return TASK_LIST[ i ]; + }; + }; + function onError(){ + var task = getTask( this ); + if( task.finish === true ) return; + task.finish = true; + AsyncCall.add( task.apiuser, task.asyncCallback, null, task ); + }; + function onLoad(){ + // if( finish === true ) return; // これがあると firefox3.6 で駄目、、、 + // if( timer ) return; // これがあると safari3.2 で駄目、、、 + var task = getTask( this ); + task.finish = true; + TASK_LIST.splice( Util.getIndex( TASK_LIST, task ), 1 ); + if( window.opera && !task.img.complete ){ + AsyncCall.add( task.apiuser, task.asyncCallback, null, task ); + return; + }; + task.size = Util.getImageSize( this ); + AsyncCall.add( task.apiuser, task.asyncCallback, null, task ); + }; + + + var FetchClass = function( apiuser, abspath, onLoadCallback, onErrorCallback, timeout ){ + this.apiuser = apiuser; + this.abspath = abspath; + this.onLoadCallback = onLoadCallback; + this.onErrorCallback = onErrorCallback; + this.timeout = timeout; + this.tick = 0; + }; + FetchClass.prototype = { + img: null, + size: null, + tick: 0, + finish: false, + load: function(){ + var img = this.img = document.createElement( 'img' ); //var img = new Image(); ではieでimgのsizeが取れない、、、removeChildも失敗し、imgSizeGetterにimgが残る + img.onabort = img.onerror = onError; + img.onload = onLoad; + img.src = this.abspath; + }, + complete: function(){ + if( this.finish === true ) return true; + if( this.img.complete ){ + this.finish = true; + if( this.img.width ) return true; + AsyncCall.add( this.apiuser, this.asyncCallback, null, this ); + return true; + }; + if( ( this.tick += 250 ) > this.timeout ){ + this.finish = true; + AsyncCall.add( this.apiuser, this.asyncCallback, null, this ); + return true; + }; + }, + asyncCallback: function(){ + this.size ? this.onLoadCallback( this.abspath, this.size.width, this.size.height ) : this.onErrorCallback( this.abspath ); + this.destroy(); + }, + destroy: function(){ + this.finish = true; + this.img.src = this.img.onload = this.img.onabort = this.img.onerror = ''; + delete this.img; + delete this.size; + delete this.onLoadCallback; + delete this.onErrorCallback; + }, + stop: function(){ + timer !== null && window.clearTimeout( timer ); + destroy(); + } + }; + + return { + load: function( URLorELM, onLoad, onError, opt_timeout ){ + var src, fetch; + if( Type.isString( URLorELM ) === true ){ + src = URLorELM; + } else + if( Type.isHTMLElement( URLorELM ) === true && URLorELM.tagName.toLowerCase() === 'img' ){ + src = URLorELM.src; + } else { + return; + }; + + fetch = new FetchClass( + Util.getAbsolutePath( src ), + onLoad, onError, + Type.isFinite( opt_timeout ) === true ? opt_timeout : undefined + ); + TASK_LIST.push( fetch ); + + SystemTimer.add( SUPER_USER_KEY, detect, 250 ); + }, + unload: function( ){ + + } + }; +})(); + /* ---------------------------------------- * @@ -4159,7 +4320,7 @@ var UI = ( function(){ elmA.innerHTML = _newValue; elmA.style.display = 'block'; - onUpdate && _newValue !== value && AsyncCall.add( apiuser, onUpdate, [ _newValue, value ] ); + onUpdate && _newValue !== value && AsyncCall.add( apiuser, onUpdate, [ _newValue, value ], instance ); value = _newValue; focus = false; @@ -4197,7 +4358,7 @@ var UI = ( function(){ function onClick(){ focus = true; // onUpdate(); - AsyncCall.add( apiuser, onUpdate ); + AsyncCall.add( apiuser, onUpdate, null, instance ); return false; }; this.focus = function(){ @@ -4282,7 +4443,7 @@ var UI = ( function(){ if( focus === true ){ OptionControl.update( instance, _value ); }; - Type.isFunction( onUpdate ) === true && AsyncCall.add( apiuser, onUpdate, [ _value ] ); + Type.isFunction( onUpdate ) === true && AsyncCall.add( apiuser, onUpdate, _value, instance ); break; }; }; @@ -4485,7 +4646,7 @@ var UI = ( function(){ onWindowResize: function( _w, _h ){ currentCombobox && AsyncCall.add( apiuser, updateWrapperPosition ); } - } + }; })(); var UIGroupClass = function( apiuser ){ @@ -4626,7 +4787,7 @@ var UI = ( function(){ i < l ? i : 0; // 0 < i < l _item = currentList[ i ]; if( _item.enabled() === true && _item.visible() === true ){ - AsyncCall.add( currentUser, _item.focus ); + AsyncCall.add( currentUser, _item.focus, null, _item ); return; }; i += _way; @@ -5296,3 +5457,22 @@ var DHTML = ( function(){ gOS.registerDriver = File.registerDriver; })( window, document ); + + + +gOS.PageApplicationRef = null; +gOS.PageApplicationClass = function(){ + var app = this; + this.bgColor = '#FFF'; + this.onOpen = function(){ + var button = document.getElementById( 'server-page-close-button' ); + if( button ){ + app.addEventListener( button, 'click', gOS.PageApplicationRef.shutdown ); + }; + var msg = document.getElementById( 'esc-msg' ); + if( msg ){ + app.addEventListener( msg, 'click', gOS.PageApplicationRef.shutdown ); + }; + app.addKeyEventListener( 'keydown', gOS.PageApplicationRef.shutdown, 27 ); // 27.esc + }; +}; \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 7a4ffeec..b363ebdc 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -15,7 +15,8 @@
<%= yield %>
-
[ESC] キーを押すと Metro ホームに入るよ.ホームの一番最後のタイルをクリックすると このページに戻るよ.
+
[ESC] キーを押すと Metro ホームに入るよ.ホームの一番最後のタイルをクリックすると このページに戻るよ.
+
ホームへ
<%= javascript_include_tag "jquery-1.6.2.min" %> <%= javascript_include_tag "system" %> <% if current_user %> -- 2.11.0