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