diff --git a/src/bramble/client/StateManager.js b/src/bramble/client/StateManager.js index 25b6f211a87..0e18a8f5425 100644 --- a/src/bramble/client/StateManager.js +++ b/src/bramble/client/StateManager.js @@ -101,6 +101,10 @@ define(function() { wordWrap: { get: function() { return getBool(storage, "wordWrap"); }, set: function(v) { storage.setItem(prefix("wordWrap"), v); } + }, + allowJavaScript: { + get: function() { return getBool(storage, "allowJavaScript"); }, + set: function(v) { storage.setItem(prefix("allowJavaScript"), v); } } }); } diff --git a/src/bramble/client/main.js b/src/bramble/client/main.js index 29ecc68e700..690c07bf553 100644 --- a/src/bramble/client/main.js +++ b/src/bramble/client/main.js @@ -204,6 +204,7 @@ define([ self.getSidebarVisible = function() { return _state.sidebarVisible; }; self.getRootDir = function() { return _root; }; self.getWordWrap = function() { return _state.wordWrap; }; + self.getAllowJavaScript = function() { return _state.allowJavaScript; }; self.getTutorialExists = function() { return _tutorialExists; }; self.getTutorialVisible = function() { return _tutorialVisible; }; self.getLayout = function() { @@ -262,6 +263,7 @@ define([ _state.previewMode = data.previewMode; _state.theme = data.theme; _state.wordWrap = data.wordWrap; + _state.allowJavaScript = data.allowJavaScript; setReadyState(Bramble.READY); } @@ -297,6 +299,8 @@ define([ _state.sidebarVisible = data.visible; } else if (eventName === "wordWrapChange") { _state.wordWrap = data.wordWrap; + } else if (eventName === "allowJavaScriptChange") { + _state.allowJavaScript = data.allowJavaScript; } else if (eventName === "tutorialVisibilityChange") { _tutorialVisible = data.visible; } @@ -412,7 +416,8 @@ define([ firstPaneWidth: _state.firstPaneWidth, secondPaneWidth: _state.secondPaneWidth, previewMode: _state.previewMode, - wordWrap: _state.wordWrap + wordWrap: _state.wordWrap, + allowJavaScript: _state.allowJavaScript } }; _brambleWindow.postMessage(JSON.stringify(initMessage), _iframe.src); diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 576026a6a67..b11ffb06158 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -96,7 +96,8 @@ define(function (require, exports, module) { TAB_SIZE = "tabSize", UPPERCASE_COLORS = "uppercaseColors", USE_TAB_CHAR = "useTabChar", - WORD_WRAP = "wordWrap"; + WORD_WRAP = "wordWrap", + ALLOW_JAVASCRIPT = "allowJavaScript"; var cmOptions = {}; @@ -125,7 +126,8 @@ define(function (require, exports, module) { cmOptions[TAB_SIZE] = "tabSize"; cmOptions[USE_TAB_CHAR] = "indentWithTabs"; cmOptions[WORD_WRAP] = "lineWrapping"; - + cmOptions[ALLOW_JAVASCRIPT] = "allowJavaScript"; + PreferencesManager.definePreference(CLOSE_BRACKETS, "boolean", false); PreferencesManager.definePreference(CLOSE_TAGS, "Object", { whenOpening: true, whenClosing: true, indentTags: [] }); PreferencesManager.definePreference(DRAG_DROP, "boolean", false); @@ -145,7 +147,8 @@ define(function (require, exports, module) { PreferencesManager.definePreference(UPPERCASE_COLORS, "boolean", false); PreferencesManager.definePreference(USE_TAB_CHAR, "boolean", false); PreferencesManager.definePreference(WORD_WRAP, "boolean", true); - + PreferencesManager.definePreference(ALLOW_JAVASCRIPT, "boolean", true); + var editorOptions = Object.keys(cmOptions); /** Editor preferences */ @@ -321,6 +324,7 @@ define(function (require, exports, module) { inputStyle : "textarea", // the "contenteditable" mode used on mobiles could cause issues lineNumbers : currentOptions[SHOW_LINE_NUMBERS], lineWrapping : currentOptions[WORD_WRAP], + allowJavaScript : currentOptions[ALLOW_JAVASCRIPT], matchBrackets : { maxScanLineLength: 50000, maxScanLines: 1000 }, matchTags : { bothTags: true }, scrollPastEnd : !range && currentOptions[SCROLL_PAST_END], @@ -2406,6 +2410,15 @@ define(function (require, exports, module) { return PreferencesManager.get(WORD_WRAP, _buildPreferencesContext(fullPath)); }; + Editor.setAllowJavaScript = function (value, fullPath) { + var options = fullPath && {context: fullPath}; + return PreferencesManager.set(ALLOW_JAVASCRIPT, value, options); + }; + + Editor.getAllowJavaScript = function (fullPath) { + return PreferencesManager.get(ALLOW_JAVASCRIPT, _buildPreferencesContext(fullPath)); + }; + /** * Runs callback for every Editor instance that currently exists * @param {!function(!Editor)} callback diff --git a/src/editor/EditorOptionHandlers.js b/src/editor/EditorOptionHandlers.js index 1af9cfa5bf3..d024360c282 100644 --- a/src/editor/EditorOptionHandlers.js +++ b/src/editor/EditorOptionHandlers.js @@ -39,6 +39,7 @@ define(function (require, exports, module) { var SHOW_LINE_NUMBERS = "showLineNumbers", STYLE_ACTIVE_LINE = "styleActiveLine", WORD_WRAP = "wordWrap", + ALLOW_JAVASCRIPT = "allowJavaScript", CLOSE_BRACKETS = "closeBrackets"; /** @@ -50,6 +51,7 @@ define(function (require, exports, module) { _optionMapping[SHOW_LINE_NUMBERS] = Commands.TOGGLE_LINE_NUMBERS; _optionMapping[STYLE_ACTIVE_LINE] = Commands.TOGGLE_ACTIVE_LINE; _optionMapping[WORD_WRAP] = Commands.TOGGLE_WORD_WRAP; + _optionMapping[ALLOW_JAVASCRIPT] = Commands.TOGGLE_ALLOW_JAVASCRIPT; _optionMapping[CLOSE_BRACKETS] = Commands.TOGGLE_CLOSE_BRACKETS; /** @@ -99,6 +101,7 @@ define(function (require, exports, module) { CommandManager.register(Strings.CMD_TOGGLE_LINE_NUMBERS, Commands.TOGGLE_LINE_NUMBERS, _getToggler(SHOW_LINE_NUMBERS)); CommandManager.register(Strings.CMD_TOGGLE_ACTIVE_LINE, Commands.TOGGLE_ACTIVE_LINE, _getToggler(STYLE_ACTIVE_LINE)); CommandManager.register(Strings.CMD_TOGGLE_WORD_WRAP, Commands.TOGGLE_WORD_WRAP, _getToggler(WORD_WRAP)); + CommandManager.register(Strings.CMD_TOGGLE_ALLOW_JAVASCRIPT, Commands.TOGGLE_ALLOW_JAVASCRIPT, _getToggler(ALLOW_JAVASCRIPT)); CommandManager.register(Strings.CMD_TOGGLE_CLOSE_BRACKETS, Commands.TOGGLE_CLOSE_BRACKETS, _getToggler(CLOSE_BRACKETS)); AppInit.htmlReady(_init); diff --git a/src/extensions/default/bramble/lib/RemoteCommandHandler.js b/src/extensions/default/bramble/lib/RemoteCommandHandler.js index e064f1e881c..3efaf5784fb 100644 --- a/src/extensions/default/bramble/lib/RemoteCommandHandler.js +++ b/src/extensions/default/bramble/lib/RemoteCommandHandler.js @@ -91,10 +91,12 @@ define(function (require, exports, module) { break; case "BRAMBLE_ENABLE_SCRIPTS": HTMLRewriter.enableScripts(); + PreferencesManager.set("allowJavaScript", true); PostMessageTransport.reload(); break; case "BRAMBLE_DISABLE_SCRIPTS": HTMLRewriter.disableScripts(); + PreferencesManager.set("allowJavaScript", false); PostMessageTransport.reload(); break; case "BRAMBLE_ENABLE_INSPECTOR": diff --git a/src/extensions/default/bramble/lib/RemoteEvents.js b/src/extensions/default/bramble/lib/RemoteEvents.js index 2c6d8240cb3..88d1f4e575e 100644 --- a/src/extensions/default/bramble/lib/RemoteEvents.js +++ b/src/extensions/default/bramble/lib/RemoteEvents.js @@ -125,6 +125,14 @@ define(function (require, exports, module) { wordWrap: PreferencesManager.get("wordWrap") }); }); + + // Listen for changes to allow javascript + PreferencesManager.on("change", "allowJavaScript", function () { + sendEvent({ + type: "bramble:allowJavaScriptChange", + allowJavaScript: PreferencesManager.get("allowJavaScript") + }); + }); } /** @@ -156,7 +164,8 @@ define(function (require, exports, module) { previewMode: UI.getPreviewMode(), fontSize: ViewCommandHandlers.getFontSize(), theme: Theme.getTheme(), - wordWrap: PreferencesManager.get("wordWrap") + wordWrap: PreferencesManager.get("wordWrap"), + allowJavaScript: PreferencesManager.get("allowJavaScript") }); } diff --git a/src/extensions/default/bramble/lib/UI.js b/src/extensions/default/bramble/lib/UI.js index 5bf675c9ea9..c4f7b52f09e 100644 --- a/src/extensions/default/bramble/lib/UI.js +++ b/src/extensions/default/bramble/lib/UI.js @@ -89,6 +89,11 @@ define(function (require, exports, module) { PreferencesManager.set("wordWrap", wordWrap); } + var allowJavaScript = BrambleStartupState.ui("allowJavaScript"); + if(typeof allowJavaScript === "boolean") { + PreferencesManager.set("allowJavaScript", allowJavaScript); + } + var sidebarWidth = BrambleStartupState.ui("sidebarWidth"); if(sidebarWidth) { SidebarView.resize(sidebarWidth); diff --git a/src/extensions/default/bramble/main.js b/src/extensions/default/bramble/main.js index 7a27e4dd964..3d31c18c7c0 100644 --- a/src/extensions/default/bramble/main.js +++ b/src/extensions/default/bramble/main.js @@ -190,7 +190,8 @@ define(function (require, exports, module) { firstPaneWidth: data.state.firstPaneWidth, secondPaneWidth: data.state.secondPaneWidth, previewMode: data.state.previewMode, - wordWrap: data.state.wordWrap + wordWrap: data.state.wordWrap, + allowJavaScript: data.state.allowJavaScript }); RemoteEvents.start();