From c79e785ae44a2630e86c35126ff2401894a0b5d7 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 4 Apr 2014 06:21:35 -0400 Subject: [PATCH] feature(edit) add suport of .jshintrc --- lib/client/edit.js | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/client/edit.js b/lib/client/edit.js index fb9401c8..63aa206b 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; Dialog = DOM.Dialog, Key = CloudCmd.Key, Images = DOM.Images, - Element; + Element, JSHintConfig; function init() { Loading = true; @@ -33,7 +33,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; } this.show = function(value) { - var mode, htmlMode, isHTML, + var mode, htmlMode, jsMode, isHTML, isJS, modesByName, isStr = Util.isString(value), name = Info.name, isDir = Info.isDir, @@ -56,13 +56,18 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; initAce(); } + modesByName = Modelist.modesByName; + if (isDir) - mode = Modelist.modesByName.json.mode; + mode = modesByName.json.mode; else mode = Modelist.getModeForPath(name).mode; - htmlMode = Modelist.modesByName.html.mode; + htmlMode = modesByName.html.mode; + jsMode = modesByName.javascript.mode; + isHTML = mode === htmlMode; + isJS = mode === jsMode; Session.setMode(mode); @@ -97,6 +102,9 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; Value = data; Ace.setValue(data); CloudCmd.View.show(Element, focus); + + if (isJS && Session.getUseWorker()) + setJsHintConfig(); }); } }; @@ -273,6 +281,28 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; }); } + function setJsHintConfig(callback) { + var JSHINT_PATH = '/.jshintrc', + func = function() { + var worker = Session.$worker; + + if (worker) + worker.send('changeOptions', [JSHintConfig]); + + Util.exec(callback); + }; + + Util.ifExec(JSHintConfig, func, function() { + DOM.ajax({ + url : JSHINT_PATH, + success : function(data) { + JSHintConfig = Util.parseJSON(data); + func(); + } + }); + }); + } + function load(callback) { var files = [