ext-server_moinsave.js 2.0 KB

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