From 4fc31d89a9512c8ed77d7f55b389f79c8b85854d Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 1 Apr 2014 09:42:20 -0400 Subject: [PATCH] refactor(edit) show: rm cssMode, add ifExec --- lib/client/edit.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/client/edit.js b/lib/client/edit.js index 6c4e193e..fb9401c8 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -32,9 +32,10 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; ]); } - this.show = function(pValue) { - var lMode, htmlMode, cssMode, url, - lName = Info.name, + this.show = function(value) { + var mode, htmlMode, isHTML, + isStr = Util.isString(value), + name = Info.name, isDir = Info.isDir, lExt = Info.ext; @@ -48,7 +49,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; 'width : 100%;' + 'height : 100%;' + 'font : 16px "Droid Sans Mono";' + - 'position: absolute;', + 'position : absolute;', not_append : true }); @@ -56,18 +57,23 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; } if (isDir) - lMode = Modelist.modesByName.json.mode; + mode = Modelist.modesByName.json.mode; else - lMode = Modelist.getModeForPath(lName).mode; + mode = Modelist.getModeForPath(name).mode; - htmlMode = Modelist.modesByName.html.mode; - cssMode = Modelist.modesByName.css.mode; + htmlMode = Modelist.modesByName.html.mode; + isHTML = mode === htmlMode; - Session.setMode(lMode); + Session.setMode(mode); - if (lMode === htmlMode) { + Util.ifExec(Emmet, function() { if (Emmet) - Ace.setOption('enableEmmet', true); + Ace.setOption('enableEmmet', isHTML); + }, function(callback) { + var url; + + if (!isHTML) + Util.exec(callback); else { url = CloudFunc.getJoinURL([ DIR + 'emmet.js', @@ -77,15 +83,13 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; DOM.jsload(url, function() { Emmet = ace.require('ace/ext/emmet'); Emmet.setCore(window.emmet); - Ace.setOption('enableEmmet', true); + Util.exec(callback); }); } - } else if (Emmet) { - Ace.setOption('enableEmmet', false); - } + }); - if (Util.isString(pValue)) { - Ace.setValue(pValue); + if (isStr) { + Ace.setValue(value); CloudCmd.View.show(Element, focus); Key.unsetBind(); } else