Files
svgedit/opera-widget/handlers.js
Brett Zamir 7c470e9909 - Linting (ESLint): Stricter rules (or switch to warning)
- Breaking internal API change: `updateGripCursor` moved to be class method of Selector rather than instance method
- Breaking internal API change: `subpathIsClosed` moved to be class method of `Path` rather than instance method
- Refactoring: Reuse utilities base64 encoder for SVG icons plugin
- Docs (JSDoc): Fix return of the `mouseUp` (can also be an object) and `mouseDown` (may also be a boolean) of `pathActions`; other JSDoc additions/improvements
2018-11-08 14:42:48 +08:00

61 lines
1.9 KiB
JavaScript

/* globals jQuery, svgCanvas */
/* eslint-disable no-console */
// Note: This JavaScript file must be included as the last script on the main
// HTML editor page to override the open/save handlers
jQuery(function () {
if (window.opera && window.opera.io && window.opera.io.filesystem) {
svgCanvas.setCustomHandlers({
open () {
try {
window.opera.io.filesystem.browseForFile(
new Date().getTime(), /* mountpoint name */
'', /* default location */
function (file) {
try {
if (file) {
const fstream = file.open(file, 'r');
let output = '';
while (!fstream.eof) {
output += fstream.readLine();
}
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.');
}
},
save (win, svg) {
try {
win.opera.io.filesystem.browseForSave(
new Date().getTime(), /* mountpoint name */
'', /* default location */
function (file) {
try {
if (file) {
const fstream = file.open(file, 'w');
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.');
}
}
});
}
});