OSDN Git Service

pettanR version0.4.15
[pettanr/clientJs.git] / 0.4.x / javascripts / common.js
index 13120a3..744cd38 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
  * pettanR common.js\r
- *   version 0.4.12\r
+ *   version 0.4.15\r
  * \r
  * author: itozyun\r
  */\r
                isNumber : function(v) {\r
                        return typeof v === 'number';\r
                },\r
-               isHTMLElement : ( 'HTMLElement' in window ?\r
-                       function(v){\r
-                               return v instanceof HTMLElement\r
-                       } :\r
-                       function(v) {\r
-                               if( Type.isObject(v) === false ){\r
-                                       return false;\r
+               isFinite : function(v){\r
+                       return Type.isNumber(v) === true && isFinite(v);\r
+               },\r
+               isHTMLElement : function(v){\r
+                       if( 'HTMLElement' in window ){\r
+                               Type.isHTMLElement = function(v){\r
+                                       return v instanceof HTMLElement;\r
                                }\r
-                               var r;\r
-                               if(v && v.nodeType === 1){\r
-                                       try{\r
-                                               r = v.cloneNode(false);\r
-                                       } catch(n) {\r
+                       } else {\r
+                               Type.isHTMLElement = function(v) {\r
+                                       if( Type.isObject(v) === false ){\r
                                                return false;\r
                                        }\r
-                                       if(r === v) return false;\r
-                                       try{\r
-                                               r.nodeType = 9;\r
-                                               return r.nodeType === 1;\r
-                                       } catch(n) {}\r
-                                       return true;\r
+                                       var r;\r
+                                       if(v && v.nodeType === 1){\r
+                                               try{\r
+                                                       r = v.cloneNode(false);\r
+                                               } catch(n) {\r
+                                                       return false;\r
+                                               }\r
+                                               if(r === v) return false;\r
+                                               try{\r
+                                                       r.nodeType = 9;\r
+                                                       return r.nodeType === 1;\r
+                                               } catch(n) {}\r
+                                               return true;\r
+                                       }\r
+                                       return false;\r
                                }\r
-                               return false;\r
                        }\r
-               ),\r
+                       return Type.isHTMLElement(v);\r
+               },\r
                /*\r
                isElementCollection : function(v) {\r
                        return (Object.prototype.toString.call(v) === "[object HTMLCollection]");\r
@@ -83,7 +90,7 @@ var pettanr = ( function(){
                                        if( elm.length === 2){\r
                                                v = decodeURIComponent( elm[ 1]);\r
                                                if( '' + parseFloat( v) === v) v = parseFloat( v);\r
-                                               if( '' + parseInt( v) === '0' + v) v = parseInt( v);\r
+                                               if( '' + parseInt( v, 10 ) === '0' + v) v = parseInt( v, 10 );\r
                                                if( v === 'true') v = true;\r
                                                if( v === 'false') v = false;\r
                                                if( v === 'null') v = null;\r
@@ -101,7 +108,7 @@ var pettanr = ( function(){
                IS_DEBUG = typeof URL_PARAMS.debug === 'boolean' ? URL_PARAMS.debug : IS_LOCAL === true,\r
                jqWindow , jqDocument , jqBody;\r
        return {\r
-               version: '0.4.11',\r
+               version: '0.4.13',\r
                init: function(){\r
                        jqWindow = $( window);\r
                        jqDocument = $( document);\r
@@ -771,7 +778,7 @@ pettanr.CONST = ( function(){
                CREATE_COMIC_JS:                        isLocal === true ? 'js\/create_new_comic.js' : PETTANR_ROOT_PATH + 'comics\/new.js',\r
                CREATE_PANEL_JS:                        isLocal === true ? 'js\/create_new_panel.js' : PETTANR_ROOT_PATH + 'panels\/new.js',\r
                UPLOAD_PICTURE_JS:                      isLocal === true ? 'js\/upload_picture.js' : PETTANR_ROOT_PATH + 'original_pictures\/new.js',\r
-               RESISTER_ARTIST_JS:                     isLocal === true ? 'js\/register_artist.js' : PETTANR_ROOT_PATH + 'artists\/new.js',\r
+               REGISTER_ARTIST_JS:                     isLocal === true ? 'js\/register_artist.js' : PETTANR_ROOT_PATH + 'artists\/new.js',\r
                JQUERY_URL:                                     isLocal === true ? 'javascripts\/jquery-1.6.2.min.js' : PETTANR_ROOT_PATH + 'assets\/jquery-162_min.js'\r
        }\r
 })();\r
@@ -781,8 +788,7 @@ pettanr.view = ( function(){
        var location = document.location.pathname,\r
                isWorkPage =    document.location.href.indexOf( 'http:\/\/localhost:3000\/' ) === 0 ||\r
                                                location.indexOf( pettanr.CONST.PETTANR_ROOT_PATH ) === 0 ||\r
-                                               location.indexOf( '\/work.html') !== -1 ||\r
-                                               location.indexOf( '\work.html') !== -1,\r
+                                               location.indexOf( '\/work.html') !== -1,\r
                deep =  location.indexOf( '\/diary\/') !== -1 ||\r
                                location.indexOf( '\/test\/') !== -1 ||\r
                                location.indexOf( '\/help\/') !== -1 ||\r
@@ -791,42 +797,26 @@ pettanr.view = ( function(){
                LoginUserNavi;\r
        \r
        if( isWorkPage === false){\r
-               LoginUserNavi = ( function(){\r
-                       var _body = document.body,\r
-                               _root = document.getElementsByTagName( 'html' )[ 0 ],\r
-                               filter,\r
-                               iframe, visible = false;\r
-                       return {\r
-                               show: function(){\r
-                                       document.location.href = [\r
-                                                       deep === true ? '../' : '',\r
-                                                       'work.html',\r
-                                                       typeof viewIndex === 'number' ? '?view=' + viewIndex : ''\r
-                                               ].join( '');\r
-                               },\r
-                               hide: function(){}\r
-                       }\r
-               })();\r
+               LoginUserNavi = {\r
+                       show: function(){\r
+                               var i = pettanr.util.getChildIndex( this.parentNode, this );\r
+                               document.location.href = [\r
+                                               deep === true ? '../' : '',\r
+                                               'work.html',\r
+                                               typeof i === 'number' ? '?view=' + i : ''\r
+                                       ].join( '');\r
+                               return false;\r
+                       },\r
+                       hide: function(){}\r
+               }\r
        } else {\r
-               LoginUserNavi = ( function(){\r
-                       return {\r
-                               show: function(){\r
-                                       var i = pettanr.util.getChildIndex( this.parentNode, this );\r
-                                       i !== -1 && pettanr.view.show( i );\r
-                                       return false;\r
-                               },\r
-                               hide: function(){}\r
-                       }\r
-               })();\r
-\r
-               if( pettanr.IS_IFRAME === true){\r
-                       var _nodes = document.getElementsByTagName( 'a'),\r
-                               _a, _href;\r
-                       for(var i=0, l = _nodes.length; i<l; i++){\r
-                               _a = _nodes[ i];\r
-                               _href = _a.href.split('?')[0].split('#')[0];\r
-                               if( pettanr.util.getAbsolutePath( _href) !== location) _a.target = '_parent';\r
-                       }\r
+               LoginUserNavi = {\r
+                       show: function(){\r
+                               var i = pettanr.util.getChildIndex( this.parentNode, this );\r
+                               i !== -1 && pettanr.view.show( i );\r
+                               return false;\r
+                       },\r
+                       hide: function(){}\r
                }\r
                \r
                if( pettanr.DEBUG === true){\r
@@ -882,10 +872,9 @@ pettanr.view = ( function(){
                        pettanr.DEBUG === true && ret.push( 'debug');\r
                        return ret;\r
                })(),\r
-               l = items.length,\r
                item;\r
        origin.href = '#';\r
-       for(var i=0; i<l; ++i){\r
+       for(var i=0, l = items.length; i<l; ++i){\r
                item = origin.cloneNode( true);\r
                item.appendChild( document.createTextNode( items[ i]) );\r
                item.onclick = LoginUserNavi.show;\r
@@ -930,21 +919,17 @@ pettanr.view = ( function(){
        \r
        pettanr.DEBUG === true && VIEW_ID_ARRAY.push( 'debug');\r
        \r
-       show();\r
+       open();\r
        \r
        function onWindowResize(){\r
                var _fn,\r
                        l = funcArray.length,\r
                        w = jqWindow.width(),\r
                        h = jqWindow.height();\r
-               //for( var i=0; i<l; ++i){\r
-               //      _fn = funcArray[ i];\r
-               //      _fn.onWindowResize && _fn.onWindowResize( w, h);\r
-               //}\r
                currentView && currentView.onWindowResize && currentView.onWindowResize( w, h);\r
                pettanr.overlay.currentID !== null && pettanr.overlay.onWindowResize( w, h);\r
        }\r
-       function show(){\r
+       function open( _option ){\r
                if( isWorkPage === false) return;\r
                \r
                var _elm = document.getElementById( currentID);\r
@@ -962,19 +947,31 @@ pettanr.view = ( function(){
                }\r
                \r
                if( !pettanr.view || pettanr.view.init !== undefined) return;\r
-               currentView = pettanr[ currentID];\r
-               if( !currentView) return;\r
-               typeof currentView.onOpen === 'function' && currentView.onOpen();\r
-               setTimeout( onWindowResize, 0);\r
+               typeof currentView.onClose === 'function' && currentView.onClose();\r
+               currentView = pettanr[ currentID ];\r
+               typeof currentView.onOpen === 'function' && currentView.onOpen( jqWindow.width(), jqWindow.height(), _option );\r
+               // setTimeout( onWindowResize, 0);\r
        }\r
        \r
        var AbstractBasicPane = function(){\r
-               this.UID = '', // element の ID と一致\r
-               this.onOpen = function(){};\r
-               this.onClose = function(){};\r
-               this.onPaneResize = function( _w, _h){};\r
-               this.MIN_WIDTH = 0;\r
-               this.MIN_HEIGHT = 0;\r
+               this.rootElement = null;\r
+               this.onOpen = function( _w, _h, _option ){};\r
+               this.onClose = function(){ return true; } // false の場合、close の拒否 \r
+               this.onPaneResize = function( _w, _h ){}\r
+               this.resize = function( _w, _h ){\r
+                       if( this.MIN_WIDTH > _w || this.MIN_HEIGHT > _h ){\r
+                               if( Type.isHTMLElement( this.rootElement ) === true ){\r
+                                       // 小さすぎる!、と表示\r
+                               }\r
+                               return;\r
+                       }\r
+                       this.onPaneResize( _w, _h );\r
+               }\r
+               this.MIN_WIDTH = 240;\r
+               this.MIN_HEIGHT = 240;\r
+       }\r
+       var AbstractApplication = function(){\r
+               this.prototype = new AbstractBasicPane();\r
        }\r
        \r
        return {\r
@@ -983,14 +980,15 @@ pettanr.view = ( function(){
                        jqWindow = pettanr.jqWindow();\r
                        jqWindow.resize( onWindowResize);\r
                        \r
-                       currentView = currentView || pettanr[ currentID];\r
-                       currentView && typeof currentView.onOpen === 'function' && currentView.onOpen();\r
+                       currentView = currentView || pettanr[ currentID ];\r
+                       var _option = {}; // urlパラメータ\r
+                       currentView && typeof currentView.onOpen === 'function' && currentView.onOpen( jqWindow.width(), jqWindow.height(), _option );\r
                        \r
-                       setTimeout( onWindowResize, 100);\r
+                       // setTimeout( onWindowResize, 100);\r
                        \r
                        delete pettanr.view.init;\r
                },\r
-               show: function( _viewID){\r
+               show: function( _viewID ){\r
                        if( typeof _viewID === 'number' && _viewID < VIEW_ID_ARRAY.length){\r
                                _viewID = VIEW_ID_ARRAY[ _viewID];\r
                        } else\r
@@ -1003,20 +1001,27 @@ pettanr.view = ( function(){
                                if( pettanr.view[ key] === _viewID){\r
                                        if( currentID !== _viewID && document.getElementById( _viewID)){\r
                                                this.currentID = currentID = _viewID;\r
-                                               show();\r
+                                               open();\r
                                        }\r
                                        return;\r
                                }\r
                        }\r
                        alert( _viewID);\r
                },\r
-               resisterAsBasicPane: function( _basicPane){\r
+               registerAsBasicPane: function( _basicPane ){\r
                        if( pettanr.view.isBasicPaneInstance( _basicPane ) === true ) return;\r
                        _basicPane.prototype = new AbstractBasicPane();\r
                },\r
-               isBasicPaneInstance: function( _basicPane){\r
+               registerApplication: function( _application ){\r
+                       if( pettanr.view.isApplicationInstance( _application ) === true ) return;\r
+                       _application.prototype = new AbstractApplication();\r
+               },\r
+               isBasicPaneInstance: function( _basicPane ){\r
                        return  _basicPane instanceof AbstractBasicPane;\r
                },\r
+               isApplicationInstance: function( _application ){\r
+                       return _application instanceof AbstractApplication;\r
+               },\r
                currentID:      currentID,\r
                HOME:           HOME_ID,\r
                COMICS:         VIEW_ID_ARRAY[ 1],\r
@@ -1060,9 +1065,11 @@ pettanr.overlay = ( function(){
                },\r
                show: function( _currentOverlay){\r
                        if( visible === true && currentOverlay === _currentOverlay) return;\r
+                       document.body.style.overflow = 'hidden';\r
                        jqConteiner.stop().css( {\r
                                filter:         '',\r
-                               opacity:        ''\r
+                               opacity:        '',\r
+                               top:            document.documentElement.scrollTop || document.body.scrollTop\r
                        }).fadeIn();\r
                        this.visible = visible = true;\r
                        currentOverlay = _currentOverlay;\r
@@ -1072,6 +1079,7 @@ pettanr.overlay = ( function(){
                hide: function(){\r
                        currentOverlay = null;\r
                        if( visible === false) return;\r
+                       document.body.style.overflow = '';\r
                        jqConteiner.stop().css( {\r
                                filter:         '',\r
                                opacity:        ''\r
@@ -1082,15 +1090,18 @@ pettanr.overlay = ( function(){
                visible: visible,\r
                currentID: null,\r
                onWindowResize: function( _windowW, _windowH){\r
-                       jqConteiner.css( { height:      _windowH});\r
+                       jqConteiner.css({\r
+                               height:         _windowH,\r
+                               top:            document.documentElement.scrollTop || document.body.scrollTop\r
+                       });\r
                        jqShadow.css( { height: _windowH});\r
                        windowW = _windowW;\r
                        windowH = _windowH;\r
                        // 先にeditorのcanvasを確定する。\r
                        currentOverlay && currentOverlay.onWindowResize && setTimeout( asyncResize, 0);\r
                },\r
-               resisterOverlay: function( _basicPane){\r
-                       pettanr.view.resisterAsBasicPane( _basicPane);\r
+               registerOverlay: function( _basicPane){\r
+                       var _api = pettanr.view.registerAsBasicPane( _basicPane);\r
                        // OverlayAPI\r
                        return {\r
                                show: function( _basicPane ){\r
@@ -2264,7 +2275,7 @@ var VisualEffect = ( function(){
        var VisualEffectClass = function( ELM){\r
                var isHtmlElement;\r
                \r
-               function resisterAnime( _cssObject, _onComplete, _onEnterFrame, _time){\r
+               function registerAnime( _cssObject, _onComplete, _onEnterFrame, _time){\r
                        var _numFrames = Math.floor( _time / fpms);\r
                        startAnimation( ELM, _cssObject, _onComplete, _onEnterFrame, _numFrames);\r
                }\r
@@ -2279,7 +2290,7 @@ var VisualEffect = ( function(){
                        \r
                }\r
                \r
-               this.anime = resisterAnime;\r
+               this.anime = registerAnime;\r
                this.fadeIn = startFadeIn;\r
                this.fadeOut = startFadeOut;\r
                this.update = update;\r