mercury-rails 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. data/app/assets/javascripts/mercury.js +1 -0
  2. data/app/assets/javascripts/mercury/lightview.js.coffee +26 -12
  3. data/app/assets/javascripts/mercury/locales/ar.locale.js.coffee +3 -5
  4. data/app/assets/javascripts/mercury/locales/da.locale.js.coffee +3 -5
  5. data/app/assets/javascripts/mercury/locales/de.locale.js.coffee +4 -6
  6. data/app/assets/javascripts/mercury/locales/es.locale.js.coffee +3 -5
  7. data/app/assets/javascripts/mercury/locales/example.local.js.coffee +3 -1
  8. data/app/assets/javascripts/mercury/locales/fr.locale.js.coffee +3 -5
  9. data/app/assets/javascripts/mercury/locales/it.locale.js.coffee +3 -5
  10. data/app/assets/javascripts/mercury/locales/ko.local.js.coffee +4 -6
  11. data/app/assets/javascripts/mercury/locales/nl.locale.js.coffee +3 -5
  12. data/app/assets/javascripts/mercury/locales/pt.locale.js.coffee +3 -5
  13. data/app/assets/javascripts/mercury/locales/sv.local.js.coffee +3 -5
  14. data/app/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +3 -5
  15. data/app/assets/javascripts/mercury/locales/zh.local.js.coffee +3 -5
  16. data/app/assets/javascripts/mercury/mercury.js.coffee +1 -1
  17. data/app/assets/javascripts/mercury/modal.js.coffee +38 -23
  18. data/app/assets/javascripts/mercury/modals/htmleditor.js.coffee +1 -0
  19. data/app/assets/javascripts/mercury/modals/insertcharacter.js.coffee +1 -0
  20. data/app/assets/javascripts/mercury/modals/insertlink.js.coffee +111 -60
  21. data/app/assets/javascripts/mercury/modals/insertmedia.js.coffee +80 -35
  22. data/app/assets/javascripts/mercury/modals/insertsnippet.js.coffee +1 -0
  23. data/app/assets/javascripts/mercury/modals/inserttable.js.coffee +59 -51
  24. data/app/assets/javascripts/mercury/page_editor.js.coffee +1 -1
  25. data/app/assets/javascripts/mercury/regions/full.coffee +1 -1
  26. data/app/assets/javascripts/mercury/regions/image.js.coffee +1 -1
  27. data/app/assets/javascripts/mercury/regions/markdown.coffee +1 -1
  28. data/app/assets/javascripts/mercury/regions/simple.js.coffee +1 -1
  29. data/app/assets/javascripts/mercury/regions/snippets.js.coffee +1 -1
  30. data/app/assets/javascripts/mercury/table_editor.js.coffee +16 -0
  31. data/app/assets/javascripts/mercury/toolbar.js.coffee +2 -2
  32. data/app/assets/stylesheets/mercury.css +0 -5
  33. data/app/assets/stylesheets/mercury/bootstrap-ish.css +1367 -0
  34. data/app/assets/stylesheets/mercury/bootstrap-overrides.css +60 -0
  35. data/app/assets/stylesheets/mercury/lightview.css +2 -52
  36. data/app/assets/stylesheets/mercury/mercury.css +2 -2
  37. data/app/assets/stylesheets/mercury/modal.css +13 -31
  38. data/app/assets/stylesheets/mercury/uploader.css +3 -3
  39. data/app/views/mercury/modals/htmleditor.html +2 -6
  40. data/app/views/mercury/modals/link.html +70 -64
  41. data/app/views/mercury/modals/media.html +80 -71
  42. data/app/views/mercury/modals/table.html +79 -73
  43. data/app/views/mercury/snippets/example/options.html.erb +11 -30
  44. data/features/loading/loading.feature +1 -1
  45. data/features/regions/full/inserting_links.feature +4 -4
  46. data/features/regions/full/inserting_media.feature +3 -3
  47. data/features/step_definitions/mercury_steps.rb +5 -5
  48. data/features/support/env.rb +1 -1
  49. data/lib/mercury/version.rb +1 -1
  50. data/spec/javascripts/mercury/lightview_spec.js.coffee +136 -129
  51. data/spec/javascripts/mercury/modal_spec.js.coffee +143 -139
  52. data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +105 -31
  53. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +76 -38
  54. data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +32 -35
  55. data/spec/javascripts/mercury/toolbar_spec.js.coffee +8 -0
  56. data/spec/javascripts/templates/mercury/modals/insertlink.html +58 -21
  57. data/spec/javascripts/templates/mercury/modals/insertmedia.html +69 -27
  58. data/spec/javascripts/templates/mercury/modals/inserttable.html +66 -20
  59. metadata +5 -5
  60. data/app/assets/stylesheets/mercury/buttons.css +0 -73
  61. data/app/assets/stylesheets/mercury/form.css +0 -125
@@ -11,8 +11,7 @@ describe "Mercury.modal", ->
11
11
 
12
12
  afterEach ->
13
13
  Mercury.config.localization.enabled = false
14
- Mercury.modal.initialized = false
15
- Mercury.modal.visible = false
14
+ Mercury.modal.instance = false
16
15
  $(window).unbind('mercury:refresh')
17
16
  $(window).unbind('mercury:resize')
18
17
  $(document).unbind('keydown')
@@ -20,104 +19,109 @@ describe "Mercury.modal", ->
20
19
  describe "singleton method", ->
21
20
 
22
21
  beforeEach ->
23
- @showSpy = spyOn(Mercury.modal, 'show').andCallFake(=>)
22
+ @showSpy = spyOn(Mercury.Modal.prototype, 'show').andCallFake(=>)
24
23
 
25
24
  it "calls show", ->
26
25
  Mercury.modal('/foo')
27
26
  expect(@showSpy.callCount).toEqual(1)
28
27
 
29
- it "returns the function object", ->
28
+ it "returns an instance", ->
30
29
  ret = Mercury.modal('/foo')
31
- expect(ret).toEqual(Mercury.modal)
30
+ expect(ret).toEqual(Mercury.modal.instance)
31
+ expect(ret).toEqual(new Mercury.Modal('/foo'))
32
32
 
33
33
 
34
34
  describe "#show", ->
35
35
 
36
36
  beforeEach ->
37
- @initializeSpy = spyOn(Mercury.modal, 'initialize').andCallFake(=>)
38
- @updateSpy = spyOn(Mercury.modal, 'update').andCallFake(=>)
39
- @appearSpy = spyOn(Mercury.modal, 'appear').andCallFake(=>)
37
+ @initializeSpy = spyOn(Mercury.Modal.prototype, 'initializeModal').andCallFake(=>)
38
+ @updateSpy = spyOn(Mercury.Modal.prototype, 'update').andCallFake(=>)
39
+ @appearSpy = spyOn(Mercury.Modal.prototype, 'appear').andCallFake(=>)
40
40
 
41
41
  it "triggers the focus:window event", ->
42
42
  spy = spyOn(Mercury, 'trigger').andCallFake(=>)
43
- Mercury.modal.show()
43
+ new Mercury.Modal().show()
44
44
  expect(spy.callCount).toEqual(1)
45
45
  expect(spy.argsForCall[0]).toEqual(['focus:window'])
46
46
 
47
47
  it "calls initialize", ->
48
- Mercury.modal.show()
48
+ new Mercury.Modal().show()
49
49
  expect(@initializeSpy.callCount).toEqual(1)
50
50
 
51
51
  describe "if already visible", ->
52
52
 
53
53
  it "calls update", ->
54
- Mercury.modal.visible = true
55
- Mercury.modal.show()
54
+ modal = new Mercury.Modal()
55
+ modal.visible = true
56
+ modal.show()
56
57
  expect(@updateSpy.callCount).toEqual(1)
57
58
 
58
59
  describe "if not visible", ->
59
60
 
60
61
  it "calls appear", ->
61
- Mercury.modal.show()
62
+ modal = new Mercury.Modal()
63
+ modal.visible = false
64
+ modal.show()
62
65
  expect(@appearSpy.callCount).toEqual(1)
63
66
 
64
67
 
65
- describe "#initialize", ->
68
+ describe "#initializeModal", ->
66
69
 
67
70
  beforeEach ->
68
- @buildSpy = spyOn(Mercury.modal, 'build').andCallFake(=>)
69
- @bindEventsSpy = spyOn(Mercury.modal, 'bindEvents').andCallFake(=>)
71
+ @buildSpy = spyOn(Mercury.Modal.prototype, 'build').andCallFake(=>)
72
+ @bindEventsSpy = spyOn(Mercury.Modal.prototype, 'bindEvents').andCallFake(=>)
73
+ @modal = new Mercury.Modal()
70
74
 
71
75
  it "calls build", ->
72
- Mercury.modal.initialize()
76
+ @modal.initializeModal()
73
77
  expect(@buildSpy.callCount).toEqual(1)
74
78
 
75
79
  it "calls bindEvents", ->
76
- Mercury.modal.initialize()
80
+ @modal.initializeModal()
77
81
  expect(@bindEventsSpy.callCount).toEqual(1)
78
82
 
79
83
  it "does nothing if already initialized", ->
80
- Mercury.modal.initialized = true
81
- Mercury.modal.initialize()
84
+ @modal.initialized = true
85
+ @modal.initializeModal()
82
86
  expect(@buildSpy.callCount).toEqual(0)
83
87
 
84
88
  it "sets initialized to true", ->
85
- Mercury.modal.initialize()
86
- expect(Mercury.modal.initialized).toEqual(true)
89
+ @modal.initializeModal()
90
+ expect(@modal.initialized).toEqual(true)
87
91
 
88
92
 
89
93
  describe "#build", ->
90
94
 
91
95
  beforeEach ->
92
- Mercury.modal.options = {appendTo: $('#test')}
96
+ @modal = new Mercury.Modal('', {appendTo: $('#test')})
93
97
 
94
98
  it "builds an element", ->
95
- Mercury.modal.build()
99
+ @modal.build()
96
100
  expect($('#test .mercury-modal').length).toEqual(1)
97
101
 
98
102
  it "builds an overlay element", ->
99
- Mercury.modal.build()
103
+ @modal.build()
100
104
  expect($('#test .mercury-modal-overlay').length).toEqual(1)
101
105
 
102
106
  it "creates a titleElement", ->
103
- Mercury.modal.build()
107
+ @modal.build()
104
108
  expect($('#test .mercury-modal-title').length).toEqual(1)
105
109
  expect($('#test .mercury-modal-title').html()).toMatch(/<span><\/span><a>.+<\/a>/)
106
- expect(Mercury.modal.titleElement).toBeDefined()
110
+ expect(@modal.titleElement).toBeDefined()
107
111
 
108
112
  it "creates a contentContainerElement", ->
109
- Mercury.modal.build()
113
+ @modal.build()
110
114
  expect($('#test .mercury-modal-content-container').length).toEqual(1)
111
- expect(Mercury.modal.contentContainerElement).toBeDefined()
115
+ expect(@modal.contentContainerElement).toBeDefined()
112
116
 
113
117
  it "creates a contentElement", ->
114
- Mercury.modal.build()
118
+ @modal.build()
115
119
  expect($('#test .mercury-modal-content-container .mercury-modal-content').length).toEqual(1)
116
- expect(Mercury.modal.contentElement).toBeDefined()
120
+ expect(@modal.contentElement).toBeDefined()
117
121
 
118
122
  it "appends to any element", ->
119
- Mercury.modal.options = {appendTo: $('#modal_container')}
120
- Mercury.modal.build()
123
+ @modal.options = {appendTo: $('#modal_container')}
124
+ @modal.build()
121
125
  expect($('#modal_container .mercury-modal').length).toEqual(1)
122
126
  expect($('#modal_container .mercury-modal-overlay').length).toEqual(1)
123
127
 
@@ -125,13 +129,13 @@ describe "Mercury.modal", ->
125
129
  describe "observed events", ->
126
130
 
127
131
  beforeEach ->
128
- spyOn(Mercury.modal, 'appear').andCallFake(=>)
129
- Mercury.modal('/foo', {appendTo: $('#test')})
132
+ spyOn(Mercury.Modal.prototype, 'appear').andCallFake(=>)
133
+ @modal = Mercury.modal('/foo', {appendTo: $('#test')})
130
134
 
131
135
  describe "custom event: refresh", ->
132
136
 
133
137
  it "calls resize telling it stay visible", ->
134
- spy = spyOn(Mercury.modal, 'resize').andCallFake(=>)
138
+ spy = spyOn(@modal, 'resize').andCallFake(=>)
135
139
  Mercury.trigger('refresh')
136
140
  expect(spy.callCount).toEqual(1)
137
141
  expect(spy.argsForCall[0]).toEqual([true])
@@ -139,39 +143,39 @@ describe "Mercury.modal", ->
139
143
  describe "custom event: resize", ->
140
144
 
141
145
  it "calls position", ->
142
- spy = spyOn(Mercury.modal, 'position').andCallFake(=>)
146
+ spy = spyOn(@modal, 'position').andCallFake(=>)
143
147
  Mercury.trigger('resize')
144
148
  expect(spy.callCount).toEqual(1)
145
149
 
146
150
  describe "clicking on the overlay (options.allowHideUsingOverlay = true)", ->
147
151
 
148
152
  it "calls hide", ->
149
- Mercury.modal.options.allowHideUsingOverlay = true
150
- spy = spyOn(Mercury.modal, 'hide').andCallFake(=>)
153
+ @modal.options.allowHideUsingOverlay = true
154
+ spy = spyOn(@modal, 'hide').andCallFake(=>)
151
155
  jasmine.simulate.click($('.mercury-modal-overlay').get(0))
152
156
  expect(spy.callCount).toEqual(1)
153
157
 
154
158
  describe "clicking on the overlay (options.allowHideUsingOverlay = false)", ->
155
159
 
156
160
  it "doesn't call hide", ->
157
- spy = spyOn(Mercury.modal, 'hide').andCallFake(=>)
161
+ spy = spyOn(@modal, 'hide').andCallFake(=>)
158
162
  jasmine.simulate.click($('.mercury-modal-overlay').get(0))
159
163
  expect(spy.callCount).toEqual(0)
160
164
 
161
165
  describe "clicking on the close button", ->
162
166
 
163
167
  it "calls hide", ->
164
- spy = spyOn(Mercury.modal, 'hide').andCallFake(=>)
168
+ spy = spyOn(@modal, 'hide').andCallFake(=>)
165
169
  jasmine.simulate.click($('.mercury-modal-title a').get(0))
166
170
  expect(spy.callCount).toEqual(1)
167
171
 
168
172
  describe "pressing esc on document", ->
169
173
 
170
174
  beforeEach ->
171
- Mercury.modal.visible = true
172
-
175
+ @modal.visible = true
176
+
173
177
  it "calls hide", ->
174
- spy = spyOn(Mercury.modal, 'hide').andCallFake(=>)
178
+ spy = spyOn(@modal, 'hide').andCallFake(=>)
175
179
  jasmine.simulate.keydown(document, {keyCode: 27})
176
180
  expect(spy.callCount).toEqual(1)
177
181
 
@@ -179,8 +183,8 @@ describe "Mercury.modal", ->
179
183
 
180
184
  it "sets a success that will load the contents of the response", ->
181
185
  options = {}
182
- spy = spyOn(Mercury.modal, 'loadContent').andCallFake(=>)
183
- Mercury.modal.element.trigger('ajax:beforeSend', [null, options])
186
+ spy = spyOn(@modal, 'loadContent').andCallFake(=>)
187
+ @modal.element.trigger('ajax:beforeSend', [null, options])
184
188
  expect(options.success).toBeDefined()
185
189
  options.success('new content')
186
190
  expect(spy.callCount).toEqual(1)
@@ -190,81 +194,83 @@ describe "Mercury.modal", ->
190
194
  describe "#appear", ->
191
195
 
192
196
  beforeEach ->
193
- Mercury.modal.visible = true
194
- spyOn(Mercury.modal, 'update').andCallFake(=>)
195
- @loadSpy = spyOn(Mercury.modal, 'load').andCallFake(=>)
196
- @positionSpy = spyOn(Mercury.modal, 'position').andCallFake(=>)
197
- Mercury.modal('/blank.html', {appendTo: $('#test')})
197
+ @modal = new Mercury.Modal('/blank.html', {appendTo: $('#test')})
198
+ @modal.visible = true
199
+ spyOn(@modal, 'update').andCallFake(=>)
200
+ @loadSpy = spyOn(@modal, 'load').andCallFake(=>)
201
+ @positionSpy = spyOn(@modal, 'position').andCallFake(=>)
202
+ @modal.show()
198
203
 
199
204
  it "calls position", ->
200
- Mercury.modal.appear()
205
+ @modal.appear()
201
206
  expect(@positionSpy.callCount).toEqual(1)
202
207
 
203
208
  it "shows the overlay", ->
204
209
  expect($('.mercury-modal-overlay').css('display')).toEqual('none')
205
- Mercury.modal.appear()
210
+ @modal.appear()
206
211
  expect($('.mercury-modal-overlay').css('display')).toEqual('block')
207
212
 
208
213
  it "animates the overlay to full opacity", ->
209
214
  expect($('.mercury-modal-overlay').css('opacity')).toEqual('0')
210
- Mercury.modal.appear()
215
+ @modal.appear()
211
216
  expect($('.mercury-modal-overlay').css('opacity')).toEqual('1')
212
217
 
213
218
  it "calls setTitle", ->
214
- spy = spyOn(Mercury.modal, 'setTitle').andCallFake(=>)
215
- Mercury.modal.appear()
219
+ spy = spyOn(@modal, 'setTitle').andCallFake(=>)
220
+ @modal.appear()
216
221
  expect(spy.callCount).toEqual(1)
217
222
 
218
223
  it "shows the element", ->
219
224
  expect($('.mercury-modal').css('display')).toEqual('none')
220
- Mercury.modal.appear()
225
+ @modal.appear()
221
226
  expect($('.mercury-modal').css('display')).toEqual('block')
222
227
 
223
228
  it "animates the element down", ->
224
229
  expect($('.mercury-modal').css('top')).toEqual('-100px')
225
- Mercury.modal.appear()
230
+ @modal.appear()
226
231
  expect($('.mercury-modal').css('top')).toEqual('0px')
227
232
 
228
233
  it "sets visible to true", ->
229
- Mercury.modal.visible = false
230
- Mercury.modal.appear()
231
- expect(Mercury.modal.visible).toEqual(true)
234
+ @modal.visible = false
235
+ @modal.appear()
236
+ expect(@modal.visible).toEqual(true)
232
237
 
233
238
  it "calls load", ->
234
- Mercury.modal.appear()
239
+ @modal.appear()
235
240
  expect(@loadSpy.callCount).toEqual(1)
236
241
 
237
242
 
238
243
  describe "#resize", ->
239
244
 
240
245
  beforeEach ->
241
- spyOn(Mercury.modal, 'appear').andCallFake(=>)
242
- Mercury.modal('/blank.html', {appendTo: $('#test')})
243
- Mercury.modal.contentPane = $()
246
+ @modal = new Mercury.Modal('/blank.html', {appendTo: $('#test')})
247
+ spyOn(@modal, 'appear').andCallFake(=>)
248
+ @modal.show()
249
+ @modal.contentPane = $()
244
250
 
245
251
  it "will keep the content element visible if asked to do so", ->
246
252
  $('.mercury-modal-content').css('visibility', 'visible')
247
- Mercury.modal.resize(true)
253
+ @modal.resize(true)
248
254
  expect($('.mercury-modal-content').css('visibility')).toEqual('visible')
249
255
 
250
256
  it "resizes the element and adjusts it's position", ->
251
257
  Mercury.displayRect.width = 1000
252
258
  $('.mercury-modal').css({display: 'block', visibility: 'visible', top: 0})
253
- Mercury.modal.resize()
259
+ @modal.resize()
254
260
  expect($('.mercury-modal').width()).toEqual(400)
255
261
  expect($('.mercury-modal').offset()).toEqual({top: 0, left: 300})
256
262
  expect($('.mercury-modal').height()).toBeGreaterThan(20)
257
263
 
258
264
  it "respects minWidth provided in options", ->
259
- Mercury.modal.minWidth = 500
260
- Mercury.modal.resize()
265
+ @modal.options.minWidth = 500
266
+ @modal.resize()
261
267
  expect($('.mercury-modal').width()).toEqual(500)
262
268
 
263
269
 
264
270
  describe "#position", ->
265
271
 
266
272
  beforeEach ->
267
- spyOn(Mercury.modal, 'appear').andCallFake(=>)
273
+ spyOn(Mercury.Modal.prototype, 'appear').andCallFake(=>)
268
274
 
269
275
  # todo: test this
270
276
  it "positions the element", ->
@@ -273,10 +279,11 @@ describe "Mercury.modal", ->
273
279
  describe "#update", ->
274
280
 
275
281
  beforeEach ->
276
- @resetSpy = spyOn(Mercury.modal, 'reset').andCallFake(=>)
277
- @resizeSpy = spyOn(Mercury.modal, 'resize').andCallFake(=>)
278
- @loadSpy = spyOn(Mercury.modal, 'load').andCallFake(=>)
279
- Mercury.modal.update()
282
+ @modal = new Mercury.Modal()
283
+ @resetSpy = spyOn(@modal, 'reset').andCallFake(=>)
284
+ @resizeSpy = spyOn(@modal, 'resize').andCallFake(=>)
285
+ @loadSpy = spyOn(@modal, 'load').andCallFake(=>)
286
+ @modal.update()
280
287
 
281
288
  it "calls reset", ->
282
289
  expect(@resetSpy.callCount).toEqual(1)
@@ -291,23 +298,23 @@ describe "Mercury.modal", ->
291
298
  describe "#load", ->
292
299
 
293
300
  beforeEach ->
294
- spyOn(Mercury.modal, 'appear').andCallFake(=>)
301
+ spyOn(Mercury.Modal.prototype, 'appear').andCallFake(=>)
295
302
  @ajaxSpy = spyOn($, 'ajax')
296
- Mercury.modal('/blank.html', {appendTo: $('#test')})
303
+ @modal = Mercury.modal('/blank.html', {appendTo: $('#test')})
297
304
 
298
305
  it "does nothing if there's no url", ->
299
- Mercury.modal.url = null
306
+ @modal.url = null
300
307
  $('.mercury-modal').removeClass('loading')
301
- Mercury.modal.load()
308
+ @modal.load()
302
309
  expect($('.mercury-modal').hasClass('loading')).toEqual(false)
303
310
 
304
311
  it "sets the loading class on the element", ->
305
- Mercury.modal.load()
312
+ @modal.load()
306
313
  expect($('.mercury-modal').hasClass('loading')).toEqual(true)
307
314
 
308
315
  it "calls setTitle", ->
309
- spy = spyOn(Mercury.modal, 'setTitle').andCallFake(=>)
310
- Mercury.modal.load()
316
+ spy = spyOn(@modal, 'setTitle').andCallFake(=>)
317
+ @modal.load()
311
318
  expect(spy.callCount).toEqual(1)
312
319
 
313
320
  describe "on a preloaded view", ->
@@ -320,8 +327,8 @@ describe "Mercury.modal", ->
320
327
  Mercury.preloadedViews = {}
321
328
 
322
329
  it "calls loadContent with the content in the preloaded view", ->
323
- spy = spyOn(Mercury.modal, 'loadContent').andCallFake(=>)
324
- Mercury.modal.load()
330
+ spy = spyOn(@modal, 'loadContent').andCallFake(=>)
331
+ @modal.load()
325
332
  expect(@setTimeoutSpy.callCount).toEqual(1)
326
333
  expect(spy.callCount).toEqual(1)
327
334
 
@@ -330,7 +337,7 @@ describe "Mercury.modal", ->
330
337
  it "makes an ajax request", ->
331
338
  @ajaxSpy.andCallFake(=>)
332
339
  spyOn(Mercury, 'ajaxHeaders').andCallFake(=> {'X-CSRFToken': 'f00'})
333
- Mercury.modal.load()
340
+ @modal.load()
334
341
  expect(@ajaxSpy.callCount).toEqual(1)
335
342
  expect(@ajaxSpy.argsForCall[0][1]['headers']).toEqual({'X-CSRFToken': 'f00'})
336
343
 
@@ -340,8 +347,8 @@ describe "Mercury.modal", ->
340
347
  @ajaxSpy.andCallFake((url, options) => options.success('return value'))
341
348
 
342
349
  it "calls loadContent and passes the returned data", ->
343
- spy = spyOn(Mercury.modal, 'loadContent').andCallFake(=>)
344
- Mercury.modal.load()
350
+ spy = spyOn(@modal, 'loadContent').andCallFake(=>)
351
+ @modal.load()
345
352
  expect(spy.callCount).toEqual(1)
346
353
  expect(spy.argsForCall[0]).toEqual(['return value'])
347
354
 
@@ -352,14 +359,14 @@ describe "Mercury.modal", ->
352
359
 
353
360
  it "calls hide", ->
354
361
  spyOn(window, 'alert').andCallFake(=>)
355
- spy = spyOn(Mercury.modal, 'hide').andCallFake(=>)
356
- Mercury.modal.load()
362
+ spy = spyOn(@modal, 'hide').andCallFake(=>)
363
+ @modal.load()
357
364
  expect(spy.callCount).toEqual(1)
358
365
 
359
366
  it "alerts an error message", ->
360
- spyOn(Mercury.modal, 'hide').andCallFake(=>)
367
+ spyOn(@modal, 'hide').andCallFake(=>)
361
368
  spy = spyOn(window, 'alert').andCallFake(=>)
362
- Mercury.modal.load()
369
+ @modal.load()
363
370
  expect(spy.callCount).toEqual(1)
364
371
  expect(spy.argsForCall[0]).toEqual(['Mercury was unable to load /blank.html for the modal.'])
365
372
 
@@ -367,98 +374,97 @@ describe "Mercury.modal", ->
367
374
  describe "#loadContent", ->
368
375
 
369
376
  beforeEach ->
370
- spyOn(Mercury.modal, 'appear').andCallFake(=>)
371
- @resizeSpy = spyOn(Mercury.modal, 'resize').andCallFake(=>)
372
- Mercury.modal('/blank.html', {appendTo: $('#test'), title: 'title'})
377
+ spyOn(Mercury.Modal.prototype, 'appear').andCallFake(=>)
378
+ @resizeSpy = spyOn(Mercury.Modal.prototype, 'resize').andCallFake(=>)
379
+ @modal = Mercury.modal('/blank.html', {appendTo: $('#test'), title: 'title'})
373
380
 
374
381
  it "accepts options and sets them to the instance options", ->
375
- Mercury.modal.loadContent('content', {title: 'title'})
376
- expect(Mercury.modal.options).toEqual({title: 'title'})
382
+ @modal.loadContent('content', {title: 'title'})
383
+ expect(@modal.options).toEqual({title: 'title'})
377
384
 
378
385
  it "calls initialize", ->
379
- spy = spyOn(Mercury.modal, 'initialize').andCallFake(=>)
380
- Mercury.modal.loadContent('content')
386
+ spy = spyOn(@modal, 'initializeModal').andCallFake(=>)
387
+ @modal.loadContent('content')
381
388
  expect(spy.callCount).toEqual(1)
382
389
 
383
390
  it "calls setTitle", ->
384
- spy = spyOn(Mercury.modal, 'setTitle').andCallFake(=>)
385
- Mercury.modal.loadContent('content')
391
+ spy = spyOn(@modal, 'setTitle').andCallFake(=>)
392
+ @modal.loadContent('content')
386
393
  expect(spy.callCount).toEqual(1)
387
394
 
388
395
  it "sets loaded to true", ->
389
- Mercury.modal.loaded = false
390
- Mercury.modal.loadContent('content')
391
- expect(Mercury.modal.loaded).toEqual(true)
396
+ @modal.loaded = false
397
+ @modal.loadContent('content')
398
+ expect(@modal.loaded).toEqual(true)
392
399
 
393
400
  it "removes the loading class", ->
394
401
  $('.mercury-modal').addClass('loading')
395
- Mercury.modal.loadContent('content')
402
+ @modal.loadContent('content')
396
403
  expect($('.mercury-modal').hasClass('loading')).toEqual(false)
397
404
 
398
405
  it "sets the content elements html to whatever was passed", ->
399
- Mercury.modal.loadContent('<span>content</span>')
406
+ @modal.loadContent('<span>content</span>')
400
407
  expect($('.mercury-modal-content').html()).toEqual('<span>content</span>')
401
408
 
402
409
  it "hides the contentElement", ->
403
410
  $('.mercury-modal-content').css('display', 'block')
404
- Mercury.modal.loadContent('content')
411
+ @modal.loadContent('content')
405
412
  expect($('.mercury-modal-content').css('display')).toEqual('none')
406
413
  expect($('.mercury-modal-content').css('visibility')).toEqual('hidden')
407
414
 
408
415
  it "finds the content panes and control elements in case they were added with the content", ->
409
- Mercury.modal.loadContent('<div class="mercury-display-pane-container"></div><div class="mercury-display-controls"></div>')
410
- expect(Mercury.modal.contentPane.get(0)).toEqual($('#test .mercury-display-pane-container').get(0))
411
- expect(Mercury.modal.contentControl.get(0)).toEqual($('#test .mercury-display-controls').get(0))
416
+ @modal.loadContent('<div class="mercury-display-pane-container"></div><div class="mercury-display-controls"></div>')
417
+ expect(@modal.contentPane.get(0)).toEqual($('#test .mercury-display-pane-container').get(0))
418
+ expect(@modal.contentControl.get(0)).toEqual($('#test .mercury-display-controls').get(0))
412
419
 
413
420
  it "calls an afterLoad callback (if provided in options)", ->
414
421
  callCount = 0
415
- Mercury.modal.loadContent('content', {afterLoad: => callCount += 1})
422
+ @modal.loadContent('content', {afterLoad: => callCount += 1})
416
423
  expect(callCount).toEqual(1)
417
424
 
418
425
  it "calls a handler method if one is set in modalHandlers", ->
419
426
  callCount = 0
420
427
  Mercury.modalHandlers['foo'] = => callCount += 1
421
- Mercury.modal.loadContent('content', {handler: 'foo'})
428
+ @modal.loadContent('content', {handler: 'foo'})
422
429
  expect(callCount).toEqual(1)
423
430
 
424
431
  it "translates the content if configured", ->
425
432
  Mercury.config.localization.enabled = true
426
- Mercury.modal.loadContent('<span>foo</span>')
433
+ @modal.loadContent('<span>foo</span>')
427
434
  expect($('.mercury-modal-content').html()).toEqual('<span>Bork!</span>')
428
435
 
429
436
  it "calls resize", ->
430
- Mercury.modal.loadContent('content')
437
+ @modal.loadContent('content')
431
438
  expect(@resizeSpy.callCount).toEqual(1)
432
439
 
433
440
 
434
441
  describe "#setTitle", ->
435
442
 
436
443
  beforeEach ->
437
- spyOn(Mercury.modal, 'appear').andCallFake(=>)
438
- Mercury.modal('/blank.html', {appendTo: $('#test'), title: 'title'})
444
+ spyOn(Mercury.Modal.prototype, 'appear').andCallFake(=>)
445
+ @modal = Mercury.modal('/blank.html', {appendTo: $('#test'), title: 'title'})
439
446
 
440
447
  it "sets the the title contents to what was provided in the options", ->
441
- Mercury.modal.options = {title: 'new title'}
442
- Mercury.modal.setTitle()
448
+ @modal.options = {title: 'new title'}
449
+ @modal.setTitle()
443
450
  expect($('.mercury-modal-title span').html()).toEqual('new title')
444
451
  expect($('.mercury-modal-title a').css('display')).toEqual('inline')
445
452
 
446
453
  it "hides the close button if the options.closeButton is false", ->
447
- Mercury.modal.options = {title: 'new title', closeButton: false}
448
- Mercury.modal.setTitle()
454
+ @modal.options = {title: 'new title', closeButton: false}
455
+ @modal.setTitle()
449
456
  expect($('.mercury-modal-title a').css('display')).toEqual('none')
450
457
 
451
458
 
452
-
453
459
  describe "#reset", ->
454
460
 
455
461
  beforeEach ->
456
- spyOn(Mercury.modal, 'appear').andCallFake(=>)
457
- Mercury.modal('/blank.html', {appendTo: $('#test'), title: 'title'})
462
+ spyOn(Mercury.Modal.prototype, 'appear').andCallFake(=>)
463
+ @modal = Mercury.modal('/blank.html', {appendTo: $('#test'), title: 'title'})
458
464
 
459
465
  it "clears the title and content elements", ->
460
466
  $('.mercury-modal-content').html('content')
461
- Mercury.modal.reset()
467
+ @modal.reset()
462
468
  expect($('.mercury-modal-content').html()).toEqual('')
463
469
  expect($('.mercury-modal-title span').html()).toEqual('')
464
470
 
@@ -466,39 +472,37 @@ describe "Mercury.modal", ->
466
472
  describe "#hide", ->
467
473
 
468
474
  beforeEach ->
469
- spyOn(Mercury.modal, 'appear').andCallFake(=>)
470
- Mercury.modal('/blank.html', {appendTo: $('#test')})
475
+ spyOn(Mercury.Modal.prototype, 'appear').andCallFake(=>)
476
+ @modal = Mercury.modal('/blank.html', {appendTo: $('#test')})
471
477
 
472
478
  it "triggers the focus:frame event", ->
473
479
  spy = spyOn(Mercury, 'trigger').andCallFake(=>)
474
- Mercury.modal.hide()
480
+ @modal.hide()
475
481
  expect(spy.callCount).toEqual(1)
476
482
  expect(spy.argsForCall[0]).toEqual(['focus:frame'])
477
483
 
478
484
  it "hides the element", ->
479
- Mercury.modal.element.css('display:block')
480
- Mercury.modal.hide()
485
+ @modal.element.css('display:block')
486
+ @modal.hide()
481
487
  expect($('.mercury-modal').css('display')).toEqual('none')
482
488
 
483
489
  it "hides the overlay element", ->
484
- Mercury.modal.overlay.css('display:block')
485
- Mercury.modal.hide()
490
+ @modal.overlay.css('display:block')
491
+ @modal.hide()
486
492
  expect($('.mercury-modal-overlay').css('display')).toEqual('none')
487
493
 
488
494
  it "calls reset", ->
489
- spy = spyOn(Mercury.modal, 'reset').andCallFake(=>)
490
- Mercury.modal.hide()
495
+ spy = spyOn(@modal, 'reset').andCallFake(=>)
496
+ @modal.hide()
491
497
  expect(spy.callCount).toEqual(1)
492
498
 
493
499
  it "sets visible to false", ->
494
- Mercury.modal.visible = true
495
- Mercury.modal.hide()
496
- expect(Mercury.modal.visible).toEqual(false)
500
+ @modal.visible = true
501
+ @modal.hide()
502
+ expect(@modal.visible).toEqual(false)
497
503
 
498
504
  it "does nothing if the modal is still in the process of showing", ->
499
- spy = spyOn(Mercury.modal, 'reset').andCallFake(=>)
500
- Mercury.modal.showing = true
501
- Mercury.modal.hide()
505
+ spy = spyOn(@modal, 'reset').andCallFake(=>)
506
+ @modal.showing = true
507
+ @modal.hide()
502
508
  expect(spy.callCount).toEqual(0)
503
-
504
-