Fix File Open for Firefox broken in previous checkin. Neaten up file open extension API.
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1203 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
8a96643f1a
commit
1b88da95f8
|
@ -729,8 +729,12 @@ function svg_edit_setup() {
|
||||||
var on_button = false;
|
var on_button = false;
|
||||||
$().mouseup(function(evt) {
|
$().mouseup(function(evt) {
|
||||||
if(!on_button) {
|
if(!on_button) {
|
||||||
|
// FIXME: figure out why the main_button stays hovered...
|
||||||
button.removeClass('down');
|
button.removeClass('down');
|
||||||
list.hide();
|
// do not hide if it was the file input as that input needs to be visible
|
||||||
|
// for its change event to fire
|
||||||
|
if (evt.target.localName != "input")
|
||||||
|
list.hide();
|
||||||
}
|
}
|
||||||
on_button = false;
|
on_button = false;
|
||||||
});
|
});
|
||||||
|
@ -1023,6 +1027,9 @@ function svg_edit_setup() {
|
||||||
svgCanvas.save(saveOpts);
|
svgCanvas.save(saveOpts);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// by default, svgCanvas.open() is a no-op.
|
||||||
|
// it is up to an extension mechanism (opera widget, etc)
|
||||||
|
// to call setCustomHandlers() which will make it do something
|
||||||
var clickOpen = function(){
|
var clickOpen = function(){
|
||||||
svgCanvas.open();
|
svgCanvas.open();
|
||||||
};
|
};
|
||||||
|
@ -1976,10 +1983,6 @@ function svg_edit_setup() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var fileOpen = function(window, str) {
|
|
||||||
svgCanvas.setSvgString(str);
|
|
||||||
};
|
|
||||||
|
|
||||||
$(window).resize( centerCanvasIfNeeded );
|
$(window).resize( centerCanvasIfNeeded );
|
||||||
|
|
||||||
function stepFontSize(elem, step) {
|
function stepFontSize(elem, step) {
|
||||||
|
@ -2229,10 +2232,19 @@ function svg_edit_setup() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Extension mechanisms must call setCustomHandlers with two functions: opts.open and opts.save
|
||||||
|
// opts.open's responsibilities are:
|
||||||
|
// - invoke a file chooser dialog in 'open' mode
|
||||||
|
// - let user pick a SVG file
|
||||||
|
// - calls setCanvas.setSvgString() with the string contents of that file
|
||||||
|
// opts.save's responsibilities are:
|
||||||
|
// - accept the string contents of the current document
|
||||||
|
// - invoke a file chooser dialog in 'save' mode
|
||||||
|
// - save the file to location chosen by the user
|
||||||
svgCanvas.setCustomHandlers = function(opts) {
|
svgCanvas.setCustomHandlers = function(opts) {
|
||||||
if(opts.open) {
|
if(opts.open) {
|
||||||
// $('#tool_open').show();
|
$('#tool_open').show();
|
||||||
svgCanvas.bind("opened", opts.open);
|
svgCanvas.open = opts.open;
|
||||||
}
|
}
|
||||||
if(opts.save) {
|
if(opts.save) {
|
||||||
svgCanvas.bind("saved", opts.save);
|
svgCanvas.bind("saved", opts.save);
|
||||||
|
@ -2240,26 +2252,21 @@ function svg_edit_setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// use HTML5 File API: http://www.w3.org/TR/FileAPI/
|
// use HTML5 File API: http://www.w3.org/TR/FileAPI/
|
||||||
// if browser has HTML5 File API support, then provide the Open button
|
// if browser has HTML5 File API support, then we will show the open menu item
|
||||||
// clicking the button will bring up a file chooser dialog, once a file is chosen
|
// and provide a file input to click. When that change event fires, it will
|
||||||
// then the change() event will fire on the file input, will call svgCanvas.open()
|
// get the text contents of the file and send it to the canvas
|
||||||
// svgCanvas.open() will fire the 'opened' handler back here,
|
|
||||||
// which is file_open here
|
|
||||||
if (window.FileReader) {
|
if (window.FileReader) {
|
||||||
var inp = $('<input type="file">').change(function() {
|
var inp = $('<input type="file">').change(function() {
|
||||||
|
$('#main_menu').hide();
|
||||||
if(this.files.length==1) {
|
if(this.files.length==1) {
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
reader.onloadend = function(e) {
|
reader.onloadend = function(e) {
|
||||||
console.log(e.target.result);
|
svgCanvas.setSvgString(e.target.result);
|
||||||
svgCanvas.open(e.target.result);
|
|
||||||
};
|
};
|
||||||
reader.readAsText(this.files[0]);
|
reader.readAsText(this.files[0]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$("#tool_open").show().prepend(inp);
|
$("#tool_open").show().prepend(inp);
|
||||||
|
|
||||||
// This doesn't appear to be necessary...
|
|
||||||
svgCanvas.setCustomHandlers( {open: fileOpen} );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set starting resolution (centers canvas)
|
// set starting resolution (centers canvas)
|
||||||
|
|
|
@ -4669,12 +4669,8 @@ function BatchCommand(text) {
|
||||||
|
|
||||||
// Group: Serialization
|
// Group: Serialization
|
||||||
|
|
||||||
// Function: open
|
this.open = function() {
|
||||||
// Calls the 'opened' handler and sends the SVG XML text. Clients of the SvgCanvas bind
|
|
||||||
// their load function (typically calls to setSvgString() to the 'opened' event.
|
|
||||||
this.open = function(str) {
|
|
||||||
// Nothing by default, handled by optional widget/extension
|
// Nothing by default, handled by optional widget/extension
|
||||||
call("opened", str);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: save
|
// Function: save
|
||||||
|
|
Loading…
Reference in New Issue