Skip to content

Commit f852505

Browse files
committed
Can download runnable program
1 parent 4f028c3 commit f852505

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

ide/ide.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ $(function () {
462462
// Reverses what router() does, returning a URI (starting with #)
463463
if (ext) route = $.extend({}, route, ext)
464464
var h = "#/"
465-
if (route.page=="welcome") return h
466-
if (route.page=="action") return h+e(route.action)
465+
if (route.page == "welcome") return h
466+
if (route.page == "action") return h+e(route.action)
467467
if (route.user) {
468468
h += "user/" + e(route.user) + "/"
469469
if (route.page == "user") return h
@@ -474,6 +474,7 @@ $(function () {
474474
h += "program/" + e(route.program)
475475
if (route.page == "run") return h
476476
if (route.page == "downloadFolder") return h + "/option/" + e(route.page)
477+
if (route.page == "downloadHTML") return h + "/option/" + e(route.page)
477478
if (route.page == "downloadProgram") return h + "/option/" + e(route.page)
478479
if (route.page == "share" || route.page == "edit") return h + "/" + e(route.page)
479480
}
@@ -558,6 +559,7 @@ $(function () {
558559

559560
/********** Pages **********/
560561
// Each of these replaces pageBody with the contents of a page
562+
var embedHTML // The JavaScript code generated at pages.share
561563
var pageBody = $("#ajaxBody")
562564
pages.redirect = function(route) { redirect(route.target) }
563565
pages.error = function(route) {
@@ -1295,6 +1297,7 @@ $(function () {
12951297
if (!header.ok)
12961298
page.find(".embedWarning").text("This program cannot be embedded because its version declaration is unknown.")
12971299
else {
1300+
embedHTML = '' // Will be an ampty string if there is a compile error
12981301
if (header.unpackaged)
12991302
page.find(".embedWarning").text("Embedding programs with development versions of GlowScript is not recommended. They will likely be broken by further changes, and the packages used for embedding may not match the packages used to run in an development version.")
13001303
var compiler_url
@@ -1343,8 +1346,8 @@ $(function () {
13431346
if (v >= 2.5 && v < 3.0) exporturl = "https://s3.amazonaws.com/glowscript/"
13441347
// Note: some already exported 3.0 programs contain references to s3.amazonaws.com
13451348
if (header.lang == 'vpython')
1346-
runner = '<script type="text/javascript" src="'+exporturl+'package/RSrun.' + header.version + '.min.js"></script>\n'
1347-
var embedHTML = (
1349+
runner = '<script type="text/javascript" src="'+exporturl+'package/RSrun.' + header.version + '.min.js"></script>\n'
1350+
embedHTML = ( // embedHTML is a var introduced above to make it easy for downloadHTML
13481351
'<div id="' + divid + '" class="glowscript">\n' +
13491352
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n' +
13501353
'<link type="text/css" href="'+exporturl+'css/redmond/' + verdir + '/jquery-ui.custom.css" rel="stylesheet" />\n' +
@@ -1359,14 +1362,29 @@ $(function () {
13591362
'\n//--><!]]></script>' +
13601363
'\n</div>');
13611364
page.find(".embedSource").text( embedHTML )
1365+
page.find(".prog-download-html.button").prop("href", unroute(route, {page:"downloadHTML"}))
1366+
page.find(".prog-download-html.button").text('Download as HTML')
1367+
// page.find(".prog-edit.button").prop("href", unroute(route, {page:"edit"}))
1368+
// if (isWritable) page.find(".prog-edit.button").text('Edit this program')
1369+
// else page.find(".prog-edit.button").text('View this program')
13621370
})
13631371
}
13641372
})
1365-
13661373
var frameSrc = run_link
13671374
var frameHTML = '<iframe style="border-style:none; border:0; width:650px; height:500px; margin:0; padding:0;" allow="hid" frameborder=0 src="' + frameSrc + '"></iframe>'
13681375
page.find(".frameSource").text( frameHTML );
13691376
}
1377+
pages.downloadHTML = function(route) { // Download an .html file suitable for running just by clicking it
1378+
if (embedHTML.length > 0) {
1379+
let a = document.createElement("a")
1380+
a.setAttribute('href', 'data:text/text;charset=utf-8,' + encodeURIComponent(embedHTML));
1381+
a.setAttribute('download', route.program+'.html');
1382+
a.click()
1383+
a.remove()
1384+
}
1385+
1386+
navigate(unroute(route, {page:"edit"})) // return to (stay on) edit page
1387+
}
13701388
pages.downloadProgram = function(route) { // Currently the only program option is download (download a program to user computer)
13711389
apiDownload( {user:route.user, folder:route.folder, program: route.program, option:'downloadProgram'}, function(ret) {
13721390
window.location = apiURL(route) // this sends the file to the user's download folder

ide/templates/index.html

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,13 @@ <h2>V e r s i o n&nbsp;&nbsp; 3.2</h2>
292292
<b>The program must be in a public folder, not a private folder.</b></li>
293293
<li>You can publish a link to an entire <b>public</b> folder: <a class="folder-link"></a>.</li>
294294
<li>Export: you can <em>embed</em> the program, including from a private folder,
295-
directly in your own web page, using the HTML provided below.
295+
directly in your own web page, using the HTML code provided below.
296296
If your page already uses jquery, you should delete that &lt;script&gt; tag.
297297
</li>
298-
<li>Another option is to save the HTML in a file ending in ".html". Doubleclick this file and it
299-
will run in your browser.
300-
You can place this file on a web site and run the program in a browser by giving the URL.
301-
You can also place the html file in an iframe portion of a web page by placing in the html of the web page a statement like this
298+
<li>Another option is to save the HTML code shown below in a file ending in ".html", then
299+
doubleclick the html file and it will run in your browser.
300+
<li>Or simply click<a class="prog-download-html button"><b>Download as HTML</b></a> and then double-click the downloaded file to run it.
301+
<li>You can also place the html file in an iframe portion of a web page by placing in the html of the web page a statement like this
302302
:<br>
303303
&nbsp;&nbsp;&nbsp;&nbsp;&lt;iframe src="test.html" width="320" height="340"&gt&lt;/iframe&gt<br>
304304
where "test.html" is the location of the program relative to the location of the iframe statement, and where
@@ -313,12 +313,8 @@ <h2>V e r s i o n&nbsp;&nbsp; 3.2</h2>
313313
the output of the minifier. You will see that it is very difficult to understand the minified program, even if
314314
you pass it through a "beautifier" program, because many of the variable names have been replaced by single letters.
315315
</ul>
316-
<!--
317-
<li>You can <em>frame</em> the program, using the following HTML
318-
(<b>Warning:</b> this doesn't actually work yet!):
319-
<p><textarea class="frameSource"></pre></textarea></p>
320-
</ul>
321-
-->
316+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<em>If the area below is blank, the program has errors.<br>
317+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbspFix the errors and then try again.</em><br>&nbsp;&nbsp;&nbsp;
322318
<span class="embedWarning errorText"></span>
323319
<p><textarea class="embedSource"></textarea></p>
324320
</div>

static/images/favicon.ico

1.23 KB
Binary file not shown.

0 commit comments

Comments
 (0)