Skip to content

Commit e15701d

Browse files
committed
Added BaseLoader.save method.
Not really meant for production use, but super-handy for dev tools and prototypes.
1 parent 8b7bf81 commit e15701d

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

v3/src/loader/BaseLoader.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,30 @@ var BaseLoader = new Class({
443443
this.storage.clear();
444444
},
445445

446+
saveJSON: function (data, filename)
447+
{
448+
return this.save(JSON.stringify(data), filename);
449+
},
450+
451+
save: function (data, filename, filetype)
452+
{
453+
if (filename === undefined) { filename = 'file.json'; }
454+
if (filetype === undefined) { filetype = 'application/json'; }
455+
456+
var blob = new Blob([data], { type: filetype });
457+
458+
var url = URL.createObjectURL(blob);
459+
460+
var a = document.createElement('a');
461+
462+
a.download = filename;
463+
a.textContent = 'Download ' + filename;
464+
a.href = url;
465+
a.click();
466+
467+
return this;
468+
},
469+
446470
reset: function ()
447471
{
448472
this.list.clear();

0 commit comments

Comments
 (0)