2018-05-18 03:25:45 +00:00
|
|
|
/* globals jQuery, svgCanvas */
|
2009-08-25 18:22:43 +00:00
|
|
|
// Note: This JavaScript file must be included as the last script on the main HTML editor page to override the open/save handlers
|
2018-05-18 03:25:45 +00:00
|
|
|
jQuery(function () {
|
2018-05-18 06:23:36 +00:00
|
|
|
if (window.opera && window.opera.io && window.opera.io.filesystem) {
|
|
|
|
svgCanvas.setCustomHandlers({
|
2018-05-18 03:25:45 +00:00
|
|
|
open () {
|
2018-05-18 06:23:36 +00:00
|
|
|
try {
|
|
|
|
window.opera.io.filesystem.browseForFile(
|
|
|
|
new Date().getTime(), /* mountpoint name */
|
|
|
|
'', /* default location */
|
|
|
|
function (file) {
|
|
|
|
try {
|
|
|
|
if (file) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const fstream = file.open(file, 'r');
|
|
|
|
let output = '';
|
2018-05-18 06:23:36 +00:00
|
|
|
while (!fstream.eof) {
|
|
|
|
output += fstream.readLine();
|
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2018-05-18 06:23:36 +00:00
|
|
|
svgCanvas.setSvgString(output); /* 'this' is bound to the filestream object here */
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Reading file failed.');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
false, /* not persistent */
|
|
|
|
false, /* no multiple selections */
|
|
|
|
'*.svg' /* file extension filter */
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Open file failed.');
|
|
|
|
}
|
|
|
|
},
|
2018-05-18 03:25:45 +00:00
|
|
|
save (window, svg) {
|
2018-05-18 06:23:36 +00:00
|
|
|
try {
|
|
|
|
window.opera.io.filesystem.browseForSave(
|
|
|
|
new Date().getTime(), /* mountpoint name */
|
|
|
|
'', /* default location */
|
|
|
|
function (file) {
|
|
|
|
try {
|
|
|
|
if (file) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const fstream = file.open(file, 'w');
|
2018-05-18 06:23:36 +00:00
|
|
|
fstream.write(svg, 'UTF-8');
|
|
|
|
fstream.close();
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Write to file failed.');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
false /* not persistent */
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Save file failed.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
});
|