Possibly fixed issue 99 and issue 108 by setting up an external handler function. Moved Opera references to seperate file and reprocessed thinker.li's patch to also use a use separate file
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@468 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
62
opera-widget/handlers.js
Normal file
62
opera-widget/handlers.js
Normal file
@@ -0,0 +1,62 @@
|
||||
// Note: This JavaScript file must be included as the last script on the main HTML editor page to override the open/close handlers
|
||||
$(function() {
|
||||
if(window.opera && window.opera.io && window.opera.io.filesystem) {
|
||||
svgCanvas.setCustomHandlers({
|
||||
'open':function() {
|
||||
try {
|
||||
window.opera.io.filesystem.browseForFile(
|
||||
new Date().getTime(), /* mountpoint name */
|
||||
"", /* default location */
|
||||
function(file) {
|
||||
try {
|
||||
if (file) {
|
||||
fstream = file.open(file, "r");
|
||||
var output = "";
|
||||
while (!fstream.eof) {
|
||||
output += fstream.readLine("UTF-16");
|
||||
}
|
||||
|
||||
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':function(svg) {
|
||||
try {
|
||||
window.opera.io.filesystem.browseForSave(
|
||||
new Date().getTime(), /* mountpoint name */
|
||||
"", /* default location */
|
||||
function(file) {
|
||||
try {
|
||||
if (file) {
|
||||
var 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.");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user