Skip to content
This repository has been archived by the owner on Jul 31, 2019. It is now read-only.

Commit

Permalink
Merge pull request #381 from Pomax/jsrun
Browse files Browse the repository at this point in the history
reload button + disable JS checkbox
  • Loading branch information
Pomax committed Mar 7, 2014
2 parents 1b4d48d + 51e2b3b commit 5d656cc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions locale/en_US/thimble.webmaker.org.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"An error occurred": "An error occurred",
"Are you sure you want to publish your page?": "Are you sure you want to publish your page?",
"auto-run JS": "auto-run JavaScript",
"Cancel": "Cancel",
"Change text size": "Change text size",
"change the text in the title": "(you will have to change the text in the <title> element on your page)",
Expand Down
11 changes: 11 additions & 0 deletions public/friendlycode/css/editor.less
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,14 @@ div.editor-actions {
height: 100%;
overflow: auto;
}

.preview-pane-nav-options fieldset {
display: inline-block;
border: none;
margin: 0;
padding: 0;
}

.preview-pane-nav-options fieldset {
font-size: 80%;
}
4 changes: 4 additions & 0 deletions public/friendlycode/js/fc/ui/live-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ define(["jquery", "backbone-events", "./mark-tracker"], function($, BackboneEven
// add the preview iframe to the editor on the first
// attempt to parse the Code Mirror text.
if(!iframe.contentWindow) {
document.querySelector(".reload-button").onclick = function() {
codeMirror.reparse();
};
previewArea.append(iframe);
telegraph = iframe.contentWindow;
listenForEvents();
Expand All @@ -63,6 +66,7 @@ define(["jquery", "backbone-events", "./mark-tracker"], function($, BackboneEven
// we treat all changes as a full refresh.
var message = JSON.stringify({
type: "overwrite",
runjs: document.getElementById('preview-run-js').checked,
sourceCode: event.sourceCode
});

Expand Down
16 changes: 13 additions & 3 deletions public/friendlycode/templates/previewloader.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,21 @@
* content management object
*/
var content = {
overwrite: function overwriteIFrame(sourceCode) {
overwrite: function overwriteIFrame(data) {
var sourceCode = data.sourceCode,
runjs = !!data.runjs;
var iframe = document.createElement("iframe");
iframe.style.opacity = 0.0;
document.body.appendChild(iframe);

// disable scripts if so instructed. We don't
// actually strip them, we just give them a
// script type that is non-executing.
if(!runjs) {
var script = /<script\s*(type=["'][^\/]+\/javascript["'])?>/g;
sourceCode = sourceCode.replace(script, "<script type='text/disabled'>");
}

// set new content
doc = iframe.contentDocument;
doc.open();
Expand Down Expand Up @@ -165,7 +175,7 @@
if(!owner) { owner = event.source; }

if ("sourceCode" in data && typeof data.sourceCode === "string") {
content[data.type](data.sourceCode);
content.overwrite(data);
} else {
console.error("preview payload had no associated, valid sourceCode", event.data);
}
Expand All @@ -188,4 +198,4 @@
<body>
<iframe></iframe>
</body>
</html>
</html>
8 changes: 7 additions & 1 deletion views/friendlycode/templates/nav-options.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
<div class="preview-pane-nav-options">
<!-- previous, save draft, publish -->
<div class="preview-nav-item nav-item">
<span class="icon">&nbsp;</span>{{ gettext("Preview") }}<div class="pane-indicator enabled"></div>
<span class="icon">&nbsp;</span>{{ gettext("Preview") }}
<button class="reload-button wm-button wm-button-blue short">{{ gettext("reload") }}</button>
<fieldset>
<input type="checkbox" id="preview-run-js" checked>
<label for="preview-run-js">{{ gettext("auto-run JS") }}</label>
</fieldset>
<div class="pane-indicator enabled"></div>
</div>
<div class="nav-item buttons">
<a class="page-view-link" href="" target="_blank"><div class="page-view-button wm-button wm-button-blue short">{{ gettext("View") }}</div></a>
Expand Down

0 comments on commit 5d656cc

Please sign in to comment.