Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
humphd committed Apr 7, 2016
1 parent 559dbc5 commit 0149402
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ to be notified when the action completes:
* `useDesktopPreview([callback])` - uses a Desktop view in the preview, as it would look on a desktop computer (default)
* `enableFullscreenPreview([callback])` - shows a fullscreen preview of the current file
* `disableFullscreenPreview([callback])` - turns off the fullscreen preview of the curent file
* `enableAutoUpdate([callback])` - turns on auto-update for the preview (default)
* `disableAutoUpdate([callback])` - turns off auto-update for the preview (manual reloads still work)
* `enableJavaScript([callback])` - turns on JavaScript execution for the preview (default)
* `disableJavaScript([callback])` - turns off JavaScript execution for the preview
* `enableInspector([callback])` - turns on the preview inspector (shows code for hovered/clicked element)
Expand Down
8 changes: 8 additions & 0 deletions src/bramble/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,14 @@ define([
this._executeRemoteCommand({commandCategory: "bramble", command: "BRAMBLE_DISABLE_FULLSCREEN_PREVIEW"}, callback);
};

BrambleProxy.prototype.enableAutoUpdate = function(callback) {
this._executeRemoteCommand({commandCategory: "bramble", command: "BRAMBLE_ENABLE_AUTO_UPDATE"}, callback);
};

BrambleProxy.prototype.disableAutoUpdate = function(callback) {
this._executeRemoteCommand({commandCategory: "bramble", command: "BRAMBLE_DISABLE_AUTO_UPDATE"}, callback);
};

BrambleProxy.prototype.enableJavaScript = function(callback) {
this._executeRemoteCommand({commandCategory: "bramble", command: "BRAMBLE_ENABLE_SCRIPTS"}, callback);
};
Expand Down
24 changes: 23 additions & 1 deletion src/extensions/default/bramble/lib/PostMessageTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,32 @@ define(function (require, exports, module) {
// URL of document being rewritten/launched (if any)
var _pendingReloadUrl;

function reload() {
// Whether or not to allow reloads in the general case (true by default)
var _autoUpdate = true;

function setAutoUpdate(value) {
_autoUpdate = value;

// Force a reload if we switch back to auto-updates
if(_autoUpdate) {
reload(true);
}
}

/**
* Reload the LiveDev preview if not auto-updates aren't disabled.
* If force=true, we ignore the current state of auto-updates and do it.
*/
function reload(force) {
var launcher = Launcher.getCurrentInstance();
var liveDoc = LiveDevMultiBrowser._getCurrentLiveDoc();
var url;

// If auto-updates are disabled, and force wasn't passed, bail.
if(!_autoUpdate && !force) {
return;
}

// Don't go any further if we don't have a live doc yet (nothing to reload)
if(!liveDoc) {
return;
Expand All @@ -226,6 +247,7 @@ define(function (require, exports, module) {

// Exports
module.exports.getRemoteScript = getRemoteScript;
module.exports.setAutoUpdate = setAutoUpdate;
module.exports.setIframe = setIframe;
module.exports.start = start;
module.exports.send = send;
Expand Down
8 changes: 7 additions & 1 deletion src/extensions/default/bramble/lib/RemoteCommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ define(function (require, exports, module) {
case "BRAMBLE_RELOAD":
// If JS is disabled, re-enable it just for this next reload.
HTMLRewriter.forceScriptsOnce();
PostMessageTransport.reload();
PostMessageTransport.reload(true);
break;
case "BRAMBLE_MOBILE_PREVIEW":
UI.showMobileView();
Expand All @@ -83,6 +83,12 @@ define(function (require, exports, module) {
case "BRAMBLE_DISABLE_FULLSCREEN_PREVIEW":
UI.disableFullscreenPreview();
break;
case "BRAMBLE_ENABLE_AUTO_UPDATE":
PostMessageTransport.setAutoUpdate(true);
break;
case "BRAMBLE_DISABLE_AUTO_UPDATE":
PostMessageTransport.setAutoUpdate(false);
break;
case "BRAMBLE_ENABLE_SCRIPTS":
HTMLRewriter.enableScripts();
PostMessageTransport.reload();
Expand Down

0 comments on commit 0149402

Please sign in to comment.