mercury-rails 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data/LICENSE +5 -0
  2. data/{README.rdoc → README.md} +150 -60
  3. data/VERSION +1 -1
  4. data/annotated_source.template +57 -0
  5. data/app/controllers/mercury_controller.rb +8 -4
  6. data/app/models/image.rb +2 -2
  7. data/app/views/layouts/mercury.html.erb +14 -0
  8. data/app/views/mercury/lightviews/about.html +7 -0
  9. data/app/views/mercury/lightviews/imageprocessor.html +3 -0
  10. data/app/views/mercury/modals/character.html +255 -0
  11. data/app/views/mercury/modals/htmleditor.html +13 -0
  12. data/app/views/mercury/modals/link.html +75 -0
  13. data/app/views/mercury/modals/media.html +82 -0
  14. data/app/views/mercury/modals/sanitizer.html +9 -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.html.erb +1 -0
  24. data/app/views/mercury/snippets/example_options.html.erb +23 -0
  25. data/config/routes.rb +1 -1
  26. data/features/editing/basic.feature +1 -1
  27. data/features/support/paths.rb +1 -0
  28. data/lib/generators/mercury/install/install_generator.rb +14 -0
  29. data/mercury-rails.gemspec +115 -106
  30. data/spec/javascripts/mercury/dialog_spec.js.coffee +54 -38
  31. data/spec/javascripts/mercury/dialogs/backcolor_spec.js.coffee +1 -1
  32. data/spec/javascripts/mercury/dialogs/forecolor_spec.js.coffee +1 -1
  33. data/spec/javascripts/mercury/dialogs/formatblock_spec.js.coffee +1 -1
  34. data/spec/javascripts/mercury/dialogs/{objectspanel_spec.js.coffee → snippetpanel_spec.js.coffee} +4 -4
  35. data/spec/javascripts/mercury/dialogs/style_spec.js.coffee +1 -1
  36. data/spec/javascripts/mercury/history_buffer_spec.js.coffee +0 -1
  37. data/spec/javascripts/mercury/lightview_spec.js.coffee +448 -0
  38. data/spec/javascripts/mercury/mercury_spec.js.coffee +1 -1
  39. data/spec/javascripts/mercury/modal_spec.js.coffee +474 -0
  40. data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +1 -1
  41. data/spec/javascripts/mercury/modals/insertcharacter_spec.js.coffee +1 -1
  42. data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +8 -2
  43. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +1 -1
  44. data/spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee +1 -1
  45. data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +1 -1
  46. data/spec/javascripts/mercury/native_extensions_spec.js.coffee +1 -1
  47. data/spec/javascripts/mercury/page_editor_spec.js.coffee +160 -20
  48. data/spec/javascripts/mercury/palette_spec.js.coffee +1 -1
  49. data/spec/javascripts/mercury/panel_spec.js.coffee +1 -1
  50. data/spec/javascripts/mercury/region_spec.js.coffee +1 -1
  51. data/spec/javascripts/mercury/regions/editable_spec.js.coffee +191 -6
  52. data/spec/javascripts/mercury/regions/markupable_spec.js.coffee +369 -0
  53. data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +1 -1
  54. data/spec/javascripts/mercury/select_spec.js.coffee +1 -1
  55. data/spec/javascripts/mercury/snippet_spec.js.coffee +3 -3
  56. data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +2 -2
  57. data/spec/javascripts/mercury/statusbar_spec.js.coffee +91 -17
  58. data/spec/javascripts/mercury/table_editor_spec.js.coffee +5 -1
  59. data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +1 -1
  60. data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +1 -1
  61. data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +1 -1
  62. data/spec/javascripts/mercury/toolbar_spec.js.coffee +70 -15
  63. data/spec/javascripts/mercury/tooltip_spec.js.coffee +1 -1
  64. data/spec/javascripts/mercury/uploader_spec.js.coffee +9 -1
  65. data/spec/javascripts/templates/mercury/dialogs/{objectspanel.html → snippetpanel.html} +0 -0
  66. data/spec/javascripts/templates/mercury/lightview.html +13 -0
  67. data/spec/javascripts/templates/mercury/modal.html +13 -0
  68. data/spec/javascripts/templates/mercury/page_editor.html +11 -1
  69. data/spec/javascripts/templates/mercury/statusbar.html +1 -0
  70. data/spec/javascripts/templates/mercury/toolbar.html +1 -0
  71. data/{app → vendor}/assets/images/mercury/button.png +0 -0
  72. data/{app → vendor}/assets/images/mercury/clippy.png +0 -0
  73. data/{app → vendor}/assets/images/mercury/default-snippet.png +0 -0
  74. data/{app → vendor}/assets/images/mercury/loading-dark.gif +0 -0
  75. data/{app → vendor}/assets/images/mercury/loading-light.gif +0 -0
  76. data/{app → vendor}/assets/images/mercury/search-icon.png +0 -0
  77. data/vendor/assets/images/mercury/temp-logo.png +0 -0
  78. data/{app → vendor}/assets/images/mercury/toolbar/editable/buttons.png +0 -0
  79. data/{app → vendor}/assets/images/mercury/toolbar/primary/_expander.png +0 -0
  80. data/{app → vendor}/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
  81. data/{app → vendor}/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
  82. data/{app → vendor}/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
  83. data/{app → vendor}/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
  84. data/{app → vendor}/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
  85. data/{app → vendor}/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
  86. data/{app → vendor}/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
  87. data/{app → vendor}/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
  88. data/{app → vendor}/assets/images/mercury/toolbar/primary/preview.png +0 -0
  89. data/{app → vendor}/assets/images/mercury/toolbar/primary/redo.png +0 -0
  90. data/{app → vendor}/assets/images/mercury/toolbar/primary/save.png +0 -0
  91. data/{app/assets/images/mercury/toolbar/primary/objectspanel.png → vendor/assets/images/mercury/toolbar/primary/snippetpanel.png} +0 -0
  92. data/{app → vendor}/assets/images/mercury/toolbar/primary/undo.png +0 -0
  93. data/{app → vendor}/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
  94. data/vendor/assets/javascripts/mercury.js +302 -0
  95. data/vendor/assets/javascripts/mercury/dialog.js.coffee +157 -0
  96. data/{app → vendor}/assets/javascripts/mercury/dialogs/backcolor.js.coffee +0 -0
  97. data/{app → vendor}/assets/javascripts/mercury/dialogs/forecolor.js.coffee +0 -0
  98. data/{app → vendor}/assets/javascripts/mercury/dialogs/formatblock.js.coffee +0 -0
  99. data/{app → vendor}/assets/javascripts/mercury/dialogs/objectspanel.js.coffee +1 -1
  100. data/{app → vendor}/assets/javascripts/mercury/dialogs/style.js.coffee +0 -0
  101. data/{app → vendor}/assets/javascripts/mercury/history_buffer.js.coffee +0 -0
  102. data/vendor/assets/javascripts/mercury/lightview.js.coffee +156 -0
  103. data/vendor/assets/javascripts/mercury/lightviews/imageprocessor.js.coffee +2 -0
  104. data/vendor/assets/javascripts/mercury/mercury.js.coffee +63 -0
  105. data/{app → vendor}/assets/javascripts/mercury/modal.js.coffee +25 -17
  106. data/{app → vendor}/assets/javascripts/mercury/modals/htmleditor.js.coffee +0 -0
  107. data/{app → vendor}/assets/javascripts/mercury/modals/insertcharacter.js.coffee +0 -0
  108. data/{app → vendor}/assets/javascripts/mercury/modals/insertlink.js.coffee +3 -0
  109. data/{app → vendor}/assets/javascripts/mercury/modals/insertmedia.js.coffee +10 -2
  110. data/{app → vendor}/assets/javascripts/mercury/modals/insertsnippet.js.coffee +0 -0
  111. data/{app → vendor}/assets/javascripts/mercury/modals/inserttable.js.coffee +2 -2
  112. data/{app → vendor}/assets/javascripts/mercury/native_extensions.js.coffee +0 -0
  113. data/{app → vendor}/assets/javascripts/mercury/page_editor.js.coffee +44 -13
  114. data/{app → vendor}/assets/javascripts/mercury/palette.js.coffee +0 -0
  115. data/{app → vendor}/assets/javascripts/mercury/panel.js.coffee +0 -0
  116. data/{app → vendor}/assets/javascripts/mercury/region.js.coffee +0 -0
  117. data/{app → vendor}/assets/javascripts/mercury/regions/editable.js.coffee +58 -12
  118. data/{app → vendor}/assets/javascripts/mercury/regions/markupable.js.coffee +26 -24
  119. data/{app → vendor}/assets/javascripts/mercury/regions/snippetable.js.coffee +0 -0
  120. data/{app → vendor}/assets/javascripts/mercury/select.js.coffee +3 -0
  121. data/{app → vendor}/assets/javascripts/mercury/snippet.js.coffee +9 -5
  122. data/{app → vendor}/assets/javascripts/mercury/snippet_toolbar.js.coffee +0 -0
  123. data/vendor/assets/javascripts/mercury/statusbar.js.coffee +51 -0
  124. data/{app → vendor}/assets/javascripts/mercury/table_editor.js.coffee +9 -8
  125. data/{app → vendor}/assets/javascripts/mercury/toolbar.button.js.coffee +0 -0
  126. data/{app → vendor}/assets/javascripts/mercury/toolbar.button_group.js.coffee +0 -0
  127. data/{app → vendor}/assets/javascripts/mercury/toolbar.expander.js.coffee +0 -0
  128. data/{app → vendor}/assets/javascripts/mercury/toolbar.js.coffee +14 -1
  129. data/{app → vendor}/assets/javascripts/mercury/tooltip.js.coffee +3 -0
  130. data/{app → vendor}/assets/javascripts/mercury/uploader.js.coffee +22 -13
  131. data/vendor/assets/javascripts/{jquery-1.6.js → mercury_dependencies/jquery-1.6.js} +0 -0
  132. data/vendor/assets/javascripts/{jquery-ui-1.8.13.custom.js → mercury_dependencies/jquery-ui-1.8.13.custom.js} +0 -0
  133. data/vendor/assets/javascripts/{jquery.additions.js → mercury_dependencies/jquery.additions.js} +0 -0
  134. data/vendor/assets/javascripts/{liquidmetal.js → mercury_dependencies/liquidmetal.js} +0 -0
  135. data/vendor/assets/javascripts/{showdown.js → mercury_dependencies/showdown.js} +0 -0
  136. data/vendor/assets/javascripts/mercury_loader.js +191 -0
  137. data/{app → vendor}/assets/stylesheets/mercury.css +3 -6
  138. data/vendor/assets/stylesheets/mercury/dialog.css +199 -0
  139. data/vendor/assets/stylesheets/mercury/lightview.css +92 -0
  140. data/vendor/assets/stylesheets/mercury/mercury.css +134 -0
  141. data/vendor/assets/stylesheets/mercury/modal.css +191 -0
  142. data/{app/assets/stylesheets/mercury/statusbar.scss → vendor/assets/stylesheets/mercury/statusbar.css} +9 -1
  143. data/vendor/assets/stylesheets/mercury/toolbar.css +329 -0
  144. data/{app/assets/stylesheets/mercury/tooltip.scss → vendor/assets/stylesheets/mercury/tooltip.css} +7 -7
  145. data/vendor/assets/stylesheets/mercury/uploader.css +111 -0
  146. metadata +230 -225
  147. data/app/assets/images/mercury/toolbar/markupable/buttons.png +0 -0
  148. data/app/assets/images/mercury/toolbar/primary/todospanel.png +0 -0
  149. data/app/assets/javascripts/mercury.js +0 -30
  150. data/app/assets/javascripts/mercury/dialog.js.coffee +0 -75
  151. data/app/assets/javascripts/mercury/mercury.js.coffee +0 -286
  152. data/app/assets/javascripts/mercury/statusbar.js.coffee +0 -29
  153. data/app/assets/javascripts/mercury_loader.js +0 -98
  154. data/app/assets/stylesheets/mercury/dialog.scss +0 -179
  155. data/app/assets/stylesheets/mercury/mercury.scss +0 -127
  156. data/app/assets/stylesheets/mercury/modal.scss +0 -194
  157. data/app/assets/stylesheets/mercury/toolbar.scss +0 -415
  158. data/app/assets/stylesheets/mercury/uploader.scss +0 -109
  159. data/app/views/layouts/mercury.html.haml +0 -8
  160. data/app/views/mercury/modals/character.html.haml +0 -252
  161. data/app/views/mercury/modals/htmleditor.html.haml +0 -8
  162. data/app/views/mercury/modals/link.html.haml +0 -31
  163. data/app/views/mercury/modals/media.html.haml +0 -33
  164. data/app/views/mercury/modals/sanitizer.html.haml +0 -4
  165. data/app/views/mercury/modals/table.html.haml +0 -49
  166. data/app/views/mercury/palettes/backcolor.html.haml +0 -79
  167. data/app/views/mercury/palettes/forecolor.html.haml +0 -79
  168. data/app/views/mercury/panels/history.html.haml +0 -0
  169. data/app/views/mercury/panels/notes.html.haml +0 -0
  170. data/app/views/mercury/panels/snippets.html.haml +0 -10
  171. data/app/views/mercury/selects/formatblock.html.haml +0 -10
  172. data/app/views/mercury/selects/style.html.haml +0 -4
  173. data/app/views/mercury/snippets/example.html.haml +0 -2
  174. data/app/views/mercury/snippets/example_options.html.haml +0 -16
  175. data/log/.gitkeep +0 -0
  176. data/spec/javascripts/mercury/regions/_markupable_.js.coffee +0 -0
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.Dialog", ->
4
4
 
@@ -184,60 +184,76 @@ describe "Mercury.Dialog", ->
184
184
  Mercury.dialogHandlers.foo = ->
185
185
  @dialog = new Mercury.Dialog('/evergreen/responses/blank.html', 'foo', {appendTo: '#test', for: $('#button')})
186
186
 
187
- it "makes an ajax request", ->
188
- spy = spyOn($, 'ajax').andCallFake(=>)
189
- @dialog.load()
190
- expect(spy.callCount).toEqual(1)
191
-
192
187
  it "does nothing if there's no url", ->
193
188
  spy = spyOn($, 'ajax').andCallFake(=>)
194
189
  @dialog.url = false
195
190
  @dialog.load()
196
191
  expect(spy.callCount).toEqual(0)
197
192
 
198
- describe "on success", ->
193
+ describe "on a preloaded view", ->
199
194
 
200
195
  beforeEach ->
201
- @loadContentSpy = spyOn(Mercury.Dialog.prototype, 'loadContent').andCallFake(=>)
202
- @ajaxSpy = spyOn($, 'ajax').andCallFake (url, options) =>
203
- options.success('return value') if (options.success)
196
+ Mercury.preloadedViews = {'/evergreen/responses/blank.html': 'this is the preloaded content'}
204
197
 
205
- it "calls loadContent with data", ->
206
- @dialog.load()
207
- expect(@loadContentSpy.callCount).toEqual(1)
208
- expect(@loadContentSpy.argsForCall[0]).toEqual(['return value'])
198
+ afterEach ->
199
+ Mercury.preloadedViews = {}
209
200
 
210
- it "calls a dialog handler if there's one", ->
211
- spy = spyOn(Mercury.dialogHandlers, 'foo').andCallFake(=>)
201
+ it "calls loadContent with the content in the preloaded view", ->
202
+ spy = spyOn(Mercury.Dialog.prototype, 'loadContent').andCallFake(=>)
212
203
  @dialog.load()
213
204
  expect(spy.callCount).toEqual(1)
205
+ expect(spy.argsForCall[0]).toEqual(['this is the preloaded content'])
214
206
 
215
- it "calls a callback if one was provided", ->
216
- spy = spyOn(@, 'spyFunction').andCallFake(=>)
217
- @dialog.load(@spyFunction)
218
- expect(spy.callCount).toEqual(1)
219
-
220
- describe "on failure", ->
221
-
222
- beforeEach ->
223
- @alertSpy = spyOn(window, 'alert').andCallFake(=>)
224
- @ajaxSpy = spyOn($, 'ajax').andCallFake (url, options) =>
225
- options.error() if (options.error)
207
+ describe "when not a preloaded view", ->
226
208
 
227
- it "hides", ->
228
- spy = spyOn(Mercury.Dialog.prototype, 'hide').andCallFake(=>)
209
+ it "makes an ajax request", ->
210
+ spy = spyOn($, 'ajax').andCallFake(=>)
229
211
  @dialog.load()
230
212
  expect(spy.callCount).toEqual(1)
231
213
 
232
- it "removes the pressed state for it's button", ->
233
- $('#button').addClass('pressed')
234
- @dialog.load()
235
- expect($('#button').hasClass('pressed')).toEqual(false)
236
-
237
- it "alerts the user", ->
238
- @dialog.load()
239
- expect(@alertSpy.callCount).toEqual(1)
240
- expect(@alertSpy.argsForCall[0]).toEqual(['Mercury was unable to load /evergreen/responses/blank.html for the foo dialog.'])
214
+ describe "on success", ->
215
+
216
+ beforeEach ->
217
+ @loadContentSpy = spyOn(Mercury.Dialog.prototype, 'loadContent').andCallFake(=>)
218
+ @ajaxSpy = spyOn($, 'ajax').andCallFake (url, options) =>
219
+ options.success('return value') if (options.success)
220
+
221
+ it "calls loadContent with data", ->
222
+ @dialog.load()
223
+ expect(@loadContentSpy.callCount).toEqual(1)
224
+ expect(@loadContentSpy.argsForCall[0]).toEqual(['return value'])
225
+
226
+ it "calls a dialog handler if there's one", ->
227
+ spy = spyOn(Mercury.dialogHandlers, 'foo').andCallFake(=>)
228
+ @dialog.load()
229
+ expect(spy.callCount).toEqual(1)
230
+
231
+ it "calls a callback if one was provided", ->
232
+ spy = spyOn(@, 'spyFunction').andCallFake(=>)
233
+ @dialog.load(@spyFunction)
234
+ expect(spy.callCount).toEqual(1)
235
+
236
+ describe "on failure", ->
237
+
238
+ beforeEach ->
239
+ @alertSpy = spyOn(window, 'alert').andCallFake(=>)
240
+ @ajaxSpy = spyOn($, 'ajax').andCallFake (url, options) =>
241
+ options.error() if (options.error)
242
+
243
+ it "hides", ->
244
+ spy = spyOn(Mercury.Dialog.prototype, 'hide').andCallFake(=>)
245
+ @dialog.load()
246
+ expect(spy.callCount).toEqual(1)
247
+
248
+ it "removes the pressed state for it's button", ->
249
+ $('#button').addClass('pressed')
250
+ @dialog.load()
251
+ expect($('#button').hasClass('pressed')).toEqual(false)
252
+
253
+ it "alerts the user", ->
254
+ @dialog.load()
255
+ expect(@alertSpy.callCount).toEqual(1)
256
+ expect(@alertSpy.argsForCall[0]).toEqual(['Mercury was unable to load /evergreen/responses/blank.html for the foo dialog.'])
241
257
 
242
258
 
243
259
  describe "#loadContent", ->
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.dialogHandlers.backColor", ->
4
4
 
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.dialogHandlers.foreColor", ->
4
4
 
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.dialogHandlers.formatblock", ->
4
4
 
@@ -1,12 +1,12 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
- describe "Mercury.dialogHandlers.backColor", ->
3
+ describe "Mercury.dialogHandlers.snippetPanel", ->
4
4
 
5
- template 'mercury/dialogs/objectspanel.html'
5
+ template 'mercury/dialogs/snippetpanel.html'
6
6
 
7
7
  beforeEach ->
8
8
  @dialog = {element: $('#test'), button: $('#button')}
9
- Mercury.dialogHandlers.objectsPanel.call(@dialog)
9
+ Mercury.dialogHandlers.snippetPanel.call(@dialog)
10
10
 
11
11
  describe "filter", ->
12
12
 
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.dialogHandlers.style", ->
4
4
 
@@ -1,4 +1,3 @@
1
- Mercury = {}
2
1
  require '/assets/mercury.js'
3
2
 
4
3
  describe "Mercury.HistoryBuffer", ->
@@ -0,0 +1,448 @@
1
+ require '/assets/mercury.js'
2
+
3
+ describe "Mercury.lightview", ->
4
+
5
+ template 'mercury/lightview.html'
6
+
7
+ beforeEach ->
8
+ $.fx.off = true
9
+ Mercury.displayRect = {fullHeight: 200, width: 1000}
10
+
11
+ afterEach ->
12
+ Mercury.lightview.initialized = false
13
+ Mercury.lightview.visible = false
14
+ $(document).unbind('mercury:refresh')
15
+ $(document).unbind('mercury:resize')
16
+ $(document).unbind('keydown')
17
+
18
+ describe "singleton method", ->
19
+
20
+ beforeEach ->
21
+ @showSpy = spyOn(Mercury.lightview, 'show').andCallFake(=>)
22
+
23
+ it "calls show", ->
24
+ Mercury.lightview('/foo')
25
+ expect(@showSpy.callCount).toEqual(1)
26
+
27
+ it "returns the function object", ->
28
+ ret = Mercury.lightview('/foo')
29
+ expect(ret).toEqual(Mercury.lightview)
30
+
31
+
32
+ describe "#show", ->
33
+
34
+ beforeEach ->
35
+ @initializeSpy = spyOn(Mercury.lightview, 'initialize').andCallFake(=>)
36
+ @updateSpy = spyOn(Mercury.lightview, 'update').andCallFake(=>)
37
+ @appearSpy = spyOn(Mercury.lightview, 'appear').andCallFake(=>)
38
+
39
+ it "triggers the focus:window event", ->
40
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
41
+ Mercury.lightview.show()
42
+ expect(spy.callCount).toEqual(1)
43
+ expect(spy.argsForCall[0]).toEqual(['focus:window'])
44
+
45
+ it "calls initialize", ->
46
+ Mercury.lightview.show()
47
+ expect(@initializeSpy.callCount).toEqual(1)
48
+
49
+ describe "if already visible", ->
50
+
51
+ it "calls update", ->
52
+ Mercury.lightview.visible = true
53
+ Mercury.lightview.show()
54
+ expect(@updateSpy.callCount).toEqual(1)
55
+
56
+ describe "if not visible", ->
57
+
58
+ it "calls appear", ->
59
+ Mercury.lightview.show()
60
+ expect(@appearSpy.callCount).toEqual(1)
61
+
62
+
63
+ describe "#initialize", ->
64
+
65
+ beforeEach ->
66
+ @buildSpy = spyOn(Mercury.lightview, 'build').andCallFake(=>)
67
+ @bindEventsSpy = spyOn(Mercury.lightview, 'bindEvents').andCallFake(=>)
68
+
69
+ it "calls build", ->
70
+ Mercury.lightview.initialize()
71
+ expect(@buildSpy.callCount).toEqual(1)
72
+
73
+ it "calls bindEvents", ->
74
+ Mercury.lightview.initialize()
75
+ expect(@bindEventsSpy.callCount).toEqual(1)
76
+
77
+ it "does nothing if already initialized", ->
78
+ Mercury.lightview.initialized = true
79
+ Mercury.lightview.initialize()
80
+ expect(@buildSpy.callCount).toEqual(0)
81
+
82
+ it "sets initialized to true", ->
83
+ Mercury.lightview.initialize()
84
+ expect(Mercury.lightview.initialized).toEqual(true)
85
+
86
+
87
+ describe "#build", ->
88
+
89
+ beforeEach ->
90
+ Mercury.lightview.options = {appendTo: $('#test')}
91
+
92
+ it "builds an element", ->
93
+ Mercury.lightview.build()
94
+ expect($('#test .mercury-lightview').length).toEqual(1)
95
+
96
+ it "builds an overlay element", ->
97
+ Mercury.lightview.build()
98
+ expect($('#test .mercury-lightview-overlay').length).toEqual(1)
99
+
100
+ it "creates a titleElement", ->
101
+ Mercury.lightview.build()
102
+ expect($('#test .mercury-lightview-title').length).toEqual(1)
103
+ expect($('#test .mercury-lightview-title').html()).toEqual("<span><\/span>")
104
+ expect(Mercury.lightview.titleElement).toBeDefined()
105
+
106
+ it "creates a contentElement", ->
107
+ Mercury.lightview.build()
108
+ expect($('#test .mercury-lightview-content').length).toEqual(1)
109
+ expect(Mercury.lightview.contentElement).toBeDefined()
110
+
111
+ it "appends to any element", ->
112
+ Mercury.lightview.options = {appendTo: $('#lightview_container')}
113
+ Mercury.lightview.build()
114
+ expect($('#lightview_container .mercury-lightview').length).toEqual(1)
115
+ expect($('#lightview_container .mercury-lightview-overlay').length).toEqual(1)
116
+
117
+ it "updates the title to reflect what was passed in the options", ->
118
+ Mercury.lightview.options.title = 'title'
119
+ Mercury.lightview.build()
120
+ expect($('#test .mercury-lightview-title span').html()).toEqual('title')
121
+
122
+
123
+ describe "observed events", ->
124
+
125
+ beforeEach ->
126
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
127
+ Mercury.lightview('/foo', {appendTo: $('#test')})
128
+
129
+ describe "custom event: refresh", ->
130
+
131
+ it "calls resize telling it stay visible", ->
132
+ spy = spyOn(Mercury.lightview, 'resize').andCallFake(=>)
133
+ Mercury.trigger('refresh')
134
+ expect(spy.callCount).toEqual(1)
135
+ expect(spy.argsForCall[0]).toEqual([true])
136
+
137
+ describe "custom event: resize", ->
138
+
139
+ beforeEach ->
140
+ Mercury.lightview.visible = true
141
+
142
+ it "calls position", ->
143
+ spy = spyOn(Mercury.lightview, 'position').andCallFake(=>)
144
+ Mercury.trigger('resize')
145
+ expect(spy.callCount).toEqual(1)
146
+
147
+ describe "clicking on the overlay", ->
148
+
149
+ it "calls hide", ->
150
+ spy = spyOn(Mercury.lightview, 'hide').andCallFake(=>)
151
+ jasmine.simulate.click($('.mercury-lightview-overlay').get(0))
152
+ expect(spy.callCount).toEqual(1)
153
+
154
+ describe "pressing esc on document", ->
155
+
156
+ beforeEach ->
157
+ Mercury.lightview.visible = true
158
+
159
+ it "calls hide", ->
160
+ spy = spyOn(Mercury.lightview, 'hide').andCallFake(=>)
161
+ jasmine.simulate.keydown(document, {keyCode: 27})
162
+ expect(spy.callCount).toEqual(1)
163
+
164
+
165
+ describe "#appear", ->
166
+
167
+ beforeEach ->
168
+ Mercury.lightview.visible = true
169
+ spyOn(Mercury.lightview, 'update').andCallFake(=>)
170
+ @loadSpy = spyOn(Mercury.lightview, 'load').andCallFake(=>)
171
+ @positionSpy = spyOn(Mercury.lightview, 'position').andCallFake(=>)
172
+ Mercury.lightview('/evergreen/responses/blank.html', {appendTo: $('#test')})
173
+
174
+ it "calls position", ->
175
+ Mercury.lightview.appear()
176
+ expect(@positionSpy.callCount).toEqual(1)
177
+
178
+ it "shows the overlay", ->
179
+ expect($('.mercury-lightview-overlay').css('display')).toEqual('none')
180
+ Mercury.lightview.appear()
181
+ expect($('.mercury-lightview-overlay').css('display')).toEqual('block')
182
+
183
+ it "animates the overlay to full opacity", ->
184
+ expect($('.mercury-lightview-overlay').css('opacity')).toEqual('0')
185
+ Mercury.lightview.appear()
186
+ expect($('.mercury-lightview-overlay').css('opacity')).toEqual('1')
187
+
188
+ it "calls setTitle", ->
189
+ spy = spyOn(Mercury.lightview, 'setTitle').andCallFake(=>)
190
+ Mercury.lightview.appear()
191
+ expect(spy.callCount).toEqual(1)
192
+
193
+ it "shows the element", ->
194
+ expect($('.mercury-lightview').css('display')).toEqual('none')
195
+ Mercury.lightview.appear()
196
+ expect($('.mercury-lightview').css('display')).toEqual('block')
197
+
198
+ it "animates the element opacity", ->
199
+ expect($('.mercury-lightview').css('opacity')).toEqual('0')
200
+ Mercury.lightview.appear()
201
+ expect($('.mercury-lightview').css('opacity')).toEqual('1')
202
+
203
+ it "sets visible to true", ->
204
+ Mercury.lightview.visible = false
205
+ Mercury.lightview.appear()
206
+ expect(Mercury.lightview.visible).toEqual(true)
207
+
208
+ it "calls load", ->
209
+ Mercury.lightview.appear()
210
+ expect(@loadSpy.callCount).toEqual(1)
211
+
212
+
213
+ describe "#resize", ->
214
+
215
+ beforeEach ->
216
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
217
+ Mercury.lightview('/evergreen/responses/blank.html', {appendTo: $('#test')})
218
+
219
+ it "resizes the element and adjusts it's position when empty", ->
220
+ $('.mercury-lightview').css({display: 'block', visibility: 'visible', top: 0})
221
+ Mercury.lightview.resize()
222
+ expect($('.mercury-lightview').width()).toEqual(300)
223
+ expect($('.mercury-lightview').offset()).toEqual({top: 35, left: 350})
224
+ expect($('.mercury-lightview').height()).toEqual(150)
225
+
226
+ it "resizes the element and adjusts it's position when it has content", ->
227
+ Mercury.lightview.loadContent('<div style="width:600px;height:400px"></div>')
228
+ $('.mercury-lightview').css({display: 'block', visibility: 'visible', top: 0})
229
+ Mercury.lightview.resize()
230
+ expect($('.mercury-lightview').width()).toEqual(642)
231
+ expect($('.mercury-lightview').offset()).toEqual({top: 20, left: 179})
232
+ expect($('.mercury-lightview').height()).toEqual(180)
233
+
234
+
235
+ describe "#position", ->
236
+
237
+ beforeEach ->
238
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
239
+
240
+ # todo: test this
241
+ it "positions the element", ->
242
+
243
+
244
+ describe "#update", ->
245
+
246
+ beforeEach ->
247
+ @resetSpy = spyOn(Mercury.lightview, 'reset').andCallFake(=>)
248
+ @resizeSpy = spyOn(Mercury.lightview, 'resize').andCallFake(=>)
249
+ @loadSpy = spyOn(Mercury.lightview, 'load').andCallFake(=>)
250
+ Mercury.lightview.update()
251
+
252
+ it "calls reset", ->
253
+ expect(@resetSpy.callCount).toEqual(1)
254
+
255
+ it "calls resize", ->
256
+ expect(@resizeSpy.callCount).toEqual(1)
257
+
258
+ it "calls load", ->
259
+ expect(@loadSpy.callCount).toEqual(1)
260
+
261
+
262
+ describe "#load", ->
263
+
264
+ beforeEach ->
265
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
266
+ @ajaxSpy = spyOn($, 'ajax')
267
+ Mercury.lightview('/evergreen/responses/blank.html', {appendTo: $('#test')})
268
+
269
+ it "does nothing if there's no url", ->
270
+ Mercury.lightview.url = null
271
+ $('.mercury-lightview').removeClass('loading')
272
+ Mercury.lightview.load()
273
+ expect($('.mercury-lightview').hasClass('loading')).toEqual(false)
274
+
275
+ it "sets the loading class on the element", ->
276
+ Mercury.lightview.load()
277
+ expect($('.mercury-lightview').hasClass('loading')).toEqual(true)
278
+
279
+ it "calls setTitle", ->
280
+ spy = spyOn(Mercury.lightview, 'setTitle').andCallFake(=>)
281
+ Mercury.lightview.load()
282
+ expect(spy.callCount).toEqual(1)
283
+
284
+ describe "on a preloaded view", ->
285
+
286
+ beforeEach ->
287
+ @setTimeoutSpy = spyOn(window, 'setTimeout').andCallFake((callback) => callback())
288
+ Mercury.preloadedViews = {'/evergreen/responses/blank.html': 'this is the preloaded content'}
289
+
290
+ afterEach ->
291
+ Mercury.preloadedViews = {}
292
+
293
+ it "calls loadContent with the content in the preloaded view", ->
294
+ spy = spyOn(Mercury.lightview, 'loadContent').andCallFake(=>)
295
+ Mercury.lightview.load()
296
+ expect(@setTimeoutSpy.callCount).toEqual(1)
297
+ expect(spy.callCount).toEqual(1)
298
+
299
+ describe "when not a preloaded view", ->
300
+
301
+ it "makes an ajax request", ->
302
+ @ajaxSpy.andCallFake(=>)
303
+ Mercury.lightview.load()
304
+ expect(@ajaxSpy.callCount).toEqual(1)
305
+
306
+ describe "on success", ->
307
+
308
+ beforeEach ->
309
+ @ajaxSpy.andCallFake((url, options) => options.success('return value'))
310
+
311
+ it "calls loadContent and passes the returned data", ->
312
+ spy = spyOn(Mercury.lightview, 'loadContent').andCallFake(=>)
313
+ Mercury.lightview.load()
314
+ expect(spy.callCount).toEqual(1)
315
+ expect(spy.argsForCall[0]).toEqual(['return value'])
316
+
317
+ describe "on failure", ->
318
+
319
+ beforeEach ->
320
+ @ajaxSpy.andCallFake((url, options) => options.error())
321
+
322
+ it "calls hide", ->
323
+ spyOn(window, 'alert').andCallFake(=>)
324
+ spy = spyOn(Mercury.lightview, 'hide').andCallFake(=>)
325
+ Mercury.lightview.load()
326
+ expect(spy.callCount).toEqual(1)
327
+
328
+ it "alerts an error message", ->
329
+ spyOn(Mercury.lightview, 'hide').andCallFake(=>)
330
+ spy = spyOn(window, 'alert').andCallFake(=>)
331
+ Mercury.lightview.load()
332
+ expect(spy.callCount).toEqual(1)
333
+ expect(spy.argsForCall[0]).toEqual(['Mercury was unable to load /evergreen/responses/blank.html for the lightview.'])
334
+
335
+
336
+ describe "#loadContent", ->
337
+
338
+ beforeEach ->
339
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
340
+ @resizeSpy = spyOn(Mercury.lightview, 'resize').andCallFake(=>)
341
+ Mercury.lightview('/evergreen/responses/blank.html', {appendTo: $('#test'), title: 'title'})
342
+
343
+ it "accepts options and sets them to the instance options", ->
344
+ Mercury.lightview.loadContent('content', {title: 'title'})
345
+ expect(Mercury.lightview.options).toEqual({title: 'title'})
346
+
347
+ it "calls initialize", ->
348
+ spy = spyOn(Mercury.lightview, 'initialize').andCallFake(=>)
349
+ Mercury.lightview.loadContent('content')
350
+ expect(spy.callCount).toEqual(1)
351
+
352
+ it "calls setTitle", ->
353
+ spy = spyOn(Mercury.lightview, 'setTitle').andCallFake(=>)
354
+ Mercury.lightview.loadContent('content')
355
+ expect(spy.callCount).toEqual(1)
356
+
357
+ it "sets loaded to true", ->
358
+ Mercury.lightview.loaded = false
359
+ Mercury.lightview.loadContent('content')
360
+ expect(Mercury.lightview.loaded).toEqual(true)
361
+
362
+ it "removes the loading class", ->
363
+ $('.mercury-lightview').addClass('loading')
364
+ Mercury.lightview.loadContent('content')
365
+ expect($('.mercury-lightview').hasClass('loading')).toEqual(false)
366
+
367
+ it "sets the content elements html to whatever was passed", ->
368
+ Mercury.lightview.loadContent('content')
369
+ expect($('.mercury-lightview-content').html()).toEqual('content')
370
+
371
+ it "hides the contentElement", ->
372
+ $('.mercury-lightview-content').css('display', 'block')
373
+ Mercury.lightview.loadContent('content')
374
+ expect($('.mercury-lightview-content').css('display')).toEqual('none')
375
+ expect($('.mercury-lightview-content').css('visibility')).toEqual('hidden')
376
+
377
+ it "calls an afterLoad callback (if provided in options)", ->
378
+ callCount = 0
379
+ Mercury.lightview.loadContent('content', {afterLoad: => callCount += 1})
380
+ expect(callCount).toEqual(1)
381
+
382
+ it "calls a handler method if one is set in lightviewHandlers", ->
383
+ callCount = 0
384
+ Mercury.lightviewHandlers['foo'] = => callCount += 1
385
+ Mercury.lightview.loadContent('content', {handler: 'foo'})
386
+ expect(callCount).toEqual(1)
387
+
388
+ it "calls resize", ->
389
+ Mercury.lightview.loadContent('content')
390
+ expect(@resizeSpy.callCount).toEqual(1)
391
+
392
+
393
+ describe "#setTitle", ->
394
+
395
+ beforeEach ->
396
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
397
+ Mercury.lightview('/evergreen/responses/blank.html', {appendTo: $('#test'), title: 'title'})
398
+
399
+ it "sets the the title contents to what was provided in the options", ->
400
+ Mercury.lightview.options = {title: 'new title'}
401
+ Mercury.lightview.setTitle()
402
+ expect($('.mercury-lightview-title span').html()).toEqual('new title')
403
+
404
+
405
+ describe "#reset", ->
406
+
407
+ beforeEach ->
408
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
409
+ Mercury.lightview('/evergreen/responses/blank.html', {appendTo: $('#test'), title: 'title'})
410
+
411
+ it "clears the title and content elements", ->
412
+ $('.mercury-lightview-content').html('content')
413
+ Mercury.lightview.reset()
414
+ expect($('.mercury-lightview-content').html()).toEqual('')
415
+ expect($('.mercury-lightview-title span').html()).toEqual('')
416
+
417
+
418
+ describe "#hide", ->
419
+
420
+ beforeEach ->
421
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
422
+ Mercury.lightview('/evergreen/responses/blank.html', {appendTo: $('#test')})
423
+
424
+ it "triggers the focus:frame event", ->
425
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
426
+ Mercury.lightview.hide()
427
+ expect(spy.callCount).toEqual(1)
428
+ expect(spy.argsForCall[0]).toEqual(['focus:frame'])
429
+
430
+ it "hides the element", ->
431
+ Mercury.lightview.element.css('display:block')
432
+ Mercury.lightview.hide()
433
+ expect($('.mercury-lightview').css('display')).toEqual('none')
434
+
435
+ it "hides the overlay element", ->
436
+ Mercury.lightview.overlay.css('display:block')
437
+ Mercury.lightview.hide()
438
+ expect($('.mercury-lightview-overlay').css('display')).toEqual('none')
439
+
440
+ it "calls reset", ->
441
+ spy = spyOn(Mercury.lightview, 'reset').andCallFake(=>)
442
+ Mercury.lightview.hide()
443
+ expect(spy.callCount).toEqual(1)
444
+
445
+ it "sets visible to false", ->
446
+ Mercury.lightview.visible = true
447
+ Mercury.lightview.hide()
448
+ expect(Mercury.lightview.visible).toEqual(false)