Commit 235ddb75 authored by Romain Casati's avatar Romain Casati
Browse files

Download function goes from notebook to GUI.

parent 68e38863
......@@ -38,7 +38,7 @@ window.basthonGUI = (function () {
'output_updated.OutputArea',
'output_appended.OutputArea'] ) {
that.notebook.events.bind(
event, () => { that.notebook.saveToStorage(); } );
event, () => { that.saveToStorage(); } );
}
};
......@@ -136,6 +136,29 @@ Un lien vers la page de Basthon avec le contenu actuel du script a été créé.
});
that.notebook.events.trigger('notebook_shared.Notebook');
};
/**
* Saving notebook to local storage.
*/
that.saveToStorage = function () {
that.notebook.saveToStorage();
};
/**
* Download notebook to file.
*/
that.download = function () {
const content = JSON.stringify(that.notebook.toJSON());
var blob = new Blob([content], { type: "text/plain" });
var anchor = document.createElement("a");
anchor.download = that.notebook.notebook_name;
anchor.href = window.URL.createObjectURL(blob);
anchor.target ="_blank";
anchor.style.display = "none"; // just to be safe!
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
};
return that;
})();
......
......@@ -877,8 +877,8 @@ define([
help_index: 'fc',
icon: 'fa-save',
handler : function (env, event) {
env.notebook.saveToStorage();
env.notebook.download();
basthonGUI.saveToStorage();
basthonGUI.download();
if(event){
event.preventDefault();
}
......
......@@ -166,7 +166,7 @@ define([
return false;
});
this.element.find('#save_notebook_as').click(function() {
that.notebook.download();
basthonGUI.download();
return false;
});
......
......@@ -3077,23 +3077,6 @@ define([
}
};
/**
* [Basthon]
* Download notebook to file.
*/
Notebook.prototype.download = function () {
const content = JSON.stringify(this.toJSON());
var blob = new Blob([content], { type: "text/plain" });
var anchor = document.createElement("a");
anchor.download = this.notebook_name;
anchor.href = window.URL.createObjectURL(blob);
anchor.target ="_blank";
anchor.style.display = "none"; // just to be safe!
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
};
/**
* [Basthon]
* Open notebook from file.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment