kiteditor 1.0.1

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