Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix https://github.com/mozilla/thimble.webmaker.org/issues/529 - force JS to run when user manually reloads the preview #497

Merged
merged 1 commit into from
Nov 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};
});