2018-05-18 03:25:45 +00:00
|
|
|
/* global svgCanvas, jQuery, Components, netscape */
|
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.Components) return;
|
2009-09-04 16:10:50 +00:00
|
|
|
|
2018-05-18 06:23:36 +00:00
|
|
|
function mozFilePicker (readflag) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const fp = window.Components.classes['@mozilla.org/filepicker;1']
|
2018-05-18 06:23:36 +00:00
|
|
|
.createInstance(Components.interfaces.nsIFilePicker);
|
|
|
|
if (readflag) fp.init(window, 'Pick a SVG file', fp.modeOpen);
|
|
|
|
else fp.init(window, 'Pick a SVG file', fp.modeSave);
|
|
|
|
fp.defaultExtension = '*.svg';
|
|
|
|
fp.show();
|
|
|
|
return fp.file;
|
|
|
|
}
|
2009-09-04 16:10:50 +00:00
|
|
|
|
2018-05-18 06:23:36 +00:00
|
|
|
svgCanvas.setCustomHandlers({
|
2018-05-18 03:25:45 +00:00
|
|
|
open () {
|
2018-05-18 06:23:36 +00:00
|
|
|
try {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
2018-05-18 03:25:45 +00:00
|
|
|
const file = mozFilePicker(true);
|
2018-05-18 06:23:36 +00:00
|
|
|
if (!file) {
|
|
|
|
return null;
|
|
|
|
}
|
2009-09-04 16:10:50 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const inputStream = Components.classes['@mozilla.org/network/file-input-stream;1'].createInstance(Components.interfaces.nsIFileInputStream);
|
2018-05-18 06:23:36 +00:00
|
|
|
inputStream.init(file, 0x01, parseInt('00004', 8), null);
|
2018-05-18 03:25:45 +00:00
|
|
|
const sInputStream = Components.classes['@mozilla.org/scriptableinputstream;1'].createInstance(Components.interfaces.nsIScriptableInputStream);
|
2018-05-18 06:23:36 +00:00
|
|
|
sInputStream.init(inputStream);
|
|
|
|
svgCanvas.setSvgString(sInputStream.read(sInputStream.available()));
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Exception while attempting to load' + e);
|
|
|
|
}
|
|
|
|
},
|
2018-05-18 03:25:45 +00:00
|
|
|
save (svg, str) {
|
2018-05-18 06:23:36 +00:00
|
|
|
try {
|
2018-05-18 03:25:45 +00:00
|
|
|
const file = mozFilePicker(false);
|
2018-05-18 06:23:36 +00:00
|
|
|
if (!file) {
|
|
|
|
return;
|
|
|
|
}
|
2009-09-04 16:10:50 +00:00
|
|
|
|
2018-05-18 06:23:36 +00:00
|
|
|
if (!file.exists()) {
|
|
|
|
file.create(0, parseInt('0664', 8));
|
|
|
|
}
|
2009-09-04 16:10:50 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const out = Components.classes['@mozilla.org/network/file-output-stream;1'].createInstance(Components.interfaces.nsIFileOutputStream);
|
2018-05-18 06:23:36 +00:00
|
|
|
out.init(file, 0x20 | 0x02, parseInt('00004', 8), null);
|
|
|
|
out.write(str, str.length);
|
|
|
|
out.flush();
|
|
|
|
out.close();
|
|
|
|
} catch (e) {
|
|
|
|
alert(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2009-09-04 16:10:50 +00:00
|
|
|
});
|