Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…e JS to run when user manually reloads the preview
  • Loading branch information
humphd committed Nov 9, 2015
1 parent 302d453 commit 4a7e0a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/extensions/default/bramble/lib/RemoteCommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ define(function (require, exports, module) {

switch(command) {
case "BRAMBLE_RELOAD":
// If JS is disabled, re-enable it just for this next reload.
HTMLRewriter.forceScriptsOnce();
PostMessageTransport.reload();
break;
case "BRAMBLE_MOBILE_PREVIEW":
Expand Down
15 changes: 14 additions & 1 deletion src/filesystem/impls/filer/lib/HTMLRewriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ define(function (require, exports, module) {
*/
var jsEnabled = true;

/**
* Provides a way to force JS to run when disabled, but only once.
* Useful when we want to allow the user to manually refresh the page with UI
* vs. when we do it automatically.
*/
var jsEnabledOverride = false;

/**
* Rewrite all external resources (links, scripts, img sources, ...) to
* blob URL Objects from the fs.
Expand Down Expand Up @@ -133,7 +140,7 @@ define(function (require, exports, module) {
return;
}

if(jsEnabled) {
if(jsEnabled || jsEnabledOverride) {
if(element.getAttribute("type") === "text/x-scripts-disabled") {
element.removeAttribute("type");
}
Expand Down Expand Up @@ -202,6 +209,9 @@ define(function (require, exports, module) {
doctype = (new XMLSerializer()).serializeToString(doc.doctype);
}

// Reset the JS scripts override in case it was set on this run
jsEnabledOverride = false;

callback(err, doctype + html);
});
}
Expand All @@ -213,4 +223,7 @@ define(function (require, exports, module) {
exports.disableScripts = function() {
jsEnabled = false;
};
exports.forceScriptsOnce = function() {
jsEnabledOverride = true;
};
});

0 comments on commit 4a7e0a7

Please sign in to comment.