<% # This partial requires svgutils.js # # Clients of this partial must supply the following variables: # id # value # hide_menu # hide_image_tool # show_hyperlink_tool # url %> var svgCanvas_<%= id %> = null; function submitHandler_<%= id %>(e) { svgCanvas_<%= id %>.getSvgString()(handleSvgData_<%= id %>); e.preventDefault(); e.stopImmediatePropagation(); } function attachSubmitHandler_<%= id %>() { $("input#<%= id %>").closest("form").on("submit", submitHandler_<%= id %>); } function handleSvgData_<%= id %>(data, error) { if (error) { alert('Error: ' + error); } else { $("input#<%= id %>").attr("value", sketchily_encode64("\n" + data)); $("input#<%= id %>").closest("form").off("submit", submitHandler_<%= id %>); $("input#<%= id %>").closest("form").one("submit", attachSubmitHandler_<%= id %>); $("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 hide_menu %> var mainButton = doc.getElementById('main_button'); mainButton.parentNode.removeChild(mainButton); var toolsTop = doc.getElementById('tools_top'); toolsTop.style.left = '5px'; <% end %> <% unless show_hyperlink_tool %> var hyperlinkTool = doc.getElementById('tool_make_link'); hyperlinkTool.parentNode.removeChild(hyperlinkTool); <% end %> <% if hide_image_tool %> var imageTool = doc.getElementById('tool_image'); imageTool.parentNode.removeChild(imageTool); <% end %> <% unless url %> svgCanvas_<%= id %>.setSvgString(sketchily_decode64("<%= value.try(:squish) %>")); <% end %> attachSubmitHandler_<%= id %>(); } $("#svgedit_<%= id %>").load(initEmbed_<%= id %>);