kuji-mercury-rails 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. data/LICENSE +25 -0
  2. data/POST_INSTALL +15 -0
  3. data/app/controllers/mercury/images_controller.rb +19 -0
  4. data/app/controllers/mercury_controller.rb +34 -0
  5. data/app/models/mercury/image.rb +16 -0
  6. data/app/views/layouts/mercury.html.erb +33 -0
  7. data/app/views/mercury/lightviews/about.html +11 -0
  8. data/app/views/mercury/modals/character.html +255 -0
  9. data/app/views/mercury/modals/htmleditor.html +13 -0
  10. data/app/views/mercury/modals/link.html +75 -0
  11. data/app/views/mercury/modals/media.html +82 -0
  12. data/app/views/mercury/modals/table.html +84 -0
  13. data/app/views/mercury/palettes/backcolor.html +73 -0
  14. data/app/views/mercury/palettes/forecolor.html +73 -0
  15. data/app/views/mercury/panels/history.html +3 -0
  16. data/app/views/mercury/panels/notes.html +3 -0
  17. data/app/views/mercury/panels/snippets.html +12 -0
  18. data/app/views/mercury/selects/formatblock.html +11 -0
  19. data/app/views/mercury/selects/style.html +5 -0
  20. data/app/views/mercury/snippets/example/options.html.erb +34 -0
  21. data/app/views/mercury/snippets/example/preview.html.erb +1 -0
  22. data/config/engine.rb +41 -0
  23. data/db/migrate/20110526035601_create_mercury_images.rb +11 -0
  24. data/features/loading/loading.feature +22 -0
  25. data/features/loading/navigating.feature +77 -0
  26. data/features/loading/user_interface.feature +67 -0
  27. data/features/regions/editable/advanced_editing.feature +0 -0
  28. data/features/regions/editable/basic_editing.feature +195 -0
  29. data/features/regions/editable/inserting_links.feature +98 -0
  30. data/features/regions/editable/inserting_media.feature +110 -0
  31. data/features/regions/editable/inserting_snippets.feature +102 -0
  32. data/features/regions/editable/inserting_special_characters.feature +24 -0
  33. data/features/regions/editable/inserting_tables.feature +109 -0
  34. data/features/regions/editable/pasting.feature +0 -0
  35. data/features/regions/editable/uploading_images.feature +0 -0
  36. data/features/regions/image/uploading_images.feature +0 -0
  37. data/features/regions/markupable/advanced_editing.feature +0 -0
  38. data/features/regions/markupable/basic_editing.feature +0 -0
  39. data/features/regions/markupable/inserting_links.feature +0 -0
  40. data/features/regions/markupable/inserting_media.feature +0 -0
  41. data/features/regions/markupable/inserting_snippets.feature +0 -0
  42. data/features/regions/markupable/inserting_special_characters.feature +0 -0
  43. data/features/regions/markupable/inserting_tables.feature +0 -0
  44. data/features/regions/markupable/uploading_images.feature +0 -0
  45. data/features/regions/simple/basic_editing.feature +5 -0
  46. data/features/regions/snippetable/advanced_editing.feature +0 -0
  47. data/features/regions/snippetable/basic_editing.feature +0 -0
  48. data/features/regions/snippetable/inserting_snippets.feature +0 -0
  49. data/features/saving/saving.feature +33 -0
  50. data/features/step_definitions/debug_steps.rb +14 -0
  51. data/features/step_definitions/mercury_steps.rb +438 -0
  52. data/features/step_definitions/web_steps.rb +211 -0
  53. data/features/support/env.rb +46 -0
  54. data/features/support/mercury_contents.rb +25 -0
  55. data/features/support/mercury_selectors.rb +148 -0
  56. data/features/support/paths.rb +38 -0
  57. data/features/support/selectors.rb +44 -0
  58. data/lib/generators/mercury/install/install_generator.rb +49 -0
  59. data/lib/generators/mercury/install/templates/mongoid_paperclip_image.rb +17 -0
  60. data/lib/mercury-rails.rb +3 -0
  61. data/lib/mercury/authentication.rb +8 -0
  62. data/spec/javascripts/mercury/dialog_spec.js.coffee +281 -0
  63. data/spec/javascripts/mercury/dialogs/backcolor_spec.js.coffee +37 -0
  64. data/spec/javascripts/mercury/dialogs/forecolor_spec.js.coffee +37 -0
  65. data/spec/javascripts/mercury/dialogs/formatblock_spec.js.coffee +25 -0
  66. data/spec/javascripts/mercury/dialogs/snippetpanel_spec.js.coffee +30 -0
  67. data/spec/javascripts/mercury/dialogs/style_spec.js.coffee +25 -0
  68. data/spec/javascripts/mercury/history_buffer_spec.js.coffee +76 -0
  69. data/spec/javascripts/mercury/lightview_spec.js.coffee +497 -0
  70. data/spec/javascripts/mercury/mercury_spec.js.coffee +132 -0
  71. data/spec/javascripts/mercury/modal_spec.js.coffee +504 -0
  72. data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +30 -0
  73. data/spec/javascripts/mercury/modals/insertcharacter_spec.js.coffee +29 -0
  74. data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +220 -0
  75. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +167 -0
  76. data/spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee +52 -0
  77. data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +160 -0
  78. data/spec/javascripts/mercury/native_extensions_spec.js.coffee +60 -0
  79. data/spec/javascripts/mercury/page_editor_spec.js.coffee +757 -0
  80. data/spec/javascripts/mercury/palette_spec.js.coffee +49 -0
  81. data/spec/javascripts/mercury/panel_spec.js.coffee +183 -0
  82. data/spec/javascripts/mercury/region_spec.js.coffee +298 -0
  83. data/spec/javascripts/mercury/regions/editable_spec.js.coffee +561 -0
  84. data/spec/javascripts/mercury/regions/image_spec.js.coffee +34 -0
  85. data/spec/javascripts/mercury/regions/markupable_spec.js.coffee +367 -0
  86. data/spec/javascripts/mercury/regions/simple_spec.js.coffee +33 -0
  87. data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +370 -0
  88. data/spec/javascripts/mercury/select_spec.js.coffee +49 -0
  89. data/spec/javascripts/mercury/snippet_spec.js.coffee +253 -0
  90. data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +184 -0
  91. data/spec/javascripts/mercury/statusbar_spec.js.coffee +150 -0
  92. data/spec/javascripts/mercury/table_editor_spec.js.coffee +194 -0
  93. data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +90 -0
  94. data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +360 -0
  95. data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +118 -0
  96. data/spec/javascripts/mercury/toolbar_spec.js.coffee +222 -0
  97. data/spec/javascripts/mercury/tooltip_spec.js.coffee +186 -0
  98. data/spec/javascripts/mercury/uploader_spec.js.coffee +530 -0
  99. data/spec/javascripts/spec_helper.js +513 -0
  100. data/spec/javascripts/templates/mercury/dialog.html +2 -0
  101. data/spec/javascripts/templates/mercury/dialogs/backcolor.html +5 -0
  102. data/spec/javascripts/templates/mercury/dialogs/forecolor.html +5 -0
  103. data/spec/javascripts/templates/mercury/dialogs/formatblock.html +3 -0
  104. data/spec/javascripts/templates/mercury/dialogs/snippetpanel.html +16 -0
  105. data/spec/javascripts/templates/mercury/dialogs/style.html +3 -0
  106. data/spec/javascripts/templates/mercury/lightview.html +13 -0
  107. data/spec/javascripts/templates/mercury/modal.html +13 -0
  108. data/spec/javascripts/templates/mercury/modals/htmleditor.html +5 -0
  109. data/spec/javascripts/templates/mercury/modals/insertcharacter.html +5 -0
  110. data/spec/javascripts/templates/mercury/modals/insertlink.html +30 -0
  111. data/spec/javascripts/templates/mercury/modals/insertmedia.html +35 -0
  112. data/spec/javascripts/templates/mercury/modals/insertsnippet.html +6 -0
  113. data/spec/javascripts/templates/mercury/modals/inserttable.html +27 -0
  114. data/spec/javascripts/templates/mercury/page_editor.html +35 -0
  115. data/spec/javascripts/templates/mercury/palette.html +16 -0
  116. data/spec/javascripts/templates/mercury/panel.html +16 -0
  117. data/spec/javascripts/templates/mercury/region.html +2 -0
  118. data/spec/javascripts/templates/mercury/regions/editable.html +3 -0
  119. data/spec/javascripts/templates/mercury/regions/image.html +1 -0
  120. data/spec/javascripts/templates/mercury/regions/simple.html +3 -0
  121. data/spec/javascripts/templates/mercury/regions/snippetable.html +4 -0
  122. data/spec/javascripts/templates/mercury/select.html +16 -0
  123. data/spec/javascripts/templates/mercury/snippet.html +1 -0
  124. data/spec/javascripts/templates/mercury/snippet_toolbar.html +16 -0
  125. data/spec/javascripts/templates/mercury/statusbar.html +8 -0
  126. data/spec/javascripts/templates/mercury/table_editor.html +65 -0
  127. data/spec/javascripts/templates/mercury/toolbar.button.html +64 -0
  128. data/spec/javascripts/templates/mercury/toolbar.button_group.html +9 -0
  129. data/spec/javascripts/templates/mercury/toolbar.expander.html +18 -0
  130. data/spec/javascripts/templates/mercury/toolbar.html +11 -0
  131. data/spec/javascripts/templates/mercury/tooltip.html +12 -0
  132. data/spec/javascripts/templates/mercury/uploader.html +11 -0
  133. data/vendor/assets/images/mercury/button.png +0 -0
  134. data/vendor/assets/images/mercury/close.png +0 -0
  135. data/vendor/assets/images/mercury/default-snippet.png +0 -0
  136. data/vendor/assets/images/mercury/loading-dark.gif +0 -0
  137. data/vendor/assets/images/mercury/loading-light.gif +0 -0
  138. data/vendor/assets/images/mercury/missing-image.png +0 -0
  139. data/vendor/assets/images/mercury/search-icon.png +0 -0
  140. data/vendor/assets/images/mercury/temp-logo.png +0 -0
  141. data/vendor/assets/images/mercury/toolbar/editable/buttons.png +0 -0
  142. data/vendor/assets/images/mercury/toolbar/primary/_expander.png +0 -0
  143. data/vendor/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
  144. data/vendor/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
  145. data/vendor/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
  146. data/vendor/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
  147. data/vendor/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
  148. data/vendor/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
  149. data/vendor/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
  150. data/vendor/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
  151. data/vendor/assets/images/mercury/toolbar/primary/preview.png +0 -0
  152. data/vendor/assets/images/mercury/toolbar/primary/redo.png +0 -0
  153. data/vendor/assets/images/mercury/toolbar/primary/save.png +0 -0
  154. data/vendor/assets/images/mercury/toolbar/primary/snippetpanel.png +0 -0
  155. data/vendor/assets/images/mercury/toolbar/primary/undo.png +0 -0
  156. data/vendor/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
  157. data/vendor/assets/javascripts/mercury.js +479 -0
  158. data/vendor/assets/javascripts/mercury/dependencies/jquery-1.7.js +9300 -0
  159. data/vendor/assets/javascripts/mercury/dependencies/jquery-ui-1.8.13.custom.js +1328 -0
  160. data/vendor/assets/javascripts/mercury/dependencies/jquery.additions.js +206 -0
  161. data/vendor/assets/javascripts/mercury/dependencies/jquery.htmlClean.js +527 -0
  162. data/vendor/assets/javascripts/mercury/dependencies/liquidmetal.js +88 -0
  163. data/vendor/assets/javascripts/mercury/dependencies/showdown.js +1340 -0
  164. data/vendor/assets/javascripts/mercury/dialog.js.coffee +159 -0
  165. data/vendor/assets/javascripts/mercury/dialogs/backcolor.js.coffee +6 -0
  166. data/vendor/assets/javascripts/mercury/dialogs/forecolor.js.coffee +6 -0
  167. data/vendor/assets/javascripts/mercury/dialogs/formatblock.js.coffee +4 -0
  168. data/vendor/assets/javascripts/mercury/dialogs/snippetpanel.js.coffee +10 -0
  169. data/vendor/assets/javascripts/mercury/dialogs/style.js.coffee +4 -0
  170. data/vendor/assets/javascripts/mercury/finalize.js.coffee +3 -0
  171. data/vendor/assets/javascripts/mercury/history_buffer.js.coffee +30 -0
  172. data/vendor/assets/javascripts/mercury/lightview.js.coffee +205 -0
  173. data/vendor/assets/javascripts/mercury/locales/ar.locale.js.coffee +207 -0
  174. data/vendor/assets/javascripts/mercury/locales/da.locale.js.coffee +211 -0
  175. data/vendor/assets/javascripts/mercury/locales/de.locale.js.coffee +206 -0
  176. data/vendor/assets/javascripts/mercury/locales/es.locale.js.coffee +211 -0
  177. data/vendor/assets/javascripts/mercury/locales/example.local.js.coffee +211 -0
  178. data/vendor/assets/javascripts/mercury/locales/fr.locale.js.coffee +211 -0
  179. data/vendor/assets/javascripts/mercury/locales/it.locale.js.coffee +208 -0
  180. data/vendor/assets/javascripts/mercury/locales/ko.local.js.coffee +206 -0
  181. data/vendor/assets/javascripts/mercury/locales/nl.locale.js.coffee +206 -0
  182. data/vendor/assets/javascripts/mercury/locales/pt.locale.js.coffee +211 -0
  183. data/vendor/assets/javascripts/mercury/locales/sv.local.js.coffee +209 -0
  184. data/vendor/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +213 -0
  185. data/vendor/assets/javascripts/mercury/mercury.js.coffee +109 -0
  186. data/vendor/assets/javascripts/mercury/modal.js.coffee +198 -0
  187. data/vendor/assets/javascripts/mercury/modals/htmleditor.js.coffee +11 -0
  188. data/vendor/assets/javascripts/mercury/modals/insertcharacter.js.coffee +4 -0
  189. data/vendor/assets/javascripts/mercury/modals/insertlink.js.coffee +92 -0
  190. data/vendor/assets/javascripts/mercury/modals/insertmedia.js.coffee +81 -0
  191. data/vendor/assets/javascripts/mercury/modals/insertsnippet.js.coffee +12 -0
  192. data/vendor/assets/javascripts/mercury/modals/inserttable.js.coffee +54 -0
  193. data/vendor/assets/javascripts/mercury/native_extensions.js.coffee +55 -0
  194. data/vendor/assets/javascripts/mercury/page_editor.js.coffee +225 -0
  195. data/vendor/assets/javascripts/mercury/palette.js.coffee +29 -0
  196. data/vendor/assets/javascripts/mercury/panel.js.coffee +115 -0
  197. data/vendor/assets/javascripts/mercury/plugins/save_as_xml/mercury/page_editor.js.coffee +28 -0
  198. data/vendor/assets/javascripts/mercury/plugins/save_as_xml/plugin.js +9 -0
  199. data/vendor/assets/javascripts/mercury/region.js.coffee +107 -0
  200. data/vendor/assets/javascripts/mercury/regions/editable.js.coffee +600 -0
  201. data/vendor/assets/javascripts/mercury/regions/image.js.coffee +114 -0
  202. data/vendor/assets/javascripts/mercury/regions/markupable.js.coffee +398 -0
  203. data/vendor/assets/javascripts/mercury/regions/simple.js.coffee +325 -0
  204. data/vendor/assets/javascripts/mercury/regions/snippetable.js.coffee +124 -0
  205. data/vendor/assets/javascripts/mercury/select.js.coffee +44 -0
  206. data/vendor/assets/javascripts/mercury/snippet.js.coffee +106 -0
  207. data/vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee +72 -0
  208. data/vendor/assets/javascripts/mercury/statusbar.js.coffee +51 -0
  209. data/vendor/assets/javascripts/mercury/support/history.js +1 -0
  210. data/vendor/assets/javascripts/mercury/table_editor.js.coffee +265 -0
  211. data/vendor/assets/javascripts/mercury/toolbar.button.js.coffee +173 -0
  212. data/vendor/assets/javascripts/mercury/toolbar.button_group.js.coffee +42 -0
  213. data/vendor/assets/javascripts/mercury/toolbar.expander.js.coffee +56 -0
  214. data/vendor/assets/javascripts/mercury/toolbar.js.coffee +86 -0
  215. data/vendor/assets/javascripts/mercury/tooltip.js.coffee +74 -0
  216. data/vendor/assets/javascripts/mercury/uploader.js.coffee +244 -0
  217. data/vendor/assets/javascripts/mercury_loader.js +193 -0
  218. data/vendor/assets/javascripts/mercury_overrides.js +6 -0
  219. data/vendor/assets/stylesheets/mercury.css +28 -0
  220. data/vendor/assets/stylesheets/mercury/all_images.css.erb +89 -0
  221. data/vendor/assets/stylesheets/mercury/dialog.css +212 -0
  222. data/vendor/assets/stylesheets/mercury/form.css +118 -0
  223. data/vendor/assets/stylesheets/mercury/lightview.css +151 -0
  224. data/vendor/assets/stylesheets/mercury/mercury.css +37 -0
  225. data/vendor/assets/stylesheets/mercury/modal.css +183 -0
  226. data/vendor/assets/stylesheets/mercury/statusbar.css +32 -0
  227. data/vendor/assets/stylesheets/mercury/toolbar.css +304 -0
  228. data/vendor/assets/stylesheets/mercury/tooltip.css +26 -0
  229. data/vendor/assets/stylesheets/mercury/uploader.css +111 -0
  230. data/vendor/assets/stylesheets/mercury_overrides.css +17 -0
  231. metadata +572 -0
@@ -0,0 +1,37 @@
1
+ describe "Mercury.dialogHandlers.foreColor", ->
2
+
3
+ template 'mercury/dialogs/forecolor.html'
4
+
5
+ beforeEach ->
6
+ @dialog = {element: $('#test'), button: $('#button')}
7
+ Mercury.dialogHandlers.foreColor.call(@dialog)
8
+
9
+ describe "when a .picker or .last-picked element is clicked", ->
10
+
11
+ it "sets the last picked color to whatever was selected", ->
12
+ $('.last-picked').css({background: '#0000FF'})
13
+ jasmine.simulate.click($('#white').get(0))
14
+ expect($('.last-picked').css('backgroundColor')).toEqual('rgb(255, 255, 255)')
15
+ jasmine.simulate.click($('#red').get(0))
16
+ expect($('.last-picked').css('backgroundColor')).toEqual('rgb(255, 0, 0)')
17
+
18
+ it "sets the background color of the button", ->
19
+ $('#button').css({background: '#0000FF'})
20
+ jasmine.simulate.click($('#white').get(0))
21
+ expect($('#button').css('backgroundColor')).toEqual('rgb(255, 255, 255)')
22
+ jasmine.simulate.click($('#red').get(0))
23
+ expect($('#button').css('backgroundColor')).toEqual('rgb(255, 0, 0)')
24
+
25
+ it "triggers an action", ->
26
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
27
+ jasmine.simulate.click($('#white').get(0))
28
+ expect(spy.callCount).toEqual(1)
29
+ expect(spy.argsForCall[0]).toEqual(['action', {action: 'foreColor', value: 'rgb(255, 255, 255)'}])
30
+
31
+
32
+ describe "when any other element is clicked", ->
33
+
34
+ it "does nothing", ->
35
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
36
+ jasmine.simulate.click($('#green').get(0))
37
+ expect(spy.callCount).toEqual(0)
@@ -0,0 +1,25 @@
1
+ describe "Mercury.dialogHandlers.formatblock", ->
2
+
3
+ template 'mercury/dialogs/formatblock.html'
4
+
5
+ beforeEach ->
6
+ @dialog = {element: $('#test')}
7
+ Mercury.dialogHandlers.formatblock.call(@dialog)
8
+
9
+ describe "when an element with a data-tag attribute is clicked", ->
10
+
11
+ it "triggers an action", ->
12
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
13
+ jasmine.simulate.click($('#h1').get(0))
14
+ expect(spy.callCount).toEqual(1)
15
+ expect(spy.argsForCall[0]).toEqual(['action', {action: 'formatblock', value: 'h1'}])
16
+ jasmine.simulate.click($('#div').get(0))
17
+ expect(spy.argsForCall[1]).toEqual(['action', {action: 'formatblock', value: 'pre'}])
18
+
19
+
20
+ describe "when any other element is clicked", ->
21
+
22
+ it "does nothing", ->
23
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
24
+ jasmine.simulate.click($('#em').get(0))
25
+ expect(spy.callCount).toEqual(0)
@@ -0,0 +1,30 @@
1
+ describe "Mercury.dialogHandlers.snippetPanel", ->
2
+
3
+ template 'mercury/dialogs/snippetpanel.html'
4
+
5
+ beforeEach ->
6
+ @dialog = {element: $('#test'), button: $('#button')}
7
+ Mercury.dialogHandlers.snippetPanel.call(@dialog)
8
+
9
+ describe "filter", ->
10
+
11
+ it "filters on keypress", ->
12
+ $('#filter').val('foo')
13
+ jasmine.simulate.keyup($('#filter').get(0))
14
+ expect($('#first').css('display')).toNotEqual('none')
15
+ expect($('#second').css('display')).toEqual('none')
16
+
17
+ $('#filter').val('b')
18
+ jasmine.simulate.keyup($('#filter').get(0))
19
+ expect($('#first').css('display')).toNotEqual('none')
20
+ expect($('#second').css('display')).toNotEqual('none')
21
+
22
+ $('#filter').val('baz')
23
+ jasmine.simulate.keyup($('#filter').get(0))
24
+ expect($('#first').css('display')).toEqual('none')
25
+ expect($('#second').css('display')).toNotEqual('none')
26
+
27
+
28
+ describe "dragging an image with a data-snippet attribute", ->
29
+
30
+ it "sets the active snippet", ->
@@ -0,0 +1,25 @@
1
+ describe "Mercury.dialogHandlers.style", ->
2
+
3
+ template 'mercury/dialogs/style.html'
4
+
5
+ beforeEach ->
6
+ @dialog = {element: $('#test')}
7
+ Mercury.dialogHandlers.style.call(@dialog)
8
+
9
+ describe "when an element with a data-class attribute is clicked", ->
10
+
11
+ it "triggers an action", ->
12
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
13
+ jasmine.simulate.click($('#red').get(0))
14
+ expect(spy.callCount).toEqual(1)
15
+ expect(spy.argsForCall[0]).toEqual(['action', {action: 'style', value: 'red'}])
16
+ jasmine.simulate.click($('#bold').get(0))
17
+ expect(spy.argsForCall[1]).toEqual(['action', {action: 'style', value: 'bold'}])
18
+
19
+
20
+ describe "when any other element is clicked", ->
21
+
22
+ it "does nothing", ->
23
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
24
+ jasmine.simulate.click($('#blue').get(0))
25
+ expect(spy.callCount).toEqual(0)
@@ -0,0 +1,76 @@
1
+ describe "Mercury.HistoryBuffer", ->
2
+
3
+ beforeEach ->
4
+ @buffer = new Mercury.HistoryBuffer(5)
5
+
6
+ afterEach ->
7
+ @buffer = null
8
+ delete(@buffer)
9
+
10
+ describe "constructor", ->
11
+
12
+ it "accepts a max length", ->
13
+ expect(@buffer.maxLength).toEqual(5)
14
+
15
+ it "initializes an empty stack", ->
16
+ expect(@buffer.index).toEqual(0)
17
+ expect(@buffer.stack).toEqual([])
18
+
19
+
20
+ describe "#push", ->
21
+
22
+ it "won't duplicate items if the content is the same", ->
23
+ @buffer.push('1')
24
+ expect(@buffer.stack).toEqual(['1'])
25
+
26
+ @buffer.push('2<em class="mercury-marker"></em>')
27
+ expect(@buffer.stack).toEqual(['1', '2<em class="mercury-marker"></em>'])
28
+
29
+ it "pushes onto the stack where it should", ->
30
+ @buffer.push('1')
31
+ @buffer.push('2')
32
+ expect(@buffer.stack).toEqual(['1', '2'])
33
+
34
+ @buffer.index = 0
35
+ @buffer.push('3')
36
+ expect(@buffer.stack).toEqual(['1', '3'])
37
+
38
+ it "keeps the number of items within the max length by dropping the oldest items", ->
39
+ @buffer.push('1')
40
+ @buffer.push('2')
41
+ @buffer.push('3')
42
+ @buffer.push('4')
43
+ @buffer.push('5')
44
+ expect(@buffer.stack).toEqual(['1', '2', '3', '4', '5'])
45
+ @buffer.push('6')
46
+ expect(@buffer.stack).toEqual(['2', '3', '4', '5', '6'])
47
+
48
+
49
+ describe "#undo", ->
50
+
51
+ beforeEach ->
52
+ @buffer.push('1')
53
+ @buffer.push('2')
54
+
55
+ it "returns the correct item", ->
56
+ expect(@buffer.undo()).toEqual('1')
57
+
58
+ it "returns null if there are no more items to undo", ->
59
+ expect(@buffer.undo()).toEqual('1')
60
+ expect(@buffer.undo()).toEqual(null)
61
+
62
+
63
+ describe "#redo", ->
64
+
65
+ beforeEach ->
66
+ @buffer.push('1')
67
+ @buffer.push('2')
68
+
69
+ it "returns the correct item", ->
70
+ @buffer.undo()
71
+ expect(@buffer.redo()).toEqual('2')
72
+
73
+ it "returns null if there are no more items to redo", ->
74
+ @buffer.undo()
75
+ expect(@buffer.redo()).toEqual('2')
76
+ expect(@buffer.redo()).toEqual(null)
@@ -0,0 +1,497 @@
1
+ describe "Mercury.lightview", ->
2
+
3
+ template 'mercury/lightview.html'
4
+
5
+ beforeEach ->
6
+ $.fx.off = true
7
+ Mercury.displayRect = {fullHeight: 200, width: 1000}
8
+ Mercury.determinedLocale =
9
+ top: {'hello world!': 'bork! bork!'}
10
+ sub: {'foo': 'Bork!'}
11
+
12
+ afterEach ->
13
+ Mercury.config.localization.enabled = false
14
+ Mercury.lightview.initialized = false
15
+ Mercury.lightview.visible = false
16
+ $(window).unbind('mercury:refresh')
17
+ $(window).unbind('mercury:resize')
18
+ $(document).unbind('keydown')
19
+
20
+ describe "singleton method", ->
21
+
22
+ beforeEach ->
23
+ @showSpy = spyOn(Mercury.lightview, 'show').andCallFake(=>)
24
+
25
+ it "calls show", ->
26
+ Mercury.lightview('/foo')
27
+ expect(@showSpy.callCount).toEqual(1)
28
+
29
+ it "returns the function object", ->
30
+ ret = Mercury.lightview('/foo')
31
+ expect(ret).toEqual(Mercury.lightview)
32
+
33
+
34
+ describe "#show", ->
35
+
36
+ beforeEach ->
37
+ @initializeSpy = spyOn(Mercury.lightview, 'initialize').andCallFake(=>)
38
+ @updateSpy = spyOn(Mercury.lightview, 'update').andCallFake(=>)
39
+ @appearSpy = spyOn(Mercury.lightview, 'appear').andCallFake(=>)
40
+
41
+ it "triggers the focus:window event", ->
42
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
43
+ Mercury.lightview.show()
44
+ expect(spy.callCount).toEqual(1)
45
+ expect(spy.argsForCall[0]).toEqual(['focus:window'])
46
+
47
+ it "calls initialize", ->
48
+ Mercury.lightview.show()
49
+ expect(@initializeSpy.callCount).toEqual(1)
50
+
51
+ describe "if already visible", ->
52
+
53
+ it "calls update", ->
54
+ Mercury.lightview.visible = true
55
+ Mercury.lightview.show()
56
+ expect(@updateSpy.callCount).toEqual(1)
57
+
58
+ describe "if not visible", ->
59
+
60
+ it "calls appear", ->
61
+ Mercury.lightview.show()
62
+ expect(@appearSpy.callCount).toEqual(1)
63
+
64
+
65
+ describe "#initialize", ->
66
+
67
+ beforeEach ->
68
+ @buildSpy = spyOn(Mercury.lightview, 'build').andCallFake(=>)
69
+ @bindEventsSpy = spyOn(Mercury.lightview, 'bindEvents').andCallFake(=>)
70
+
71
+ it "calls build", ->
72
+ Mercury.lightview.initialize()
73
+ expect(@buildSpy.callCount).toEqual(1)
74
+
75
+ it "calls bindEvents", ->
76
+ Mercury.lightview.initialize()
77
+ expect(@bindEventsSpy.callCount).toEqual(1)
78
+
79
+ it "does nothing if already initialized", ->
80
+ Mercury.lightview.initialized = true
81
+ Mercury.lightview.initialize()
82
+ expect(@buildSpy.callCount).toEqual(0)
83
+
84
+ it "sets initialized to true", ->
85
+ Mercury.lightview.initialize()
86
+ expect(Mercury.lightview.initialized).toEqual(true)
87
+
88
+
89
+ describe "#build", ->
90
+
91
+ beforeEach ->
92
+ Mercury.lightview.options = {appendTo: $('#test')}
93
+
94
+ it "builds an element", ->
95
+ Mercury.lightview.build()
96
+ expect($('#test .mercury-lightview').length).toEqual(1)
97
+
98
+ it "builds an overlay element", ->
99
+ Mercury.lightview.build()
100
+ expect($('#test .mercury-lightview-overlay').length).toEqual(1)
101
+
102
+ it "creates a titleElement", ->
103
+ Mercury.lightview.build()
104
+ expect($('#test .mercury-lightview-title').length).toEqual(1)
105
+ expect($('#test .mercury-lightview-title').html()).toEqual("<span><\/span>")
106
+ expect(Mercury.lightview.titleElement).toBeDefined()
107
+
108
+ it "creates a contentElement", ->
109
+ Mercury.lightview.build()
110
+ expect($('#test .mercury-lightview-content').length).toEqual(1)
111
+ expect(Mercury.lightview.contentElement).toBeDefined()
112
+
113
+ it "appends to any element", ->
114
+ Mercury.lightview.options = {appendTo: $('#lightview_container')}
115
+ Mercury.lightview.build()
116
+ expect($('#lightview_container .mercury-lightview').length).toEqual(1)
117
+ expect($('#lightview_container .mercury-lightview-overlay').length).toEqual(1)
118
+
119
+ it "creates a close button if asked to in the options", ->
120
+ Mercury.lightview.options.closeButton = true
121
+ Mercury.lightview.build()
122
+ expect($('#test .mercury-lightview-close').length).toEqual(1)
123
+
124
+
125
+ describe "observed events", ->
126
+
127
+ beforeEach ->
128
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
129
+
130
+ describe "without a close button", ->
131
+
132
+ beforeEach ->
133
+ Mercury.lightview('/foo', {appendTo: $('#test')})
134
+
135
+ describe "custom event: refresh", ->
136
+
137
+ it "calls resize telling it stay visible", ->
138
+ spy = spyOn(Mercury.lightview, 'resize').andCallFake(=>)
139
+ Mercury.trigger('refresh')
140
+ expect(spy.callCount).toEqual(1)
141
+ expect(spy.argsForCall[0]).toEqual([true])
142
+
143
+ describe "custom event: resize", ->
144
+
145
+ beforeEach ->
146
+ Mercury.lightview.visible = true
147
+
148
+ it "calls position", ->
149
+ spy = spyOn(Mercury.lightview, 'position').andCallFake(=>)
150
+ Mercury.trigger('resize')
151
+ expect(spy.callCount).toEqual(1)
152
+
153
+ describe "clicking on the overlay", ->
154
+
155
+ it "calls hide", ->
156
+ spy = spyOn(Mercury.lightview, 'hide').andCallFake(=>)
157
+ jasmine.simulate.click($('.mercury-lightview-overlay').get(0))
158
+ expect(spy.callCount).toEqual(1)
159
+
160
+ describe "pressing esc on document", ->
161
+
162
+ beforeEach ->
163
+ Mercury.lightview.visible = true
164
+
165
+ it "calls hide", ->
166
+ spy = spyOn(Mercury.lightview, 'hide').andCallFake(=>)
167
+ jasmine.simulate.keydown(document, {keyCode: 27})
168
+ expect(spy.callCount).toEqual(1)
169
+
170
+ describe "with a close button", ->
171
+
172
+ beforeEach ->
173
+ Mercury.lightview('/foo', {appendTo: $('#test'), closeButton: true})
174
+
175
+ describe "clicking on the close button", ->
176
+
177
+ it "calls hide", ->
178
+ spy = spyOn(Mercury.lightview, 'hide').andCallFake(=>)
179
+ jasmine.simulate.click($('.mercury-lightview-close').get(0))
180
+ expect(spy.callCount).toEqual(1)
181
+
182
+ describe "clicking on the overlay", ->
183
+
184
+ it "doesn't call hide", ->
185
+ spy = spyOn(Mercury.lightview, 'hide').andCallFake(=>)
186
+ jasmine.simulate.click($('.mercury-lightview-overlay').get(0))
187
+ expect(spy.callCount).toEqual(0)
188
+
189
+ describe "ajax:beforeSend", ->
190
+
191
+ it "sets a success that will load the contents of the response", ->
192
+ options = {}
193
+ spy = spyOn(Mercury.lightview, 'loadContent').andCallFake(=>)
194
+ Mercury.lightview.element.trigger('ajax:beforeSend', [null, options])
195
+ expect(options.success).toBeDefined()
196
+ options.success('new content')
197
+ expect(spy.callCount).toEqual(1)
198
+ expect(spy.argsForCall[0]).toEqual(['new content'])
199
+
200
+
201
+ describe "#appear", ->
202
+
203
+ beforeEach ->
204
+ Mercury.lightview.visible = true
205
+ spyOn(Mercury.lightview, 'update').andCallFake(=>)
206
+ @loadSpy = spyOn(Mercury.lightview, 'load').andCallFake(=>)
207
+ @positionSpy = spyOn(Mercury.lightview, 'position').andCallFake(=>)
208
+ Mercury.lightview('/blank.html', {appendTo: $('#test')})
209
+
210
+ it "calls position", ->
211
+ Mercury.lightview.appear()
212
+ expect(@positionSpy.callCount).toEqual(1)
213
+
214
+ it "shows the overlay", ->
215
+ expect($('.mercury-lightview-overlay').css('display')).toEqual('none')
216
+ Mercury.lightview.appear()
217
+ expect($('.mercury-lightview-overlay').css('display')).toEqual('block')
218
+
219
+ it "animates the overlay to full opacity", ->
220
+ expect($('.mercury-lightview-overlay').css('opacity')).toEqual('0')
221
+ Mercury.lightview.appear()
222
+ expect($('.mercury-lightview-overlay').css('opacity')).toEqual('1')
223
+
224
+ it "calls setTitle", ->
225
+ spy = spyOn(Mercury.lightview, 'setTitle').andCallFake(=>)
226
+ Mercury.lightview.appear()
227
+ expect(spy.callCount).toEqual(1)
228
+
229
+ it "shows the element", ->
230
+ expect($('.mercury-lightview').css('display')).toEqual('none')
231
+ Mercury.lightview.appear()
232
+ expect($('.mercury-lightview').css('display')).toEqual('block')
233
+
234
+ it "animates the element opacity", ->
235
+ expect($('.mercury-lightview').css('opacity')).toEqual('0')
236
+ Mercury.lightview.appear()
237
+ expect($('.mercury-lightview').css('opacity')).toEqual('1')
238
+
239
+ it "sets visible to true", ->
240
+ Mercury.lightview.visible = false
241
+ Mercury.lightview.appear()
242
+ expect(Mercury.lightview.visible).toEqual(true)
243
+
244
+ it "calls load", ->
245
+ Mercury.lightview.appear()
246
+ expect(@loadSpy.callCount).toEqual(1)
247
+
248
+
249
+ describe "#resize", ->
250
+
251
+ beforeEach ->
252
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
253
+ Mercury.lightview('/blank.html', {appendTo: $('#test')})
254
+ Mercury.lightview.contentPane = $()
255
+
256
+ it "will keep the content element visible if asked to do so", ->
257
+ $('.mercury-lightview-content').css('visibility', 'visible')
258
+ Mercury.lightview.resize(true)
259
+ expect($('.mercury-lightview-content').css('visibility')).toEqual('visible')
260
+
261
+ it "resizes the element and adjusts it's position when empty", ->
262
+ $('.mercury-lightview').css({display: 'block', visibility: 'visible', top: 0})
263
+ Mercury.lightview.resize()
264
+ expect($('.mercury-lightview').width()).toEqual(300)
265
+ expect($('.mercury-lightview').offset()).toEqual({top: 35, left: 350})
266
+ expect($('.mercury-lightview').height()).toEqual(150)
267
+
268
+ it "resizes the element and adjusts it's position when it has content", ->
269
+ Mercury.lightview.loadContent('<div style="width:600px;height:400px"></div>')
270
+ $('.mercury-lightview').css({display: 'block', visibility: 'visible', top: 0})
271
+ Mercury.lightview.resize()
272
+ expect($('.mercury-lightview').width()).toEqual(300)
273
+ expect($('.mercury-lightview').offset()).toEqual({top: 20, left: 350})
274
+ expect($('.mercury-lightview').height()).toEqual(180)
275
+
276
+
277
+ describe "#position", ->
278
+
279
+ beforeEach ->
280
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
281
+
282
+ # todo: test this
283
+ it "positions the element", ->
284
+
285
+
286
+ describe "#update", ->
287
+
288
+ beforeEach ->
289
+ @resetSpy = spyOn(Mercury.lightview, 'reset').andCallFake(=>)
290
+ @resizeSpy = spyOn(Mercury.lightview, 'resize').andCallFake(=>)
291
+ @loadSpy = spyOn(Mercury.lightview, 'load').andCallFake(=>)
292
+ Mercury.lightview.update()
293
+
294
+ it "calls reset", ->
295
+ expect(@resetSpy.callCount).toEqual(1)
296
+
297
+ it "calls resize", ->
298
+ expect(@resizeSpy.callCount).toEqual(1)
299
+
300
+ it "calls load", ->
301
+ expect(@loadSpy.callCount).toEqual(1)
302
+
303
+
304
+ describe "#load", ->
305
+
306
+ beforeEach ->
307
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
308
+ @ajaxSpy = spyOn($, 'ajax')
309
+ Mercury.lightview('/blank.html', {appendTo: $('#test')})
310
+
311
+ it "does nothing if there's no url", ->
312
+ Mercury.lightview.url = null
313
+ $('.mercury-lightview').removeClass('loading')
314
+ Mercury.lightview.load()
315
+ expect($('.mercury-lightview').hasClass('loading')).toEqual(false)
316
+
317
+ it "sets the loading class on the element", ->
318
+ Mercury.lightview.load()
319
+ expect($('.mercury-lightview').hasClass('loading')).toEqual(true)
320
+
321
+ it "calls setTitle", ->
322
+ spy = spyOn(Mercury.lightview, 'setTitle').andCallFake(=>)
323
+ Mercury.lightview.load()
324
+ expect(spy.callCount).toEqual(1)
325
+
326
+ describe "on a preloaded view", ->
327
+
328
+ beforeEach ->
329
+ @setTimeoutSpy = spyOn(window, 'setTimeout').andCallFake((timeout, callback) => callback())
330
+ Mercury.preloadedViews = {'/blank.html': 'this is the preloaded content'}
331
+
332
+ afterEach ->
333
+ Mercury.preloadedViews = {}
334
+
335
+ it "calls loadContent with the content in the preloaded view", ->
336
+ spy = spyOn(Mercury.lightview, 'loadContent').andCallFake(=>)
337
+ Mercury.lightview.load()
338
+ expect(@setTimeoutSpy.callCount).toEqual(1)
339
+ expect(spy.callCount).toEqual(1)
340
+
341
+ describe "when not a preloaded view", ->
342
+
343
+ it "makes an ajax request", ->
344
+ @ajaxSpy.andCallFake(=>)
345
+ spyOn(Mercury, 'ajaxHeaders').andCallFake(=> {'X-CSRFToken': 'f00'})
346
+ Mercury.lightview.load()
347
+ expect(@ajaxSpy.callCount).toEqual(1)
348
+ expect(@ajaxSpy.argsForCall[0][1]['headers']).toEqual({'X-CSRFToken': 'f00'})
349
+
350
+ describe "on success", ->
351
+
352
+ beforeEach ->
353
+ @ajaxSpy.andCallFake((url, options) => options.success('return value'))
354
+
355
+ it "calls loadContent and passes the returned data", ->
356
+ spy = spyOn(Mercury.lightview, 'loadContent').andCallFake(=>)
357
+ Mercury.lightview.load()
358
+ expect(spy.callCount).toEqual(1)
359
+ expect(spy.argsForCall[0]).toEqual(['return value'])
360
+
361
+ describe "on failure", ->
362
+
363
+ beforeEach ->
364
+ @ajaxSpy.andCallFake((url, options) => options.error())
365
+
366
+ it "calls hide", ->
367
+ spyOn(window, 'alert').andCallFake(=>)
368
+ spy = spyOn(Mercury.lightview, 'hide').andCallFake(=>)
369
+ Mercury.lightview.load()
370
+ expect(spy.callCount).toEqual(1)
371
+
372
+ it "alerts an error message", ->
373
+ spyOn(Mercury.lightview, 'hide').andCallFake(=>)
374
+ spy = spyOn(window, 'alert').andCallFake(=>)
375
+ Mercury.lightview.load()
376
+ expect(spy.callCount).toEqual(1)
377
+ expect(spy.argsForCall[0]).toEqual(['Mercury was unable to load /blank.html for the lightview.'])
378
+
379
+
380
+ describe "#loadContent", ->
381
+
382
+ beforeEach ->
383
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
384
+ @resizeSpy = spyOn(Mercury.lightview, 'resize').andCallFake(=>)
385
+ Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
386
+
387
+ it "accepts options and sets them to the instance options", ->
388
+ Mercury.lightview.loadContent('content', {title: 'title'})
389
+ expect(Mercury.lightview.options).toEqual({title: 'title'})
390
+
391
+ it "calls initialize", ->
392
+ spy = spyOn(Mercury.lightview, 'initialize').andCallFake(=>)
393
+ Mercury.lightview.loadContent('content')
394
+ expect(spy.callCount).toEqual(1)
395
+
396
+ it "calls setTitle", ->
397
+ spy = spyOn(Mercury.lightview, 'setTitle').andCallFake(=>)
398
+ Mercury.lightview.loadContent('content')
399
+ expect(spy.callCount).toEqual(1)
400
+
401
+ it "sets loaded to true", ->
402
+ Mercury.lightview.loaded = false
403
+ Mercury.lightview.loadContent('content')
404
+ expect(Mercury.lightview.loaded).toEqual(true)
405
+
406
+ it "removes the loading class", ->
407
+ $('.mercury-lightview').addClass('loading')
408
+ Mercury.lightview.loadContent('content')
409
+ expect($('.mercury-lightview').hasClass('loading')).toEqual(false)
410
+
411
+ it "sets the content elements html to whatever was passed", ->
412
+ Mercury.lightview.loadContent('<span>content</span>')
413
+ expect($('.mercury-lightview-content').html()).toEqual('<span>content</span>')
414
+
415
+ it "hides the contentElement", ->
416
+ $('.mercury-lightview-content').css('display', 'block')
417
+ Mercury.lightview.loadContent('content')
418
+ expect($('.mercury-lightview-content').css('display')).toEqual('none')
419
+ expect($('.mercury-lightview-content').css('visibility')).toEqual('hidden')
420
+
421
+ it "calls an afterLoad callback (if provided in options)", ->
422
+ callCount = 0
423
+ Mercury.lightview.loadContent('content', {afterLoad: => callCount += 1})
424
+ expect(callCount).toEqual(1)
425
+
426
+ it "calls a handler method if one is set in lightviewHandlers", ->
427
+ callCount = 0
428
+ Mercury.lightviewHandlers['foo'] = => callCount += 1
429
+ Mercury.lightview.loadContent('content', {handler: 'foo'})
430
+ expect(callCount).toEqual(1)
431
+
432
+ it "translates the content if configured", ->
433
+ Mercury.config.localization.enabled = true
434
+ Mercury.lightview.loadContent('<span>foo</span>')
435
+ expect($('.mercury-lightview-content').html()).toEqual('<span>Bork!</span>')
436
+
437
+ it "calls resize", ->
438
+ Mercury.lightview.loadContent('content')
439
+ expect(@resizeSpy.callCount).toEqual(1)
440
+
441
+
442
+ describe "#setTitle", ->
443
+
444
+ beforeEach ->
445
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
446
+ Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
447
+
448
+ it "sets the the title contents to what was provided in the options", ->
449
+ Mercury.lightview.options = {title: 'new title'}
450
+ Mercury.lightview.setTitle()
451
+ expect($('.mercury-lightview-title span').html()).toEqual('new title')
452
+
453
+
454
+ describe "#reset", ->
455
+
456
+ beforeEach ->
457
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
458
+ Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
459
+
460
+ it "clears the title and content elements", ->
461
+ $('.mercury-lightview-content').html('content')
462
+ Mercury.lightview.reset()
463
+ expect($('.mercury-lightview-content').html()).toEqual('')
464
+ expect($('.mercury-lightview-title span').html()).toEqual('')
465
+
466
+
467
+ describe "#hide", ->
468
+
469
+ beforeEach ->
470
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
471
+ Mercury.lightview('/blank.html', {appendTo: $('#test')})
472
+
473
+ it "triggers the focus:frame event", ->
474
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
475
+ Mercury.lightview.hide()
476
+ expect(spy.callCount).toEqual(1)
477
+ expect(spy.argsForCall[0]).toEqual(['focus:frame'])
478
+
479
+ it "hides the element", ->
480
+ Mercury.lightview.element.css('display:block')
481
+ Mercury.lightview.hide()
482
+ expect($('.mercury-lightview').css('display')).toEqual('none')
483
+
484
+ it "hides the overlay element", ->
485
+ Mercury.lightview.overlay.css('display:block')
486
+ Mercury.lightview.hide()
487
+ expect($('.mercury-lightview-overlay').css('display')).toEqual('none')
488
+
489
+ it "calls reset", ->
490
+ spy = spyOn(Mercury.lightview, 'reset').andCallFake(=>)
491
+ Mercury.lightview.hide()
492
+ expect(spy.callCount).toEqual(1)
493
+
494
+ it "sets visible to false", ->
495
+ Mercury.lightview.visible = true
496
+ Mercury.lightview.hide()
497
+ expect(Mercury.lightview.visible).toEqual(false)