From bb8013c818833b9416ccb5786c03be69060fea7f Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 5 Jun 2013 11:19:04 -0400 Subject: [PATCH] added hide method to view module --- ChangeLog | 4 + lib/client/view.js | 249 ++++++++++++++++++++++----------------------- 2 files changed, 127 insertions(+), 126 deletions(-) diff --git a/ChangeLog b/ChangeLog index 96b4eae6..bd9889d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -46,6 +46,10 @@ getJSONfromFileTable. * Simpified plugins id's. +* Rewrited _codemirror and view modules with prototypes. + +* Added hide method to view module. + 2012.04.22, v0.2.0 diff --git a/lib/client/view.js b/lib/client/view.js index d8bfd558..94d0979e 100644 --- a/lib/client/view.js +++ b/lib/client/view.js @@ -1,137 +1,136 @@ var CloudCmd, Util, DOM, CloudFunc, $; -/* object contains viewer FancyBox - * https://github.com/fancyapps/fancyBox - */ + (function(CloudCmd, Util, DOM, CloudFunc){ 'use strict'; - var Key = CloudCmd.Key, - FancyBox = {}, + CloudCmd.View = new ViewProto(CloudCmd, Util, DOM, CloudFunc); - Config = { - beforeShow : function(){ - DOM.Images.hideLoad(); - Key.unsetBind(); - }, + function ViewProto(CloudCmd, Util, DOM, CloudFunc){ + var Key = CloudCmd.Key, + FancyBox = this, - afterShow : function(){ - var lEditor = DOM.getById('View'); - if(lEditor) - lEditor.focus(); - }, - - beforeClose : Util.retFunc( Key.setBind ), - - openEffect : 'none', - closeEffect : 'none', - autoSize : false, - height : window.innerHeight, - helpers : { - overlay : { - css : { - 'background' : 'rgba(255, 255, 255, 0.1)' - } - } - }, - padding : 0 - }; - - CloudCmd.View = { - get: function(){ - return this.FancyBox; - } - }; - - /** - * function loads css and js of FancyBox - * @pParent - this - * @pCallBack - executes, when everything loaded - */ - FancyBox.load = function(pCallBack){ - Util.time('fancybox load'); - var lDir = CloudCmd.LIBDIRCLIENT + 'view/fancyBox/source/', - lFiles = [ lDir + 'jquery.fancybox.css', - lDir + 'jquery.fancybox.js' ]; - - DOM.anyLoadOnLoad([lFiles], function(){ - Util.timeEnd('fancybox load'); - Util.exec( pCallBack ); - }) - .cssSet({id:'view-css', - inner : '#view{' + - 'font-size: 16px;' + - 'white-space :pre' + - '}' + - '#view::selection{' + - /* - 'background: #fe57a1;' - 'color: #fff;' - */ - 'background: #b3d4fc;' + - 'text-shadow: none;' + - '}' - }); - - }; - - - FancyBox.showHelp = function(){ - DOM.Images.showLoad(); - DOM.ajax({ - url: '/README.md', - success: function (pData){ - var lData = {text: pData}; - DOM.ajax({ - method : 'post', - url : 'https://api.github.com/markdown', - data : Util.stringifyJSON(lData), - success:function(pResult){ - DOM.Images.hideLoad(); - $.fancybox(pResult, Config); - }, + Config = { + beforeShow : function(){ + DOM.Images.hideLoad(); + Key.unsetBind(); + }, - error: DOM.Images.showError - }); - }, + afterShow : function(){ + var lEditor = DOM.getById('View'); + if(lEditor) + lEditor.focus(); + }, + + beforeClose : Util.retFunc( Key.setBind ), + + openEffect : 'none', + closeEffect : 'none', + autoSize : false, + height : window.innerHeight, + helpers : { + overlay : { + css : { + 'background' : 'rgba(255, 255, 255, 0.1)' + } + } + }, + padding : 0 + }; + + this.init = function(pCallBack){ + Util.loadOnLoad([ + pCallBack, + FancyBox.show, + load, + DOM.jqueryLoad + ]); - error:DOM.Images.showError - }); - }; - - /** - * function shows FancyBox - */ - FancyBox.show = function(pCallBack){ - var lPath = CloudFunc.FS + DOM.getCurrentPath(); + DOM.Events.addKey(listener); + DOM.setButtonKey('f3', view); + }; - if( Util.checkExtension(lPath, ['png','jpg', 'gif','ico']) ) - $.fancybox.open({ href : lPath }, Config); - else - DOM.getCurrentData(function(pParams){ - $.fancybox('
' + - pParams.data + '
', Config); - }); - - Util.exec(pCallBack); - }; - - CloudCmd.View.init = function(pCallBack){ - Util.loadOnLoad([ - pCallBack, - FancyBox.show, - FancyBox.load, - DOM.jqueryLoad - ]); - - DOM.Events.addKey(lListener); - DOM.setButtonKey('f3', lView); - - function lView(){ + this.showHelp = function(){ DOM.Images.showLoad(); - FancyBox.show( DOM.getCurrentFile() ); + DOM.ajax({ + url: '/README.md', + success: function (pData){ + var lData = {text: pData}; + DOM.ajax({ + method : 'post', + url : 'https://api.github.com/markdown', + data : Util.stringifyJSON(lData), + success:function(pResult){ + DOM.Images.hideLoad(); + $.fancybox(pResult, Config); + }, + + error: DOM.Images.showError + }); + }, + + error:DOM.Images.showError + }); + }; + + /** + * function shows FancyBox + */ + this.show = function(pCallBack){ + var lPath = CloudFunc.FS + DOM.getCurrentPath(); + + if( Util.checkExtension(lPath, ['png','jpg', 'gif','ico']) ) + $.fancybox.open({ href : lPath }, Config); + else + DOM.getCurrentData(function(pParams){ + $.fancybox('
' + + pParams.data + '
', Config); + }); + + Util.exec(pCallBack); + }; + + this.hide = function(){ + $.fancybox.close(); + }; + + /** + * function loads css and js of FancyBox + * @pParent - this + * @pCallBack - executes, when everything loaded + */ + function load(pCallBack){ + Util.time('fancybox load'); + var lDir = CloudCmd.LIBDIRCLIENT + 'view/fancyBox/source/', + lFiles = [ lDir + 'jquery.fancybox.css', + lDir + 'jquery.fancybox.js' ]; + + DOM.anyLoadOnLoad([lFiles], function(){ + Util.timeEnd('fancybox load'); + Util.exec( pCallBack ); + }) + .cssSet({id:'view-css', + inner : '#view{' + + 'font-size: 16px;' + + 'white-space :pre' + + '}' + + '#view::selection{' + + /* + 'background: #fe57a1;' + 'color: #fff;' + */ + 'background: #b3d4fc;' + + 'text-shadow: none;' + + '}' + }); + } - function lListener(pEvent){ + function view(){ + DOM.Images.showLoad(); + FancyBox.show( DOM.getCurrentFile() ); + } + + function listener(pEvent){ var lF3 = Key.F3, lF1 = Key.F1, lIsBind = Key.isBind(), @@ -141,7 +140,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; if (lIsBind) { switch(lKey){ case lF3: - lView(); + view(); DOM.preventDefault(pEvent); break; @@ -151,8 +150,6 @@ var CloudCmd, Util, DOM, CloudFunc, $; } } } - }; - - CloudCmd.View.FancyBox = FancyBox; + } })(CloudCmd, Util, DOM, CloudFunc);