sketchily 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,81 @@
1
1
  //= require embedapi
2
2
  //= require base64
3
+
4
+ var svgCanvas = svgCanvas || {};
5
+
6
+ function submitHandler(event) {
7
+ var id = event.data;
8
+ svgCanvas[id].getSvgString()(function (data, error) {
9
+ handleSvgData(data, error, id);
10
+ });
11
+ event.preventDefault();
12
+ event.stopImmediatePropagation();
13
+ }
14
+
15
+ function attachSubmitHandler(event) {
16
+ var id = event.data;
17
+ $("input#" + id).closest("form").on("submit.svgedit_" + id, null, id, submitHandler);
18
+ }
19
+
20
+ function handleSvgData(data, error, id) {
21
+ if (error) {
22
+ alert('Error: ' + error);
23
+ }
24
+ else {
25
+ var input = $("input#" + id);
26
+ var form = input.closest("form");
27
+ input.attr("value", sketchily_encode64("<?xml version=\"1.0\"?>\n" + data));
28
+ form.off("submit.svgedit_" + id);
29
+ form.one("submit.svgedit_" + id, null, id, attachSubmitHandler);
30
+ form.submit();
31
+ }
32
+ }
33
+
34
+ function initEmbed(id, value, hide_menu, hide_image_tool, show_hyperlink_tool, url) {
35
+ var frame = document.getElementById("svgedit_" + id);
36
+ svgCanvas[id] = new embedded_svg_edit(frame);
37
+
38
+ var doc = frame.contentDocument;
39
+ if (!doc) {
40
+ doc = frame.contentWindow.document;
41
+ }
42
+
43
+ if (hide_menu) {
44
+ var mainButton = doc.getElementById('main_button');
45
+ mainButton.parentNode.removeChild(mainButton);
46
+ var toolsTop = doc.getElementById('tools_top');
47
+ toolsTop.style.left = '5px';
48
+ }
49
+
50
+ if (hide_image_tool) {
51
+ var imageTool = doc.getElementById('tool_image');
52
+ imageTool.parentNode.removeChild(imageTool);
53
+ }
54
+
55
+ if (!show_hyperlink_tool) {
56
+ var hyperlinkTool = doc.getElementById('tool_make_link');
57
+ hyperlinkTool.parentNode.removeChild(hyperlinkTool);
58
+ }
59
+
60
+ if (!url) {
61
+ svgCanvas[id].setSvgString(sketchily_decode64(value));
62
+ }
63
+
64
+ $("input#" + id).closest("form").on("submit.svgedit_" + id, null, id, submitHandler);
65
+
66
+ $("#svgedit_" + id).css('visibility', '');
67
+ }
68
+
69
+ function attachLoadHandler(id, value, hide_menu, hide_image_tool, show_hyperlink_tool, url) {
70
+ var frame = $("#svgedit_" + id);
71
+ if (frame.attr('src')) {
72
+ frame.load(function () {
73
+ initEmbed(id, value, hide_menu, hide_image_tool, show_hyperlink_tool, url);
74
+ });
75
+ }
76
+ else {
77
+ setTimeout(function () {
78
+ attachLoadHandler(id, value, hide_menu, hide_image_tool, show_hyperlink_tool, url);
79
+ }, 0);
80
+ }
81
+ }
@@ -1 +1,84 @@
1
1
  //= require embedapi
2
+ //= require base64
3
+
4
+ var svgCanvas = svgCanvas || {};
5
+
6
+ function submitHandler(event) {
7
+ var id = event.data;
8
+ alert('sub' + id);
9
+ svgCanvas[id].getSvgString()(function (data, error) {
10
+ handleSvgData(data, error, id);
11
+ });
12
+ event.preventDefault();
13
+ event.stopImmediatePropagation();
14
+ }
15
+
16
+ function attachSubmitHandler(event) {
17
+ var id = event.data;
18
+ alert('attach' + id);
19
+ $("input#" + id).closest("form").on("submit.svgedit_" + id, null, id, submitHandler);
20
+ }
21
+
22
+ function handleSvgData(data, error, id) {
23
+ if (error) {
24
+ alert('Error: ' + error);
25
+ }
26
+ else {
27
+ alert('handle' + id);
28
+ var input = $("input#" + id);
29
+ var form = input.closest("form");
30
+ input.attr("value", sketchily_encode64("<?xml version=\"1.0\"?>\n" + data));
31
+ form.off("submit.svgedit_" + id);
32
+ form.one("submit.svgedit_" + id, null, id, attachSubmitHandler);
33
+ form.submit();
34
+ }
35
+ }
36
+
37
+ function initEmbed(id, value, hide_menu, hide_image_tool, show_hyperlink_tool, url) {
38
+ var frame = document.getElementById("svgedit_" + id);
39
+ svgCanvas[id] = new embedded_svg_edit(frame);
40
+
41
+ var doc = frame.contentDocument;
42
+ if (!doc) {
43
+ doc = frame.contentWindow.document;
44
+ }
45
+
46
+ if (hide_menu) {
47
+ var mainButton = doc.getElementById('main_button');
48
+ mainButton.parentNode.removeChild(mainButton);
49
+ var toolsTop = doc.getElementById('tools_top');
50
+ toolsTop.style.left = '5px';
51
+ }
52
+
53
+ if (hide_image_tool) {
54
+ var imageTool = doc.getElementById('tool_image');
55
+ imageTool.parentNode.removeChild(imageTool);
56
+ }
57
+
58
+ if (!show_hyperlink_tool) {
59
+ var hyperlinkTool = doc.getElementById('tool_make_link');
60
+ hyperlinkTool.parentNode.removeChild(hyperlinkTool);
61
+ }
62
+
63
+ if (!url) {
64
+ svgCanvas[id].setSvgString(sketchily_decode64(value));
65
+ }
66
+
67
+ $("input#" + id).closest("form").on("submit.svgedit_" + id, null, id, submitHandler);
68
+
69
+ $("#svgedit_" + id).css('visibility', '');
70
+ }
71
+
72
+ function attachLoadHandler(id, value, hide_menu, hide_image_tool, show_hyperlink_tool, url) {
73
+ var frame = $("#svgedit_" + id);
74
+ if (frame.attr('src')) {
75
+ frame.load(function () {
76
+ initEmbed(id, value, hide_menu, hide_image_tool, show_hyperlink_tool, url);
77
+ });
78
+ }
79
+ else {
80
+ setTimeout(function () {
81
+ attachLoadHandler(id, value, hide_menu, hide_image_tool, show_hyperlink_tool, url);
82
+ }, 0);
83
+ }
84
+ }
@@ -11,6 +11,7 @@ module SketchilyHelper
11
11
  xml.title 'Background Image Layer'
12
12
  xml.image :id => 'background_image', :width => '100%', :height => '100%', :preserveAspectRatio => 'xMinYMin', 'xlink:href' => data_uri
13
13
  end
14
+ doc.root.add_namespace "xlink", "http://www.w3.org/1999/xlink"
14
15
  doc.at('g').before(bkgd_file_node)
15
16
  end
16
17
 
@@ -11,6 +11,7 @@ module SketchilyHelper
11
11
  xml.title 'Background Image Layer'
12
12
  xml.image :id => 'background_image', :width => '100%', :height => '100%', :preserveAspectRatio => 'xMinYMin', 'xlink:href' => data_uri
13
13
  end
14
+ doc.root.add_namespace "xmlns:xlink", "http://www.w3.org/1999/xlink"
14
15
  doc.at('g').before(bkgd_file_node)
15
16
  end
16
17
 
@@ -22,7 +23,7 @@ module SketchilyHelper
22
23
  end
23
24
  doc.at('g').before(bkgd_color_node)
24
25
  end
25
- print doc.to_xml
26
+
26
27
  uri = Base64.strict_encode64(doc.to_xml)
27
28
  end
28
29
 
@@ -38,16 +38,15 @@
38
38
  :src => iframe_src.to_s.html_safe,
39
39
  :width => width,
40
40
  :height => height,
41
- :id => "svgedit_#{id}") %>
41
+ :id => "svgedit_#{id}",
42
+ :style => "visibility: hidden") %>
42
43
 
43
44
  <script type="text/javascript">
44
- <%= render :partial => "sketchily/embed",
45
- :formats => :js,
46
- :locals => {:id => id,
47
- :value => value,
48
- :hide_menu => hide_menu,
49
- :hide_image_tool => hide_image_tool,
50
- :show_hyperlink_tool => show_hyperlink_tool,
51
- :url => url} %>
45
+ attachLoadHandler("<%= id %>",
46
+ "<%= value.try(:squish) %>",
47
+ <%= hide_menu %>,
48
+ <%= hide_image_tool %>,
49
+ <%= show_hyperlink_tool %>,
50
+ "<%= url %>");
52
51
  </script>
53
52
 
@@ -38,16 +38,15 @@
38
38
  :src => iframe_src.to_s.html_safe,
39
39
  :width => width,
40
40
  :height => height,
41
- :id => "svgedit_#{id}") %>
41
+ :id => "svgedit_#{id}",
42
+ :style => "visibility: hidden") %>
42
43
 
43
44
  <script type="text/javascript">
44
- <%= render :partial => "sketchily/embed",
45
- :formats => :js,
46
- :locals => {:id => id,
47
- :value => value,
48
- :hide_menu => hide_menu,
49
- :show_hyperlink_tool => show_hyperlink_tool,
50
- :hide_image_tool => hide_image_tool,
51
- :url => url} %>
45
+ attachLoadHandler("<%= id %>",
46
+ "<%= value.try(:squish) %>",
47
+ <%= hide_menu %>,
48
+ <%= hide_image_tool %>,
49
+ <%= show_hyperlink_tool %>,
50
+ <%= url %>);
52
51
  </script>
53
52
 
@@ -49,21 +49,36 @@ function initEmbed_<%= id %>() {
49
49
  toolsTop.style.left = '5px';
50
50
  <% end %>
51
51
 
52
- <% unless show_hyperlink_tool %>
53
- var hyperlinkTool = doc.getElementById('tool_make_link');
54
- hyperlinkTool.parentNode.removeChild(hyperlinkTool);
55
- <% end %>
56
-
57
52
  <% if hide_image_tool %>
58
53
  var imageTool = doc.getElementById('tool_image');
59
54
  imageTool.parentNode.removeChild(imageTool);
60
55
  <% end %>
61
56
 
57
+ <% unless show_hyperlink_tool %>
58
+ var hyperlinkTool = doc.getElementById('tool_make_link');
59
+ hyperlinkTool.parentNode.removeChild(hyperlinkTool);
60
+ <% end %>
61
+
62
62
  <% unless url %>
63
63
  svgCanvas_<%= id %>.setSvgString(sketchily_decode64("<%= value.try(:squish) %>"));
64
64
  <% end %>
65
65
 
66
66
  attachSubmitHandler_<%= id %>();
67
+
68
+ $("#svgedit_<%= id %>").css('visibility', '');
69
+ }
70
+
71
+ function attachLoadHandler_<%= id %>() {
72
+ if ($("#svgedit_<%= id %>").attr('src')) {
73
+ $("#svgedit_<%= id %>").load(initEmbed_<%= id %>);
74
+ }
75
+ else {
76
+ $("#svgedit_<%= id %>").css('visibility', 'hidden');
77
+ setTimeout(function () {
78
+ attachLoadHandler_<%= id %>();
79
+ }, 0);
80
+ }
67
81
  }
68
82
 
69
- $("#svgedit_<%= id %>").load(initEmbed_<%= id %>);
83
+ attachLoadHandler_<%= id %>();
84
+
@@ -1,3 +1,3 @@
1
1
  module Sketchily
2
- VERSION = "1.4.1"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module Sketchily
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sketchily
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-05 00:00:00.000000000 Z
12
+ date: 2013-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -125,7 +125,6 @@ files:
125
125
  - app/helpers/sketchily_helper.rb~
126
126
  - app/helpers/sketchily_helper.rb
127
127
  - app/views/sketchily/_sketchily.html.erb
128
- - app/views/sketchily/_embed.js.erb
129
128
  - app/views/sketchily/_sketchily_tag.html.erb
130
129
  - app/views/sketchily/_sketchily.html.erb~
131
130
  - app/views/sketchily/_sketchily_tag.html.erb~
@@ -1,69 +0,0 @@
1
- <% # This partial requires svgutils.js
2
- #
3
- # Clients of this partial must supply the following variables:
4
- # id
5
- # value
6
- # hide_menu
7
- # hide_image_tool
8
- # show_hyperlink_tool
9
- # url %>
10
-
11
- var svgCanvas_<%= id %> = null;
12
-
13
- function submitHandler_<%= id %>(e) {
14
- svgCanvas_<%= id %>.getSvgString()(handleSvgData_<%= id %>);
15
- e.preventDefault();
16
- e.stopImmediatePropagation();
17
- }
18
-
19
- function attachSubmitHandler_<%= id %>() {
20
- $("input#<%= id %>").closest("form").on("submit", submitHandler_<%= id %>);
21
- }
22
-
23
- function handleSvgData_<%= id %>(data, error) {
24
- if (error) {
25
- alert('Error: ' + error);
26
- }
27
- else {
28
- $("input#<%= id %>").attr("value", sketchily_encode64("<?xml version=\"1.0\"?>\n" + data));
29
- $("input#<%= id %>").closest("form").off("submit", submitHandler_<%= id %>);
30
- $("input#<%= id %>").closest("form").one("submit", attachSubmitHandler_<%= id %>);
31
- $("input#<%= id %>").closest("form").submit();
32
- }
33
- }
34
-
35
- function initEmbed_<%= id %>() {
36
- var frame = document.getElementById('svgedit_<%= id %>');
37
- svgCanvas_<%= id %> = new embedded_svg_edit(frame);
38
-
39
- var doc;
40
- doc = frame.contentDocument;
41
- if (!doc) {
42
- doc = frame.contentWindow.document;
43
- }
44
-
45
- <% if hide_menu %>
46
- var mainButton = doc.getElementById('main_button');
47
- mainButton.parentNode.removeChild(mainButton);
48
- var toolsTop = doc.getElementById('tools_top');
49
- toolsTop.style.left = '5px';
50
- <% end %>
51
-
52
- <% if hide_image_tool %>
53
- var imageTool = doc.getElementById('tool_image');
54
- imageTool.parentNode.removeChild(imageTool);
55
- <% end %>
56
-
57
- <% unless show_hyperlink_tool %>
58
- var hyperlinkTool = doc.getElementById('tool_make_link');
59
- hyperlinkTool.parentNode.removeChild(hyperlinkTool);
60
- <% end %>
61
-
62
- <% unless url %>
63
- svgCanvas_<%= id %>.setSvgString(sketchily_decode64("<%= value.try(:squish) %>"));
64
- <% end %>
65
-
66
- attachSubmitHandler_<%= id %>();
67
- }
68
-
69
- $("#svgedit_<%= id %>").load(initEmbed_<%= id %>);