Skip to content

Commit c299ed2

Browse files
committed
Functions CATMAID.saveTextAs and CATMAID.saveJSONAs to abstract away
the need for a Blob and mimetype when invoking saveAs.
1 parent 4555344 commit c299ed2

File tree

1 file changed

+22
-0
lines changed
  • django/applications/catmaid/static/libs/catmaid

1 file changed

+22
-0
lines changed

django/applications/catmaid/static/libs/catmaid/io.js

+22
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,26 @@
8080
).join(recordSep);
8181
};
8282

83+
/**
84+
* A convenient function to invoke saveAs with the appropriate Blob
85+
* and mimetype, for plain text.
86+
* The filename is optional.
87+
*/
88+
CATMAID.saveTextAs = function(text, filename)
89+
{
90+
return saveAs(new Blob([text], {type: 'text/plain'}),
91+
undefined === filename ? "content.txt" : filename);
92+
};
93+
94+
/**
95+
* A convenient function to invoke saveAs with the appropriate Blob
96+
* and mimetype, for a javascript object (array, object, etc.)
97+
* The filename is optional.
98+
*/
99+
CATMAID.saveJSONAs = function(ob, filename)
100+
{
101+
return saveAs(new Blob([JSON.stringify(ob)], {type: 'text/plain'}),
102+
undefined === filename ? "ob.json" : filename);
103+
};
104+
83105
})(CATMAID);

0 commit comments

Comments
 (0)