diff --git a/download.php b/download.php new file mode 100755 index 00000000..13a3e84b --- /dev/null +++ b/download.php @@ -0,0 +1,15 @@ + diff --git a/include/fs.js b/include/fs.js index 07b1f1d2..6cff0a3d 100644 --- a/include/fs.js +++ b/include/fs.js @@ -299,6 +299,14 @@ cp.deleteFile = function (filename) { cp.fs.deleteFile(filename); }; +function basename(filename) { + return filename.replace(/\\/g,'/').replace( /.*\//, ''); +} + +function endsWith(str, suffix) { + return str.indexOf(suffix, str.length - suffix.length) !== -1; +} + cp.makeEditorToolbar = function (filename) { var $toolbar = makeToolbar(); @@ -315,6 +323,16 @@ cp.makeEditorToolbar = function (filename) { }); $loadButton.appendTo($group); + $saveButton = makeTBButton($(''), {"title" : "Download"}); + $saveButton.click(function () { + var name = basename(filename); + if (!endsWith(name, ".js")) { + name = name + ".js"; + } + saveAs(cp.fs.getContent(filename), name); + }); + $saveButton.appendTo($group); + return $toolbar; }; diff --git a/index.html b/index.html index 0626b46a..bc81bfea 100644 --- a/index.html +++ b/index.html @@ -256,6 +256,13 @@ function focusREPL() { cp.repl.focus(); } + + function saveAs(content, filename) { + $("#form-download-content").val(content); + $("#form-download-filename").val(filename); + + $("#form-download").submit(); + } @@ -265,5 +272,10 @@ + +
+ + +