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,222 @@
1
+ describe "Mercury.Toolbar", ->
2
+
3
+ template 'mercury/toolbar.html'
4
+
5
+ beforeEach ->
6
+ $.fx.off = true
7
+ spyOn($, 'ajax').andCallFake (url, options) =>
8
+ options.success('data') if options.success
9
+
10
+ afterEach ->
11
+ @toolbar = null
12
+ delete(@toolbar)
13
+
14
+ describe "constructor", ->
15
+
16
+ beforeEach ->
17
+ @buildSpy = spyOn(Mercury.Toolbar.prototype, 'build').andCallFake(=>)
18
+ @bindEventsSpy = spyOn(Mercury.Toolbar.prototype, 'bindEvents').andCallFake(=>)
19
+ @toolbar = new Mercury.Toolbar({appendTo: '#test', foo: true})
20
+
21
+ it "accepts options as an argument", ->
22
+ expect(@toolbar.options).toEqual({appendTo: '#test', foo: true})
23
+
24
+ it "calls build", ->
25
+ expect(@buildSpy.callCount).toEqual(1)
26
+
27
+ it "calls bindEvents", ->
28
+ expect(@bindEventsSpy.callCount).toEqual(1)
29
+
30
+
31
+ describe "#build", ->
32
+
33
+ describe "with a primary toolbar", ->
34
+
35
+ beforeEach ->
36
+ @buildButtonSpy = spyOn(Mercury.Toolbar.prototype, 'buildButton').andCallFake(=> $('<div>'))
37
+ @toolbar = new Mercury.Toolbar({appendTo: '#toolbar_container', visible: false})
38
+
39
+ it "builds an element", ->
40
+ expect($('.mercury-toolbar-container').length).toEqual(1)
41
+
42
+ it "hides the element if options.visible is false", ->
43
+ expect($('.mercury-toolbar-container').css('display')).toEqual('none')
44
+
45
+ it "can append to any element", ->
46
+ expect($('#toolbar_container .mercury-toolbar-container').length).toEqual(1)
47
+
48
+ it "builds out toolbar elements from the configuration", ->
49
+ expect($('.mercury-primary-toolbar').length).toEqual(1)
50
+ expect($('.mercury-editable-toolbar').length).toEqual(1)
51
+ expect($('.mercury-editable-toolbar').data('regions')).toEqual('editable,markupable')
52
+
53
+ it "builds buttons etc.", ->
54
+ expect(@buildButtonSpy.callCount).toBeGreaterThan(10)
55
+
56
+ it "sets it's width back to 100%", ->
57
+ expect(@toolbar.element.get(0).style.width).toEqual('100%')
58
+
59
+ it "disables all but the primary toolbar", ->
60
+ expect($('.mercury-editable-toolbar').hasClass('disabled')).toEqual(true)
61
+
62
+ it "adds an expander when white-space: nowrap (meaning the toolbar shouldn't wrap)", ->
63
+ expect($('.mercury-toolbar-button-container').length).toBeGreaterThan(1)
64
+ expect($('.mercury-toolbar-expander').length).toEqual(1)
65
+
66
+ describe "without a primary toolbar", ->
67
+
68
+ beforeEach ->
69
+ @primaryToolbar = Mercury.config.toolbars.primary
70
+ delete(Mercury.config.toolbars.primary)
71
+ @buildButtonSpy = spyOn(Mercury.Toolbar.prototype, 'buildButton').andCallFake(=> $('<div>'))
72
+ @toolbar = new Mercury.Toolbar({appendTo: '#toolbar_container', visible: false})
73
+
74
+ afterEach ->
75
+ Mercury.config.toolbars.primary = @primaryToolbar
76
+
77
+ it "doesn't disable the toolbars", ->
78
+ expect($('.mercury-editable-toolbar').hasClass('disabled')).toEqual(false)
79
+
80
+
81
+
82
+ describe "#buildButton", ->
83
+
84
+ beforeEach ->
85
+ @toolbar = new Mercury.Toolbar({appendTo: '#test'})
86
+
87
+ it "throws an exception when invalid options are passed", ->
88
+ expect(=> @toolbar.buildButton('foo', false)).toThrow('Unknown button structure -- please provide an array, object, or string for "foo".')
89
+
90
+ it "returns false if the name is _custom, or _regions", ->
91
+ expect(@toolbar.buildButton('_custom', 'foo')).toEqual(false)
92
+ expect(@toolbar.buildButton('_regions', ['regiontype', 'another_regiontype'])).toEqual(false)
93
+
94
+ it "builds buttons", ->
95
+ html = $('<div>').html(@toolbar.buildButton('foobutton', ['title', 'summary', {}])).html()
96
+ expect(html).toContain('title="summary"')
97
+ expect(html).toContain('class="mercury-button mercury-foobutton-button"')
98
+ expect(html).toContain('<em>title</em>')
99
+
100
+ it "builds button groups", ->
101
+ html = $('<div>').html(@toolbar.buildButton('foogroup', {foobutton: ['title', 'summary', {}]})).html()
102
+ expect(html).toContain('class="mercury-button-group mercury-foogroup-group"')
103
+ expect(html).toContain('title="summary"')
104
+ expect(html).toContain('class="mercury-button mercury-foobutton-button"')
105
+ expect(html).toContain('<em>title</em>')
106
+
107
+ it "builds separators", ->
108
+ html = $('<div>').html(@toolbar.buildButton('foosep1', ' ')).html()
109
+ expect(html).toEqual('<hr class="mercury-separator">')
110
+
111
+ html = $('<div>').html(@toolbar.buildButton('foosep1', '-')).html()
112
+ expect(html).toEqual('<hr class="mercury-line-separator">')
113
+
114
+ it "builds buttons from configuration", ->
115
+ expect($('.mercury-primary-toolbar .mercury-save-button').length).toEqual(1)
116
+ expect($('.mercury-primary-toolbar .mercury-preview-button').length).toEqual(1)
117
+
118
+ it "builds button groups from configuration", ->
119
+ expect($('.mercury-editable-toolbar .mercury-decoration-group').length).toEqual(1)
120
+ expect($('.mercury-editable-toolbar .mercury-script-group').length).toEqual(1)
121
+
122
+ it "builds separators from configuration", ->
123
+ expect($('.mercury-separator').length).toBeGreaterThan(1);
124
+ expect($('.mercury-line-separator').length).toBeGreaterThan(1);
125
+
126
+
127
+ describe "observed events", ->
128
+
129
+ beforeEach ->
130
+ @toolbar = new Mercury.Toolbar({appendTo: '#test'})
131
+
132
+ describe "custom event: region:focused", ->
133
+
134
+ it "enables toolbars based on the region type", ->
135
+ $('.mercury-editable-toolbar').addClass('disabled')
136
+ Mercury.trigger('region:focused', {region: {type: 'editable'}})
137
+ expect($('.mercury.editable-toolbar').hasClass('disabled')).toEqual(false)
138
+
139
+ $('.mercury-editable-toolbar').addClass('disabled')
140
+ Mercury.trigger('region:focused', {region: {type: 'markupable'}})
141
+ expect($('.mercury.editable-toolbar').hasClass('disabled')).toEqual(false)
142
+
143
+ describe "custom event: region:blurred", ->
144
+
145
+ it "disables toolbars for the region type", ->
146
+ $('.mercury-editable-toolbar').removeClass('disabled')
147
+ Mercury.trigger('region:blurred', {region: {type: 'editable'}})
148
+ expect($('.mercury-editable-toolbar').hasClass('disabled')).toEqual(true)
149
+
150
+ describe "click", ->
151
+
152
+ it "triggers hide:dialogs", ->
153
+ spy = spyOn(Mercury, 'trigger')
154
+
155
+ jasmine.simulate.click(@toolbar.element.get(0))
156
+
157
+ expect(spy.callCount).toEqual(1)
158
+ expect(spy.argsForCall[0]).toEqual(['hide:dialogs'])
159
+
160
+
161
+ describe "#height", ->
162
+
163
+ beforeEach ->
164
+ spyOn(Mercury.Toolbar.prototype, 'buildButton').andCallFake(=> $('<div>'))
165
+ spyOn(Mercury.Toolbar.prototype, 'bindEvents').andCallFake(=>)
166
+
167
+ describe "when visible", ->
168
+
169
+ beforeEach ->
170
+ @toolbar = new Mercury.Toolbar({appendTo: '#test', visible: true})
171
+
172
+ it "returns the element outerheight", ->
173
+ expect(@toolbar.height()).toEqual($('.mercury-toolbar-container').outerHeight())
174
+
175
+ describe "when not visible", ->
176
+
177
+ beforeEach ->
178
+ @toolbar = new Mercury.Toolbar({appendTo: '#test', visible: false})
179
+
180
+ it "returns 0", ->
181
+ expect(@toolbar.height()).toEqual(0)
182
+
183
+
184
+ describe "#show", ->
185
+
186
+ beforeEach ->
187
+ spyOn(Mercury.Toolbar.prototype, 'buildButton').andCallFake(=> $('<div>'))
188
+ spyOn(Mercury.Toolbar.prototype, 'bindEvents').andCallFake(=>)
189
+ @toolbar = new Mercury.Toolbar({appendTo: '#test', visible: false})
190
+
191
+ it "sets visible to true", ->
192
+ @toolbar.visible = false
193
+ @toolbar.show()
194
+ expect(@toolbar.visible).toEqual(true)
195
+
196
+ it "displays the element", ->
197
+ $('.mercury-toolbar-container').css({display: 'none'})
198
+ @toolbar.show()
199
+ expect($('.mercury-toolbar-container').css('display')).toEqual('block')
200
+
201
+ it "sets the top of the element", ->
202
+ $('.mercury-toolbar-container').css({top: '-20px'})
203
+ @toolbar.show()
204
+ expect($('.mercury-toolbar-container').css('top')).toEqual('0px')
205
+
206
+
207
+ describe "#hide", ->
208
+
209
+ beforeEach ->
210
+ spyOn(Mercury.Toolbar.prototype, 'buildButton').andCallFake(=> $('<div>'))
211
+ spyOn(Mercury.Toolbar.prototype, 'bindEvents').andCallFake(=>)
212
+ @toolbar = new Mercury.Toolbar({appendTo: '#test', visible: true})
213
+
214
+ it "sets visible to false", ->
215
+ @toolbar.visible = true
216
+ @toolbar.hide()
217
+ expect(@toolbar.visible).toEqual(false)
218
+
219
+ it "hides the element", ->
220
+ $('.mercury-toolbar-container').css({display: 'block'})
221
+ @toolbar.hide()
222
+ expect($('.mercury-toolbar-container').css('display')).toEqual('none')
@@ -0,0 +1,186 @@
1
+ describe "Mercury.tooltip", ->
2
+
3
+ template 'mercury/tooltip.html'
4
+
5
+ beforeEach ->
6
+ @forElement = $('#for_element')
7
+ $.fx.off = true
8
+
9
+ afterEach ->
10
+ Mercury.tooltip.visible = false
11
+ Mercury.tooltip.initialized = false
12
+
13
+ describe "singleton method", ->
14
+
15
+ beforeEach ->
16
+ @showSpy = spyOn(Mercury.tooltip, 'show').andCallFake(=>)
17
+
18
+ it "calls show", ->
19
+ Mercury.tooltip()
20
+ expect(@showSpy.callCount).toEqual(1)
21
+
22
+ it "returns the function object", ->
23
+ ret = Mercury.tooltip()
24
+ expect(ret).toEqual(Mercury.tooltip)
25
+
26
+
27
+ describe "#show", ->
28
+
29
+ beforeEach ->
30
+ @initializeSpy = spyOn(Mercury.tooltip, 'initialize').andCallFake(=>)
31
+ @updateSpy = spyOn(Mercury.tooltip, 'update').andCallFake(=>)
32
+ @appearSpy = spyOn(Mercury.tooltip, 'appear').andCallFake(=>)
33
+
34
+ it "gets the document from the element passed in", ->
35
+ Mercury.tooltip.show(@forElement, 'content')
36
+ expect(Mercury.tooltip.document).toEqual(document)
37
+
38
+ it "calls initialize", ->
39
+ Mercury.tooltip.show(@forElement, 'content')
40
+ expect(@initializeSpy.callCount).toEqual(1)
41
+
42
+ describe "if visible", ->
43
+
44
+ beforeEach ->
45
+ Mercury.tooltip.visible = true
46
+
47
+ it "calls update", ->
48
+ Mercury.tooltip.show(@forElement, 'content')
49
+ expect(@updateSpy.callCount).toEqual(1)
50
+
51
+ describe "if not visible", ->
52
+
53
+ beforeEach ->
54
+ Mercury.tooltip.visible = false
55
+
56
+ it "calls appear", ->
57
+ Mercury.tooltip.show(@forElement, 'content')
58
+ expect(@appearSpy.callCount).toEqual(1)
59
+
60
+
61
+ describe "#initialize", ->
62
+
63
+ it "calls build", ->
64
+ spy = spyOn(Mercury.tooltip, 'build').andCallFake(=>)
65
+ spyOn(Mercury.tooltip, 'bindEvents').andCallFake(=>)
66
+ Mercury.tooltip.initialize()
67
+ expect(spy.callCount).toEqual(1)
68
+
69
+ it "calls bindEvents", ->
70
+ spy = spyOn(Mercury.tooltip, 'bindEvents').andCallFake(=>)
71
+ Mercury.tooltip.initialize()
72
+ expect(spy.callCount).toEqual(1)
73
+
74
+ it "sets initialized to true", ->
75
+ Mercury.tooltip.initialize()
76
+ expect(Mercury.tooltip.initialized).toEqual(true)
77
+
78
+ it "does nothing if already initialized", ->
79
+ spy = spyOn(Mercury.tooltip, 'bindEvents').andCallFake(=>)
80
+ Mercury.tooltip.initialized = true
81
+ Mercury.tooltip.initialize()
82
+ expect(spy.callCount).toEqual(0)
83
+
84
+
85
+ describe "#build", ->
86
+
87
+ it "builds an element", ->
88
+ Mercury.tooltip.build()
89
+ html = $('<div>').html(Mercury.tooltip.element).html()
90
+ expect(html).toContain('class="mercury-tooltip"')
91
+
92
+ it "can append to any element", ->
93
+ Mercury.tooltip.options = {appendTo: '#tooltip_container'}
94
+ Mercury.tooltip.build()
95
+ expect($('#tooltip_container').html()).toContain('class="mercury-tooltip"')
96
+
97
+
98
+ describe "observed events", ->
99
+
100
+ describe "custom event: resize", ->
101
+
102
+ it "call position if visible", ->
103
+ Mercury.tooltip.visible = true
104
+ spy = spyOn(Mercury.tooltip, 'position').andCallFake(=>)
105
+ Mercury.trigger('resize')
106
+ expect(spy.callCount).toEqual(1)
107
+
108
+ Mercury.tooltip.visible = false
109
+ Mercury.trigger('resize')
110
+ expect(spy.callCount).toEqual(1)
111
+
112
+ describe "document scrolling", ->
113
+
114
+ # untestable
115
+ it "calls position if visible", ->
116
+
117
+ describe "element mousedown", ->
118
+
119
+ # untestable
120
+ it "stops the event", ->
121
+
122
+
123
+ describe "#appear", ->
124
+
125
+ beforeEach ->
126
+ Mercury.tooltip.build()
127
+ @updateSpy = spyOn(Mercury.tooltip, 'update').andCallFake(=>)
128
+
129
+ it "calls update", ->
130
+ Mercury.tooltip.appear()
131
+ expect(@updateSpy.callCount).toEqual(1)
132
+
133
+ it "shows the element", ->
134
+ Mercury.tooltip.appear()
135
+ expect(Mercury.tooltip.element.css('display')).toEqual('block')
136
+ expect(Mercury.tooltip.element.css('opacity')).toEqual('1')
137
+
138
+ it "sets visible to true", ->
139
+ Mercury.tooltip.visible = false
140
+ Mercury.tooltip.appear()
141
+ expect(Mercury.tooltip.visible).toEqual(true)
142
+
143
+
144
+ describe "#update", ->
145
+
146
+ beforeEach ->
147
+ Mercury.tooltip.build()
148
+ @positionSpy = spyOn(Mercury.tooltip, 'position').andCallFake(=>)
149
+
150
+ it "sets the html", ->
151
+ Mercury.tooltip.content = 'foo'
152
+ Mercury.tooltip.update()
153
+ expect(Mercury.tooltip.element.html()).toEqual('foo')
154
+
155
+ it "calls position", ->
156
+ Mercury.tooltip.update()
157
+ expect(@positionSpy.callCount).toEqual(1)
158
+
159
+
160
+ describe "#position", ->
161
+
162
+ beforeEach ->
163
+ Mercury.tooltip.build()
164
+ Mercury.displayRect = {top: 0, left: 0, width: 200, height: 200}
165
+
166
+ it "positions based on the element we're showing for", ->
167
+ Mercury.tooltip.forElement = @forElement
168
+ Mercury.tooltip.position()
169
+ expect(Mercury.tooltip.element.offset()).toEqual({top: 20 + @forElement.outerHeight(), left: 42})
170
+
171
+
172
+ describe "#hide", ->
173
+
174
+ beforeEach ->
175
+ Mercury.tooltip.build()
176
+ Mercury.tooltip.initialized = true
177
+
178
+ it "hides the element", ->
179
+ Mercury.tooltip.element.css({display: 'block'})
180
+ Mercury.tooltip.hide()
181
+ expect(Mercury.tooltip.element.css('display')).toEqual('none')
182
+
183
+ it "sets visible to false", ->
184
+ Mercury.tooltip.visible = true
185
+ Mercury.tooltip.hide()
186
+ expect(Mercury.tooltip.visible).toEqual(false)