From 4a7e0a7c62b4ba657bf217839558e5b53779c1b2 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Fri, 6 Nov 2015 12:22:01 -0500 Subject: [PATCH] Fix https://github.com/mozilla/thimble.webmaker.org/issues/529 - force JS to run when user manually reloads the preview --- .../default/bramble/lib/RemoteCommandHandler.js | 2 ++ src/filesystem/impls/filer/lib/HTMLRewriter.js | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/extensions/default/bramble/lib/RemoteCommandHandler.js b/src/extensions/default/bramble/lib/RemoteCommandHandler.js index fecb08775ce..c99f7bc5e76 100644 --- a/src/extensions/default/bramble/lib/RemoteCommandHandler.js +++ b/src/extensions/default/bramble/lib/RemoteCommandHandler.js @@ -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": diff --git a/src/filesystem/impls/filer/lib/HTMLRewriter.js b/src/filesystem/impls/filer/lib/HTMLRewriter.js index 3c61992ba51..8784401ab03 100644 --- a/src/filesystem/impls/filer/lib/HTMLRewriter.js +++ b/src/filesystem/impls/filer/lib/HTMLRewriter.js @@ -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. @@ -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"); } @@ -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); }); } @@ -213,4 +223,7 @@ define(function (require, exports, module) { exports.disableScripts = function() { jsEnabled = false; }; + exports.forceScriptsOnce = function() { + jsEnabledOverride = true; + }; });