diff --git a/client.js b/client.js index 610cfd7a..9225b5c5 100644 --- a/client.js +++ b/client.js @@ -47,7 +47,8 @@ var CloudClient = { /* height of Cloud Commander * seting up in init() */ - HEIGHT :0 + HEIGHT :0, + MIN_ONE_PANEL_WIDTH :1155 }; /* short names used all the time functions */ @@ -321,14 +322,13 @@ CloudClient.Util = (function(){ return lE; } }; - - - /* - * Function shows loading spinner - * @pElem - top element of screen - */ + var lThis = this; this.Images = { + /* + * Function shows loading spinner + * @pElem - top element of screen + */ showLoad : function(pElem){ if(!lLoadingImage) lLoadingImage = LImages_o.loading(); @@ -358,7 +358,9 @@ CloudClient.Util = (function(){ }, hideLoad : function(){ - if(lLoadingImage) + if(!lLoadingImage) + lLoadingImage = LImages_o.loading(); + lLoadingImage.className ='hidden'; }, @@ -390,6 +392,56 @@ CloudClient.Util = (function(){ console.log(lText); } }; + + this.getCurrentFile = function(){ + var lCurrent = lThis.getByClass(CloudCommander.CURRENT_FILE)[0]; + if(!lCurrent) + console.log('Error: Can not find Current File'); + + return lCurrent; + }; + + /* function getting panel active, or passive + * @pPanel_o = {active: true} + */ + this.getPanel = function(pActive){ + var lPanel; + + lPanel = lThis.getCurrentFile().parentElement; + + /* if two panels showed + * then always work with passive + * panel + */ + if(window.innerWidth > CloudCommander.MIN_ONE_PANEL_WIDTH) + pActive = {active: false}; + + /* if {active : false} getting passive panel */ + if(pActive && !pActive.active){ + var lId = lPanel.id === 'left' ? 'right' : 'left'; + lPanel = lThis.getById(lId); + } + + + if(!lPanel) + console.log('Error can not find Active Panel'); + + return lPanel; + }; + + this.showPanel = function(pActive){ + var lPanel = lThis.getPanel(pActive); + + if(lPanel) + lPanel.className = 'panel'; + }; + + this.hidePanel = function(pActive){ + var lPanel = lThis.getPanel(pActive); + + if(lPanel) + lPanel.className = 'panel hidden'; + }; }); diff --git a/lib/client/editor.js b/lib/client/editor.js index cce0d9e2..d082e4d2 100644 --- a/lib/client/editor.js +++ b/lib/client/editor.js @@ -99,44 +99,38 @@ CloudCommander.Editor.CodeMirror.show = (function(){ }); }; - var lLeft = this.getById('left'); var lCloudEditor = this.getById('CloudEditor'); - var lCURRENTFILE = CloudCommander.CURRENT_FILE; - - - var lCurrent = this.getByClass(lCURRENTFILE); + + var lCurrent = this.getCurrentFile(); var lA; - if(lCurrent.length){ - lCurrent = lCurrent[0]; + + /* getting link */ + lA = lCurrent.getElementsByTagName('a'); + if(!lA.length) + return console.log('Error:' + + 'can not find links in current file'); + + lA = lA[0].href; + + /* убираем адрес хоста*/ + lA = '/' + lA.replace(document.location.href,''); + + /* checking is this link is to directory */ + var lSize = lCurrent.getElementsByClassName('size'); + if(lSize){ + lSize = lSize[0].textContent; - /* getting link */ - lA = lCurrent.getElementsByTagName('a'); - if(!lA.length) - return console.log('Error:' + - 'can not find links in current file'); - - lA = lA[0].href; + /* if directory - load json + * not html data + */ + if (lSize === ''){ + if (lA.indexOf(CloudFunc.NOJS) === + CloudFunc.FS.length) { - /* убираем адрес хоста*/ - lA = '/' + lA.replace(document.location.href,''); - - /* checking is this link is to directory */ - var lSize = lCurrent.getElementsByClassName('size'); - if(lSize){ - lSize = lSize[0].textContent; - - /* if directory - load json - * not html data - */ - if (lSize === ''){ - if (lA.indexOf(CloudFunc.NOJS) === - CloudFunc.FS.length) { - - lA = lA.replace(CloudFunc.NOJS, ''); - lReadOnly = true; - } + lA = lA.replace(CloudFunc.NOJS, ''); + lReadOnly = true; } - } + } } this.loading = true; @@ -157,10 +151,8 @@ CloudCommander.Editor.CodeMirror.show = (function(){ /* removing keyBinding if set */ CloudCommander.keyBinded = false; - - lLeft && - (lLeft.className = 'panel hidden'); - + + lParent.hidePanel(); lParent.Images.hideLoad(); lParent.loading = false; @@ -171,19 +163,12 @@ CloudCommander.Editor.CodeMirror.show = (function(){ /* function hides CodeMirror editor */ CloudCommander.Editor.CodeMirror.hide = (function(pParent) { return function(){ - CloudCommander.keyBinded = true; + CloudCommander.keyBinded = true; + pParent.showPanel(); - var lLeft = pParent.getById('left'); - var lCloudEditor = pParent.getById('CloudEditor'); - - /* - lCloudEditor && - (lCloudEditor.className = 'hidden'); - */ - lLeft && - (lLeft.className = 'panel'); - + var lCloudEditor = pParent.getById('CloudEditor'); var lCodeMirror = pParent.getByClass('CodeMirror'); + if(lCodeMirror.length) lCloudEditor .removeChild(lCodeMirror[0]);