Sha256: 345152bc6c435ef197224386ae81bcc5dcebd7ef471b0670ed3ce0d0f830a053

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

<% # This partial requires svgutils.js
   #
   # Clients of this partial must supply the following variables:
   # id
   # value
   # hide_menu
   # hide_image_tool
   # hide_hyperlink_tool %>

var svgCanvas_<%= id %> = null;

function attachSubmitHandler_<%= id %>() {
  $("input#<%= id %>").closest("form").one("submit", function(event) {
    svgCanvas_<%= id %>.getSvgString()(handleSvgData_<%= id %>);
    return false;
  });
}

function handleSvgData_<%= id %>(data, error) {
  if (error) {
    alert('Error: ' + error);
  }
  else {
    $("input#<%= id %>").attr("value", svgedit.utilities.encode64("<?xml version=\"1.0\"?>\n" + data));
    $("input#<%= id %>").closest("form").submit();
    attachSubmitHandler_<%= id %>();
  }
}

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 %>
  
  <% if hide_image_tool %>
    var imageTool = doc.getElementById('tool_image');
    imageTool.parentNode.removeChild(imageTool);
  <% end %>

  <% if hide_hyperlink_tool %>
    var hyperlinkTool = doc.getElementById('tool_make_link');
    hyperlinkTool.parentNode.removeChild(hyperlinkTool);
  <% end %>
  
  attachSubmitHandler_<%= id %>();

  svgCanvas_<%= id %>.setSvgString(svgedit.utilities.decode64("<%= value.try(:squish) %>"));
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sketchily-1.0.1 app/views/sketchily/_embed.js.erb
sketchily-1.0.0 app/views/sketchily/_embed.js.erb
sketchily-0.3.0 app/views/sketchily/_embed.js.erb