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:
@@ -20,6 +20,8 @@
|
||||
<!--script type="text/javascript" src="svgcanvas.min.js"></script-->
|
||||
<script type="text/javascript" src="svg-editor.js"></script>
|
||||
<!--script type="text/javascript" src="svg-editor.min.js"></script-->
|
||||
|
||||
<!-- Add script with custom handlers here -->
|
||||
<title>SVG-edit demo</title>
|
||||
</head>
|
||||
<body>
|
||||
@@ -42,7 +44,7 @@
|
||||
<div>
|
||||
<img class="tool_sep" src="images/sep.png" alt="|"/>
|
||||
<img class="tool_button" id="tool_clear" src="images/clear.png" title="New Image [N]" alt="Clear" />
|
||||
<img style="display:none" eeclass="tool_button" id="tool_open" src="images/open.png" title="Open Image [O]" alt="Open"/>
|
||||
<img style="display:none" class="tool_button" id="tool_open" src="images/open.png" title="Open Image [O]" alt="Open"/>
|
||||
<img class="tool_button" id="tool_save" src="images/save.png" title="Save Image [S]" alt="Save"/>
|
||||
<img class="tool_button" id="tool_source" src="images/source.png" title="Edit Source [U]" alt="Source"/>
|
||||
</div>
|
||||
@@ -286,9 +288,5 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(svg_edit_setup);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -36,35 +36,7 @@ function svg_edit_setup() {
|
||||
// with a gradient will appear black in Firefox, etc. See bug 308590
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=308590
|
||||
var saveHandler = function(window,svg) {
|
||||
if(window.opera && window.opera.io && window.opera.io.filesystem)
|
||||
{
|
||||
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.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
window.open("data:image/svg+xml;base64," + Utils.encode64(svg));
|
||||
}
|
||||
window.open("data:image/svg+xml;base64," + Utils.encode64(svg));
|
||||
};
|
||||
|
||||
// called when we've selected a different element
|
||||
@@ -924,13 +896,20 @@ function svg_edit_setup() {
|
||||
$('#stroke_width').SpinButton({ min: 1, max: 99, step: 1, callback: changeStrokeWidth });
|
||||
$('#angle').SpinButton({ min: -180, max: 180, step: 5, callback: changeRotationAngle });
|
||||
|
||||
// if Opera and in widget form, enable the Open button
|
||||
if (window.opera) {
|
||||
opera.postError('opera.io=' + opera.io);
|
||||
if(opera && opera.io && opera.io.filesystem) {
|
||||
svgCanvas.setCustomHandlers = function(opts) {
|
||||
if(opts.open) {
|
||||
$('#tool_open').show();
|
||||
svgCanvas.bind("opened", opts.open);
|
||||
}
|
||||
if(opts.save) {
|
||||
svgCanvas.bind("saved", opts.save);
|
||||
}
|
||||
}
|
||||
|
||||
return svgCanvas;
|
||||
};
|
||||
|
||||
// This happens when the page is loaded
|
||||
$(function() {
|
||||
svgCanvas = svg_edit_setup();
|
||||
});
|
||||
|
||||
@@ -1985,38 +1985,9 @@ function SvgCanvas(c)
|
||||
|
||||
// public functions
|
||||
|
||||
this.open = function() {
|
||||
if(window.opera && window.opera.io && window.opera.io.filesystem)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
canvas.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.");
|
||||
}
|
||||
}
|
||||
this.open = function(str) {
|
||||
// Nothing by default, handled by optional widget/extention
|
||||
call("opened", str);
|
||||
};
|
||||
|
||||
this.save = function() {
|
||||
|
||||
Reference in New Issue
Block a user