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 Utils = svgedit.utilities;
  17. var save_svg_action = '/+modify';
  18. // Create upload target (hidden iframe)
  19. var target = $('<iframe name="output_frame" src="#"/>').hide().appendTo('body');
  20. svgEditor.setCustomHandlers({
  21. save: function(win, data) {
  22. var svg = "<?xml version=\"1.0\"?>\n" + data;
  23. var qstr = $.param.querystring();
  24. var name = qstr.substr(9).split('/+get/')[1];
  25. var svg_data = Utils.encode64(svg);
  26. if(!$('#export_canvas').length) {
  27. $('<canvas>', {id: 'export_canvas'}).hide().appendTo('body');
  28. }
  29. var c = $('#export_canvas')[0];
  30. c.width = svgCanvas.contentW;
  31. c.height = svgCanvas.contentH;
  32. Utils.buildCanvgCallback(function () {
  33. canvg(c, svg, {renderCallback: function() {
  34. var datauri = c.toDataURL('image/png');
  35. // var uiStrings = svgEditor.uiStrings;
  36. var png_data = Utils.encode64(datauri); // Brett: This encoding seems unnecessary
  37. var form = $('<form>').attr({
  38. method: 'post',
  39. action: save_svg_action + '/' + name,
  40. target: 'output_frame'
  41. }).append('<input type="hidden" name="png_data" value="' + png_data + '">')
  42. .append('<input type="hidden" name="filepath" value="' + svg_data + '">')
  43. .append('<input type="hidden" name="filename" value="' + 'drawing.svg">')
  44. .append('<input type="hidden" name="contenttype" value="application/x-svgdraw">')
  45. .appendTo('body')
  46. .submit().remove();
  47. }});
  48. })();
  49. alert("Saved! Return to Item View!");
  50. top.window.location = '/'+name;
  51. }
  52. });
  53. }
  54. });