diff --git a/lib/client/edit.js b/lib/client/edit.js index 2780cd60..5438078f 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -6,6 +6,7 @@ var CloudCmd, Util, DOM, JsDiff, ace; function EditProto(CloudCmd, Util, DOM){ var Name = 'Edit', + DIR = CloudCmd.LIBDIRCLIENT + 'edit/', Value, Edit = this, Ace, @@ -35,7 +36,9 @@ var CloudCmd, Util, DOM, JsDiff, ace; }; this.show = function(pValue) { - var lMode, lSession; + var lName = DOM.getCurrentName(), + lExt = Util.getExtension(lName), + lUseWorker = Util.strCmp(lExt, ['.js', '.json']); Images.showLoad(); @@ -50,36 +53,12 @@ var CloudCmd, Util, DOM, JsDiff, ace; 'position: absolute;', not_append : true }); - - Ace = ace.edit(Element); - lSession = Ace.getSession(); - - Ace.setTheme('ace/theme/tomorrow_night_blue'); - lSession.setMode('ace/mode/javascript'); - Ace.setShowPrintMargin(false); - Ace.setShowInvisibles(true); - lSession.setUseSoftTabs(true); - - Ace.commands.addCommand({ - name : 'hide', - bindKey : { win: 'Esc', mac: 'Esc' }, - exec : function () { - Edit.hide(); - } - }); - - Ace.commands.addCommand({ - name : 'save', - bindKey : { win: 'Ctrl-S', mac: 'Command-S' }, - exec : function (pEditor) { - var lPath = DOM.getCurrentPath(), - lValue = Ace.getValue(); - - DOM.RESTfull.save(lPath, lValue); - } - }); + + initAce(); } + Ace.session.setOption('useWorker', lUseWorker); + if ( Util.isString(pValue) ) { Ace.setValue(pValue); CloudCmd.View.show(Element, focus); @@ -111,15 +90,44 @@ var CloudCmd, Util, DOM, JsDiff, ace; Ace.moveCursorTo(0, 0); } + function initAce() { + var lSession; + + Ace = ace.edit(Element); + lSession = Ace.getSession(); + + Ace.setTheme('ace/theme/tomorrow_night_blue'); + lSession.setMode('ace/mode/javascript'); + Ace.setShowPrintMargin(false); + Ace.setShowInvisibles(true); + lSession.setUseSoftTabs(true); + + Ace.commands.addCommand({ + name : 'hide', + bindKey : { win: 'Esc', mac: 'Esc' }, + exec : function () { + Edit.hide(); + } + }); + + Ace.commands.addCommand({ + name : 'save', + bindKey : { win: 'Ctrl-S', mac: 'Command-S' }, + exec : function (pEditor) { + var lPath = DOM.getCurrentPath(), + lValue = Ace.getValue(); + + DOM.RESTfull.save(lPath, lValue); + } + }); + } + function load(pCallBack){ Util.time(Name + ' load'); - var lDir = CloudCmd.LIBDIRCLIENT + 'edit/', - - lFiles = [ - lDir + 'mode-javascript.js', - lDir + 'worker-javascript.js', - lDir + 'ace.js', + var lFiles = [ + DIR + 'theme-tomorrow_night_blue.js', + DIR + 'ace.js', ]; DOM.anyLoadOnLoad(lFiles, function(){