mercury-rails 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data/LICENSE +5 -0
  2. data/{README.rdoc → README.md} +150 -60
  3. data/VERSION +1 -1
  4. data/annotated_source.template +57 -0
  5. data/app/controllers/mercury_controller.rb +8 -4
  6. data/app/models/image.rb +2 -2
  7. data/app/views/layouts/mercury.html.erb +14 -0
  8. data/app/views/mercury/lightviews/about.html +7 -0
  9. data/app/views/mercury/lightviews/imageprocessor.html +3 -0
  10. data/app/views/mercury/modals/character.html +255 -0
  11. data/app/views/mercury/modals/htmleditor.html +13 -0
  12. data/app/views/mercury/modals/link.html +75 -0
  13. data/app/views/mercury/modals/media.html +82 -0
  14. data/app/views/mercury/modals/sanitizer.html +9 -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.html.erb +1 -0
  24. data/app/views/mercury/snippets/example_options.html.erb +23 -0
  25. data/config/routes.rb +1 -1
  26. data/features/editing/basic.feature +1 -1
  27. data/features/support/paths.rb +1 -0
  28. data/lib/generators/mercury/install/install_generator.rb +14 -0
  29. data/mercury-rails.gemspec +115 -106
  30. data/spec/javascripts/mercury/dialog_spec.js.coffee +54 -38
  31. data/spec/javascripts/mercury/dialogs/backcolor_spec.js.coffee +1 -1
  32. data/spec/javascripts/mercury/dialogs/forecolor_spec.js.coffee +1 -1
  33. data/spec/javascripts/mercury/dialogs/formatblock_spec.js.coffee +1 -1
  34. data/spec/javascripts/mercury/dialogs/{objectspanel_spec.js.coffee → snippetpanel_spec.js.coffee} +4 -4
  35. data/spec/javascripts/mercury/dialogs/style_spec.js.coffee +1 -1
  36. data/spec/javascripts/mercury/history_buffer_spec.js.coffee +0 -1
  37. data/spec/javascripts/mercury/lightview_spec.js.coffee +448 -0
  38. data/spec/javascripts/mercury/mercury_spec.js.coffee +1 -1
  39. data/spec/javascripts/mercury/modal_spec.js.coffee +474 -0
  40. data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +1 -1
  41. data/spec/javascripts/mercury/modals/insertcharacter_spec.js.coffee +1 -1
  42. data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +8 -2
  43. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +1 -1
  44. data/spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee +1 -1
  45. data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +1 -1
  46. data/spec/javascripts/mercury/native_extensions_spec.js.coffee +1 -1
  47. data/spec/javascripts/mercury/page_editor_spec.js.coffee +160 -20
  48. data/spec/javascripts/mercury/palette_spec.js.coffee +1 -1
  49. data/spec/javascripts/mercury/panel_spec.js.coffee +1 -1
  50. data/spec/javascripts/mercury/region_spec.js.coffee +1 -1
  51. data/spec/javascripts/mercury/regions/editable_spec.js.coffee +191 -6
  52. data/spec/javascripts/mercury/regions/markupable_spec.js.coffee +369 -0
  53. data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +1 -1
  54. data/spec/javascripts/mercury/select_spec.js.coffee +1 -1
  55. data/spec/javascripts/mercury/snippet_spec.js.coffee +3 -3
  56. data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +2 -2
  57. data/spec/javascripts/mercury/statusbar_spec.js.coffee +91 -17
  58. data/spec/javascripts/mercury/table_editor_spec.js.coffee +5 -1
  59. data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +1 -1
  60. data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +1 -1
  61. data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +1 -1
  62. data/spec/javascripts/mercury/toolbar_spec.js.coffee +70 -15
  63. data/spec/javascripts/mercury/tooltip_spec.js.coffee +1 -1
  64. data/spec/javascripts/mercury/uploader_spec.js.coffee +9 -1
  65. data/spec/javascripts/templates/mercury/dialogs/{objectspanel.html → snippetpanel.html} +0 -0
  66. data/spec/javascripts/templates/mercury/lightview.html +13 -0
  67. data/spec/javascripts/templates/mercury/modal.html +13 -0
  68. data/spec/javascripts/templates/mercury/page_editor.html +11 -1
  69. data/spec/javascripts/templates/mercury/statusbar.html +1 -0
  70. data/spec/javascripts/templates/mercury/toolbar.html +1 -0
  71. data/{app → vendor}/assets/images/mercury/button.png +0 -0
  72. data/{app → vendor}/assets/images/mercury/clippy.png +0 -0
  73. data/{app → vendor}/assets/images/mercury/default-snippet.png +0 -0
  74. data/{app → vendor}/assets/images/mercury/loading-dark.gif +0 -0
  75. data/{app → vendor}/assets/images/mercury/loading-light.gif +0 -0
  76. data/{app → vendor}/assets/images/mercury/search-icon.png +0 -0
  77. data/vendor/assets/images/mercury/temp-logo.png +0 -0
  78. data/{app → vendor}/assets/images/mercury/toolbar/editable/buttons.png +0 -0
  79. data/{app → vendor}/assets/images/mercury/toolbar/primary/_expander.png +0 -0
  80. data/{app → vendor}/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
  81. data/{app → vendor}/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
  82. data/{app → vendor}/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
  83. data/{app → vendor}/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
  84. data/{app → vendor}/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
  85. data/{app → vendor}/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
  86. data/{app → vendor}/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
  87. data/{app → vendor}/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
  88. data/{app → vendor}/assets/images/mercury/toolbar/primary/preview.png +0 -0
  89. data/{app → vendor}/assets/images/mercury/toolbar/primary/redo.png +0 -0
  90. data/{app → vendor}/assets/images/mercury/toolbar/primary/save.png +0 -0
  91. data/{app/assets/images/mercury/toolbar/primary/objectspanel.png → vendor/assets/images/mercury/toolbar/primary/snippetpanel.png} +0 -0
  92. data/{app → vendor}/assets/images/mercury/toolbar/primary/undo.png +0 -0
  93. data/{app → vendor}/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
  94. data/vendor/assets/javascripts/mercury.js +302 -0
  95. data/vendor/assets/javascripts/mercury/dialog.js.coffee +157 -0
  96. data/{app → vendor}/assets/javascripts/mercury/dialogs/backcolor.js.coffee +0 -0
  97. data/{app → vendor}/assets/javascripts/mercury/dialogs/forecolor.js.coffee +0 -0
  98. data/{app → vendor}/assets/javascripts/mercury/dialogs/formatblock.js.coffee +0 -0
  99. data/{app → vendor}/assets/javascripts/mercury/dialogs/objectspanel.js.coffee +1 -1
  100. data/{app → vendor}/assets/javascripts/mercury/dialogs/style.js.coffee +0 -0
  101. data/{app → vendor}/assets/javascripts/mercury/history_buffer.js.coffee +0 -0
  102. data/vendor/assets/javascripts/mercury/lightview.js.coffee +156 -0
  103. data/vendor/assets/javascripts/mercury/lightviews/imageprocessor.js.coffee +2 -0
  104. data/vendor/assets/javascripts/mercury/mercury.js.coffee +63 -0
  105. data/{app → vendor}/assets/javascripts/mercury/modal.js.coffee +25 -17
  106. data/{app → vendor}/assets/javascripts/mercury/modals/htmleditor.js.coffee +0 -0
  107. data/{app → vendor}/assets/javascripts/mercury/modals/insertcharacter.js.coffee +0 -0
  108. data/{app → vendor}/assets/javascripts/mercury/modals/insertlink.js.coffee +3 -0
  109. data/{app → vendor}/assets/javascripts/mercury/modals/insertmedia.js.coffee +10 -2
  110. data/{app → vendor}/assets/javascripts/mercury/modals/insertsnippet.js.coffee +0 -0
  111. data/{app → vendor}/assets/javascripts/mercury/modals/inserttable.js.coffee +2 -2
  112. data/{app → vendor}/assets/javascripts/mercury/native_extensions.js.coffee +0 -0
  113. data/{app → vendor}/assets/javascripts/mercury/page_editor.js.coffee +44 -13
  114. data/{app → vendor}/assets/javascripts/mercury/palette.js.coffee +0 -0
  115. data/{app → vendor}/assets/javascripts/mercury/panel.js.coffee +0 -0
  116. data/{app → vendor}/assets/javascripts/mercury/region.js.coffee +0 -0
  117. data/{app → vendor}/assets/javascripts/mercury/regions/editable.js.coffee +58 -12
  118. data/{app → vendor}/assets/javascripts/mercury/regions/markupable.js.coffee +26 -24
  119. data/{app → vendor}/assets/javascripts/mercury/regions/snippetable.js.coffee +0 -0
  120. data/{app → vendor}/assets/javascripts/mercury/select.js.coffee +3 -0
  121. data/{app → vendor}/assets/javascripts/mercury/snippet.js.coffee +9 -5
  122. data/{app → vendor}/assets/javascripts/mercury/snippet_toolbar.js.coffee +0 -0
  123. data/vendor/assets/javascripts/mercury/statusbar.js.coffee +51 -0
  124. data/{app → vendor}/assets/javascripts/mercury/table_editor.js.coffee +9 -8
  125. data/{app → vendor}/assets/javascripts/mercury/toolbar.button.js.coffee +0 -0
  126. data/{app → vendor}/assets/javascripts/mercury/toolbar.button_group.js.coffee +0 -0
  127. data/{app → vendor}/assets/javascripts/mercury/toolbar.expander.js.coffee +0 -0
  128. data/{app → vendor}/assets/javascripts/mercury/toolbar.js.coffee +14 -1
  129. data/{app → vendor}/assets/javascripts/mercury/tooltip.js.coffee +3 -0
  130. data/{app → vendor}/assets/javascripts/mercury/uploader.js.coffee +22 -13
  131. data/vendor/assets/javascripts/{jquery-1.6.js → mercury_dependencies/jquery-1.6.js} +0 -0
  132. data/vendor/assets/javascripts/{jquery-ui-1.8.13.custom.js → mercury_dependencies/jquery-ui-1.8.13.custom.js} +0 -0
  133. data/vendor/assets/javascripts/{jquery.additions.js → mercury_dependencies/jquery.additions.js} +0 -0
  134. data/vendor/assets/javascripts/{liquidmetal.js → mercury_dependencies/liquidmetal.js} +0 -0
  135. data/vendor/assets/javascripts/{showdown.js → mercury_dependencies/showdown.js} +0 -0
  136. data/vendor/assets/javascripts/mercury_loader.js +191 -0
  137. data/{app → vendor}/assets/stylesheets/mercury.css +3 -6
  138. data/vendor/assets/stylesheets/mercury/dialog.css +199 -0
  139. data/vendor/assets/stylesheets/mercury/lightview.css +92 -0
  140. data/vendor/assets/stylesheets/mercury/mercury.css +134 -0
  141. data/vendor/assets/stylesheets/mercury/modal.css +191 -0
  142. data/{app/assets/stylesheets/mercury/statusbar.scss → vendor/assets/stylesheets/mercury/statusbar.css} +9 -1
  143. data/vendor/assets/stylesheets/mercury/toolbar.css +329 -0
  144. data/{app/assets/stylesheets/mercury/tooltip.scss → vendor/assets/stylesheets/mercury/tooltip.css} +7 -7
  145. data/vendor/assets/stylesheets/mercury/uploader.css +111 -0
  146. metadata +230 -225
  147. data/app/assets/images/mercury/toolbar/markupable/buttons.png +0 -0
  148. data/app/assets/images/mercury/toolbar/primary/todospanel.png +0 -0
  149. data/app/assets/javascripts/mercury.js +0 -30
  150. data/app/assets/javascripts/mercury/dialog.js.coffee +0 -75
  151. data/app/assets/javascripts/mercury/mercury.js.coffee +0 -286
  152. data/app/assets/javascripts/mercury/statusbar.js.coffee +0 -29
  153. data/app/assets/javascripts/mercury_loader.js +0 -98
  154. data/app/assets/stylesheets/mercury/dialog.scss +0 -179
  155. data/app/assets/stylesheets/mercury/mercury.scss +0 -127
  156. data/app/assets/stylesheets/mercury/modal.scss +0 -194
  157. data/app/assets/stylesheets/mercury/toolbar.scss +0 -415
  158. data/app/assets/stylesheets/mercury/uploader.scss +0 -109
  159. data/app/views/layouts/mercury.html.haml +0 -8
  160. data/app/views/mercury/modals/character.html.haml +0 -252
  161. data/app/views/mercury/modals/htmleditor.html.haml +0 -8
  162. data/app/views/mercury/modals/link.html.haml +0 -31
  163. data/app/views/mercury/modals/media.html.haml +0 -33
  164. data/app/views/mercury/modals/sanitizer.html.haml +0 -4
  165. data/app/views/mercury/modals/table.html.haml +0 -49
  166. data/app/views/mercury/palettes/backcolor.html.haml +0 -79
  167. data/app/views/mercury/palettes/forecolor.html.haml +0 -79
  168. data/app/views/mercury/panels/history.html.haml +0 -0
  169. data/app/views/mercury/panels/notes.html.haml +0 -0
  170. data/app/views/mercury/panels/snippets.html.haml +0 -10
  171. data/app/views/mercury/selects/formatblock.html.haml +0 -10
  172. data/app/views/mercury/selects/style.html.haml +0 -4
  173. data/app/views/mercury/snippets/example.html.haml +0 -2
  174. data/app/views/mercury/snippets/example_options.html.haml +0 -16
  175. data/log/.gitkeep +0 -0
  176. data/spec/javascripts/mercury/regions/_markupable_.js.coffee +0 -0
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.modalHandlers.htmlEditor", ->
4
4
 
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.modalHandlers.insertCharacter", ->
4
4
 
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.modalHandlers.insertLink", ->
4
4
 
@@ -56,7 +56,10 @@ describe "Mercury.modalHandlers.insertLink", ->
56
56
  describe "a standard link", ->
57
57
 
58
58
  beforeEach ->
59
- Mercury.region = selection: => {commonAncestor: -> $('<a>', {href: 'http://cnn.com', target: '_top'}).html('foo')}
59
+ Mercury.region = selection: => {
60
+ commonAncestor: -> $('<a>', {href: 'http://cnn.com', target: '_top'}).html('foo'),
61
+ textContent: -> 'content'
62
+ }
60
63
  Mercury.modalHandlers.insertLink.call(@modal)
61
64
 
62
65
  it "hides the link text input", ->
@@ -68,6 +71,9 @@ describe "Mercury.modalHandlers.insertLink", ->
68
71
  it "selects the target if one's available", ->
69
72
  expect($('#link_target').val()).toEqual('_top')
70
73
 
74
+ it "fills the content", ->
75
+ expect($('#link_text').val()).toEqual('content')
76
+
71
77
  describe "a javascript popup link", ->
72
78
 
73
79
  beforeEach ->
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.modalHandlers.insertMedia", ->
4
4
 
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.modalHandlers.insertSnippet", ->
4
4
 
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.modalHandlers.insertTable", ->
4
4
 
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "String", ->
4
4
 
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.PageEditor", ->
4
4
 
@@ -11,6 +11,7 @@ describe "Mercury.PageEditor", ->
11
11
  $(document).unbind('mercury:initialize:frame')
12
12
  $(document).unbind('mercury:focus:frame')
13
13
  $(document).unbind('mercury:focus:window')
14
+ $(document).unbind('mercury:toggle:interface')
14
15
  $(document).unbind('mercury:action')
15
16
  $(document).unbind('mousedown')
16
17
  $(window).unbind('resize')
@@ -41,7 +42,21 @@ describe "Mercury.PageEditor", ->
41
42
  it "accepts a saveUrl, and options", ->
42
43
  @pageEditor = new Mercury.PageEditor('/foo/1', {foo: 'bar'})
43
44
  expect(@pageEditor.saveUrl).toEqual('/foo/1')
44
- expect(@pageEditor.options).toEqual({foo: 'bar'})
45
+ expect(@pageEditor.options).toEqual({foo: 'bar', visible: true})
46
+
47
+ it "sets the visible option to true unless it's set", ->
48
+ @pageEditor = new Mercury.PageEditor('/foo/1', {foo: 'bar', visible: false})
49
+ expect(@pageEditor.options.visible).toEqual(false)
50
+ window.mercuryInstance = null
51
+ @pageEditor = new Mercury.PageEditor('/foo/1', {foo: 'bar', visible: true})
52
+ expect(@pageEditor.options.visible).toEqual(true)
53
+
54
+ it "sets visible based on the options", ->
55
+ @pageEditor = new Mercury.PageEditor('/foo/1', {foo: 'bar', visible: false})
56
+ expect(@pageEditor.visible).toEqual(false)
57
+ window.mercuryInstance = null
58
+ @pageEditor = new Mercury.PageEditor('/foo/1', {foo: 'bar', visible: true})
59
+ expect(@pageEditor.visible).toEqual(true)
45
60
 
46
61
  it "calls initializeInterface", ->
47
62
  @pageEditor = new Mercury.PageEditor()
@@ -84,6 +99,7 @@ describe "Mercury.PageEditor", ->
84
99
  describe "#initializeFrame", ->
85
100
 
86
101
  beforeEach ->
102
+ @resizeSpy = spyOn(Mercury.PageEditor.prototype, 'resize').andCallFake(=>)
87
103
  @bindEventsSpy = spyOn(Mercury.PageEditor.prototype, 'bindEvents').andCallFake(=>)
88
104
  @initializeRegionsSpy = spyOn(Mercury.PageEditor.prototype, 'initializeRegions').andCallFake(=>)
89
105
  @finalizeInterfaceSpy = spyOn(Mercury.PageEditor.prototype, 'finalizeInterface')
@@ -111,11 +127,21 @@ describe "Mercury.PageEditor", ->
111
127
  @pageEditor.initializeFrame()
112
128
  expect(spy.callCount).toEqual(1)
113
129
 
130
+ it "injects mercury namespace into the iframe", ->
131
+ @finalizeInterfaceSpy.andCallFake(=>)
132
+ @pageEditor.initializeFrame()
133
+ expect(@pageEditor.iframe.get(0).contentWindow.Mercury).toEqual(Mercury)
134
+
114
135
  it "calls bindEvents", ->
115
136
  @finalizeInterfaceSpy.andCallFake(=>)
116
137
  @pageEditor.initializeFrame()
117
138
  expect(@bindEventsSpy.callCount).toEqual(1)
118
139
 
140
+ it "calls resize", ->
141
+ @finalizeInterfaceSpy.andCallFake(=>)
142
+ @pageEditor.initializeFrame()
143
+ expect(@resizeSpy.callCount).toEqual(1)
144
+
119
145
  it "calls initializeRegions", ->
120
146
  @finalizeInterfaceSpy.andCallFake(=>)
121
147
  @pageEditor.initializeFrame()
@@ -126,10 +152,18 @@ describe "Mercury.PageEditor", ->
126
152
  @pageEditor.initializeFrame()
127
153
  expect(@finalizeInterfaceSpy.callCount).toEqual(1)
128
154
 
155
+ it "fires the ready event", ->
156
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
157
+ @finalizeInterfaceSpy.andCallFake(=>)
158
+ @pageEditor.initializeFrame()
159
+ expect(spy.callCount).toEqual(1)
160
+ expect(spy.argsForCall[0]).toEqual(['ready'])
161
+
129
162
  it "shows the iframe", ->
163
+ @pageEditor.iframe.css({visibility: 'visible'})
130
164
  @finalizeInterfaceSpy.andCallFake(=>)
131
165
  @pageEditor.initializeFrame()
132
- @pageEditor.iframe.css('loaded', true)
166
+ expect(@pageEditor.iframe.css('visibility')).toEqual('visible')
133
167
 
134
168
  it "captures errors and alerts them", ->
135
169
  @finalizeInterfaceSpy.andCallFake(=> throw('unknown error' ))
@@ -157,6 +191,13 @@ describe "Mercury.PageEditor", ->
157
191
  @pageEditor.initializeRegions()
158
192
  expect(firstFocusCalled).toEqual(true)
159
193
 
194
+ it "doesn't focus the first region if it's not supposed to be visible", ->
195
+ firstFocusCalled = false
196
+ @pageEditor.regions = [{focus: => firstFocusCalled = true}, {}, {}]
197
+ @pageEditor.options.visible = false
198
+ @pageEditor.initializeRegions()
199
+ expect(firstFocusCalled).toEqual(false)
200
+
160
201
 
161
202
  describe "#buildRegion", ->
162
203
 
@@ -185,20 +226,21 @@ describe "Mercury.PageEditor", ->
185
226
  Mercury.PageEditor.prototype.initializeFrame = ->
186
227
  Mercury.SnippetToolbar = -> {snippetToolbar: true}
187
228
  @pageEditor = new Mercury.PageEditor('', {appendTo: $('#test')})
188
- @highjackLinksSpy = spyOn(Mercury.PageEditor.prototype, 'hijackLinks').andCallFake(=>)
189
- @resizeSpy = spyOn(Mercury.PageEditor.prototype, 'resize').andCallFake(=>)
229
+ @highjackLinksAndFormsSpy = spyOn(Mercury.PageEditor.prototype, 'hijackLinksAndForms').andCallFake(=>)
190
230
 
191
231
  it "it builds a snippetToolbar", ->
192
232
  @pageEditor.finalizeInterface()
193
233
  expect(@pageEditor.snippetToolbar).toEqual({snippetToolbar: true})
194
234
 
195
- it "calls hijackLinks", ->
235
+ it "calls hijackLinksAndForms", ->
196
236
  @pageEditor.finalizeInterface()
197
- expect(@highjackLinksSpy.callCount).toEqual(1)
237
+ expect(@highjackLinksAndFormsSpy.callCount).toEqual(1)
198
238
 
199
- it "calls resize", ->
239
+ it "fires a mode event to put things into preview mode if it's not visible yet", ->
240
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
241
+ @pageEditor.options.visible = false
200
242
  @pageEditor.finalizeInterface()
201
- expect(@resizeSpy.callCount).toEqual(1)
243
+ expect(spy.callCount).toEqual(1)
202
244
 
203
245
 
204
246
  describe "observed events", ->
@@ -235,6 +277,13 @@ describe "Mercury.PageEditor", ->
235
277
  Mercury.trigger('focus:window')
236
278
  expect(callCount).toEqual(1)
237
279
 
280
+ describe "custom event: toggle:interface", ->
281
+
282
+ it "calls toggleInterface", ->
283
+ spy = spyOn(Mercury.PageEditor.prototype, 'toggleInterface').andCallFake(=>)
284
+ Mercury.trigger('toggle:interface')
285
+ expect(spy.callCount).toEqual(1)
286
+
238
287
  describe "custom event: action", ->
239
288
 
240
289
  it "calls save if the action was save", ->
@@ -279,6 +328,66 @@ describe "Mercury.PageEditor", ->
279
328
  #expect(spy.callCount).toEqual(1)
280
329
 
281
330
 
331
+ describe "#toggleInterface", ->
332
+
333
+ beforeEach ->
334
+ spec = @
335
+ spec.toolbarShowCallCount = 0
336
+ spec.toolbarHideCallCount = 0
337
+ spec.statusbarShowCallCount = 0
338
+ spec.statusbarHideCallCount = 0
339
+ Mercury.Toolbar = -> {toolbar: true, height: (-> 100), show: (=> spec.toolbarShowCallCount += 1), hide: (=> spec.toolbarHideCallCount += 1)}
340
+ Mercury.Statusbar = -> {statusbar: true, top: (-> 500), show: (=> spec.statusbarShowCallCount += 1), hide: (=> spec.statusbarHideCallCount += 1)}
341
+ Mercury.PageEditor.prototype.initializeFrame = ->
342
+ @pageEditor = new Mercury.PageEditor('', {appendTo: $('#test')})
343
+
344
+ it "calls resize", ->
345
+ spy = spyOn(Mercury.PageEditor.prototype, 'resize').andCallFake(=>)
346
+ @pageEditor.toggleInterface()
347
+ expect(spy.callCount).toEqual(1)
348
+
349
+ it "triggers the mode event to toggle preview mode", ->
350
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
351
+ @pageEditor.toggleInterface()
352
+ expect(spy.callCount).toEqual(2)
353
+ expect(spy.argsForCall[0]).toEqual(['mode', {mode: 'preview'}])
354
+ expect(spy.argsForCall[1]).toEqual(['resize'])
355
+
356
+ describe "when visible", ->
357
+
358
+ beforeEach ->
359
+ @pageEditor.visible = true
360
+
361
+ it "sets visible to false", ->
362
+ @pageEditor.toggleInterface()
363
+ expect(@pageEditor.visible).toEqual(false)
364
+
365
+ it "calls hide on the toolbar", ->
366
+ @pageEditor.toggleInterface()
367
+ expect(@toolbarHideCallCount).toEqual(1)
368
+
369
+ it "calls hide on the statusbar", ->
370
+ @pageEditor.toggleInterface()
371
+ expect(@statusbarHideCallCount).toEqual(1)
372
+
373
+ describe "when not visible", ->
374
+
375
+ beforeEach ->
376
+ @pageEditor.visible = false
377
+
378
+ it "sets visible to true", ->
379
+ @pageEditor.toggleInterface()
380
+ expect(@pageEditor.visible).toEqual(true)
381
+
382
+ it "calls show on the toolbar", ->
383
+ @pageEditor.toggleInterface()
384
+ expect(@toolbarShowCallCount).toEqual(1)
385
+
386
+ it "calls show on the statusbar", ->
387
+ @pageEditor.toggleInterface()
388
+ expect(@statusbarShowCallCount).toEqual(1)
389
+
390
+
282
391
  describe "#resize", ->
283
392
 
284
393
  beforeEach ->
@@ -313,31 +422,49 @@ describe "Mercury.PageEditor", ->
313
422
  expect(@pageEditor.iframeSrc('http://foo.com/editor/path')).toEqual('http://foo.com/path')
314
423
 
315
424
 
316
- describe "#hijackLinks", ->
425
+ describe "#hijackLinksAndForms", ->
317
426
 
318
427
  beforeEach ->
428
+ Mercury.config.nonHijackableClasses = ['lightview']
429
+
319
430
  Mercury.PageEditor.prototype.initializeFrame = ->
320
431
  @pageEditor = new Mercury.PageEditor('', {appendTo: $('#test')})
321
- @pageEditor.options.ignoredLinks = ['lightview']
322
432
  @pageEditor.document = $(document)
323
433
 
324
- it "finds links and set their target to top if it's not already set", ->
325
- @pageEditor.hijackLinks()
434
+ afterEach ->
435
+ Mercury.config.nonHijackableClasses = []
436
+
437
+ it "finds links and forms and sets their target to top if it's not already set", ->
438
+ @pageEditor.hijackLinksAndForms()
326
439
  expect($('#anchor1').attr('target')).toEqual('_top')
327
440
  expect($('#anchor2').attr('target')).toEqual('_blank')
328
441
  expect($('#anchor3').attr('target')).toEqual('_top')
329
442
  expect($('#anchor4').attr('target')).toEqual('_top')
443
+ expect($('#form1').attr('target')).toEqual('_top')
444
+ expect($('#form2').attr('target')).toEqual('_blank')
445
+ expect($('#form3').attr('target')).toEqual('_top')
446
+ expect($('#form4').attr('target')).toEqual('_top')
330
447
 
331
448
  it "ignores links in regions", ->
332
- @pageEditor.hijackLinks()
449
+ @pageEditor.hijackLinksAndForms()
333
450
  expect($('#anchor1r').attr('target')).toEqual('_top')
334
451
  expect($('#anchor2r').attr('target')).toEqual('_blank')
335
452
  expect($('#anchor3r').attr('target')).toEqual('_self')
336
453
  expect($('#anchor4r').attr('target')).toBeUndefined()
454
+ expect($('#form1r').attr('target')).toEqual('_top')
455
+ expect($('#form2r').attr('target')).toEqual('_blank')
456
+ expect($('#form3r').attr('target')).toEqual('_self')
457
+ expect($('#form4r').attr('target')).toBeUndefined()
337
458
 
338
- it "ignores links that are in the config to be ignored (by class)", ->
339
- @pageEditor.hijackLinks()
459
+ it "ignores links and forms that are in the config to be ignored (by class)", ->
460
+ @pageEditor.hijackLinksAndForms()
340
461
  expect($('#anchor5').attr('target')).toEqual('_self')
462
+ expect($('#form5').attr('target')).toEqual('_self')
463
+
464
+ it "doesn't change targets of links and forms that are set to anything besides _self", ->
465
+ @pageEditor.hijackLinksAndForms()
466
+ expect($('#anchor6').attr('target')).toEqual('foo')
467
+ expect($('#form6').attr('target')).toEqual('foo')
341
468
 
342
469
 
343
470
  describe "#beforeUnload", ->
@@ -372,30 +499,43 @@ describe "Mercury.PageEditor", ->
372
499
  @pageEditor.save()
373
500
  expect(@ajaxSpy.callCount).toEqual(1)
374
501
 
375
- it "uses the save url passed in via options, or the iframe src", ->
502
+ it "uses the save url passed in via options, the configured save url, or the iframe src", ->
376
503
  @ajaxSpy.andCallFake(=>)
377
504
  @pageEditor.saveUrl = '/foo/bar'
378
505
  @pageEditor.save()
379
506
  expect(@ajaxSpy.argsForCall[0][0]).toEqual('/foo/bar')
380
507
 
381
508
  @pageEditor.saveUrl = null
509
+ Mercury.saveURL = '/foo/bit'
510
+ @pageEditor.save()
511
+ expect(@ajaxSpy.argsForCall[1][0]).toEqual('/foo/bit')
512
+
513
+ @pageEditor.saveUrl = null
514
+ Mercury.saveURL = null
382
515
  @pageEditor.save()
383
- expect(@ajaxSpy.argsForCall[1][0]).toEqual('/foo/baz')
516
+ expect(@ajaxSpy.argsForCall[2][0]).toEqual('/foo/baz')
384
517
 
385
518
  it "serializes the data in json", ->
386
519
  @ajaxSpy.andCallFake(=>)
387
520
  Mercury.config.saveStyle = 'json'
388
- spy = spyOn(Mercury.PageEditor.prototype, 'serialize').andCallFake(=> {region1: 'region1'})
521
+ spyOn(Mercury.PageEditor.prototype, 'serialize').andCallFake(=> {region1: 'region1'})
389
522
  @pageEditor.save()
390
523
  expect(@ajaxSpy.argsForCall[0][1]['data']).toEqual({content: '{"region1":"region1"}' })
391
524
 
392
525
  it "can serialize as form values", ->
393
526
  @ajaxSpy.andCallFake(=>)
394
527
  @pageEditor.options.saveStyle = 'form'
395
- spy = spyOn(Mercury.PageEditor.prototype, 'serialize').andCallFake(=> {region1: 'region1'})
528
+ spyOn(Mercury.PageEditor.prototype, 'serialize').andCallFake(=> {region1: 'region1'})
396
529
  @pageEditor.save()
397
530
  expect(@ajaxSpy.argsForCall[0][1]['data']).toEqual({content: {region1: 'region1'}})
398
531
 
532
+ it "sets headers by calling #saveHeaders", ->
533
+ @ajaxSpy.andCallFake(=>)
534
+ spyOn(Mercury.PageEditor.prototype, 'serialize').andCallFake(=> {region1: 'region1'})
535
+ spy = spyOn(Mercury.PageEditor.prototype, 'saveHeaders').andCallFake(=> {'X-CSRFToken': 'f00'})
536
+ @pageEditor.save()
537
+ expect(@ajaxSpy.argsForCall[0][1]['headers']).toEqual({'X-CSRFToken': 'f00'})
538
+
399
539
  describe "on successful ajax request", ->
400
540
 
401
541
  beforeEach ->
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.Palette", ->
4
4
 
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.Panel", ->
4
4
 
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.Region", ->
4
4
 
@@ -1,4 +1,4 @@
1
- require '/assets/mercury/mercury.js'
1
+ require '/assets/mercury.js'
2
2
 
3
3
  describe "Mercury.Regions.Editable", ->
4
4
 
@@ -86,13 +86,13 @@ describe "Mercury.Regions.Editable", ->
86
86
 
87
87
  it "does nothing if previewing", ->
88
88
 
89
- it "it prevents the default action if shift is pressed", ->
89
+ it "prevents the default action if shift is pressed", ->
90
90
 
91
91
  describe "dragover", ->
92
92
 
93
93
  it "does nothing if previewing", ->
94
94
 
95
- it "it prevents the default action if shift is pressed", ->
95
+ it "prevents the default action if shift is pressed", ->
96
96
 
97
97
  describe "drop", ->
98
98
 
@@ -165,6 +165,8 @@ describe "Mercury.Regions.Editable", ->
165
165
 
166
166
  it "does nothing if previewing", ->
167
167
 
168
+ it "tells mercury that changes have been made", ->
169
+
168
170
  it "calls pushHistory", ->
169
171
 
170
172
  it "calls execCommand with undo on meta+z", ->
@@ -210,7 +212,11 @@ describe "Mercury.Regions.Editable", ->
210
212
 
211
213
  describe "#focus", ->
212
214
 
213
- it "calls focus on the element", ->
215
+ describe "if this isn't the active region", ->
216
+
217
+ it "calls focus on the element", ->
218
+
219
+ it "collapses the selection", ->
214
220
 
215
221
  it "sets a timeout that forces the selection", ->
216
222
 
@@ -341,6 +347,7 @@ describe "Mercury.Regions.Editable", ->
341
347
  it "strips style attributes from the pasted content and inserts the cleaned html", ->
342
348
 
343
349
 
350
+
344
351
  describe "Mercury.Regions.Editable.actions", ->
345
352
 
346
353
  template 'mercury/regions/editable.html'
@@ -349,50 +356,228 @@ describe "Mercury.Regions.Editable.actions", ->
349
356
  #@region = new Mercury.Regions.Editable($('#editable_region1'), window)
350
357
  #@actions = Mercury.Regions.Editable.actions
351
358
 
359
+ #
352
360
  # behaviors
361
+ #
362
+
353
363
  describe "*horizontalRule", ->
364
+
365
+ it "replaces the selection with an hr tag", ->
366
+
367
+
354
368
  describe "*htmlEditor", ->
355
369
 
370
+ it "opens a modal", ->
371
+
372
+ #
356
373
  # native actions
374
+ #
375
+
357
376
  describe "-formatblock", ->
377
+
378
+ it "wraps the line of the selection in a given tag", ->
379
+
380
+
358
381
  describe "-foreColor", ->
382
+
383
+ it "wraps the selection in a span styled with the color", ->
384
+
385
+
359
386
  describe "-bold", ->
387
+
388
+ it "wraps the selection in a strong or s tag", ->
389
+
390
+
360
391
  describe "-italic", ->
392
+
393
+ it "wraps the selection in an em or i tag", ->
394
+
395
+
361
396
  describe "-strikethrough", ->
397
+
398
+ it "wraps the selection in a strike tag", ->
399
+
400
+
362
401
  describe "-underline", ->
402
+
403
+ it "wraps the selection in a u tag", ->
404
+
405
+
363
406
  describe "-subscript", ->
407
+
408
+ it "wraps the selection in a sub tag", ->
409
+
410
+
364
411
  describe "-superscript", ->
412
+
413
+ it "wraps the selection in a sup tag", ->
414
+
415
+
365
416
  describe "-justifyLeft", ->
417
+
418
+ it "justifies the text to the left", ->
419
+
420
+
366
421
  describe "-justifyCenter", ->
422
+
423
+ it "justifies the test to be in the center", ->
424
+
425
+
367
426
  describe "-justifyRight", ->
427
+
428
+ it "justifies the text to the right", ->
429
+
430
+
368
431
  describe "-justifyFull", ->
432
+
433
+ it "styles the text to be fully justified", ->
434
+
435
+
369
436
  describe "-insertUnorderedList", ->
437
+
438
+ it "wraps the line of the selection in an unordered list", ->
439
+
440
+
370
441
  describe "-insertOrderedList", ->
442
+
443
+ it "wraps the line of the selection in an ordered list", ->
444
+
445
+
371
446
  describe "-outdent", ->
447
+
448
+ it "unwraps the line of the selection in a blockquote tag", ->
449
+
450
+
372
451
  describe "-indent", ->
373
452
 
453
+ it "wraps the line of the selection in a blockquote tag", ->
454
+
455
+ #
374
456
  # custom actions
457
+ #
458
+
459
+ describe ".undo", ->
460
+
461
+ it "calls undo on the history buffer", ->
462
+
463
+ it "sets the contents", ->
464
+
465
+
466
+ describe ".redo", ->
467
+
468
+ it "calls redo on the history buffer", ->
469
+
470
+ it "sets the contents", ->
471
+
472
+
375
473
  describe ".style", ->
474
+
475
+ it "wraps the selection in a span tag with a given class", ->
476
+
477
+
376
478
  describe ".backColor", ->
479
+
480
+ it "wraps the selection in a span styled with the background color", ->
481
+
482
+
377
483
  describe ".removeFormatting", ->
484
+
485
+ it "replaces the selection with the text content of the selection", ->
486
+
487
+
378
488
  describe ".overline", ->
489
+
490
+ it "wraps the selection in a span styled with an overline", ->
491
+
492
+
379
493
  describe ".insertRowBefore", ->
494
+
495
+ it "calls addRow on the table editor", ->
496
+
497
+
380
498
  describe ".insertRowAfter", ->
499
+
500
+ it "calls addRow on the table editor", ->
501
+
502
+
381
503
  describe ".deleteRow", ->
504
+
505
+ it "calls removeRow on the table editor", ->
506
+
507
+
382
508
  describe ".insertColumnBefore", ->
509
+
510
+ it "calls addColumn on the table editor", ->
511
+
512
+
383
513
  describe ".insertColumnAfter", ->
514
+
515
+ it "calls addColumn on the table editor", ->
516
+
517
+
384
518
  describe ".deleteColumn", ->
519
+
520
+ it "calls removeColumn on the table editor", ->
521
+
522
+
385
523
  describe ".increaseColspan", ->
524
+
525
+ it "calls increaseColspan on the table editor", ->
526
+
527
+
386
528
  describe ".decreaseColspan", ->
529
+
530
+ it "calls decreaseColspan on the table editor", ->
531
+
532
+
387
533
  describe ".increaseRowspan", ->
534
+
535
+ it "calls increaseRowspan on the table editor", ->
536
+
537
+
388
538
  describe ".decreaseRowspan", ->
389
- describe ".undo", ->
390
- describe ".redo", ->
539
+
540
+ it "calls decreaseRowspan on the table editor", ->
541
+
542
+
391
543
  describe ".replaceHTML", ->
544
+
545
+ it "sets the content", ->
546
+
547
+
392
548
  describe ".insertImage", ->
549
+
550
+ it "replaces the selection with an image tag", ->
551
+
552
+
393
553
  describe ".insertLink", ->
554
+
555
+ it "inserts a link node", ->
556
+
557
+
394
558
  describe ".replaceLink", ->
559
+
560
+ it "selects the anchor tag that we're going to replace", ->
561
+
562
+ it "replaces the selection with an anchor tag", ->
563
+
564
+
395
565
  describe ".insertSnippet", ->
566
+
567
+ it "selects any snippets that have the same identity", ->
568
+
569
+ it "replaces the selection with the content returned from the snippets getHTML", ->
570
+
571
+
396
572
  describe ".editSnippet", ->
573
+
574
+ it "does nothing if there's no snippet being hovered over", ->
575
+
576
+ it "calls displayOntions for the snippet", ->
577
+
578
+
397
579
  describe ".removeSnippet", ->
398
580
 
581
+ it "calls remove on the snippet element", ->
582
+
583
+ it "fires a hide:toolbar event", ->