kuji-mercury-rails 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. data/LICENSE +25 -0
  2. data/POST_INSTALL +15 -0
  3. data/app/controllers/mercury/images_controller.rb +19 -0
  4. data/app/controllers/mercury_controller.rb +34 -0
  5. data/app/models/mercury/image.rb +16 -0
  6. data/app/views/layouts/mercury.html.erb +33 -0
  7. data/app/views/mercury/lightviews/about.html +11 -0
  8. data/app/views/mercury/modals/character.html +255 -0
  9. data/app/views/mercury/modals/htmleditor.html +13 -0
  10. data/app/views/mercury/modals/link.html +75 -0
  11. data/app/views/mercury/modals/media.html +82 -0
  12. data/app/views/mercury/modals/table.html +84 -0
  13. data/app/views/mercury/palettes/backcolor.html +73 -0
  14. data/app/views/mercury/palettes/forecolor.html +73 -0
  15. data/app/views/mercury/panels/history.html +3 -0
  16. data/app/views/mercury/panels/notes.html +3 -0
  17. data/app/views/mercury/panels/snippets.html +12 -0
  18. data/app/views/mercury/selects/formatblock.html +11 -0
  19. data/app/views/mercury/selects/style.html +5 -0
  20. data/app/views/mercury/snippets/example/options.html.erb +34 -0
  21. data/app/views/mercury/snippets/example/preview.html.erb +1 -0
  22. data/config/engine.rb +41 -0
  23. data/db/migrate/20110526035601_create_mercury_images.rb +11 -0
  24. data/features/loading/loading.feature +22 -0
  25. data/features/loading/navigating.feature +77 -0
  26. data/features/loading/user_interface.feature +67 -0
  27. data/features/regions/editable/advanced_editing.feature +0 -0
  28. data/features/regions/editable/basic_editing.feature +195 -0
  29. data/features/regions/editable/inserting_links.feature +98 -0
  30. data/features/regions/editable/inserting_media.feature +110 -0
  31. data/features/regions/editable/inserting_snippets.feature +102 -0
  32. data/features/regions/editable/inserting_special_characters.feature +24 -0
  33. data/features/regions/editable/inserting_tables.feature +109 -0
  34. data/features/regions/editable/pasting.feature +0 -0
  35. data/features/regions/editable/uploading_images.feature +0 -0
  36. data/features/regions/image/uploading_images.feature +0 -0
  37. data/features/regions/markupable/advanced_editing.feature +0 -0
  38. data/features/regions/markupable/basic_editing.feature +0 -0
  39. data/features/regions/markupable/inserting_links.feature +0 -0
  40. data/features/regions/markupable/inserting_media.feature +0 -0
  41. data/features/regions/markupable/inserting_snippets.feature +0 -0
  42. data/features/regions/markupable/inserting_special_characters.feature +0 -0
  43. data/features/regions/markupable/inserting_tables.feature +0 -0
  44. data/features/regions/markupable/uploading_images.feature +0 -0
  45. data/features/regions/simple/basic_editing.feature +5 -0
  46. data/features/regions/snippetable/advanced_editing.feature +0 -0
  47. data/features/regions/snippetable/basic_editing.feature +0 -0
  48. data/features/regions/snippetable/inserting_snippets.feature +0 -0
  49. data/features/saving/saving.feature +33 -0
  50. data/features/step_definitions/debug_steps.rb +14 -0
  51. data/features/step_definitions/mercury_steps.rb +438 -0
  52. data/features/step_definitions/web_steps.rb +211 -0
  53. data/features/support/env.rb +46 -0
  54. data/features/support/mercury_contents.rb +25 -0
  55. data/features/support/mercury_selectors.rb +148 -0
  56. data/features/support/paths.rb +38 -0
  57. data/features/support/selectors.rb +44 -0
  58. data/lib/generators/mercury/install/install_generator.rb +49 -0
  59. data/lib/generators/mercury/install/templates/mongoid_paperclip_image.rb +17 -0
  60. data/lib/mercury-rails.rb +3 -0
  61. data/lib/mercury/authentication.rb +8 -0
  62. data/spec/javascripts/mercury/dialog_spec.js.coffee +281 -0
  63. data/spec/javascripts/mercury/dialogs/backcolor_spec.js.coffee +37 -0
  64. data/spec/javascripts/mercury/dialogs/forecolor_spec.js.coffee +37 -0
  65. data/spec/javascripts/mercury/dialogs/formatblock_spec.js.coffee +25 -0
  66. data/spec/javascripts/mercury/dialogs/snippetpanel_spec.js.coffee +30 -0
  67. data/spec/javascripts/mercury/dialogs/style_spec.js.coffee +25 -0
  68. data/spec/javascripts/mercury/history_buffer_spec.js.coffee +76 -0
  69. data/spec/javascripts/mercury/lightview_spec.js.coffee +497 -0
  70. data/spec/javascripts/mercury/mercury_spec.js.coffee +132 -0
  71. data/spec/javascripts/mercury/modal_spec.js.coffee +504 -0
  72. data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +30 -0
  73. data/spec/javascripts/mercury/modals/insertcharacter_spec.js.coffee +29 -0
  74. data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +220 -0
  75. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +167 -0
  76. data/spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee +52 -0
  77. data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +160 -0
  78. data/spec/javascripts/mercury/native_extensions_spec.js.coffee +60 -0
  79. data/spec/javascripts/mercury/page_editor_spec.js.coffee +757 -0
  80. data/spec/javascripts/mercury/palette_spec.js.coffee +49 -0
  81. data/spec/javascripts/mercury/panel_spec.js.coffee +183 -0
  82. data/spec/javascripts/mercury/region_spec.js.coffee +298 -0
  83. data/spec/javascripts/mercury/regions/editable_spec.js.coffee +561 -0
  84. data/spec/javascripts/mercury/regions/image_spec.js.coffee +34 -0
  85. data/spec/javascripts/mercury/regions/markupable_spec.js.coffee +367 -0
  86. data/spec/javascripts/mercury/regions/simple_spec.js.coffee +33 -0
  87. data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +370 -0
  88. data/spec/javascripts/mercury/select_spec.js.coffee +49 -0
  89. data/spec/javascripts/mercury/snippet_spec.js.coffee +253 -0
  90. data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +184 -0
  91. data/spec/javascripts/mercury/statusbar_spec.js.coffee +150 -0
  92. data/spec/javascripts/mercury/table_editor_spec.js.coffee +194 -0
  93. data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +90 -0
  94. data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +360 -0
  95. data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +118 -0
  96. data/spec/javascripts/mercury/toolbar_spec.js.coffee +222 -0
  97. data/spec/javascripts/mercury/tooltip_spec.js.coffee +186 -0
  98. data/spec/javascripts/mercury/uploader_spec.js.coffee +530 -0
  99. data/spec/javascripts/spec_helper.js +513 -0
  100. data/spec/javascripts/templates/mercury/dialog.html +2 -0
  101. data/spec/javascripts/templates/mercury/dialogs/backcolor.html +5 -0
  102. data/spec/javascripts/templates/mercury/dialogs/forecolor.html +5 -0
  103. data/spec/javascripts/templates/mercury/dialogs/formatblock.html +3 -0
  104. data/spec/javascripts/templates/mercury/dialogs/snippetpanel.html +16 -0
  105. data/spec/javascripts/templates/mercury/dialogs/style.html +3 -0
  106. data/spec/javascripts/templates/mercury/lightview.html +13 -0
  107. data/spec/javascripts/templates/mercury/modal.html +13 -0
  108. data/spec/javascripts/templates/mercury/modals/htmleditor.html +5 -0
  109. data/spec/javascripts/templates/mercury/modals/insertcharacter.html +5 -0
  110. data/spec/javascripts/templates/mercury/modals/insertlink.html +30 -0
  111. data/spec/javascripts/templates/mercury/modals/insertmedia.html +35 -0
  112. data/spec/javascripts/templates/mercury/modals/insertsnippet.html +6 -0
  113. data/spec/javascripts/templates/mercury/modals/inserttable.html +27 -0
  114. data/spec/javascripts/templates/mercury/page_editor.html +35 -0
  115. data/spec/javascripts/templates/mercury/palette.html +16 -0
  116. data/spec/javascripts/templates/mercury/panel.html +16 -0
  117. data/spec/javascripts/templates/mercury/region.html +2 -0
  118. data/spec/javascripts/templates/mercury/regions/editable.html +3 -0
  119. data/spec/javascripts/templates/mercury/regions/image.html +1 -0
  120. data/spec/javascripts/templates/mercury/regions/simple.html +3 -0
  121. data/spec/javascripts/templates/mercury/regions/snippetable.html +4 -0
  122. data/spec/javascripts/templates/mercury/select.html +16 -0
  123. data/spec/javascripts/templates/mercury/snippet.html +1 -0
  124. data/spec/javascripts/templates/mercury/snippet_toolbar.html +16 -0
  125. data/spec/javascripts/templates/mercury/statusbar.html +8 -0
  126. data/spec/javascripts/templates/mercury/table_editor.html +65 -0
  127. data/spec/javascripts/templates/mercury/toolbar.button.html +64 -0
  128. data/spec/javascripts/templates/mercury/toolbar.button_group.html +9 -0
  129. data/spec/javascripts/templates/mercury/toolbar.expander.html +18 -0
  130. data/spec/javascripts/templates/mercury/toolbar.html +11 -0
  131. data/spec/javascripts/templates/mercury/tooltip.html +12 -0
  132. data/spec/javascripts/templates/mercury/uploader.html +11 -0
  133. data/vendor/assets/images/mercury/button.png +0 -0
  134. data/vendor/assets/images/mercury/close.png +0 -0
  135. data/vendor/assets/images/mercury/default-snippet.png +0 -0
  136. data/vendor/assets/images/mercury/loading-dark.gif +0 -0
  137. data/vendor/assets/images/mercury/loading-light.gif +0 -0
  138. data/vendor/assets/images/mercury/missing-image.png +0 -0
  139. data/vendor/assets/images/mercury/search-icon.png +0 -0
  140. data/vendor/assets/images/mercury/temp-logo.png +0 -0
  141. data/vendor/assets/images/mercury/toolbar/editable/buttons.png +0 -0
  142. data/vendor/assets/images/mercury/toolbar/primary/_expander.png +0 -0
  143. data/vendor/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
  144. data/vendor/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
  145. data/vendor/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
  146. data/vendor/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
  147. data/vendor/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
  148. data/vendor/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
  149. data/vendor/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
  150. data/vendor/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
  151. data/vendor/assets/images/mercury/toolbar/primary/preview.png +0 -0
  152. data/vendor/assets/images/mercury/toolbar/primary/redo.png +0 -0
  153. data/vendor/assets/images/mercury/toolbar/primary/save.png +0 -0
  154. data/vendor/assets/images/mercury/toolbar/primary/snippetpanel.png +0 -0
  155. data/vendor/assets/images/mercury/toolbar/primary/undo.png +0 -0
  156. data/vendor/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
  157. data/vendor/assets/javascripts/mercury.js +479 -0
  158. data/vendor/assets/javascripts/mercury/dependencies/jquery-1.7.js +9300 -0
  159. data/vendor/assets/javascripts/mercury/dependencies/jquery-ui-1.8.13.custom.js +1328 -0
  160. data/vendor/assets/javascripts/mercury/dependencies/jquery.additions.js +206 -0
  161. data/vendor/assets/javascripts/mercury/dependencies/jquery.htmlClean.js +527 -0
  162. data/vendor/assets/javascripts/mercury/dependencies/liquidmetal.js +88 -0
  163. data/vendor/assets/javascripts/mercury/dependencies/showdown.js +1340 -0
  164. data/vendor/assets/javascripts/mercury/dialog.js.coffee +159 -0
  165. data/vendor/assets/javascripts/mercury/dialogs/backcolor.js.coffee +6 -0
  166. data/vendor/assets/javascripts/mercury/dialogs/forecolor.js.coffee +6 -0
  167. data/vendor/assets/javascripts/mercury/dialogs/formatblock.js.coffee +4 -0
  168. data/vendor/assets/javascripts/mercury/dialogs/snippetpanel.js.coffee +10 -0
  169. data/vendor/assets/javascripts/mercury/dialogs/style.js.coffee +4 -0
  170. data/vendor/assets/javascripts/mercury/finalize.js.coffee +3 -0
  171. data/vendor/assets/javascripts/mercury/history_buffer.js.coffee +30 -0
  172. data/vendor/assets/javascripts/mercury/lightview.js.coffee +205 -0
  173. data/vendor/assets/javascripts/mercury/locales/ar.locale.js.coffee +207 -0
  174. data/vendor/assets/javascripts/mercury/locales/da.locale.js.coffee +211 -0
  175. data/vendor/assets/javascripts/mercury/locales/de.locale.js.coffee +206 -0
  176. data/vendor/assets/javascripts/mercury/locales/es.locale.js.coffee +211 -0
  177. data/vendor/assets/javascripts/mercury/locales/example.local.js.coffee +211 -0
  178. data/vendor/assets/javascripts/mercury/locales/fr.locale.js.coffee +211 -0
  179. data/vendor/assets/javascripts/mercury/locales/it.locale.js.coffee +208 -0
  180. data/vendor/assets/javascripts/mercury/locales/ko.local.js.coffee +206 -0
  181. data/vendor/assets/javascripts/mercury/locales/nl.locale.js.coffee +206 -0
  182. data/vendor/assets/javascripts/mercury/locales/pt.locale.js.coffee +211 -0
  183. data/vendor/assets/javascripts/mercury/locales/sv.local.js.coffee +209 -0
  184. data/vendor/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +213 -0
  185. data/vendor/assets/javascripts/mercury/mercury.js.coffee +109 -0
  186. data/vendor/assets/javascripts/mercury/modal.js.coffee +198 -0
  187. data/vendor/assets/javascripts/mercury/modals/htmleditor.js.coffee +11 -0
  188. data/vendor/assets/javascripts/mercury/modals/insertcharacter.js.coffee +4 -0
  189. data/vendor/assets/javascripts/mercury/modals/insertlink.js.coffee +92 -0
  190. data/vendor/assets/javascripts/mercury/modals/insertmedia.js.coffee +81 -0
  191. data/vendor/assets/javascripts/mercury/modals/insertsnippet.js.coffee +12 -0
  192. data/vendor/assets/javascripts/mercury/modals/inserttable.js.coffee +54 -0
  193. data/vendor/assets/javascripts/mercury/native_extensions.js.coffee +55 -0
  194. data/vendor/assets/javascripts/mercury/page_editor.js.coffee +225 -0
  195. data/vendor/assets/javascripts/mercury/palette.js.coffee +29 -0
  196. data/vendor/assets/javascripts/mercury/panel.js.coffee +115 -0
  197. data/vendor/assets/javascripts/mercury/plugins/save_as_xml/mercury/page_editor.js.coffee +28 -0
  198. data/vendor/assets/javascripts/mercury/plugins/save_as_xml/plugin.js +9 -0
  199. data/vendor/assets/javascripts/mercury/region.js.coffee +107 -0
  200. data/vendor/assets/javascripts/mercury/regions/editable.js.coffee +600 -0
  201. data/vendor/assets/javascripts/mercury/regions/image.js.coffee +114 -0
  202. data/vendor/assets/javascripts/mercury/regions/markupable.js.coffee +398 -0
  203. data/vendor/assets/javascripts/mercury/regions/simple.js.coffee +325 -0
  204. data/vendor/assets/javascripts/mercury/regions/snippetable.js.coffee +124 -0
  205. data/vendor/assets/javascripts/mercury/select.js.coffee +44 -0
  206. data/vendor/assets/javascripts/mercury/snippet.js.coffee +106 -0
  207. data/vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee +72 -0
  208. data/vendor/assets/javascripts/mercury/statusbar.js.coffee +51 -0
  209. data/vendor/assets/javascripts/mercury/support/history.js +1 -0
  210. data/vendor/assets/javascripts/mercury/table_editor.js.coffee +265 -0
  211. data/vendor/assets/javascripts/mercury/toolbar.button.js.coffee +173 -0
  212. data/vendor/assets/javascripts/mercury/toolbar.button_group.js.coffee +42 -0
  213. data/vendor/assets/javascripts/mercury/toolbar.expander.js.coffee +56 -0
  214. data/vendor/assets/javascripts/mercury/toolbar.js.coffee +86 -0
  215. data/vendor/assets/javascripts/mercury/tooltip.js.coffee +74 -0
  216. data/vendor/assets/javascripts/mercury/uploader.js.coffee +244 -0
  217. data/vendor/assets/javascripts/mercury_loader.js +193 -0
  218. data/vendor/assets/javascripts/mercury_overrides.js +6 -0
  219. data/vendor/assets/stylesheets/mercury.css +28 -0
  220. data/vendor/assets/stylesheets/mercury/all_images.css.erb +89 -0
  221. data/vendor/assets/stylesheets/mercury/dialog.css +212 -0
  222. data/vendor/assets/stylesheets/mercury/form.css +118 -0
  223. data/vendor/assets/stylesheets/mercury/lightview.css +151 -0
  224. data/vendor/assets/stylesheets/mercury/mercury.css +37 -0
  225. data/vendor/assets/stylesheets/mercury/modal.css +183 -0
  226. data/vendor/assets/stylesheets/mercury/statusbar.css +32 -0
  227. data/vendor/assets/stylesheets/mercury/toolbar.css +304 -0
  228. data/vendor/assets/stylesheets/mercury/tooltip.css +26 -0
  229. data/vendor/assets/stylesheets/mercury/uploader.css +111 -0
  230. data/vendor/assets/stylesheets/mercury_overrides.css +17 -0
  231. metadata +572 -0
@@ -0,0 +1,150 @@
1
+ describe "Mercury.Statusbar", ->
2
+
3
+ template 'mercury/statusbar.html'
4
+
5
+ beforeEach ->
6
+ $.fx.off = true
7
+ @region = {
8
+ path: -> [{tagName: 'A'}, {tagName: 'B'}, {tagName: 'C'}]
9
+ }
10
+
11
+ afterEach ->
12
+ @statusbar = null
13
+ delete(@statusbar)
14
+
15
+ describe "constructor", ->
16
+
17
+ beforeEach ->
18
+ @buildSpy = spyOn(Mercury.Statusbar.prototype, 'build')
19
+ @bindEventsSpy = spyOn(Mercury.Statusbar.prototype, 'bindEvents')
20
+ @statusbar = new Mercury.Statusbar({appendTo: '#test', foo: 'bar', visible: false})
21
+
22
+ it "accepts options", ->
23
+ expect(@statusbar.options.foo).toEqual('bar')
24
+
25
+ it "sets visible based on options", ->
26
+ expect(@statusbar.visible).toEqual(false)
27
+
28
+ it "calls build", ->
29
+ expect(@buildSpy.callCount).toEqual(1)
30
+
31
+ it "calls bindEvents", ->
32
+ expect(@bindEventsSpy.callCount).toEqual(1)
33
+
34
+
35
+ describe "#build", ->
36
+
37
+ beforeEach ->
38
+ spyOn(Mercury.Statusbar.prototype, 'bindEvents').andCallFake(=>)
39
+ @statusbar = new Mercury.Statusbar({appendTo: '#statusbar_container', visible: false})
40
+
41
+ it "builds an element", ->
42
+ expect($('.mercury-statusbar').length).toEqual(1)
43
+
44
+ it "builds an about element", ->
45
+ expect($('.mercury-statusbar-about').length).toEqual(1)
46
+ expect(@statusbar.aboutElement).toBeDefined()
47
+
48
+ it "hides the element if it's not supposed to be visible", ->
49
+ expect($('.mercury-statusbar').css('visibility')).toEqual('hidden')
50
+
51
+ it "can append to any element", ->
52
+ expect($('#statusbar_container .mercury-statusbar').length).toEqual(1)
53
+
54
+
55
+ describe "observed events ", ->
56
+
57
+ beforeEach ->
58
+ @statusbar = new Mercury.Statusbar({appendTo: '#test'})
59
+
60
+ describe "custom event: region:update", ->
61
+
62
+ it "calls setPath if a region was provided", ->
63
+ spy = spyOn(Mercury.Statusbar.prototype, 'setPath').andCallFake(=>)
64
+ Mercury.trigger('region:update', {region: @region})
65
+ expect(spy.callCount).toEqual(1)
66
+
67
+ describe "clicking on the about element", ->
68
+
69
+ it "opens a lightview", ->
70
+ spy = spyOn(Mercury, 'lightview').andCallFake(=>)
71
+ jasmine.simulate.click($('.mercury-statusbar-about').get(0))
72
+ expect(spy.callCount).toEqual(1)
73
+
74
+
75
+ describe "#height", ->
76
+
77
+ beforeEach ->
78
+ spyOn(Mercury.Statusbar.prototype, 'bindEvents').andCallFake(=>)
79
+ @statusbar = new Mercury.Statusbar({appendTo: '#test', visible: true})
80
+
81
+ it "knows it's own height", ->
82
+ expect(@statusbar.height()).toEqual(20) # styled with css in the template
83
+
84
+
85
+ describe "#top", ->
86
+
87
+ describe "when visible", ->
88
+
89
+ beforeEach ->
90
+ spyOn(Mercury.Statusbar.prototype, 'bindEvents').andCallFake(=>)
91
+ @statusbar = new Mercury.Statusbar({appendTo: '#test', visible: true})
92
+
93
+ it "returns the offset top of the element", ->
94
+ expect(@statusbar.top()).toEqual($('.mercury-statusbar').offset().top)
95
+
96
+ describe "when not visible", ->
97
+
98
+ beforeEach ->
99
+ spyOn(Mercury.Statusbar.prototype, 'bindEvents').andCallFake(=>)
100
+ @statusbar = new Mercury.Statusbar({appendTo: '#test', visible: false})
101
+
102
+ it "returns the offset top of the element + it's outer height", ->
103
+ expect(@statusbar.top()).toEqual($('.mercury-statusbar').offset().top + $('.mercury-statusbar').outerHeight())
104
+
105
+
106
+ describe "#setPath", ->
107
+
108
+ beforeEach ->
109
+ @statusbar = new Mercury.Statusbar({appendTo: '#test'})
110
+
111
+ it "builds a path and displays it", ->
112
+ @statusbar.setPath(@region.path())
113
+ expect($('.mercury-statusbar').html()).toMatch(/<span><strong>Path: <\/strong><a>c<\/a> .+ <a>b<\/a> .+ <a>a<\/a><\/span>/)
114
+
115
+
116
+ describe "#show", ->
117
+
118
+ beforeEach ->
119
+ @statusbar = new Mercury.Statusbar({appendTo: '#test', visible: false})
120
+
121
+ it "sets visible to true", ->
122
+ @statusbar.visible = false
123
+ @statusbar.show()
124
+ expect(@statusbar.visible).toEqual(true)
125
+
126
+ it "displays the element", ->
127
+ $('.mercury-statusbar').css({visibility: 'hidden'})
128
+ @statusbar.show()
129
+ expect($('.mercury-statusbar').css('visibility')).toEqual('visible')
130
+
131
+ it "sets the opacity of the element", ->
132
+ $('.mercury-statusbar').css({opacity: 0})
133
+ @statusbar.show()
134
+ expect($('.mercury-statusbar').css('opacity')).toEqual('1')
135
+
136
+
137
+ describe "#hide", ->
138
+
139
+ beforeEach ->
140
+ @statusbar = new Mercury.Statusbar({appendTo: '#test', visible: true})
141
+
142
+ it "sets visible to false", ->
143
+ @statusbar.visible = true
144
+ @statusbar.hide()
145
+ expect(@statusbar.visible).toEqual(false)
146
+
147
+ it "hides the element", ->
148
+ $('.mercury-statusbar').css({visibility: 'visible'})
149
+ @statusbar.hide()
150
+ expect($('.mercury-statusbar').css('visibility')).toEqual('hidden')
@@ -0,0 +1,194 @@
1
+ describe "Mercury.tableEditor", ->
2
+
3
+ template 'mercury/table_editor.html'
4
+
5
+ beforeEach ->
6
+ @table = $('#table1')
7
+ @cell = @table.find('th, td').first()
8
+
9
+ describe "singleton method", ->
10
+
11
+ beforeEach ->
12
+ @loadSpy = spyOn(Mercury.tableEditor, 'load').andCallFake(=>)
13
+
14
+ it "calls load", ->
15
+ Mercury.tableEditor(@table, @cell)
16
+ expect(@loadSpy.callCount).toEqual(1)
17
+
18
+ it "returns the function object", ->
19
+ ret = Mercury.tableEditor(@table, @cell)
20
+ expect(ret).toEqual(Mercury.tableEditor)
21
+
22
+
23
+ describe "#load", ->
24
+
25
+ it "expects a table and a table cell", ->
26
+ Mercury.tableEditor(@table, @cell)
27
+ expect(Mercury.tableEditor.table).toEqual(@table)
28
+ expect(Mercury.tableEditor.cell).toEqual(@cell)
29
+
30
+ it "accepts content that will be placed inside cells", ->
31
+ Mercury.tableEditor(@table, @cell, '<br/>')
32
+ expect(Mercury.tableEditor.cellContent).toEqual('<br/>')
33
+
34
+ it "sets row based on where the cell is", ->
35
+ Mercury.tableEditor(@table, @cell)
36
+ expect(Mercury.tableEditor.row.get(0)).toEqual(@table.find('tr').get(0))
37
+
38
+ it "gets the column count", ->
39
+ Mercury.tableEditor(@table, @cell)
40
+ expect(Mercury.tableEditor.columnCount).toEqual(6)
41
+
42
+ it "gets the row count", ->
43
+ Mercury.tableEditor(@table, @cell)
44
+ expect(Mercury.tableEditor.rowCount).toEqual(8)
45
+
46
+
47
+ describe "#getColumnCount", ->
48
+
49
+ it "gets the column count from the alpha row", ->
50
+ Mercury.tableEditor(@table, @cell)
51
+ expect(Mercury.tableEditor.columnCount).toEqual(6)
52
+
53
+
54
+ describe "#getRowCount", ->
55
+
56
+ it "gets the row count", ->
57
+ Mercury.tableEditor(@table, @cell)
58
+ expect(Mercury.tableEditor.rowCount).toEqual(8)
59
+
60
+
61
+ describe "#cellIndexFor", ->
62
+
63
+ it "gives the right index for different cells", ->
64
+ cell = @table.find('#row1 td:nth-child(1n)').get(0)
65
+ expect(Mercury.tableEditor.cellIndexFor(cell)).toEqual(0)
66
+
67
+ cell = @table.find('#row2 th:nth-child(2n)').get(0)
68
+ expect(Mercury.tableEditor.cellIndexFor(cell)).toEqual(1)
69
+
70
+ cell = @table.find('#row2 th:nth-child(6n)').get(0)
71
+ expect(Mercury.tableEditor.cellIndexFor(cell)).toEqual(5)
72
+
73
+ cell = @table.find('#row3 td:nth-child(4n)').get(0)
74
+ expect(Mercury.tableEditor.cellIndexFor(cell)).toEqual(5)
75
+
76
+ cell = @table.find('#row7 td:nth-child(2n)').get(0)
77
+ expect(Mercury.tableEditor.cellIndexFor(cell)).toEqual(2)
78
+
79
+
80
+ describe "#cellSignatureFor", ->
81
+
82
+ it "returns an object with cell information", ->
83
+ cell = @table.find('#row2 th:nth-child(3n)').get(0)
84
+ sig = Mercury.tableEditor.cellSignatureFor(cell)
85
+ expect(sig.width).toEqual(1)
86
+ expect(sig.height).toEqual(2)
87
+ expect(sig.right).toEqual(3)
88
+
89
+ cell = @table.find('#row2 th:nth-child(5n)').get(0)
90
+ sig = Mercury.tableEditor.cellSignatureFor(cell)
91
+ expect(sig.width).toEqual(1)
92
+ expect(sig.height).toEqual(4)
93
+ expect(sig.right).toEqual(5)
94
+
95
+ cell = @table.find('#row7 td:nth-child(1n)').get(0)
96
+ sig = Mercury.tableEditor.cellSignatureFor(cell)
97
+ expect(sig.width).toEqual(2)
98
+ expect(sig.height).toEqual(1)
99
+ expect(sig.right).toEqual(2)
100
+
101
+ describe "#findCellByOptionsFor", ->
102
+
103
+ it "finds a matching cell in a specific row, based on right", ->
104
+ row = @table.find('#row2').get(0)
105
+ sig = Mercury.tableEditor.findCellByOptionsFor(row, { right: 5 })
106
+ expect(sig.cell.get(0)).toEqual(@table.find('#row2 th:nth-child(5n)').get(0))
107
+
108
+ it "finds a cell based on left", ->
109
+ row = @table.find('#row5').get(0)
110
+ sig = Mercury.tableEditor.findCellByOptionsFor(row, { left: 5 })
111
+ expect(sig.cell.get(0)).toEqual(@table.find('#row5 th:nth-child(5n)').get(0))
112
+
113
+ it "finds a cell based on left and width", ->
114
+ row = @table.find('#row7').get(0)
115
+ sig = Mercury.tableEditor.findCellByOptionsFor(row, { left: 2, width: 4 })
116
+ expect(sig.cell.get(0)).toEqual(@table.find('#row7 td:nth-child(2n)').get(0))
117
+
118
+ describe "when a cell isn't there", ->
119
+
120
+ beforeEach ->
121
+ @row = @table.find('#row3').get(0)
122
+
123
+ it "returns null", ->
124
+ sig = Mercury.tableEditor.findCellByOptionsFor(@row, { left: 2 })
125
+ expect(sig).toEqual(null)
126
+
127
+ it "can force to an adjacent cell", ->
128
+ sig = Mercury.tableEditor.findCellByOptionsFor(@row, { left: 2, forceAdjacent: true })
129
+ expect(sig.cell.get(0)).toEqual(@table.find('#row3 td:nth-child(2n)').get(0))
130
+ expect(sig.direction).toEqual('after')
131
+
132
+
133
+ describe "#findCellByIntersectionFor", ->
134
+
135
+ it "finds cells that intersect vertically, based on the signature of another cell", ->
136
+ sig = Mercury.tableEditor.cellSignatureFor(@table.find('#row6 td:nth-child(3n)'))
137
+ intersectingSig = Mercury.tableEditor.findCellByIntersectionFor(@table.find('#row7'), sig)
138
+ expect(intersectingSig.cell.get(0)).toEqual(@table.find('#row7 td:nth-child(2n)').get(0))
139
+
140
+
141
+ describe "#columnsFor", ->
142
+
143
+ it "returns the total number of cells and colspans for a given collection of cells", ->
144
+ expect(Mercury.tableEditor.columnsFor(@table.find('#row7 td'))).toEqual(6)
145
+
146
+
147
+ describe "#colspanFor", ->
148
+
149
+ it "returns the colspan of a given cell", ->
150
+ cell = @table.find('#row7 td:nth-child(2n)')
151
+ expect(Mercury.tableEditor.colspanFor(cell)).toEqual(4)
152
+
153
+ it "defaults to 1", ->
154
+ cell = @table.find('#row6 td:first-child')
155
+ expect(Mercury.tableEditor.colspanFor(cell)).toEqual(1)
156
+
157
+
158
+ describe "#rowspanFor", ->
159
+
160
+ it "returns the rowspan of a given cell", ->
161
+ cell = @table.find('#row2 th:nth-child(5n)')
162
+ expect(Mercury.tableEditor.rowspanFor(cell)).toEqual(4)
163
+
164
+ it "defaults to 1", ->
165
+ cell = @table.find('#row6 td:first-child')
166
+ expect(Mercury.tableEditor.rowspanFor(cell)).toEqual(1)
167
+
168
+
169
+ describe "setColspanFor", ->
170
+
171
+ beforeEach ->
172
+ @cell = @table.find('#row2 th:first-child')
173
+
174
+ it "sets the colspan for a cell", ->
175
+ Mercury.tableEditor.setColspanFor(@cell, 20)
176
+ expect(@cell.attr('colspan')).toEqual('20')
177
+
178
+ it "removes the attribute if it's 1", ->
179
+ Mercury.tableEditor.setColspanFor(@cell, 1)
180
+ expect(@cell.attr('colspan')).toEqual(undefined)
181
+
182
+
183
+ describe "setRowspanFor", ->
184
+
185
+ beforeEach ->
186
+ @cell = @table.find('#row2 th:first-child')
187
+
188
+ it "sets the rowspan for a cell", ->
189
+ Mercury.tableEditor.setRowspanFor(@cell, 20)
190
+ expect(@cell.attr('rowspan')).toEqual('20')
191
+
192
+ it "removes the attribute if it's 1", ->
193
+ Mercury.tableEditor.setRowspanFor(@cell, 1)
194
+ expect(@cell.attr('rowspan')).toEqual(undefined)
@@ -0,0 +1,90 @@
1
+ describe "Mercury.Toolbar.ButtonGroup", ->
2
+
3
+ template 'mercury/toolbar.button_group.html'
4
+
5
+ beforeEach ->
6
+ Mercury.Toolbar.ButtonGroup.contexts.foo = -> false
7
+ @region = {
8
+ element: $('<div class="mercury-region">')
9
+ currentElement: -> $('<div>')
10
+ }
11
+
12
+ afterEach ->
13
+ @buttonGroup = null
14
+ delete(@buttonGroup)
15
+ $(window).unbind('mercury:region:update')
16
+
17
+ describe "constructor", ->
18
+
19
+ beforeEach ->
20
+ @buildSpy = spyOn(Mercury.Toolbar.ButtonGroup.prototype, 'build').andCallThrough()
21
+ @bindEventsSpy = spyOn(Mercury.Toolbar.ButtonGroup.prototype, 'bindEvents').andCallThrough()
22
+ @buttonGroup = new Mercury.Toolbar.ButtonGroup('foo', {_context: true})
23
+
24
+ it "returns an element", ->
25
+ html = $('<div>').html(@buttonGroup).html()
26
+ expect(html).toEqual('<div class="mercury-button-group mercury-foo-group disabled"></div>')
27
+
28
+ it "calls build", ->
29
+ expect(@buildSpy.callCount).toEqual(1)
30
+
31
+ it "calls bindEvents", ->
32
+ expect(@bindEventsSpy.callCount).toEqual(1)
33
+
34
+
35
+ describe "observed events", ->
36
+
37
+ describe "custom event: region:update", ->
38
+
39
+ it "sets disabled/enabled state based on it's context", ->
40
+ @buttonGroup = new Mercury.Toolbar.ButtonGroup('foo', {_context: true})
41
+ contextSpy = spyOn(Mercury.Toolbar.ButtonGroup.contexts, 'foo').andCallFake(-> true)
42
+
43
+ expect(@buttonGroup.hasClass('disabled')).toEqual(true)
44
+
45
+ Mercury.trigger('region:update', {region: @region})
46
+ expect(contextSpy.callCount).toEqual(1)
47
+ expect(@buttonGroup.hasClass('disabled')).toEqual(false)
48
+
49
+ describe "custom event: region:focused", ->
50
+
51
+ beforeEach ->
52
+ @region = {
53
+ type: 'editable'
54
+ element: $('<div class="mercury-region">')
55
+ }
56
+
57
+ it "disables if the region type isn't supported", ->
58
+ @buttonGroup = new Mercury.Toolbar.ButtonGroup('foo', {_regions: ['foo']})
59
+ @buttonGroup.removeClass('disabled')
60
+ Mercury.trigger('region:focused', {region: @region})
61
+ expect(@buttonGroup.hasClass('disabled')).toEqual(true)
62
+
63
+ it "enables if the region type is supported", ->
64
+ @buttonGroup = new Mercury.Toolbar.ButtonGroup('foo', {_regions: ['editable']})
65
+ @buttonGroup.addClass('disabled')
66
+ Mercury.trigger('region:focused', {region: @region})
67
+ expect(@buttonGroup.hasClass('disabled')).toEqual(false)
68
+
69
+ describe "custom event: region:blurred", ->
70
+
71
+ it "disables if it's a button group for specific region types", ->
72
+ @buttonGroup = new Mercury.Toolbar.ButtonGroup('foo', {_regions: ['editable']})
73
+ @buttonGroup.removeClass('disabled')
74
+ Mercury.trigger('region:blurred', {region: @region})
75
+
76
+
77
+
78
+ describe "Mercury.Toolbar.ButtonGroup.contexts", ->
79
+
80
+ template 'mercury/toolbar.button_group.html'
81
+
82
+ beforeEach ->
83
+ @contexts = Mercury.Toolbar.ButtonGroup.contexts
84
+ @region = $('#context_container')
85
+
86
+ describe "table", ->
87
+
88
+ it "looks up for a table tag", ->
89
+ expect(@contexts.table($('#context_td'), @region)).toEqual(true)
90
+ expect(@contexts.table($('#context_em'), @region)).toEqual(false)
@@ -0,0 +1,360 @@
1
+ describe "Mercury.Toolbar.Button", ->
2
+
3
+ template 'mercury/toolbar.button.html'
4
+
5
+ beforeEach ->
6
+ Mercury.displayRect = {0, 0, 500, 200}
7
+ Mercury.Toolbar.Button.contexts.foo = -> true
8
+ @region = {
9
+ type: 'editable'
10
+ element: $('<div class="mercury-region">')
11
+ currentElement: -> $('<div>')
12
+ }
13
+ Mercury.preloadedViews['/nothing'] = 'nothing'
14
+
15
+ afterEach ->
16
+ @button = null
17
+ delete(@button)
18
+ $(document).unbind('mercury:region:update')
19
+ $(document).unbind('mercury:button')
20
+
21
+ describe "constructor", ->
22
+
23
+ it "expects name and title values", ->
24
+ @button = new Mercury.Toolbar.Button('foo', 'title')
25
+ html = $('<div>').html(@button).html()
26
+ expect(html).toContain('title="title"')
27
+ expect(html).toContain('class="mercury-button mercury-foo-button"')
28
+ expect(html).toContain('<em>title</em>')
29
+
30
+ it "accepts summary, types and options", ->
31
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {palette: '/nothing'}, {appendDialogsTo: $('#test')})
32
+ html = $('<div>').html(@button).html()
33
+ expect(html).toContain('title="summary"')
34
+ expect(html).toContain('class="mercury-button mercury-foo-button mercury-button-palette"')
35
+ expect(html).toContain('<em>title</em>')
36
+
37
+ it "calls build", ->
38
+ spy = spyOn(Mercury.Toolbar.Button.prototype, 'build').andCallFake(=>)
39
+ spyOn(Mercury.Toolbar.Button.prototype, 'bindEvents').andCallFake(=>)
40
+ @button = new Mercury.Toolbar.Button('foo', 'title')
41
+ expect(spy.callCount).toEqual(1)
42
+
43
+ it "calls bindEvents", ->
44
+ spyOn(Mercury.Toolbar.Button.prototype, 'build').andCallFake(=>)
45
+ spy = spyOn(Mercury.Toolbar.Button.prototype, 'bindEvents').andCallFake(=>)
46
+ @button = new Mercury.Toolbar.Button('foo', 'title')
47
+ expect(spy.callCount).toEqual(1)
48
+
49
+
50
+ describe "#build for various button types", ->
51
+
52
+ it "attaches an element meant for the expander in button data", ->
53
+ @button = new Mercury.Toolbar.Button('foo', 'title')
54
+ expect(@button.data('expander')).toEqual('<div class="mercury-expander-button" data-button="foo"><em></em><span>title</span></div>')
55
+
56
+ it "builds toggle buttons, that when clicked toggle their state", ->
57
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {toggle: true})
58
+
59
+ jasmine.simulate.click(@button.get(0))
60
+ expect(@button.hasClass('pressed')).toEqual(true)
61
+
62
+ jasmine.simulate.click(@button.get(0))
63
+ expect(@button.hasClass('pressed')).toEqual(false)
64
+
65
+ it "builds mode buttons, that when clicked fire a mode event", ->
66
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {mode: true})
67
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
68
+
69
+ jasmine.simulate.click(@button.get(0))
70
+ expect(spy.callCount).toEqual(1)
71
+ expect(spy.argsForCall[0]).toEqual(['mode', {mode: 'foo'}])
72
+
73
+ it "builds buttons that understand context", ->
74
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {context: true})
75
+
76
+ expect(@button.hasClass('active')).toEqual(false)
77
+ Mercury.trigger('region:update', {region: @region})
78
+ expect(@button.hasClass('active')).toEqual(true)
79
+
80
+ it "builds panel buttons (and assigns toggle)", ->
81
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {panel: '/blank.html'}, {appendDialogsTo: $('#test')})
82
+ expect($('#test .mercury-panel').length).toEqual(1)
83
+
84
+ jasmine.simulate.click(@button.get(0))
85
+ expect(@button.hasClass('pressed')).toEqual(true)
86
+
87
+ jasmine.simulate.click(@button.get(0))
88
+ expect(@button.hasClass('pressed')).toEqual(false)
89
+
90
+ it "builds palette buttons", ->
91
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {palette: '/blank.html'}, {appendDialogsTo: $('#test')})
92
+ expect($('#test .mercury-palette').length).toEqual(1)
93
+
94
+ it "builds select buttons", ->
95
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {select: '/blank.html'}, {appendDialogsTo: $('#test')})
96
+ expect($('#test .mercury-select').length).toEqual(1)
97
+
98
+ it "builds modal buttons", ->
99
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {modal: '/blank.html'}, {appendDialogsTo: $('#test')})
100
+ # nothing unique about this in building -- the modal is built/fired on click
101
+
102
+ it "builds lightview buttons", ->
103
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {lightview: '/blank.html'}, {appendDialogsTo: $('#test')})
104
+ # nothing unique about this in building -- the lightview is built/fired on click
105
+
106
+ it "throws an error when an unknown type is encountered", ->
107
+ expect(=>
108
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {foo: '/blank.html'})
109
+ ).toThrow('Unknown button type "foo" used for the "foo" button.')
110
+
111
+
112
+ describe "observed events", ->
113
+
114
+ describe "custom event: button", ->
115
+
116
+ it "calls click on the button itself", ->
117
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {context: true})
118
+ spy = spyOn(@button, 'click').andCallFake(=>)
119
+
120
+ Mercury.trigger('button', {action: 'foo'})
121
+ expect(spy.callCount).toEqual(1)
122
+
123
+ describe "custom event: mode", ->
124
+
125
+ it "toggles a button when that mode is triggered and the button is toggleable", ->
126
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {mode: 'preview', toggle: true})
127
+ spy = spyOn(Mercury.Toolbar.Button.prototype, 'togglePressed').andCallFake(=>)
128
+
129
+ Mercury.trigger('mode', {mode: 'preview'})
130
+ expect(spy.callCount).toEqual(1)
131
+
132
+ describe "custom event: region:update", ->
133
+
134
+ it "calls contexts if one is available and set", ->
135
+ contextSpy = spyOn(Mercury.Toolbar.Button.contexts, 'foo').andCallFake(-> true)
136
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {context: true})
137
+
138
+ expect(@button.hasClass('active')).toEqual(false)
139
+
140
+ Mercury.trigger('region:update', {region: @region})
141
+ expect(contextSpy.callCount).toEqual(1)
142
+ expect(@button.hasClass('active')).toEqual(true)
143
+
144
+ describe "custom event: region:focused", ->
145
+
146
+ it "disables if the region type isn't supported", ->
147
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {context: true, regions: ['foo']})
148
+ @button.removeClass('disabled')
149
+ Mercury.trigger('region:focused', {region: @region})
150
+ expect(@button.hasClass('disabled')).toEqual(true)
151
+
152
+ it "enables if the region type is supported", ->
153
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {context: true, regions: ['editable']})
154
+ @button.addClass('disabled')
155
+ Mercury.trigger('region:focused', {region: @region})
156
+ expect(@button.hasClass('disabled')).toEqual(false)
157
+
158
+ describe "custom event: region:blurred", ->
159
+
160
+ it "disables if it's a button for specific region types", ->
161
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {context: true, regions: ['editable']})
162
+ @button.addClass('disabled')
163
+ Mercury.trigger('region:blurred', {region: @region})
164
+ expect(@button.hasClass('disabled')).toEqual(true)
165
+
166
+ describe "mousedown", ->
167
+
168
+ it "sets the active state", ->
169
+ @button = new Mercury.Toolbar.Button('foo', 'title')
170
+
171
+ expect(@button.hasClass('active')).toEqual(false)
172
+ jasmine.simulate.mousedown(@button.get(0))
173
+ expect(@button.hasClass('active')).toEqual(true)
174
+
175
+ describe "mouseup", ->
176
+
177
+ it "removes the active state", ->
178
+ @button = new Mercury.Toolbar.Button('foo', 'title')
179
+ @button.addClass('active')
180
+
181
+ jasmine.simulate.mouseup(@button.get(0))
182
+ expect(@button.hasClass('active')).toEqual(false)
183
+
184
+ describe "click for various button types", ->
185
+
186
+ it "does nothing if the button is disabled", ->
187
+ spy = spyOn(Mercury.Toolbar.Button.prototype, 'togglePressed').andCallThrough()
188
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {toggle: true})
189
+
190
+ jasmine.simulate.click(@button.get(0))
191
+ expect(spy.callCount).toEqual(1)
192
+
193
+ @button.addClass('disabled')
194
+ jasmine.simulate.click(@button.get(0))
195
+ expect(spy.callCount).toEqual(1)
196
+
197
+ it "triggers an action event", ->
198
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary')
199
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
200
+
201
+ jasmine.simulate.click(@button.get(0))
202
+ expect(spy.argsForCall[0]).toEqual(['action', {action: 'foo'}])
203
+
204
+ it "triggers a focus:frame event", ->
205
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
206
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {}, {regions: ['editable']})
207
+
208
+ jasmine.simulate.click(@button.get(0))
209
+ expect(spy.argsForCall[1]).toEqual(['focus:frame'])
210
+
211
+ it "toggles toggle button pressed state", ->
212
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {toggle: true})
213
+
214
+ jasmine.simulate.click(@button.get(0))
215
+ expect(@button.hasClass('pressed')).toEqual(true)
216
+
217
+ jasmine.simulate.click(@button.get(0))
218
+ expect(@button.hasClass('pressed')).toEqual(false)
219
+
220
+ it "triggers a mode event", ->
221
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
222
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {mode: true})
223
+
224
+ jasmine.simulate.click(@button.get(0))
225
+ expect(spy.argsForCall[0]).toEqual(['mode', {mode: 'foo'}])
226
+
227
+ it "opens a modal window", ->
228
+ spy = spyOn(Mercury, 'modal').andCallFake(=>)
229
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {modal: '/blank.html'})
230
+
231
+ jasmine.simulate.click(@button.get(0))
232
+ expect(spy.argsForCall[0]).toEqual(['/blank.html', {title: 'summary', handler: 'foo'}])
233
+
234
+ it "opens a lightview window", ->
235
+ spy = spyOn(Mercury, 'lightview').andCallFake(=>)
236
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {lightview: '/blank.html'})
237
+
238
+ jasmine.simulate.click(@button.get(0))
239
+ expect(spy.argsForCall[0]).toEqual(['/blank.html', {title: 'summary', handler: 'foo', closeButton: true}])
240
+
241
+ it "shows and hides palettes", ->
242
+ spy = spyOn(Mercury.Palette.prototype, 'toggle').andCallFake(=>)
243
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {palette: '/blank.html'})
244
+
245
+ jasmine.simulate.click(@button.get(0))
246
+ expect(spy.callCount).toEqual(1)
247
+
248
+ jasmine.simulate.click(@button.get(0))
249
+ expect(spy.callCount).toEqual(2)
250
+
251
+ it "shows and hides selects", ->
252
+ spy = spyOn(Mercury.Select.prototype, 'toggle').andCallFake(=>)
253
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {select: '/blank.html'})
254
+
255
+ jasmine.simulate.click(@button.get(0))
256
+ expect(spy.callCount).toEqual(1)
257
+
258
+ jasmine.simulate.click(@button.get(0))
259
+ expect(spy.callCount).toEqual(2)
260
+
261
+ it "shows and hides panels, and toggles the button pressed state", ->
262
+ spy = spyOn(Mercury.Panel.prototype, 'toggle').andCallFake(=>)
263
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {panel: '/blank.html'})
264
+
265
+ jasmine.simulate.click(@button.get(0))
266
+ expect(spy.callCount).toEqual(1)
267
+
268
+ jasmine.simulate.click(@button.get(0))
269
+ expect(spy.callCount).toEqual(2)
270
+
271
+
272
+ describe "Mercury.Toolbar.Button.contexts", ->
273
+
274
+ template 'mercury/toolbar.button.html'
275
+
276
+ beforeEach ->
277
+ @contexts = Mercury.Toolbar.Button.contexts
278
+ @region = $('#context_container')
279
+ @element = $('#context_button')
280
+
281
+ it "handles background color", ->
282
+ @contexts.backColor.call(@, $('#context_backcolor'), @region)
283
+ expect(@element.css('background-color')).toEqual('rgb(255, 0, 0)')
284
+
285
+ @contexts.backColor.call(@, $('#context_none'), @region)
286
+ if $.browser.mozilla
287
+ expect(@element.css('background-color')).toEqual('transparent')
288
+ else
289
+ expect(@element.css('background-color')).toEqual('rgba(0, 0, 0, 0)')
290
+
291
+ it "handles foreground color", ->
292
+ @contexts.foreColor.call(@, $('#context_forecolor'), @region)
293
+ expect(@element.css('background-color')).toEqual('rgb(0, 255, 0)')
294
+
295
+ @contexts.foreColor.call(@, $('#context_none'), @region)
296
+ expect(@element.css('background-color')).toEqual('rgb(0, 0, 0)')
297
+
298
+ it "knows when something is bold", ->
299
+ expect(@contexts.bold.call(@, $('#context_bold1 span'), @region)).toEqual(true)
300
+ expect(@contexts.bold.call(@, $('#context_bold2 span'), @region)).toEqual(true)
301
+ expect(@contexts.bold.call(@, $('#context_bold3 span'), @region)).toEqual(true)
302
+ expect(@contexts.bold.call(@, $('#context_bold4 span'), @region)).toEqual(true)
303
+ expect(@contexts.bold.call(@, $('#context_bold5 span'), @region)).toEqual(false)
304
+ expect(@contexts.bold.call(@, $('#context_bold6 span'), @region)).toEqual(true)
305
+ expect(@contexts.bold.call(@, $('#context_none'), @region)).toEqual(false)
306
+
307
+ it "knows when something is italic", ->
308
+ expect(@contexts.italic.call(@, $('#context_italic1 span'), @region)).toEqual(true)
309
+ expect(@contexts.italic.call(@, $('#context_italic2 span'), @region)).toEqual(true)
310
+ expect(@contexts.italic.call(@, $('#context_none'), @region)).toEqual(false)
311
+
312
+ it "knows when something is overlined", ->
313
+ expect(@contexts.overline.call(@, $('#context_overline'), @region)).toEqual(true)
314
+ expect(@contexts.overline.call(@, $('#context_none'), @region)).toEqual(false)
315
+
316
+ it "knows when something is striked through", ->
317
+ expect(@contexts.strikethrough.call(@, $('#context_strikethrough1 span'), @region)).toEqual(true)
318
+ expect(@contexts.strikethrough.call(@, $('#context_strikethrough2'), @region)).toEqual(true)
319
+ expect(@contexts.strikethrough.call(@, $('#context_none'), @region)).toEqual(false)
320
+
321
+ it "knows when something is underlined", ->
322
+ expect(@contexts.underline.call(@, $('#context_underline1 span'), @region)).toEqual(true)
323
+ expect(@contexts.underline.call(@, $('#context_underline2'), @region)).toEqual(true)
324
+ expect(@contexts.underline.call(@, $('#context_none'), @region)).toEqual(false)
325
+
326
+ it "knows when something is subscript", ->
327
+ expect(@contexts.subscript.call(@, $('#context_subscript span'), @region)).toEqual(true)
328
+ expect(@contexts.subscript.call(@, $('#context_none'), @region)).toEqual(false)
329
+
330
+ it "knows when something is superscript", ->
331
+ expect(@contexts.superscript.call(@, $('#context_superscript span'), @region)).toEqual(true)
332
+ expect(@contexts.superscript.call(@, $('#context_none'), @region)).toEqual(false)
333
+
334
+ it "knows when something is justified left", ->
335
+ expect(@contexts.justifyLeft.call(@, $('#context_justifyLeft span'), @region)).toEqual(true)
336
+ expect(@contexts.justifyLeft.call(@, $('#context_none'), @region)).toEqual(false)
337
+
338
+ it "knows when something is justified center", ->
339
+ expect(@contexts.justifyCenter.call(@, $('#context_justifyCenter span'), @region)).toEqual(true)
340
+ expect(@contexts.justifyCenter.call(@, $('#context_none'), @region)).toEqual(false)
341
+
342
+ it "knows when something is justified right", ->
343
+ expect(@contexts.justifyRight.call(@, $('#context_justifyRight span'), @region)).toEqual(true)
344
+ expect(@contexts.justifyRight.call(@, $('#context_none'), @region)).toEqual(false)
345
+
346
+ it "knows when something is justified fully", ->
347
+ expect(@contexts.justifyFull.call(@, $('#context_justifyFull span'), @region)).toEqual(true)
348
+ expect(@contexts.justifyFull.call(@, $('#context_none'), @region)).toEqual(false)
349
+
350
+ it "knows when something is inside an ordered list", ->
351
+ expect(@contexts.insertOrderedList.call(@, $('#context_orderedlist span'), @region)).toEqual(true)
352
+ expect(@contexts.insertOrderedList.call(@, $('#context_none'), @region)).toEqual(false)
353
+
354
+ it "knows when something is inside an unordered list", ->
355
+ expect(@contexts.insertUnorderedList.call(@, $('#context_unorderedlist span'), @region)).toEqual(true)
356
+ expect(@contexts.insertUnorderedList.call(@, $('#context_none'), @region)).toEqual(false)
357
+
358
+ # todo: fix in jquery
359
+ # it "understands nested text-decoration styles", ->
360
+ # expect(@contexts.underline.call(@, $('#context_decoration'), @region)).toEqual(true)