Added file select option for raster images in server_open extension. Also added Uploading file dialog box for server-based uploads
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1624 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
@@ -12,6 +12,8 @@ svgEditor.addExtension("server_open", {
|
||||
// Do nothing if client support is found
|
||||
if(window.FileReader) return;
|
||||
|
||||
var cancelled = false;
|
||||
|
||||
// Change these to appropriate script file
|
||||
var open_svg_action = 'extensions/fileopen.php?type=load_svg';
|
||||
var import_svg_action = 'extensions/fileopen.php?type=import_svg';
|
||||
@@ -19,7 +21,16 @@ svgEditor.addExtension("server_open", {
|
||||
|
||||
// Set up function for PHP uploader to use
|
||||
svgEditor.processFile = function(str64, type) {
|
||||
var xmlstr = svgCanvas.Utils.decode64(str64);
|
||||
if(cancelled) {
|
||||
cancelled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
$('#dialog_box').hide();
|
||||
|
||||
if(type != 'import_img') {
|
||||
var xmlstr = svgCanvas.Utils.decode64(str64);
|
||||
}
|
||||
|
||||
switch ( type ) {
|
||||
case 'load_svg':
|
||||
@@ -31,6 +42,9 @@ svgEditor.addExtension("server_open", {
|
||||
svgCanvas.importSvgString(xmlstr);
|
||||
svgEditor.updateCanvas();
|
||||
break;
|
||||
case 'import_img':
|
||||
svgCanvas.setGoodImage(str64);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +69,18 @@ svgEditor.addExtension("server_open", {
|
||||
form.empty();
|
||||
var inp = $('<input type="file" name="svg_file">').appendTo(form);
|
||||
|
||||
|
||||
function submit() {
|
||||
// This submits the form, which returns the file data using svgEditor.uploadSVG
|
||||
form.submit();
|
||||
|
||||
rebuildInput(form);
|
||||
$.process_cancel("Uploading...", function() {
|
||||
cancelled = true;
|
||||
$('#dialog_box').hide();
|
||||
});
|
||||
}
|
||||
|
||||
if(form[0] == open_svg_form[0]) {
|
||||
inp.change(function() {
|
||||
// This takes care of the "are you sure" dialog box
|
||||
@@ -63,17 +89,13 @@ svgEditor.addExtension("server_open", {
|
||||
rebuildInput(form);
|
||||
return;
|
||||
}
|
||||
// This submits the form, which returns the file data using svgEditor.uploadSVG
|
||||
form.submit();
|
||||
|
||||
rebuildInput(form);
|
||||
submit();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
inp.change(function() {
|
||||
// This submits the form, which returns the file data using svgEditor.uploadSVG
|
||||
form.submit();
|
||||
rebuildInput(form);
|
||||
submit();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -89,6 +111,7 @@ svgEditor.addExtension("server_open", {
|
||||
// Add forms to buttons
|
||||
$("#tool_open").show().prepend(open_svg_form);
|
||||
$("#tool_import").show().prepend(import_svg_form);
|
||||
$("#tool_image").prepend(import_img_form);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -2,8 +2,21 @@
|
||||
<?php
|
||||
// Very minimal PHP file, all we do is Base64 encode the uploaded file and
|
||||
// return it to the editor
|
||||
$output = file_get_contents($_FILES['svg_file']['tmp_name']);
|
||||
|
||||
$file = $_FILES['svg_file']['tmp_name'];
|
||||
|
||||
$output = file_get_contents($file);
|
||||
|
||||
$type = $_REQUEST['type'];
|
||||
|
||||
$prefix = '';
|
||||
|
||||
// Make Data URL prefix for import image
|
||||
if($type == 'import_img') {
|
||||
$info = getimagesize($file);
|
||||
$prefix = 'data:' . $info['mime'] . ';base64,';
|
||||
}
|
||||
?>
|
||||
<script>
|
||||
window.top.window.svgEditor.processFile("<?php echo base64_encode($output); ?>", "<?php echo $_REQUEST['type'] ?>");
|
||||
window.top.window.svgEditor.processFile("<?php echo $prefix . base64_encode($output); ?>", "<?php echo $type ?>");
|
||||
</script>
|
||||
Reference in New Issue
Block a user