ext-server_moinsave.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * ext-server_moinsave.js
  3. *
  4. * Licensed under the Apache License, Version 2
  5. *
  6. * Copyright(c) 2010 Alexis Deveria
  7. * 2011 MoinMoin:ReimarBauer
  8. * adopted for moinmoins item storage. it sends in one post png and svg data
  9. * (I agree to dual license my work to additional GPLv2 or later)
  10. *
  11. */
  12. svgEditor.addExtension("server_opensave", {
  13. callback: function() {
  14. var save_svg_action = '/+modify';
  15. // Create upload target (hidden iframe)
  16. var target = $('<iframe name="output_frame" src="#"/>').hide().appendTo('body');
  17. svgEditor.setCustomHandlers({
  18. save: function(win, data) {
  19. var svg = "<?xml version=\"1.0\"?>\n" + data;
  20. var qstr = $.param.querystring();
  21. var name = qstr.substr(9).split('/+get/')[1];
  22. var svg_data = svgedit.utilities.encode64(svg);
  23. if(!$('#export_canvas').length) {
  24. $('<canvas>', {id: 'export_canvas'}).hide().appendTo('body');
  25. }
  26. var c = $('#export_canvas')[0];
  27. c.width = svgCanvas.contentW;
  28. c.height = svgCanvas.contentH;
  29. $.getScript('canvg/canvg.js', function() {
  30. canvg(c, svg, {renderCallback: function() {
  31. var datauri = c.toDataURL('image/png');
  32. var uiStrings = svgEditor.uiStrings;
  33. var png_data = svgedit.utilities.encode64(datauri);
  34. var form = $('<form>').attr({
  35. method: 'post',
  36. action: save_svg_action + '/' + name,
  37. target: 'output_frame'
  38. }) .append('<input type="hidden" name="png_data" value="' + png_data + '">')
  39. .append('<input type="hidden" name="filepath" value="' + svg_data + '">')
  40. .append('<input type="hidden" name="filename" value="' + 'drawing.svg">')
  41. .append('<input type="hidden" name="contenttype" value="application/x-svgdraw">')
  42. .appendTo('body')
  43. .submit().remove();
  44. }})});
  45. alert("Saved! Return to Item View!");
  46. top.window.location = '/'+name;
  47. },
  48. });
  49. }
  50. });