<% # This partial requires svgutils.js # # Clients of this partial must supply the following variables: # id # value # show_menu # hide_image_tool %> var svgCanvas_<%= id %> = null; function handleSvgData_<%= id %>(data, error) { if (error) { alert('Error: ' + error); } else { $("input#<%= id %>").attr("value", svgedit.utilities.encode64("\n" + data)); $("input#<%= id %>").closest("form").submit(); } } function initEmbed_<%= id %>() { var frame = document.getElementById('svgedit_<%= id %>'); svgCanvas_<%= id %> = new embedded_svg_edit(frame); var doc; doc = frame.contentDocument; if (!doc) { doc = frame.contentWindow.document; } <% if show_menu %> var mainButton = doc.getElementById('main_button'); mainButton.style.display = 'block'; var toolsTop = doc.getElementById('tools_top'); toolsTop.style.left = '120px'; toolsTop.style.right = '2px'; <% end %> <% if hide_image %> var imageTool = doc.getElementById('tool_image'); imageTool.style.display = 'none'; <% end %> $("input#<%= id %>").closest("form").one("submit", function(event) { svgCanvas_<%= id %>.getSvgString()(handleSvgData_<%= id %>); event.preventDefault(); }); svgCanvas_<%= id %>.setSvgString(svgedit.utilities.decode64("<%= value.try(:squish) %>")); }