From 457cf9f5fd7446222d4b6f47a884dc8b7dc8879c Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sun, 11 May 2014 06:07:11 -0400 Subject: [PATCH] feature(edit) mv options to file --- json/edit.json | 13 ++++++++ lib/client/edit.js | 82 +++++++++++++++++++++++++++++----------------- 2 files changed, 65 insertions(+), 30 deletions(-) create mode 100644 json/edit.json diff --git a/json/edit.json b/json/edit.json new file mode 100644 index 00000000..31f5d745 --- /dev/null +++ b/json/edit.json @@ -0,0 +1,13 @@ +{ + "options": { + "enableBasicAutocompletion": true, + "enableSnippets": false, + "showPrintMargin": false, + "showInvisibles": true, + "useSoftTabs": true + }, + + "extensions": { + "emmet": false + } +} diff --git a/lib/client/edit.js b/lib/client/edit.js index 3cf9b548..f34c4716 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -21,7 +21,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; Events = DOM.Events, Dialog = DOM.Dialog, Images = DOM.Images, - Element, JSHintConfig; + Element, JSHintConfig, EditConfig; function init() { Loading = true; @@ -83,28 +83,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; Session.setMode(mode); setUseOfWorker(mode); - Util.ifExec(Emmet, function() { - if (Emmet) - Ace.setOption('enableEmmet', isHTML); - }, function(callback) { - var url; - - if (!isHTML) - Util.exec(callback); - else { - url = CloudFunc.getJoinURL([ - DIR + 'emmet.js', - DIR + 'ext-emmet.js' - ]); - - DOM.jsload(url, function() { - Emmet = ace.require('ace/ext/emmet'); - Emmet.setCore(window.emmet); - Util.exec(callback); - }); - } - }); - + setEmmet(isHTML); Util.ifExec(isStr, function() { var UndoManager = ace.require('ace/undomanager').UndoManager; @@ -142,6 +121,36 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; Ace.gotoLine(number); }; + function setEmmet(isHTML) { + getEditConfig(function(config) { + var extensions = config.extensions, + isEmmet = extensions.emmet; + + if (isEmmet) + Util.ifExec(Emmet, function() { + if (Emmet) + Ace.setOption('enableEmmet', isHTML); + }, function(callback) { + var url; + + if (!isHTML) + Util.exec(callback); + else { + url = CloudFunc.getJoinURL([ + DIR + 'emmet.js', + DIR + 'ext-emmet.js' + ]); + + DOM.jsload(url, function() { + Emmet = ace.require('ace/ext/emmet'); + Emmet.setCore(window.emmet); + Util.exec(callback); + }); + } + }); + }); + } + function setUseOfWorker(mode) { var isMatch, isStr = Util.isString(mode), @@ -160,10 +169,6 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; Ace.setTheme('ace/theme/tomorrow_night_blue'); - Ace.setShowPrintMargin(false); - Ace.setShowInvisibles(true); - Session.setUseSoftTabs(true); - Ace.commands.addCommand({ name : 'hide', bindKey : { win: 'Esc', mac: 'Esc' }, @@ -195,9 +200,10 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; ace.require('ace/ext/language_tools'); Modelist = ace.require('ace/ext/modelist'); - Ace.setOptions({ - enableBasicAutocompletion : true, - enableSnippets : true + getEditConfig(function(config) { + var options = config.options; + + Ace.setOptions(options); }); } @@ -326,6 +332,22 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; }); } + function getEditConfig(callback) { + var CONFIG_PATH = '/json/edit.json', + func = Util.retExec(callback); + + Util.ifExec(EditConfig, function() { + func(EditConfig); + }, function() { + DOM.ajax({ + url : CONFIG_PATH, + success : function(data) { + EditConfig = data; + func(EditConfig); + } + }); + }); + } function load(callback) { var files = [