diff --git a/client.js b/client.js index c39837f1..c2efe6dd 100644 --- a/client.js +++ b/client.js @@ -364,7 +364,13 @@ CloudClient.Util = (function(){ return this.anyload(pParams_o); }; - this.getById = function(pId){return document.getElementById(pId);}; + this.getByTag = function(pTag, pElement){ + return (pElement || document).getElementsByTagName(pTag); + }; + + this.getById = function(pId, pElement){ + return (pElement || document).getElementById(pId); + }; /* @@ -675,7 +681,7 @@ CloudClient.keyBinding=(function(){ /* function loads and shows editor */ CloudClient.Editor = (function() { - /* loading CloudMirror plagin */ + /* loading CloudMirror plagin */ Util.jsload(CloudClient.LIBDIRCLIENT + 'editor.js',{ onload:(function(){ diff --git a/index.html b/index.html index dab51587..dbb32d09 100644 --- a/index.html +++ b/index.html @@ -10,9 +10,8 @@ diff --git a/lib/client/editor.js b/lib/client/editor.js index 1c027a4a..accc6282 100644 --- a/lib/client/editor.js +++ b/lib/client/editor.js @@ -107,10 +107,7 @@ CloudCommander.Editor.CodeMirror.show = (function(){ var lA; /* getting link */ - lA = lCurrent.getElementsByTagName('a'); - if(!lA.length) - return console.log('Error:' + - 'can not find links in current file'); + lA = this.getByTag('a', lCurrent); lA = lA[0].href; diff --git a/lib/client/menu.js b/lib/client/menu.js index 4a2f5428..9baac7ee 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -12,6 +12,7 @@ CloudCommander.Menu.dir = './lib/client/menu/'; * for menu */ CloudCommander.Menu.getConfig = (function(){ + var lThis = this; return{ // define which elements trigger this menu selector: 'li', @@ -27,9 +28,11 @@ CloudCommander.Menu.getConfig = (function(){ } }}, edit: {name: "Edit", callback: function(key, opt){ + lThis.Images.showLoad(); + if(typeof CloudCommander.Editor === 'function') CloudCommander.Editor(); - else{ + else{ var lEditor = CloudCommander.Editor.get(); if(lEditor && lEditor.show) lEditor.show(); @@ -87,39 +90,41 @@ CloudCommander.Menu.set = (function(){ */ document.onclick = function(pEvent){ if(pEvent && pEvent.x && pEvent.y){ - var lLayer = lThis.getById('context-menu-layer'); - var lStyle; - - if(lLayer) - lStyle = lLayer.style.cssText; - /* hide invisible menu layer */ - if(lStyle) - lLayer.style.cssText = lStyle - .replace('z-index: 1', 'z-index:-1'); - - /* get element by point */ - var lElement = document.elementFromPoint(pEvent.x, pEvent.y); - var lTag = lElement.tagName; - var lParent; - - if(lTag === 'A' || lTag === 'SPAN'){ - if (lElement.tagName === 'A') - lParent = lElement.parentElement.parentElement; - else if(lElement.tagName === 'SPAN') - lParent = lElement.parentElement; - - lThis.setCurrentFile(lParent); + if(lLayer){ + var lLayer = lThis.getById('context-menu-layer'); + var lStyle; + + if(lLayer) + lStyle = lLayer.style.cssText; + /* hide invisible menu layer */ + if(lStyle) + lLayer.style.cssText = lStyle + .replace('z-index: 1', 'z-index:-1'); + + /* get element by point */ + var lElement = document.elementFromPoint(pEvent.x, pEvent.y); + var lTag = lElement.tagName; + var lParent; + + if(lTag === 'A' || lTag === 'SPAN'){ + if (lElement.tagName === 'A') + lParent = lElement.parentElement.parentElement; + else if(lElement.tagName === 'SPAN') + lParent = lElement.parentElement; + + lThis.setCurrentFile(lParent); + } + + /* show invisible menu layer */ + if(lLayer && lStyle) + lLayer.style.cssText = lStyle; + + /* if document.onclick was set up + * before us, it's best time to call it + */ + if(typeof lFunc_f === 'function') + lFunc_f(); } - - /* show invisible menu layer */ - if(lLayer && lStyle) - lLayer.style.cssText = lStyle; - - /* if document.onclick was set up - * before us, it's best time to call it - */ - if(typeof lFunc_f === 'function') - lFunc_f(); } };