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,497 @@
1
+ describe "Mercury.lightview", ->
2
+
3
+ template 'mercury/lightview.html'
4
+
5
+ beforeEach ->
6
+ $.fx.off = true
7
+ Mercury.displayRect = {fullHeight: 200, width: 1000}
8
+ Mercury.determinedLocale =
9
+ top: {'hello world!': 'bork! bork!'}
10
+ sub: {'foo': 'Bork!'}
11
+
12
+ afterEach ->
13
+ Mercury.config.localization.enabled = false
14
+ Mercury.lightview.initialized = false
15
+ Mercury.lightview.visible = false
16
+ $(window).unbind('mercury:refresh')
17
+ $(window).unbind('mercury:resize')
18
+ $(document).unbind('keydown')
19
+
20
+ describe "singleton method", ->
21
+
22
+ beforeEach ->
23
+ @showSpy = spyOn(Mercury.lightview, 'show').andCallFake(=>)
24
+
25
+ it "calls show", ->
26
+ Mercury.lightview('/foo')
27
+ expect(@showSpy.callCount).toEqual(1)
28
+
29
+ it "returns the function object", ->
30
+ ret = Mercury.lightview('/foo')
31
+ expect(ret).toEqual(Mercury.lightview)
32
+
33
+
34
+ describe "#show", ->
35
+
36
+ beforeEach ->
37
+ @initializeSpy = spyOn(Mercury.lightview, 'initialize').andCallFake(=>)
38
+ @updateSpy = spyOn(Mercury.lightview, 'update').andCallFake(=>)
39
+ @appearSpy = spyOn(Mercury.lightview, 'appear').andCallFake(=>)
40
+
41
+ it "triggers the focus:window event", ->
42
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
43
+ Mercury.lightview.show()
44
+ expect(spy.callCount).toEqual(1)
45
+ expect(spy.argsForCall[0]).toEqual(['focus:window'])
46
+
47
+ it "calls initialize", ->
48
+ Mercury.lightview.show()
49
+ expect(@initializeSpy.callCount).toEqual(1)
50
+
51
+ describe "if already visible", ->
52
+
53
+ it "calls update", ->
54
+ Mercury.lightview.visible = true
55
+ Mercury.lightview.show()
56
+ expect(@updateSpy.callCount).toEqual(1)
57
+
58
+ describe "if not visible", ->
59
+
60
+ it "calls appear", ->
61
+ Mercury.lightview.show()
62
+ expect(@appearSpy.callCount).toEqual(1)
63
+
64
+
65
+ describe "#initialize", ->
66
+
67
+ beforeEach ->
68
+ @buildSpy = spyOn(Mercury.lightview, 'build').andCallFake(=>)
69
+ @bindEventsSpy = spyOn(Mercury.lightview, 'bindEvents').andCallFake(=>)
70
+
71
+ it "calls build", ->
72
+ Mercury.lightview.initialize()
73
+ expect(@buildSpy.callCount).toEqual(1)
74
+
75
+ it "calls bindEvents", ->
76
+ Mercury.lightview.initialize()
77
+ expect(@bindEventsSpy.callCount).toEqual(1)
78
+
79
+ it "does nothing if already initialized", ->
80
+ Mercury.lightview.initialized = true
81
+ Mercury.lightview.initialize()
82
+ expect(@buildSpy.callCount).toEqual(0)
83
+
84
+ it "sets initialized to true", ->
85
+ Mercury.lightview.initialize()
86
+ expect(Mercury.lightview.initialized).toEqual(true)
87
+
88
+
89
+ describe "#build", ->
90
+
91
+ beforeEach ->
92
+ Mercury.lightview.options = {appendTo: $('#test')}
93
+
94
+ it "builds an element", ->
95
+ Mercury.lightview.build()
96
+ expect($('#test .mercury-lightview').length).toEqual(1)
97
+
98
+ it "builds an overlay element", ->
99
+ Mercury.lightview.build()
100
+ expect($('#test .mercury-lightview-overlay').length).toEqual(1)
101
+
102
+ it "creates a titleElement", ->
103
+ Mercury.lightview.build()
104
+ expect($('#test .mercury-lightview-title').length).toEqual(1)
105
+ expect($('#test .mercury-lightview-title').html()).toEqual("<span><\/span>")
106
+ expect(Mercury.lightview.titleElement).toBeDefined()
107
+
108
+ it "creates a contentElement", ->
109
+ Mercury.lightview.build()
110
+ expect($('#test .mercury-lightview-content').length).toEqual(1)
111
+ expect(Mercury.lightview.contentElement).toBeDefined()
112
+
113
+ it "appends to any element", ->
114
+ Mercury.lightview.options = {appendTo: $('#lightview_container')}
115
+ Mercury.lightview.build()
116
+ expect($('#lightview_container .mercury-lightview').length).toEqual(1)
117
+ expect($('#lightview_container .mercury-lightview-overlay').length).toEqual(1)
118
+
119
+ it "creates a close button if asked to in the options", ->
120
+ Mercury.lightview.options.closeButton = true
121
+ Mercury.lightview.build()
122
+ expect($('#test .mercury-lightview-close').length).toEqual(1)
123
+
124
+
125
+ describe "observed events", ->
126
+
127
+ beforeEach ->
128
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
129
+
130
+ describe "without a close button", ->
131
+
132
+ beforeEach ->
133
+ Mercury.lightview('/foo', {appendTo: $('#test')})
134
+
135
+ describe "custom event: refresh", ->
136
+
137
+ it "calls resize telling it stay visible", ->
138
+ spy = spyOn(Mercury.lightview, 'resize').andCallFake(=>)
139
+ Mercury.trigger('refresh')
140
+ expect(spy.callCount).toEqual(1)
141
+ expect(spy.argsForCall[0]).toEqual([true])
142
+
143
+ describe "custom event: resize", ->
144
+
145
+ beforeEach ->
146
+ Mercury.lightview.visible = true
147
+
148
+ it "calls position", ->
149
+ spy = spyOn(Mercury.lightview, 'position').andCallFake(=>)
150
+ Mercury.trigger('resize')
151
+ expect(spy.callCount).toEqual(1)
152
+
153
+ describe "clicking on the overlay", ->
154
+
155
+ it "calls hide", ->
156
+ spy = spyOn(Mercury.lightview, 'hide').andCallFake(=>)
157
+ jasmine.simulate.click($('.mercury-lightview-overlay').get(0))
158
+ expect(spy.callCount).toEqual(1)
159
+
160
+ describe "pressing esc on document", ->
161
+
162
+ beforeEach ->
163
+ Mercury.lightview.visible = true
164
+
165
+ it "calls hide", ->
166
+ spy = spyOn(Mercury.lightview, 'hide').andCallFake(=>)
167
+ jasmine.simulate.keydown(document, {keyCode: 27})
168
+ expect(spy.callCount).toEqual(1)
169
+
170
+ describe "with a close button", ->
171
+
172
+ beforeEach ->
173
+ Mercury.lightview('/foo', {appendTo: $('#test'), closeButton: true})
174
+
175
+ describe "clicking on the close button", ->
176
+
177
+ it "calls hide", ->
178
+ spy = spyOn(Mercury.lightview, 'hide').andCallFake(=>)
179
+ jasmine.simulate.click($('.mercury-lightview-close').get(0))
180
+ expect(spy.callCount).toEqual(1)
181
+
182
+ describe "clicking on the overlay", ->
183
+
184
+ it "doesn't call hide", ->
185
+ spy = spyOn(Mercury.lightview, 'hide').andCallFake(=>)
186
+ jasmine.simulate.click($('.mercury-lightview-overlay').get(0))
187
+ expect(spy.callCount).toEqual(0)
188
+
189
+ describe "ajax:beforeSend", ->
190
+
191
+ it "sets a success that will load the contents of the response", ->
192
+ options = {}
193
+ spy = spyOn(Mercury.lightview, 'loadContent').andCallFake(=>)
194
+ Mercury.lightview.element.trigger('ajax:beforeSend', [null, options])
195
+ expect(options.success).toBeDefined()
196
+ options.success('new content')
197
+ expect(spy.callCount).toEqual(1)
198
+ expect(spy.argsForCall[0]).toEqual(['new content'])
199
+
200
+
201
+ describe "#appear", ->
202
+
203
+ beforeEach ->
204
+ Mercury.lightview.visible = true
205
+ spyOn(Mercury.lightview, 'update').andCallFake(=>)
206
+ @loadSpy = spyOn(Mercury.lightview, 'load').andCallFake(=>)
207
+ @positionSpy = spyOn(Mercury.lightview, 'position').andCallFake(=>)
208
+ Mercury.lightview('/blank.html', {appendTo: $('#test')})
209
+
210
+ it "calls position", ->
211
+ Mercury.lightview.appear()
212
+ expect(@positionSpy.callCount).toEqual(1)
213
+
214
+ it "shows the overlay", ->
215
+ expect($('.mercury-lightview-overlay').css('display')).toEqual('none')
216
+ Mercury.lightview.appear()
217
+ expect($('.mercury-lightview-overlay').css('display')).toEqual('block')
218
+
219
+ it "animates the overlay to full opacity", ->
220
+ expect($('.mercury-lightview-overlay').css('opacity')).toEqual('0')
221
+ Mercury.lightview.appear()
222
+ expect($('.mercury-lightview-overlay').css('opacity')).toEqual('1')
223
+
224
+ it "calls setTitle", ->
225
+ spy = spyOn(Mercury.lightview, 'setTitle').andCallFake(=>)
226
+ Mercury.lightview.appear()
227
+ expect(spy.callCount).toEqual(1)
228
+
229
+ it "shows the element", ->
230
+ expect($('.mercury-lightview').css('display')).toEqual('none')
231
+ Mercury.lightview.appear()
232
+ expect($('.mercury-lightview').css('display')).toEqual('block')
233
+
234
+ it "animates the element opacity", ->
235
+ expect($('.mercury-lightview').css('opacity')).toEqual('0')
236
+ Mercury.lightview.appear()
237
+ expect($('.mercury-lightview').css('opacity')).toEqual('1')
238
+
239
+ it "sets visible to true", ->
240
+ Mercury.lightview.visible = false
241
+ Mercury.lightview.appear()
242
+ expect(Mercury.lightview.visible).toEqual(true)
243
+
244
+ it "calls load", ->
245
+ Mercury.lightview.appear()
246
+ expect(@loadSpy.callCount).toEqual(1)
247
+
248
+
249
+ describe "#resize", ->
250
+
251
+ beforeEach ->
252
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
253
+ Mercury.lightview('/blank.html', {appendTo: $('#test')})
254
+ Mercury.lightview.contentPane = $()
255
+
256
+ it "will keep the content element visible if asked to do so", ->
257
+ $('.mercury-lightview-content').css('visibility', 'visible')
258
+ Mercury.lightview.resize(true)
259
+ expect($('.mercury-lightview-content').css('visibility')).toEqual('visible')
260
+
261
+ it "resizes the element and adjusts it's position when empty", ->
262
+ $('.mercury-lightview').css({display: 'block', visibility: 'visible', top: 0})
263
+ Mercury.lightview.resize()
264
+ expect($('.mercury-lightview').width()).toEqual(300)
265
+ expect($('.mercury-lightview').offset()).toEqual({top: 35, left: 350})
266
+ expect($('.mercury-lightview').height()).toEqual(150)
267
+
268
+ it "resizes the element and adjusts it's position when it has content", ->
269
+ Mercury.lightview.loadContent('<div style="width:600px;height:400px"></div>')
270
+ $('.mercury-lightview').css({display: 'block', visibility: 'visible', top: 0})
271
+ Mercury.lightview.resize()
272
+ expect($('.mercury-lightview').width()).toEqual(300)
273
+ expect($('.mercury-lightview').offset()).toEqual({top: 20, left: 350})
274
+ expect($('.mercury-lightview').height()).toEqual(180)
275
+
276
+
277
+ describe "#position", ->
278
+
279
+ beforeEach ->
280
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
281
+
282
+ # todo: test this
283
+ it "positions the element", ->
284
+
285
+
286
+ describe "#update", ->
287
+
288
+ beforeEach ->
289
+ @resetSpy = spyOn(Mercury.lightview, 'reset').andCallFake(=>)
290
+ @resizeSpy = spyOn(Mercury.lightview, 'resize').andCallFake(=>)
291
+ @loadSpy = spyOn(Mercury.lightview, 'load').andCallFake(=>)
292
+ Mercury.lightview.update()
293
+
294
+ it "calls reset", ->
295
+ expect(@resetSpy.callCount).toEqual(1)
296
+
297
+ it "calls resize", ->
298
+ expect(@resizeSpy.callCount).toEqual(1)
299
+
300
+ it "calls load", ->
301
+ expect(@loadSpy.callCount).toEqual(1)
302
+
303
+
304
+ describe "#load", ->
305
+
306
+ beforeEach ->
307
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
308
+ @ajaxSpy = spyOn($, 'ajax')
309
+ Mercury.lightview('/blank.html', {appendTo: $('#test')})
310
+
311
+ it "does nothing if there's no url", ->
312
+ Mercury.lightview.url = null
313
+ $('.mercury-lightview').removeClass('loading')
314
+ Mercury.lightview.load()
315
+ expect($('.mercury-lightview').hasClass('loading')).toEqual(false)
316
+
317
+ it "sets the loading class on the element", ->
318
+ Mercury.lightview.load()
319
+ expect($('.mercury-lightview').hasClass('loading')).toEqual(true)
320
+
321
+ it "calls setTitle", ->
322
+ spy = spyOn(Mercury.lightview, 'setTitle').andCallFake(=>)
323
+ Mercury.lightview.load()
324
+ expect(spy.callCount).toEqual(1)
325
+
326
+ describe "on a preloaded view", ->
327
+
328
+ beforeEach ->
329
+ @setTimeoutSpy = spyOn(window, 'setTimeout').andCallFake((timeout, callback) => callback())
330
+ Mercury.preloadedViews = {'/blank.html': 'this is the preloaded content'}
331
+
332
+ afterEach ->
333
+ Mercury.preloadedViews = {}
334
+
335
+ it "calls loadContent with the content in the preloaded view", ->
336
+ spy = spyOn(Mercury.lightview, 'loadContent').andCallFake(=>)
337
+ Mercury.lightview.load()
338
+ expect(@setTimeoutSpy.callCount).toEqual(1)
339
+ expect(spy.callCount).toEqual(1)
340
+
341
+ describe "when not a preloaded view", ->
342
+
343
+ it "makes an ajax request", ->
344
+ @ajaxSpy.andCallFake(=>)
345
+ spyOn(Mercury, 'ajaxHeaders').andCallFake(=> {'X-CSRFToken': 'f00'})
346
+ Mercury.lightview.load()
347
+ expect(@ajaxSpy.callCount).toEqual(1)
348
+ expect(@ajaxSpy.argsForCall[0][1]['headers']).toEqual({'X-CSRFToken': 'f00'})
349
+
350
+ describe "on success", ->
351
+
352
+ beforeEach ->
353
+ @ajaxSpy.andCallFake((url, options) => options.success('return value'))
354
+
355
+ it "calls loadContent and passes the returned data", ->
356
+ spy = spyOn(Mercury.lightview, 'loadContent').andCallFake(=>)
357
+ Mercury.lightview.load()
358
+ expect(spy.callCount).toEqual(1)
359
+ expect(spy.argsForCall[0]).toEqual(['return value'])
360
+
361
+ describe "on failure", ->
362
+
363
+ beforeEach ->
364
+ @ajaxSpy.andCallFake((url, options) => options.error())
365
+
366
+ it "calls hide", ->
367
+ spyOn(window, 'alert').andCallFake(=>)
368
+ spy = spyOn(Mercury.lightview, 'hide').andCallFake(=>)
369
+ Mercury.lightview.load()
370
+ expect(spy.callCount).toEqual(1)
371
+
372
+ it "alerts an error message", ->
373
+ spyOn(Mercury.lightview, 'hide').andCallFake(=>)
374
+ spy = spyOn(window, 'alert').andCallFake(=>)
375
+ Mercury.lightview.load()
376
+ expect(spy.callCount).toEqual(1)
377
+ expect(spy.argsForCall[0]).toEqual(['Mercury was unable to load /blank.html for the lightview.'])
378
+
379
+
380
+ describe "#loadContent", ->
381
+
382
+ beforeEach ->
383
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
384
+ @resizeSpy = spyOn(Mercury.lightview, 'resize').andCallFake(=>)
385
+ Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
386
+
387
+ it "accepts options and sets them to the instance options", ->
388
+ Mercury.lightview.loadContent('content', {title: 'title'})
389
+ expect(Mercury.lightview.options).toEqual({title: 'title'})
390
+
391
+ it "calls initialize", ->
392
+ spy = spyOn(Mercury.lightview, 'initialize').andCallFake(=>)
393
+ Mercury.lightview.loadContent('content')
394
+ expect(spy.callCount).toEqual(1)
395
+
396
+ it "calls setTitle", ->
397
+ spy = spyOn(Mercury.lightview, 'setTitle').andCallFake(=>)
398
+ Mercury.lightview.loadContent('content')
399
+ expect(spy.callCount).toEqual(1)
400
+
401
+ it "sets loaded to true", ->
402
+ Mercury.lightview.loaded = false
403
+ Mercury.lightview.loadContent('content')
404
+ expect(Mercury.lightview.loaded).toEqual(true)
405
+
406
+ it "removes the loading class", ->
407
+ $('.mercury-lightview').addClass('loading')
408
+ Mercury.lightview.loadContent('content')
409
+ expect($('.mercury-lightview').hasClass('loading')).toEqual(false)
410
+
411
+ it "sets the content elements html to whatever was passed", ->
412
+ Mercury.lightview.loadContent('<span>content</span>')
413
+ expect($('.mercury-lightview-content').html()).toEqual('<span>content</span>')
414
+
415
+ it "hides the contentElement", ->
416
+ $('.mercury-lightview-content').css('display', 'block')
417
+ Mercury.lightview.loadContent('content')
418
+ expect($('.mercury-lightview-content').css('display')).toEqual('none')
419
+ expect($('.mercury-lightview-content').css('visibility')).toEqual('hidden')
420
+
421
+ it "calls an afterLoad callback (if provided in options)", ->
422
+ callCount = 0
423
+ Mercury.lightview.loadContent('content', {afterLoad: => callCount += 1})
424
+ expect(callCount).toEqual(1)
425
+
426
+ it "calls a handler method if one is set in lightviewHandlers", ->
427
+ callCount = 0
428
+ Mercury.lightviewHandlers['foo'] = => callCount += 1
429
+ Mercury.lightview.loadContent('content', {handler: 'foo'})
430
+ expect(callCount).toEqual(1)
431
+
432
+ it "translates the content if configured", ->
433
+ Mercury.config.localization.enabled = true
434
+ Mercury.lightview.loadContent('<span>foo</span>')
435
+ expect($('.mercury-lightview-content').html()).toEqual('<span>Bork!</span>')
436
+
437
+ it "calls resize", ->
438
+ Mercury.lightview.loadContent('content')
439
+ expect(@resizeSpy.callCount).toEqual(1)
440
+
441
+
442
+ describe "#setTitle", ->
443
+
444
+ beforeEach ->
445
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
446
+ Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
447
+
448
+ it "sets the the title contents to what was provided in the options", ->
449
+ Mercury.lightview.options = {title: 'new title'}
450
+ Mercury.lightview.setTitle()
451
+ expect($('.mercury-lightview-title span').html()).toEqual('new title')
452
+
453
+
454
+ describe "#reset", ->
455
+
456
+ beforeEach ->
457
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
458
+ Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
459
+
460
+ it "clears the title and content elements", ->
461
+ $('.mercury-lightview-content').html('content')
462
+ Mercury.lightview.reset()
463
+ expect($('.mercury-lightview-content').html()).toEqual('')
464
+ expect($('.mercury-lightview-title span').html()).toEqual('')
465
+
466
+
467
+ describe "#hide", ->
468
+
469
+ beforeEach ->
470
+ spyOn(Mercury.lightview, 'appear').andCallFake(=>)
471
+ Mercury.lightview('/blank.html', {appendTo: $('#test')})
472
+
473
+ it "triggers the focus:frame event", ->
474
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
475
+ Mercury.lightview.hide()
476
+ expect(spy.callCount).toEqual(1)
477
+ expect(spy.argsForCall[0]).toEqual(['focus:frame'])
478
+
479
+ it "hides the element", ->
480
+ Mercury.lightview.element.css('display:block')
481
+ Mercury.lightview.hide()
482
+ expect($('.mercury-lightview').css('display')).toEqual('none')
483
+
484
+ it "hides the overlay element", ->
485
+ Mercury.lightview.overlay.css('display:block')
486
+ Mercury.lightview.hide()
487
+ expect($('.mercury-lightview-overlay').css('display')).toEqual('none')
488
+
489
+ it "calls reset", ->
490
+ spy = spyOn(Mercury.lightview, 'reset').andCallFake(=>)
491
+ Mercury.lightview.hide()
492
+ expect(spy.callCount).toEqual(1)
493
+
494
+ it "sets visible to false", ->
495
+ Mercury.lightview.visible = true
496
+ Mercury.lightview.hide()
497
+ expect(Mercury.lightview.visible).toEqual(false)
@@ -0,0 +1,132 @@
1
+ describe "Mercury", ->
2
+
3
+ afterEach: ->
4
+ Mercury.config.localization.enabled = false
5
+
6
+ describe "supported:", ->
7
+
8
+ # this is here for documentation -- unable to test, because this is evaluated on script load
9
+ it "checks document.getElementById", ->
10
+ it "checks document.designMode", ->
11
+ it "disallows konqueror and msie", ->
12
+
13
+
14
+ describe ".on", ->
15
+
16
+ it "binds an event prefixed with 'mercury:' to the top window", ->
17
+ callCount = 0
18
+ Mercury.on('test', -> callCount += 1)
19
+ $(top).trigger("mercury:test")
20
+ expect(callCount).toEqual(1)
21
+
22
+
23
+ describe ".trigger", ->
24
+
25
+ it "triggers an event prefixed with 'mercury:' on the top window", ->
26
+ argsForCall = []
27
+ callCount = 0
28
+ Mercury.on('test', -> argsForCall[callCount] = arguments; callCount += 1)
29
+ Mercury.trigger("test", {foo: 'bar'})
30
+ expect(callCount).toEqual(1)
31
+ expect(argsForCall[0][1]).toEqual({foo: 'bar'})
32
+
33
+
34
+ describe ".notify", ->
35
+
36
+ beforeEach ->
37
+ @alertSpy = spyOn(window, 'alert').andCallFake(=>)
38
+ @i18nSpy = spyOn(Mercury, 'I18n').andCallFake(=>)
39
+ Mercury.notify('hello world!')
40
+
41
+ it "translates the text first by calling Mercury.I18n", ->
42
+ expect(@i18nSpy.callCount).toEqual(1)
43
+ expect(@i18nSpy.argsForCall[0]).toEqual(['hello world!'])
44
+
45
+ it "alerts the message", ->
46
+ expect(@alertSpy.callCount).toEqual(1)
47
+ expect(@i18nSpy.argsForCall[0]).toEqual(['hello world!'])
48
+
49
+
50
+ describe ".warn", ->
51
+
52
+ beforeEach ->
53
+ window.console = {warn: (-> ''), trace: (-> '')}
54
+ @warnSpy = spyOn(window.console, 'warn').andCallFake(=>)
55
+ @notifySpy = spyOn(Mercury, 'notify').andCallFake(=>)
56
+
57
+ it "calls console.warn", ->
58
+ Mercury.warn('message', 2)
59
+ expect(@warnSpy.callCount).toEqual(1)
60
+
61
+ it "calls Mercury.notify if there's no console", ->
62
+ window.console = null
63
+ Mercury.warn('message', 2)
64
+ expect(@notifySpy.callCount).toEqual(1)
65
+
66
+
67
+ describe ".log", ->
68
+
69
+ beforeEach ->
70
+ window.console = {debug: -> ''}
71
+ @debugSpy = spyOn(window.console, 'debug').andCallFake(=>)
72
+ Mercury.debug = true
73
+
74
+ it "calls console.debug", ->
75
+ Mercury.log(1, 2)
76
+ expect(@debugSpy.callCount).toEqual(1)
77
+
78
+ it "does nothing if debug mode isn't on", ->
79
+ Mercury.debug = false
80
+ Mercury.log(1, 2)
81
+ expect(@debugSpy.callCount).toEqual(0)
82
+
83
+ it "does nothing if there's no console", ->
84
+ window.console = null
85
+ Mercury.log(1, 2)
86
+ expect(@debugSpy.callCount).toEqual(0)
87
+
88
+
89
+ describe ".locale", ->
90
+
91
+ beforeEach ->
92
+ @translationSource = Mercury.I18n['en'] = {
93
+ 'original-top': 'translated-top'
94
+ _US_: {'original-sub': 'translated-sub'}
95
+ }
96
+
97
+ it "memoizes array for what the browsers language is set to (breaks with a different language set)", ->
98
+ Mercury.config.localization.enabled = true
99
+ expect(Mercury.determinedLocale).toEqual(undefined)
100
+ expect(Mercury.locale()).toEqual({top: @translationSource, sub: @translationSource['_US_']})
101
+ expect(Mercury.determinedLocale).toEqual({top: @translationSource, sub: @translationSource['_US_']})
102
+
103
+
104
+ describe ".I18n", ->
105
+
106
+ beforeEach ->
107
+ Mercury.I18n['foo'] =
108
+ 'originaL': 'translated -- top level'
109
+ 'uniquE': 'translated unique'
110
+ 'complex %s with %d, and %f': 'translated %s with %d, and %f'
111
+ BAR:
112
+ 'originaL': 'translated -- sub level'
113
+ 'unique': 'undesired unique'
114
+ Mercury.determinedLocale = {top: Mercury.I18n['foo'], sub: Mercury.I18n['foo']['BAR']}
115
+
116
+
117
+ it "translates from a top level locale", ->
118
+ Mercury.determinedLocale.sub = {}
119
+ expect(Mercury.I18n('originaL')).toEqual('translated -- top level')
120
+
121
+ it "translates from a sub level locale", ->
122
+ expect(Mercury.I18n('originaL')).toEqual('translated -- sub level')
123
+
124
+ it "falls back from a sub level locale", ->
125
+ expect(Mercury.I18n('uniquE')).toEqual('translated unique')
126
+
127
+ it "falls back to no translation", ->
128
+ Mercury.determinedLocale = {top: {}, sub: {}}
129
+ expect(Mercury.I18n('original')).toEqual('original')
130
+
131
+ it "uses printf to get any number of variables into the translation", ->
132
+ expect(Mercury.I18n('complex %s with %d, and %f', 'string', 1, 2.4)).toEqual('translated string with 1, and 2.4')