kiteditor 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. data/LICENSE +25 -0
  2. data/app/controllers/mercury/images_controller.rb +5 -0
  3. data/app/controllers/mercury_controller.rb +34 -0
  4. data/app/models/mercury/image.rb +17 -0
  5. data/app/views/layouts/mercury.html.erb +33 -0
  6. data/app/views/layouts/popup.html.haml +9 -0
  7. data/app/views/mercury/images/_list.html.haml +22 -0
  8. data/app/views/mercury/images/index.html.haml +4 -0
  9. data/app/views/mercury/images/index.js.erb +2 -0
  10. data/app/views/mercury/lightviews/about.html +11 -0
  11. data/app/views/mercury/modals/character.html +255 -0
  12. data/app/views/mercury/modals/htmleditor.html +13 -0
  13. data/app/views/mercury/modals/link.html +94 -0
  14. data/app/views/mercury/modals/media.html +1 -0
  15. data/app/views/mercury/modals/table.html +84 -0
  16. data/app/views/mercury/palettes/backcolor.html +73 -0
  17. data/app/views/mercury/palettes/forecolor.html +73 -0
  18. data/app/views/mercury/panels/history.html +3 -0
  19. data/app/views/mercury/panels/notes.html +3 -0
  20. data/app/views/mercury/panels/snippets.html +12 -0
  21. data/app/views/mercury/selects/formatblock.html +11 -0
  22. data/app/views/mercury/selects/style.html +5 -0
  23. data/app/views/mercury/snippets/example/options.html.erb +34 -0
  24. data/app/views/mercury/snippets/example/preview.html.erb +1 -0
  25. data/config/engine.rb +44 -0
  26. data/db/migrate/20110526035601_create_mercury_images.rb +11 -0
  27. data/features/loading/loading.feature +22 -0
  28. data/features/loading/navigating.feature +77 -0
  29. data/features/loading/user_interface.feature +67 -0
  30. data/features/regions/editable/advanced_editing.feature +0 -0
  31. data/features/regions/editable/basic_editing.feature +195 -0
  32. data/features/regions/editable/inserting_links.feature +98 -0
  33. data/features/regions/editable/inserting_media.feature +110 -0
  34. data/features/regions/editable/inserting_snippets.feature +102 -0
  35. data/features/regions/editable/inserting_special_characters.feature +24 -0
  36. data/features/regions/editable/inserting_tables.feature +109 -0
  37. data/features/regions/editable/pasting.feature +0 -0
  38. data/features/regions/editable/uploading_images.feature +0 -0
  39. data/features/regions/markupable/advanced_editing.feature +0 -0
  40. data/features/regions/markupable/basic_editing.feature +0 -0
  41. data/features/regions/markupable/inserting_links.feature +0 -0
  42. data/features/regions/markupable/inserting_media.feature +0 -0
  43. data/features/regions/markupable/inserting_snippets.feature +0 -0
  44. data/features/regions/markupable/inserting_special_characters.feature +0 -0
  45. data/features/regions/markupable/inserting_tables.feature +0 -0
  46. data/features/regions/markupable/uploading_images.feature +0 -0
  47. data/features/regions/snippetable/advanced_editing.feature +0 -0
  48. data/features/regions/snippetable/basic_editing.feature +0 -0
  49. data/features/regions/snippetable/inserting_snippets.feature +0 -0
  50. data/features/saving/saving.feature +33 -0
  51. data/features/step_definitions/debug_steps.rb +14 -0
  52. data/features/step_definitions/mercury_steps.rb +438 -0
  53. data/features/step_definitions/web_steps.rb +211 -0
  54. data/features/support/env.rb +46 -0
  55. data/features/support/mercury_contents.rb +25 -0
  56. data/features/support/mercury_selectors.rb +148 -0
  57. data/features/support/paths.rb +38 -0
  58. data/features/support/selectors.rb +44 -0
  59. data/lib/generators/mercury/install/install_generator.rb +49 -0
  60. data/lib/generators/mercury/install/templates/mongoid_paperclip_image.rb +17 -0
  61. data/lib/mercury/authentication.rb +8 -0
  62. data/lib/mercury-rails.rb +3 -0
  63. data/spec/javascripts/mercury/dialog_spec.js.coffee +281 -0
  64. data/spec/javascripts/mercury/dialogs/backcolor_spec.js.coffee +37 -0
  65. data/spec/javascripts/mercury/dialogs/forecolor_spec.js.coffee +37 -0
  66. data/spec/javascripts/mercury/dialogs/formatblock_spec.js.coffee +25 -0
  67. data/spec/javascripts/mercury/dialogs/snippetpanel_spec.js.coffee +30 -0
  68. data/spec/javascripts/mercury/dialogs/style_spec.js.coffee +25 -0
  69. data/spec/javascripts/mercury/history_buffer_spec.js.coffee +76 -0
  70. data/spec/javascripts/mercury/lightview_spec.js.coffee +497 -0
  71. data/spec/javascripts/mercury/mercury_spec.js.coffee +132 -0
  72. data/spec/javascripts/mercury/modal_spec.js.coffee +504 -0
  73. data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +30 -0
  74. data/spec/javascripts/mercury/modals/insertcharacter_spec.js.coffee +29 -0
  75. data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +220 -0
  76. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +167 -0
  77. data/spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee +52 -0
  78. data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +160 -0
  79. data/spec/javascripts/mercury/native_extensions_spec.js.coffee +60 -0
  80. data/spec/javascripts/mercury/page_editor_spec.js.coffee +750 -0
  81. data/spec/javascripts/mercury/palette_spec.js.coffee +49 -0
  82. data/spec/javascripts/mercury/panel_spec.js.coffee +185 -0
  83. data/spec/javascripts/mercury/region_spec.js.coffee +298 -0
  84. data/spec/javascripts/mercury/regions/editable_spec.js.coffee +561 -0
  85. data/spec/javascripts/mercury/regions/markupable_spec.js.coffee +367 -0
  86. data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +370 -0
  87. data/spec/javascripts/mercury/select_spec.js.coffee +49 -0
  88. data/spec/javascripts/mercury/snippet_spec.js.coffee +245 -0
  89. data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +184 -0
  90. data/spec/javascripts/mercury/statusbar_spec.js.coffee +150 -0
  91. data/spec/javascripts/mercury/table_editor_spec.js.coffee +194 -0
  92. data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +90 -0
  93. data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +360 -0
  94. data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +118 -0
  95. data/spec/javascripts/mercury/toolbar_spec.js.coffee +222 -0
  96. data/spec/javascripts/mercury/tooltip_spec.js.coffee +186 -0
  97. data/spec/javascripts/mercury/uploader_spec.js.coffee +514 -0
  98. data/spec/javascripts/spec_helper.js +513 -0
  99. data/spec/javascripts/templates/mercury/dialog.html +2 -0
  100. data/spec/javascripts/templates/mercury/dialogs/backcolor.html +5 -0
  101. data/spec/javascripts/templates/mercury/dialogs/forecolor.html +5 -0
  102. data/spec/javascripts/templates/mercury/dialogs/formatblock.html +3 -0
  103. data/spec/javascripts/templates/mercury/dialogs/snippetpanel.html +16 -0
  104. data/spec/javascripts/templates/mercury/dialogs/style.html +3 -0
  105. data/spec/javascripts/templates/mercury/lightview.html +13 -0
  106. data/spec/javascripts/templates/mercury/modal.html +13 -0
  107. data/spec/javascripts/templates/mercury/modals/htmleditor.html +5 -0
  108. data/spec/javascripts/templates/mercury/modals/insertcharacter.html +5 -0
  109. data/spec/javascripts/templates/mercury/modals/insertlink.html +30 -0
  110. data/spec/javascripts/templates/mercury/modals/insertmedia.html +35 -0
  111. data/spec/javascripts/templates/mercury/modals/insertsnippet.html +6 -0
  112. data/spec/javascripts/templates/mercury/modals/inserttable.html +27 -0
  113. data/spec/javascripts/templates/mercury/page_editor.html +35 -0
  114. data/spec/javascripts/templates/mercury/palette.html +16 -0
  115. data/spec/javascripts/templates/mercury/panel.html +16 -0
  116. data/spec/javascripts/templates/mercury/region.html +2 -0
  117. data/spec/javascripts/templates/mercury/regions/editable.html +3 -0
  118. data/spec/javascripts/templates/mercury/regions/snippetable.html +4 -0
  119. data/spec/javascripts/templates/mercury/select.html +16 -0
  120. data/spec/javascripts/templates/mercury/snippet.html +1 -0
  121. data/spec/javascripts/templates/mercury/snippet_toolbar.html +16 -0
  122. data/spec/javascripts/templates/mercury/statusbar.html +8 -0
  123. data/spec/javascripts/templates/mercury/table_editor.html +65 -0
  124. data/spec/javascripts/templates/mercury/toolbar.button.html +64 -0
  125. data/spec/javascripts/templates/mercury/toolbar.button_group.html +9 -0
  126. data/spec/javascripts/templates/mercury/toolbar.expander.html +18 -0
  127. data/spec/javascripts/templates/mercury/toolbar.html +11 -0
  128. data/spec/javascripts/templates/mercury/tooltip.html +12 -0
  129. data/spec/javascripts/templates/mercury/uploader.html +11 -0
  130. data/vendor/assets/images/mercury/button.png +0 -0
  131. data/vendor/assets/images/mercury/close.png +0 -0
  132. data/vendor/assets/images/mercury/default-snippet.png +0 -0
  133. data/vendor/assets/images/mercury/loading-dark.gif +0 -0
  134. data/vendor/assets/images/mercury/loading-light.gif +0 -0
  135. data/vendor/assets/images/mercury/missing-image.png +0 -0
  136. data/vendor/assets/images/mercury/search-icon.png +0 -0
  137. data/vendor/assets/images/mercury/temp-logo.png +0 -0
  138. data/vendor/assets/images/mercury/toolbar/editable/buttons.png +0 -0
  139. data/vendor/assets/images/mercury/toolbar/primary/_expander.png +0 -0
  140. data/vendor/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
  141. data/vendor/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
  142. data/vendor/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
  143. data/vendor/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
  144. data/vendor/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
  145. data/vendor/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
  146. data/vendor/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
  147. data/vendor/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
  148. data/vendor/assets/images/mercury/toolbar/primary/preview.png +0 -0
  149. data/vendor/assets/images/mercury/toolbar/primary/redo.png +0 -0
  150. data/vendor/assets/images/mercury/toolbar/primary/save.png +0 -0
  151. data/vendor/assets/images/mercury/toolbar/primary/snippetpanel.png +0 -0
  152. data/vendor/assets/images/mercury/toolbar/primary/undo.png +0 -0
  153. data/vendor/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
  154. data/vendor/assets/javascripts/mercury/dependencies/jquery-1.7.js +9300 -0
  155. data/vendor/assets/javascripts/mercury/dependencies/jquery-ui-1.8.13.custom.js +1328 -0
  156. data/vendor/assets/javascripts/mercury/dependencies/jquery-ui-1.8.18.custom.min.js +356 -0
  157. data/vendor/assets/javascripts/mercury/dependencies/jquery-ui.1.8.13.custom.min.js +356 -0
  158. data/vendor/assets/javascripts/mercury/dependencies/jquery.additions.js +206 -0
  159. data/vendor/assets/javascripts/mercury/dependencies/jquery.htmlClean.js +527 -0
  160. data/vendor/assets/javascripts/mercury/dependencies/liquidmetal.js +88 -0
  161. data/vendor/assets/javascripts/mercury/dependencies/showdown.js +1340 -0
  162. data/vendor/assets/javascripts/mercury/dialog.js.coffee +159 -0
  163. data/vendor/assets/javascripts/mercury/dialogs/backcolor.js.coffee +6 -0
  164. data/vendor/assets/javascripts/mercury/dialogs/forecolor.js.coffee +6 -0
  165. data/vendor/assets/javascripts/mercury/dialogs/formatblock.js.coffee +4 -0
  166. data/vendor/assets/javascripts/mercury/dialogs/snippetpanel.js.coffee +10 -0
  167. data/vendor/assets/javascripts/mercury/dialogs/style.js.coffee +4 -0
  168. data/vendor/assets/javascripts/mercury/finalize.js.coffee +3 -0
  169. data/vendor/assets/javascripts/mercury/history_buffer.js.coffee +30 -0
  170. data/vendor/assets/javascripts/mercury/lightview.js.coffee +205 -0
  171. data/vendor/assets/javascripts/mercury/locales/da.locale.js.coffee +0 -0
  172. data/vendor/assets/javascripts/mercury/locales/de.locale.js.coffee +206 -0
  173. data/vendor/assets/javascripts/mercury/locales/es.locale.js.coffee +211 -0
  174. data/vendor/assets/javascripts/mercury/locales/example.local.js.coffee +211 -0
  175. data/vendor/assets/javascripts/mercury/locales/fr.locale.js.coffee +211 -0
  176. data/vendor/assets/javascripts/mercury/locales/it.locale.js.coffee +208 -0
  177. data/vendor/assets/javascripts/mercury/locales/ko.local.js.coffee +206 -0
  178. data/vendor/assets/javascripts/mercury/locales/nl.locale.js.coffee +206 -0
  179. data/vendor/assets/javascripts/mercury/locales/pt.locale.js.coffee +211 -0
  180. data/vendor/assets/javascripts/mercury/locales/sv.local.js.coffee +209 -0
  181. data/vendor/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +213 -0
  182. data/vendor/assets/javascripts/mercury/mercury.js.coffee +109 -0
  183. data/vendor/assets/javascripts/mercury/modal.js.coffee +204 -0
  184. data/vendor/assets/javascripts/mercury/modals/htmleditor.js.coffee +11 -0
  185. data/vendor/assets/javascripts/mercury/modals/insertcharacter.js.coffee +4 -0
  186. data/vendor/assets/javascripts/mercury/modals/insertlink.js.coffee +95 -0
  187. data/vendor/assets/javascripts/mercury/modals/insertmedia.js.coffee +107 -0
  188. data/vendor/assets/javascripts/mercury/modals/insertsnippet.js.coffee +12 -0
  189. data/vendor/assets/javascripts/mercury/modals/inserttable.js.coffee +54 -0
  190. data/vendor/assets/javascripts/mercury/native_extensions.js.coffee +55 -0
  191. data/vendor/assets/javascripts/mercury/page_editor.js.coffee +241 -0
  192. data/vendor/assets/javascripts/mercury/palette.js.coffee +29 -0
  193. data/vendor/assets/javascripts/mercury/panel.js.coffee +115 -0
  194. data/vendor/assets/javascripts/mercury/plugins/save_as_xml/mercury/page_editor.js.coffee +28 -0
  195. data/vendor/assets/javascripts/mercury/plugins/save_as_xml/plugin.js +9 -0
  196. data/vendor/assets/javascripts/mercury/region.js.coffee +107 -0
  197. data/vendor/assets/javascripts/mercury/regions/editable.js.coffee +600 -0
  198. data/vendor/assets/javascripts/mercury/regions/markupable.js.coffee +398 -0
  199. data/vendor/assets/javascripts/mercury/regions/simple.js.coffee +339 -0
  200. data/vendor/assets/javascripts/mercury/regions/snippetable.js.coffee +124 -0
  201. data/vendor/assets/javascripts/mercury/select.js.coffee +44 -0
  202. data/vendor/assets/javascripts/mercury/snippet.js.coffee +104 -0
  203. data/vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee +72 -0
  204. data/vendor/assets/javascripts/mercury/statusbar.js.coffee +51 -0
  205. data/vendor/assets/javascripts/mercury/support/history.js +1 -0
  206. data/vendor/assets/javascripts/mercury/table_editor.js.coffee +265 -0
  207. data/vendor/assets/javascripts/mercury/toolbar.button.js.coffee +173 -0
  208. data/vendor/assets/javascripts/mercury/toolbar.button_group.js.coffee +42 -0
  209. data/vendor/assets/javascripts/mercury/toolbar.expander.js.coffee +56 -0
  210. data/vendor/assets/javascripts/mercury/toolbar.js.coffee +86 -0
  211. data/vendor/assets/javascripts/mercury/tooltip.js.coffee +74 -0
  212. data/vendor/assets/javascripts/mercury/uploader.js.coffee +227 -0
  213. data/vendor/assets/javascripts/mercury.js +479 -0
  214. data/vendor/assets/javascripts/mercury_loader.js +193 -0
  215. data/vendor/assets/javascripts/mercury_overrides.js +6 -0
  216. data/vendor/assets/javascripts/popup.js +8 -0
  217. data/vendor/assets/stylesheets/mercury/all_images.css.erb +89 -0
  218. data/vendor/assets/stylesheets/mercury/dialog.css +208 -0
  219. data/vendor/assets/stylesheets/mercury/lightview.css +151 -0
  220. data/vendor/assets/stylesheets/mercury/mercury.css +151 -0
  221. data/vendor/assets/stylesheets/mercury/modal.css +183 -0
  222. data/vendor/assets/stylesheets/mercury/statusbar.css +32 -0
  223. data/vendor/assets/stylesheets/mercury/toolbar.css +304 -0
  224. data/vendor/assets/stylesheets/mercury/tooltip.css +26 -0
  225. data/vendor/assets/stylesheets/mercury/uploader.css +111 -0
  226. data/vendor/assets/stylesheets/mercury.css +28 -0
  227. data/vendor/assets/stylesheets/mercury_overrides.css +17 -0
  228. data/vendor/assets/stylesheets/popup.css.erb +37 -0
  229. metadata +634 -0
@@ -0,0 +1,370 @@
1
+ describe "Mercury.Regions.Snippetable", ->
2
+
3
+ template 'mercury/regions/snippetable.html'
4
+
5
+ beforeEach ->
6
+ @regionElement = $('#snippetable_region1')
7
+
8
+ afterEach ->
9
+ @region = null
10
+ delete(@region)
11
+
12
+ describe "constructor", ->
13
+
14
+ beforeEach ->
15
+ @buildSpy = spyOn(Mercury.Regions.Snippetable.prototype, 'build').andCallFake(=>)
16
+ @bindEventsSpy = spyOn(Mercury.Regions.Snippetable.prototype, 'bindEvents').andCallFake(=>)
17
+ @makeSortableSpy = spyOn(Mercury.Regions.Snippetable.prototype, 'makeSortable').andCallFake(=>)
18
+
19
+ it "expects an element and window", ->
20
+ @region = new Mercury.Regions.Snippetable(@regionElement, window)
21
+ expect(@region.element.get(0)).toEqual($('#snippetable_region1').get(0))
22
+ expect(@region.window).toEqual(window)
23
+
24
+ it "accepts options", ->
25
+ @region = new Mercury.Regions.Snippetable(@regionElement, window, {foo: 'something'})
26
+ expect(@region.options).toEqual({foo: 'something'})
27
+
28
+ it "sets it's type", ->
29
+ @region = new Mercury.Regions.Snippetable(@regionElement, window)
30
+ expect(@region.type).toEqual('snippetable')
31
+
32
+ it "calls build", ->
33
+ @region = new Mercury.Regions.Snippetable(@regionElement, window)
34
+ expect(@buildSpy.callCount).toEqual(1)
35
+
36
+ it "calls bindEvents", ->
37
+ @region = new Mercury.Regions.Snippetable(@regionElement, window)
38
+ expect(@bindEventsSpy.callCount).toEqual(1)
39
+
40
+ it "makes the snippets sortable", ->
41
+ @region = new Mercury.Regions.Snippetable(@regionElement, window)
42
+ expect(@makeSortableSpy.callCount).toEqual(1)
43
+
44
+
45
+ describe "#build", ->
46
+
47
+ beforeEach ->
48
+ spyOn(Mercury.Regions.Snippetable.prototype, 'bindEvents').andCallFake(=>)
49
+
50
+ it "sets the element min-height to 20 if it's min-height is 0 (or not set)", ->
51
+ @region = new Mercury.Regions.Snippetable(@regionElement, window)
52
+ expect($('#snippetable_region1').css('minHeight')).toEqual('20px')
53
+
54
+
55
+ describe "observed events", ->
56
+
57
+ beforeEach ->
58
+ @region = new Mercury.Regions.Snippetable(@regionElement, window)
59
+ Mercury.region = @region
60
+
61
+ describe "custom event: unfocus:regions", ->
62
+
63
+ it "removes the focus class", ->
64
+ @region.element.addClass('focus')
65
+ Mercury.trigger('unfocus:regions')
66
+ expect(@region.element.hasClass('focus')).toEqual(false)
67
+
68
+ it "destroys the sortable", ->
69
+ spy = spyOn($.fn, 'sortable').andCallFake(=>)
70
+ Mercury.trigger('unfocus:regions')
71
+ expect(spy.argsForCall[0]).toEqual(['destroy'])
72
+
73
+ it "triggers the region:blurred event", ->
74
+ spy = spyOn(Mercury, 'trigger').andCallThrough()
75
+ Mercury.trigger('unfocus:regions')
76
+ expect(spy.callCount).toEqual(2)
77
+ expect(spy.argsForCall[1]).toEqual(['region:blurred', {region: @region}])
78
+
79
+ it "does nothing if previewing", ->
80
+ @region.previewing = true
81
+ @region.element.addClass('focus')
82
+ Mercury.trigger('unfocus:regions')
83
+ expect(@region.element.hasClass('focus')).toEqual(true)
84
+
85
+ it "does nothing if it's not the active region", ->
86
+ Mercury.region = null
87
+ @region.element.addClass('focus')
88
+ Mercury.trigger('unfocus:regions')
89
+ expect(@region.element.hasClass('focus')).toEqual(true)
90
+
91
+ describe "custom event: focus:window", ->
92
+
93
+ it "removes the focus class", ->
94
+ @region.element.addClass('focus')
95
+ Mercury.trigger('focus:window')
96
+ expect(@region.element.hasClass('focus')).toEqual(false)
97
+
98
+ it "destroys the sortable", ->
99
+ spy = spyOn($.fn, 'sortable').andCallFake(=>)
100
+ Mercury.trigger('focus:window')
101
+ expect(spy.argsForCall[0]).toEqual(['destroy'])
102
+
103
+ it "triggers the region:blurred event", ->
104
+ spy = spyOn(Mercury, 'trigger').andCallThrough()
105
+ Mercury.trigger('focus:window')
106
+ expect(spy.callCount).toEqual(2)
107
+ expect(spy.argsForCall[1]).toEqual(['region:blurred', {region: @region}])
108
+
109
+ it "does nothing if previewing", ->
110
+ @region.previewing = true
111
+ @region.element.addClass('focus')
112
+ Mercury.trigger('focus:window')
113
+ expect(@region.element.hasClass('focus')).toEqual(true)
114
+
115
+ it "does nothing if it's not the active region", ->
116
+ Mercury.region = null
117
+ @region.element.addClass('focus')
118
+ Mercury.trigger('focus:window')
119
+ expect(@region.element.hasClass('focus')).toEqual(true)
120
+
121
+ describe "keydown on document (for undo / redo)", ->
122
+
123
+ it "calls execCommand with undo on meta+z", ->
124
+ spy = spyOn(Mercury.Regions.Snippetable.prototype, 'execCommand')
125
+ jasmine.simulate.keydown(document, {shiftKey: false, metaKey: true, keyCode: 90})
126
+ expect(spy.callCount).toEqual(1)
127
+ expect(spy.argsForCall[0]).toEqual(['undo'])
128
+
129
+ it "calls execCommand with redo on shift+meta+z", ->
130
+ spy = spyOn(Mercury.Regions.Snippetable.prototype, 'execCommand')
131
+ jasmine.simulate.keydown(document, {shiftKey: true, metaKey: true, keyCode: 90})
132
+ expect(spy.callCount).toEqual(1)
133
+ expect(spy.argsForCall[0]).toEqual(['redo'])
134
+
135
+ it "does nothing if previewing", ->
136
+ @region.previewing = true
137
+ spy = spyOn(Mercury.Regions.Snippetable.prototype, 'execCommand')
138
+ jasmine.simulate.keydown(document, {shiftKey: true, metaKey: true, keyCode: 90})
139
+ expect(spy.callCount).toEqual(0)
140
+
141
+ it "does nothing if it's not the active region", ->
142
+ Mercury.region = null
143
+ spy = spyOn(Mercury.Regions.Snippetable.prototype, 'execCommand')
144
+ jasmine.simulate.keydown(document, {shiftKey: true, metaKey: true, keyCode: 90})
145
+ expect(spy.callCount).toEqual(0)
146
+
147
+ describe "mouseup", ->
148
+
149
+ it "calls focus", ->
150
+ spy = spyOn(Mercury.Regions.Snippetable.prototype, 'focus')
151
+ jasmine.simulate.mouseup(@region.element.get(0))
152
+ expect(spy.callCount).toEqual(1)
153
+
154
+ it "triggers the region:focused event", ->
155
+ spy = spyOn(Mercury, 'trigger')
156
+ jasmine.simulate.mouseup(@region.element.get(0))
157
+ expect(spy.callCount).toEqual(1)
158
+
159
+ it "does nothing if previewing", ->
160
+ @region.previewing = true
161
+ spy = spyOn(Mercury.Regions.Snippetable.prototype, 'focus')
162
+ jasmine.simulate.mouseup(@region.element.get(0))
163
+ expect(spy.callCount).toEqual(0)
164
+
165
+ describe "dragover", ->
166
+
167
+ # untestable
168
+ it "prevents the default event", ->
169
+ it "does nothing if previewing", ->
170
+
171
+ describe "drop", ->
172
+
173
+ # untestable
174
+ it "calls focus", ->
175
+ it "prevents the default event", ->
176
+ it "displays the options for the snippet that was dropped", ->
177
+ it "does nothing if previewing", ->
178
+ it "does nothing if there's no active snippet", ->
179
+
180
+
181
+ describe "#focus", ->
182
+
183
+ beforeEach ->
184
+ @region = new Mercury.Regions.Snippetable(@regionElement, window)
185
+
186
+ it "sets the active mercury region", ->
187
+ Mercury.region = null
188
+ @region.focus()
189
+ expect(Mercury.region).toEqual(@region)
190
+
191
+ it "makes the snippets sortable again", ->
192
+ spy = spyOn(Mercury.Regions.Snippetable.prototype, 'makeSortable')
193
+ @region.focus()
194
+ expect(spy.callCount).toEqual(1)
195
+
196
+ it "adds the focus class to the element", ->
197
+ @region.focus()
198
+ expect($('#snippetable_region1').hasClass('focus')).toEqual(true)
199
+
200
+
201
+ describe "#togglePreview", ->
202
+
203
+ beforeEach ->
204
+ @region = new Mercury.Regions.Snippetable(@regionElement, window)
205
+
206
+ describe "when not previewing", ->
207
+
208
+ it "it destroys the sortable", ->
209
+ spy = spyOn($.fn, 'sortable').andCallFake(=>)
210
+ @region.togglePreview()
211
+ expect(spy.callCount).toEqual(1)
212
+ expect(spy.argsForCall[0]).toEqual(['destroy'])
213
+
214
+ it "removes the focus class", ->
215
+ @regionElement.addClass('focus')
216
+ @region.togglePreview()
217
+ expect($('#snippetable_region1').hasClass('focus')).toEqual(false)
218
+
219
+ describe "when previewing", ->
220
+
221
+ beforeEach ->
222
+ @region.previewing = true
223
+
224
+ it "makes the snippets sortable again", ->
225
+ spy = spyOn(Mercury.Regions.Snippetable.prototype, 'makeSortable')
226
+ @region.togglePreview()
227
+ expect(spy.callCount).toEqual(1)
228
+
229
+
230
+ describe "#execCommand", ->
231
+
232
+ beforeEach ->
233
+ @region = new Mercury.Regions.Snippetable(@regionElement, window)
234
+ Mercury.Regions.Snippetable.actions['foo'] = ->
235
+ @handlerSpy = spyOn(Mercury.Regions.Snippetable.actions, 'foo')
236
+
237
+ it "calls a handler (from the actions) if one exists", ->
238
+ @region.execCommand('foo', {value: 'something'})
239
+ expect(@handlerSpy.callCount).toEqual(1)
240
+ expect(@handlerSpy.argsForCall[0]).toEqual([{value: 'something'}])
241
+
242
+
243
+ describe "#makeSortable", ->
244
+
245
+ beforeEach ->
246
+ @region = new Mercury.Regions.Snippetable(@regionElement, window)
247
+ @sortableSpy = spyOn($.fn, 'sortable')
248
+
249
+ it "makes the snippets sortable", ->
250
+ @sortableSpy.andCallFake((arg) => return @region.element if arg == 'destroy' )
251
+ @region.makeSortable()
252
+ expect(@sortableSpy.callCount).toEqual(2)
253
+ expect(@sortableSpy.argsForCall[0]).toEqual(['destroy'])
254
+ expect(@sortableSpy.argsForCall[1][0]['document']).toEqual(@region.document)
255
+
256
+ it "triggers the hide:toolbar event at the end of the dragging", ->
257
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
258
+ @sortableSpy.andCallFake((arg) => if arg == 'destroy' then return @region.element else arg.beforeStop())
259
+ @region.makeSortable()
260
+ expect(spy.callCount).toEqual(1)
261
+ expect(spy.argsForCall[0]).toEqual(['hide:toolbar', {type: 'snippet', immediately: true}])
262
+
263
+ it "pushes to the history after dragging", ->
264
+ spy = spyOn(Mercury.Regions.Snippetable.prototype, 'pushHistory').andCallFake(=>)
265
+ spyOn(window, 'setTimeout').andCallFake((timeout, callback)=> callback())
266
+ @sortableSpy.andCallFake((arg) => if arg == 'destroy' then return @region.element else arg.stop())
267
+ @region.makeSortable()
268
+ expect(spy.callCount).toEqual(1)
269
+
270
+
271
+
272
+ describe "Mercury.Regions.Snippetable.actions", ->
273
+
274
+ template 'mercury/regions/snippetable.html'
275
+
276
+ beforeEach ->
277
+ @region = new Mercury.Regions.Snippetable($('#snippetable_region2'), window)
278
+ @actions = Mercury.Regions.Snippetable.actions
279
+
280
+ describe ".undo", ->
281
+
282
+ it "calls undo on the history buffer and sets the content", ->
283
+ htmlSpy = spyOn(Mercury.Regions.Snippetable.prototype, 'content').andCallFake(=>)
284
+ historySpy = spyOn(@region.history, 'undo').andCallFake(=> 'history -1')
285
+ @actions['undo'].call(@region)
286
+ expect(historySpy.callCount).toEqual(1)
287
+ expect(htmlSpy.callCount).toEqual(1)
288
+ expect(htmlSpy.argsForCall[0]).toEqual(['history -1'])
289
+
290
+
291
+ describe ".redo", ->
292
+
293
+ it "calls redo on the history buffer and sets the content", ->
294
+ htmlSpy = spyOn(Mercury.Regions.Snippetable.prototype, 'content').andCallFake(=>)
295
+ historySpy = spyOn(@region.history, 'redo').andCallFake(=> 'history +1')
296
+ @actions['redo'].call(@region)
297
+ expect(historySpy.callCount).toEqual(1)
298
+ expect(htmlSpy.callCount).toEqual(1)
299
+ expect(htmlSpy.argsForCall[0]).toEqual(['history +1'])
300
+
301
+
302
+ describe ".insertSnippet", ->
303
+
304
+ beforeEach ->
305
+ Mercury.Snippet.load({
306
+ 'snippet_1': {name: 'example', options: {'foo': 'bar'}},
307
+ 'snippet_2': {name: 'example', options: {'foo': 'bar'}},
308
+ })
309
+ spyOn(Mercury.Snippet.prototype, 'loadPreview').andCallFake(=>)
310
+
311
+ describe "updating a snippet", ->
312
+
313
+ it "finds the snippet by it's identity and replaces it with the new snippet", ->
314
+ @actions['insertSnippet'].call(@region, {value: Mercury.Snippet.find('snippet_1')})
315
+ expect($('#snippetable_region2').html()).toContain('class="mercury-snippet"')
316
+ expect($('#snippetable_region2').html()).toContain('contenteditable="false"')
317
+ expect($('#snippetable_region2').html()).toContain('data-version="1"')
318
+ expect($('#snippetable_region2').html()).toContain('data-snippet="snippet_1"')
319
+ expect($('#snippetable_region2').html()).toContain('[snippet_1]')
320
+
321
+ it "pushes to the history after it's been rendered", ->
322
+ spyOn(Mercury.Snippet.prototype, 'getHTML').andCallFake((x, callback) => callback() if callback)
323
+ spy = spyOn(Mercury.Regions.Snippetable.prototype, 'pushHistory').andCallFake(=>)
324
+ @actions['insertSnippet'].call(@region, {value: Mercury.Snippet.find('snippet_1')})
325
+ expect(spy.callCount).toEqual(1)
326
+
327
+ describe "inserting a snippet", ->
328
+
329
+ it "appends the new snippet html to the element", ->
330
+ @actions['insertSnippet'].call(@region, {value: Mercury.Snippet.find('snippet_2')})
331
+ expect($('#snippetable_region2 .mercury-snippet').length).toEqual(2)
332
+
333
+ it "pushes to the history after it's been rendered", ->
334
+ spyOn(Mercury.Snippet.prototype, 'getHTML').andCallFake((x, callback) => callback() if callback)
335
+ spy = spyOn(Mercury.Regions.Snippetable.prototype, 'pushHistory').andCallFake(=>)
336
+ @actions['insertSnippet'].call(@region, {value: Mercury.Snippet.find('snippet_2')})
337
+ expect(spy.callCount).toEqual(1)
338
+
339
+
340
+ describe ".editSnippet", ->
341
+
342
+ beforeEach ->
343
+ @region.snippet = $('#snippetable_region2 .mercury-snippet')
344
+
345
+ it "finds and displays the options for the given snippet", ->
346
+ spy = spyOn(Mercury.Snippet.prototype, 'displayOptions')
347
+ @actions['editSnippet'].call(@region)
348
+ expect(spy.callCount).toEqual(1)
349
+
350
+ it "does nothing if there's no active snippet (eg. hovered over)", ->
351
+ @region.snippet = null
352
+ spy = spyOn(Mercury.Snippet.prototype, 'displayOptions')
353
+ @actions['editSnippet'].call(@region)
354
+ expect(spy.callCount).toEqual(0)
355
+
356
+
357
+ describe ".removeSnippet", ->
358
+
359
+ beforeEach ->
360
+ @region.snippet = $('#snippetable_region2 .mercury-snippet')
361
+
362
+ it "removes the snippet if there's an active one", ->
363
+ @actions['removeSnippet'].call(@region)
364
+ expect($('#snippetable_region2 .mercury-snippet').length).toEqual(0)
365
+
366
+ it "triggers the hide:toolbar event", ->
367
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
368
+ @actions['removeSnippet'].call(@region)
369
+ expect(spy.callCount).toEqual(1)
370
+ expect(spy.argsForCall[0]).toEqual(['hide:toolbar', {type: 'snippet', immediately: true}])
@@ -0,0 +1,49 @@
1
+ describe "Mercury.Select", ->
2
+
3
+ template 'mercury/select.html'
4
+
5
+ beforeEach ->
6
+ $.fx.off = true
7
+
8
+ afterEach ->
9
+ @select = null
10
+ delete(@select)
11
+
12
+ describe "#build", ->
13
+
14
+ it "builds an element", ->
15
+ @select = new Mercury.Select('/blank.html', 'foo', {appendTo: '#test', for: $('#button')})
16
+ html = $('<div>').html(@select.element).html()
17
+ expect(html).toContain('class="mercury-select mercury-foo-select loading"')
18
+ expect(html).toContain('style="display:none"')
19
+
20
+ it "appends to any element", ->
21
+ @select = new Mercury.Select('/blank.html', 'foo', {appendTo: '#select_container', for: $('#button')})
22
+ expect($('#select_container .mercury-select').length).toEqual(1)
23
+
24
+
25
+ describe "observed events", ->
26
+
27
+ beforeEach ->
28
+ @select = new Mercury.Select('/blank.html', 'foo', {appendTo: '#test', for: $('#button')})
29
+
30
+ it "hides", ->
31
+ @select.element.css({display: 'block'})
32
+ Mercury.trigger('hide:dialogs')
33
+ expect(@select.element.css('display')).toEqual('none')
34
+
35
+ it "doesn't hide if it's the same dialog", ->
36
+ @select.element.css({display: 'block'})
37
+ Mercury.trigger('hide:dialogs', @select)
38
+ expect(@select.element.css('display')).toEqual('block')
39
+
40
+
41
+ describe "#position", ->
42
+
43
+ beforeEach ->
44
+ @select = new Mercury.Select('/blank.html', 'foo', {appendTo: '#test', for: $('#button')})
45
+
46
+ it "positions based on it's button", ->
47
+ @select.element.css({display: 'block'})
48
+ @select.position(true)
49
+ expect(@select.element.offset()).toEqual({top: 20, left: 42})
@@ -0,0 +1,245 @@
1
+ describe "Mercury.Snippet", ->
2
+
3
+ template 'mercury/snippet.html'
4
+
5
+ afterEach ->
6
+ Mercury.Snippet.all = []
7
+
8
+ describe "constructor", ->
9
+
10
+ beforeEach ->
11
+ @setOptionsSpy = spyOn(Mercury.Snippet.prototype, 'setOptions').andCallFake(=>)
12
+ @snippet = new Mercury.Snippet('foo', 'identity', {foo: 'bar'})
13
+
14
+ it "expects name and identity", ->
15
+ expect(@snippet.name).toEqual('foo')
16
+ expect(@snippet.identity).toEqual('identity')
17
+
18
+ it "sets the version", ->
19
+ expect(@snippet.version).toEqual(0)
20
+ expect(@snippet.identity).toEqual('identity')
21
+
22
+ it "creates a history buffer", ->
23
+ expect(@snippet.history).toBeDefined()
24
+
25
+ it "calls setOptions", ->
26
+ expect(@setOptionsSpy.callCount).toEqual(1)
27
+
28
+
29
+ describe "#getHTML", ->
30
+
31
+ beforeEach ->
32
+ @loadPreviewSpy = spyOn(Mercury.Snippet.prototype, 'loadPreview').andCallFake(=>)
33
+ @snippet = new Mercury.Snippet('foo', 'identity', {foo: 'bar'})
34
+
35
+ it "builds an element (in whatever context is provided", ->
36
+ ret = @snippet.getHTML($(document))
37
+ html = $('<div>').html(ret).html()
38
+ expect(html).toContain('class="mercury-snippet"')
39
+ expect(html).toContain('contenteditable="false"')
40
+ expect(html).toContain('data-snippet="identity"')
41
+ expect(html).toContain('data-version="1"')
42
+
43
+ it "sets the default content to the identity", ->
44
+ ret = @snippet.getHTML($(document))
45
+ expect(ret.html()).toEqual('[identity]')
46
+
47
+ it "calls loadPreview", ->
48
+ @snippet.getHTML($(document))
49
+ expect(@loadPreviewSpy.callCount).toEqual(1)
50
+
51
+ it "passes callback method to loadPreview", ->
52
+ callback = =>
53
+ @snippet.getHTML($(document), callback)
54
+ expect(@loadPreviewSpy.argsForCall[0][1]).toEqual(callback)
55
+
56
+
57
+ describe "#getText", ->
58
+
59
+ beforeEach ->
60
+ @snippet = new Mercury.Snippet('foo', 'identity', {foo: 'bar'})
61
+
62
+ it "returns an identity string", ->
63
+ expect(@snippet.getText()).toEqual('[--identity--]')
64
+
65
+
66
+ describe "#loadPreview", ->
67
+
68
+ beforeEach ->
69
+ @ajaxSpy = spyOn($, 'ajax')
70
+ @snippet = new Mercury.Snippet('foo', 'identity', {foo: 'bar'})
71
+
72
+ it "makes an ajax request", ->
73
+ @ajaxSpy.andCallFake(=>)
74
+ spyOn(Mercury, 'ajaxHeaders').andCallFake(=> {'X-CSRFToken': 'f00'})
75
+ @snippet.loadPreview()
76
+ expect(@ajaxSpy.callCount).toEqual(1)
77
+ expect(@ajaxSpy.argsForCall[0][0]).toEqual("/mercury/snippets/foo/preview.html")
78
+ expect(@ajaxSpy.argsForCall[0][1]['data']).toEqual({foo: 'bar'})
79
+ expect(@ajaxSpy.argsForCall[0][1]['type']).toEqual('POST')
80
+ expect(@ajaxSpy.argsForCall[0][1]['headers']).toEqual({'X-CSRFToken': 'f00'})
81
+
82
+ describe "ajax success", ->
83
+
84
+ beforeEach ->
85
+ @ajaxSpy.andCallFake((url, options) => options.success('data'))
86
+
87
+ it "sets the data", ->
88
+ @snippet.loadPreview($('#snippet'))
89
+ expect(@snippet.data).toEqual('data')
90
+
91
+ it "puts the data into the element", ->
92
+ @snippet.loadPreview($('#snippet'))
93
+ expect($('#snippet').html()).toEqual('data')
94
+
95
+ it "calls the callback if one was provided", ->
96
+ callCount = 0
97
+ callback = => callCount += 1
98
+ @snippet.loadPreview($('#snippet'), callback)
99
+ expect(callCount).toEqual(1)
100
+
101
+ describe "ajax failure", ->
102
+
103
+ beforeEach ->
104
+ @ajaxSpy.andCallFake((url, options) => options.error())
105
+
106
+ it "alerts the error", ->
107
+ spy = spyOn(window, 'alert').andCallFake(=>)
108
+ @snippet.loadPreview($('#snippet'))
109
+ expect(spy.callCount).toEqual(1)
110
+ expect(spy.argsForCall[0]).toEqual(['Error loading the preview for the "foo" snippet.'])
111
+
112
+
113
+ describe "#displayOptions", ->
114
+
115
+ beforeEach ->
116
+ @modalSpy = spyOn(Mercury, 'modal').andCallFake(=>)
117
+ @snippet = new Mercury.Snippet('foo', 'identity', {foo: 'bar'})
118
+
119
+ it "sets the global snippet to itself", ->
120
+ @snippet.displayOptions()
121
+ expect(Mercury.snippet).toEqual(@snippet)
122
+
123
+ it "opens a modal", ->
124
+ @snippet.displayOptions()
125
+ expect(@modalSpy.callCount).toEqual(1)
126
+
127
+
128
+ describe "#setOptions", ->
129
+
130
+ beforeEach ->
131
+ @snippet = new Mercury.Snippet('foo', 'identity', {foo: 'bar'})
132
+
133
+ it "removes rails form default options that aren't for storing", ->
134
+ @snippet.setOptions({foo: 'baz', utf8: 'check', authenticity_token: 'auth_token'})
135
+ expect(@snippet.options).toEqual({foo: 'baz'})
136
+
137
+ it "increases the version", ->
138
+ @snippet.setOptions({foo: 'baz'})
139
+ expect(@snippet.version).toEqual(2)
140
+
141
+ it "pushes the options to the history buffer", ->
142
+ @snippet.setOptions({foo: 'baz'})
143
+ expect(@snippet.history.stack.length).toEqual(2)
144
+
145
+
146
+ describe "#setVersion", ->
147
+
148
+ beforeEach ->
149
+ @snippet = new Mercury.Snippet('foo', 'identity', {foo: 'bar'})
150
+ @snippet.history.stack = [1, 2, {foo: 'baz'}, 4, 5, 6, 7, 8, 9, 10]
151
+
152
+ it "sets the version", ->
153
+ @snippet.setVersion(5)
154
+ expect(@snippet.version).toEqual(4)
155
+
156
+ it "accepts a version (can be a string)", ->
157
+ @snippet.setVersion('2')
158
+ expect(@snippet.version).toEqual(1)
159
+
160
+ it "pulls the version out of the history buffer", ->
161
+ @snippet.setVersion(3)
162
+ expect(@snippet.options).toEqual({foo: 'baz'})
163
+
164
+ it "returns true if successful", ->
165
+ ret = @snippet.setVersion('2')
166
+ expect(ret).toEqual(true)
167
+
168
+ it "returns false if not successful", ->
169
+ ret = @snippet.setVersion('abc')
170
+ expect(ret).toEqual(false)
171
+
172
+
173
+ describe "#serialize", ->
174
+
175
+ beforeEach ->
176
+ @snippet = new Mercury.Snippet('foo', 'identity', {foo: 'bar'})
177
+
178
+ it "returns an object with name and options", ->
179
+ ret = @snippet.serialize()
180
+ expect(ret).toEqual({name: 'foo', options: {foo: 'bar'}})
181
+
182
+
183
+
184
+ describe "Mercury.Snippet class methods", ->
185
+
186
+ afterEach ->
187
+ Mercury.Snippet.all = []
188
+
189
+ describe ".displayOptionsFor", ->
190
+
191
+ beforeEach ->
192
+ @modalSpy = spyOn(Mercury, 'modal').andCallFake(=>)
193
+
194
+ it "opens a modal with the name in the url", ->
195
+ Mercury.Snippet.displayOptionsFor('foo')
196
+ expect(@modalSpy.callCount).toEqual(1)
197
+ expect(@modalSpy.argsForCall[0]).toEqual(["/mercury/snippets/foo/options.html", {title: 'Snippet Options', handler: 'insertSnippet', snippetName: 'foo'}])
198
+
199
+ it "sets the snippet back to nothing", ->
200
+ Mercury.snippet = 'foo'
201
+ Mercury.Snippet.displayOptionsFor('foo')
202
+ expect(Mercury.snippet).toEqual(null)
203
+
204
+
205
+ describe ".create", ->
206
+
207
+ beforeEach ->
208
+ Mercury.Snippet.all = []
209
+
210
+ it "creates a new instance of Mercury.Snippet", ->
211
+ ret = Mercury.Snippet.create('foo', {foo: 'bar'})
212
+ expect(ret.options).toEqual({foo: 'bar'})
213
+
214
+ it "generates an identity and passes it to the instance", ->
215
+ ret = Mercury.Snippet.create('foo', {foo: 'bar'})
216
+ expect(ret.identity).toEqual('snippet_0')
217
+
218
+ it "pushes into the collection array", ->
219
+ Mercury.Snippet.create('foo', {foo: 'bar'})
220
+ expect(Mercury.Snippet.all.length).toEqual(1)
221
+
222
+
223
+ describe ".find", ->
224
+
225
+ beforeEach ->
226
+ Mercury.Snippet.create('foo', {foo: 'bar'})
227
+
228
+ it "finds a snippet by identity", ->
229
+ expect(Mercury.Snippet.find('snippet_0').options).toEqual({foo: 'bar'})
230
+
231
+ it "returns null if no snippet was found", ->
232
+ expect(Mercury.Snippet.find('snippet_x')).toEqual(null)
233
+
234
+
235
+ describe ".load", ->
236
+
237
+ beforeEach ->
238
+ @snippets = {
239
+ snippet_1: {name: 'foo', options: {foo: 'bar'}}
240
+ snippet_2: {name: 'bar', options: {baz: 'pizza'}}
241
+ }
242
+
243
+ it "creates a new instance for each item in the collection", ->
244
+ Mercury.Snippet.load(@snippets)
245
+ expect(Mercury.Snippet.all.length).toEqual(2)