mercury-rails 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. data/app/controllers/{images_controller.rb → mercury/images_controller.rb} +3 -3
  2. data/app/controllers/mercury_controller.rb +13 -3
  3. data/app/models/{image.rb → mercury/image.rb} +3 -1
  4. data/app/views/layouts/mercury.html.erb +14 -6
  5. data/app/views/mercury/lightviews/about.html +7 -3
  6. data/app/views/mercury/modals/character.html +2 -2
  7. data/app/views/mercury/modals/htmleditor.html +2 -2
  8. data/app/views/mercury/modals/link.html +3 -3
  9. data/app/views/mercury/modals/media.html +3 -3
  10. data/app/views/mercury/modals/table.html +3 -3
  11. data/app/views/mercury/panels/snippets.html +1 -1
  12. data/app/views/mercury/selects/formatblock.html +9 -9
  13. data/app/views/mercury/snippets/example/options.html.erb +27 -16
  14. data/config/engine.rb +35 -0
  15. data/db/migrate/{20110526035601_create_images.rb → 20110526035601_create_mercury_images.rb} +2 -2
  16. data/features/loading/loading.feature +1 -1
  17. data/features/loading/navigating.feature +1 -1
  18. data/features/loading/user_interface.feature +2 -2
  19. data/features/regions/editable/basic_editing.feature +8 -8
  20. data/features/regions/editable/inserting_snippets.feature +4 -5
  21. data/features/regions/editable/inserting_tables.feature +9 -9
  22. data/features/step_definitions/mercury_steps.rb +20 -23
  23. data/features/step_definitions/web_steps.rb +5 -5
  24. data/features/support/mercury_selectors.rb +1 -0
  25. data/lib/generators/mercury/install/install_generator.rb +24 -3
  26. data/lib/generators/mercury/install/templates/mongoid_paperclip_image.rb +17 -0
  27. data/lib/mercury-rails.rb +0 -1
  28. data/lib/mercury/authentication.rb +8 -0
  29. data/spec/javascripts/mercury/dialog_spec.js.coffee +28 -21
  30. data/spec/javascripts/mercury/dialogs/backcolor_spec.js.coffee +0 -2
  31. data/spec/javascripts/mercury/dialogs/forecolor_spec.js.coffee +0 -2
  32. data/spec/javascripts/mercury/dialogs/formatblock_spec.js.coffee +0 -2
  33. data/spec/javascripts/mercury/dialogs/snippetpanel_spec.js.coffee +0 -2
  34. data/spec/javascripts/mercury/dialogs/style_spec.js.coffee +0 -2
  35. data/spec/javascripts/mercury/history_buffer_spec.js.coffee +0 -2
  36. data/spec/javascripts/mercury/lightview_spec.js.coffee +42 -21
  37. data/spec/javascripts/mercury/mercury_spec.js.coffee +87 -7
  38. data/spec/javascripts/mercury/modal_spec.js.coffee +53 -23
  39. data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +0 -2
  40. data/spec/javascripts/mercury/modals/insertcharacter_spec.js.coffee +2 -3
  41. data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +0 -2
  42. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +2 -2
  43. data/spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee +0 -2
  44. data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +2 -4
  45. data/spec/javascripts/mercury/native_extensions_spec.js.coffee +20 -2
  46. data/spec/javascripts/mercury/page_editor_spec.js.coffee +130 -35
  47. data/spec/javascripts/mercury/palette_spec.js.coffee +4 -6
  48. data/spec/javascripts/mercury/panel_spec.js.coffee +44 -6
  49. data/spec/javascripts/mercury/region_spec.js.coffee +42 -8
  50. data/spec/javascripts/mercury/regions/editable_spec.js.coffee +0 -2
  51. data/spec/javascripts/mercury/regions/markupable_spec.js.coffee +0 -2
  52. data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +3 -5
  53. data/spec/javascripts/mercury/select_spec.js.coffee +4 -6
  54. data/spec/javascripts/mercury/snippet_spec.js.coffee +3 -4
  55. data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +2 -4
  56. data/spec/javascripts/mercury/statusbar_spec.js.coffee +0 -2
  57. data/spec/javascripts/mercury/table_editor_spec.js.coffee +2 -4
  58. data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +0 -2
  59. data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +34 -15
  60. data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +0 -2
  61. data/spec/javascripts/mercury/toolbar_spec.js.coffee +41 -26
  62. data/spec/javascripts/mercury/tooltip_spec.js.coffee +3 -5
  63. data/spec/javascripts/mercury/uploader_spec.js.coffee +8 -14
  64. data/spec/javascripts/spec_helper.js +1 -0
  65. data/spec/javascripts/templates/mercury/page_editor.html +1 -0
  66. data/spec/javascripts/templates/mercury/region.html +2 -2
  67. data/vendor/assets/images/mercury/missing-image.png +0 -0
  68. data/vendor/assets/javascripts/mercury.js +218 -112
  69. data/vendor/assets/javascripts/mercury/dependencies/{jquery-1.6.js → jquery-1.7.js} +2030 -1595
  70. data/vendor/assets/javascripts/mercury/dependencies/jquery.additions.js +55 -0
  71. data/vendor/assets/javascripts/mercury/dialog.js.coffee +7 -5
  72. data/vendor/assets/javascripts/mercury/dialogs/backcolor.js.coffee +1 -1
  73. data/vendor/assets/javascripts/mercury/dialogs/forecolor.js.coffee +1 -1
  74. data/vendor/assets/javascripts/mercury/dialogs/formatblock.js.coffee +1 -1
  75. data/vendor/assets/javascripts/mercury/dialogs/{objectspanel.js.coffee → snippetpanel.js.coffee} +2 -2
  76. data/vendor/assets/javascripts/mercury/dialogs/style.js.coffee +1 -1
  77. data/vendor/assets/javascripts/mercury/finalize.js.coffee +3 -0
  78. data/vendor/assets/javascripts/mercury/lightview.js.coffee +76 -30
  79. data/vendor/assets/javascripts/mercury/locales/da.locale.js.coffee +211 -0
  80. data/vendor/assets/javascripts/mercury/locales/de.locale.js.coffee +206 -0
  81. data/vendor/assets/javascripts/mercury/locales/es.locale.js.coffee +211 -0
  82. data/vendor/assets/javascripts/mercury/locales/example.local.js.coffee +211 -0
  83. data/vendor/assets/javascripts/mercury/locales/fr.locale.js.coffee +211 -0
  84. data/vendor/assets/javascripts/mercury/locales/it.locale.js.coffee +208 -0
  85. data/vendor/assets/javascripts/mercury/locales/ko.local.js.coffee +206 -0
  86. data/vendor/assets/javascripts/mercury/locales/nl.locale.js.coffee +206 -0
  87. data/vendor/assets/javascripts/mercury/locales/pt.locale.js.coffee +211 -0
  88. data/vendor/assets/javascripts/mercury/locales/sv.local.js.coffee +209 -0
  89. data/vendor/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +213 -0
  90. data/vendor/assets/javascripts/mercury/mercury.js.coffee +62 -17
  91. data/vendor/assets/javascripts/mercury/modal.js.coffee +34 -21
  92. data/vendor/assets/javascripts/mercury/modals/htmleditor.js.coffee +1 -2
  93. data/vendor/assets/javascripts/mercury/modals/insertcharacter.js.coffee +3 -3
  94. data/vendor/assets/javascripts/mercury/modals/insertlink.js.coffee +4 -4
  95. data/vendor/assets/javascripts/mercury/modals/insertmedia.js.coffee +10 -9
  96. data/vendor/assets/javascripts/mercury/modals/insertsnippet.js.coffee +1 -1
  97. data/vendor/assets/javascripts/mercury/modals/inserttable.js.coffee +8 -9
  98. data/vendor/assets/javascripts/mercury/native_extensions.js.coffee +26 -8
  99. data/vendor/assets/javascripts/mercury/page_editor.js.coffee +68 -46
  100. data/vendor/assets/javascripts/mercury/palette.js.coffee +1 -1
  101. data/vendor/assets/javascripts/mercury/panel.js.coffee +25 -7
  102. data/vendor/assets/javascripts/mercury/plugins/save_as_xml/mercury/page_editor.js.coffee +1 -0
  103. data/vendor/assets/javascripts/mercury/region.js.coffee +21 -17
  104. data/vendor/assets/javascripts/mercury/regions/editable.js.coffee +47 -35
  105. data/vendor/assets/javascripts/mercury/regions/markupable.js.coffee +43 -36
  106. data/vendor/assets/javascripts/mercury/regions/snippetable.js.coffee +22 -24
  107. data/vendor/assets/javascripts/mercury/select.js.coffee +3 -2
  108. data/vendor/assets/javascripts/mercury/snippet.js.coffee +2 -1
  109. data/vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee +10 -7
  110. data/vendor/assets/javascripts/mercury/statusbar.js.coffee +4 -4
  111. data/vendor/assets/javascripts/mercury/table_editor.js.coffee +1 -3
  112. data/vendor/assets/javascripts/mercury/toolbar.button.js.coffee +42 -20
  113. data/vendor/assets/javascripts/mercury/toolbar.button_group.js.coffee +3 -3
  114. data/vendor/assets/javascripts/mercury/toolbar.expander.js.coffee +2 -2
  115. data/vendor/assets/javascripts/mercury/toolbar.js.coffee +8 -6
  116. data/vendor/assets/javascripts/mercury/tooltip.js.coffee +13 -9
  117. data/vendor/assets/javascripts/mercury/uploader.js.coffee +22 -16
  118. data/vendor/assets/javascripts/mercury_loader.js +2 -0
  119. data/vendor/assets/javascripts/mercury_overrides.js +6 -0
  120. data/vendor/assets/stylesheets/mercury/all_images.css.erb +89 -0
  121. data/vendor/assets/stylesheets/mercury/dialog.css +13 -4
  122. data/vendor/assets/stylesheets/mercury/lightview.css +66 -15
  123. data/vendor/assets/stylesheets/mercury/mercury.css +12 -7
  124. data/vendor/assets/stylesheets/mercury/modal.css +9 -5
  125. data/vendor/assets/stylesheets/mercury/toolbar.css +3 -29
  126. metadata +266 -144
  127. data/POST_INSTALL +0 -15
  128. data/README.md +0 -299
  129. data/VERSION +0 -1
  130. data/annotated_source.template +0 -57
  131. data/config/routes.rb +0 -15
  132. data/mercury-rails.gemspec +0 -288
  133. data/spec/javascripts/responses/blank.html +0 -1
  134. data/vendor/assets/javascripts/mercury/lightviews/imageprocessor.js.coffee +0 -2
@@ -1,5 +1,3 @@
1
- require '/assets/mercury.js'
2
-
3
1
  describe "Mercury.Toolbar.Expander", ->
4
2
 
5
3
  template 'mercury/toolbar.expander.html'
@@ -1,12 +1,10 @@
1
- require '/assets/mercury.js'
2
-
3
1
  describe "Mercury.Toolbar", ->
4
2
 
5
3
  template 'mercury/toolbar.html'
6
4
 
7
5
  beforeEach ->
8
6
  $.fx.off = true
9
- ajaxSpy = spyOn($, 'ajax').andCallFake (url, options) =>
7
+ spyOn($, 'ajax').andCallFake (url, options) =>
10
8
  options.success('data') if options.success
11
9
 
12
10
  afterEach ->
@@ -32,36 +30,53 @@ describe "Mercury.Toolbar", ->
32
30
 
33
31
  describe "#build", ->
34
32
 
35
- beforeEach ->
36
- @buildButtonSpy = spyOn(Mercury.Toolbar.prototype, 'buildButton').andCallFake(=> $('<div>'))
37
- @toolbar = new Mercury.Toolbar({appendTo: '#toolbar_container', visible: false})
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
38
 
39
- it "builds an element", ->
40
- expect($('.mercury-toolbar-container').length).toEqual(1)
39
+ it "builds an element", ->
40
+ expect($('.mercury-toolbar-container').length).toEqual(1)
41
41
 
42
- it "hides the element if options.visible is false", ->
43
- expect($('.mercury-toolbar-container').css('display')).toEqual('none')
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)
44
47
 
45
- it "can append to any element", ->
46
- expect($('#toolbar_container .mercury-toolbar-container').length).toEqual(1)
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')
47
52
 
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')
53
+ it "builds buttons etc.", ->
54
+ expect(@buildButtonSpy.callCount).toBeGreaterThan(10)
52
55
 
53
- it "builds buttons etc.", ->
54
- expect(@buildButtonSpy.callCount).toBeGreaterThan(10)
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})
55
73
 
56
- it "sets it's width back to 100%", ->
57
- expect(@toolbar.element.get(0).style.width).toEqual('100%')
74
+ afterEach ->
75
+ Mercury.config.toolbars.primary = @primaryToolbar
58
76
 
59
- it "disables all but the primary toolbar", ->
60
- expect($('.mercury-editable-toolbar').hasClass('disabled')).toEqual(true)
77
+ it "doesn't disable the toolbars", ->
78
+ expect($('.mercury-editable-toolbar').hasClass('disabled')).toEqual(false)
61
79
 
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
80
 
66
81
 
67
82
  describe "#buildButton", ->
@@ -70,7 +85,7 @@ describe "Mercury.Toolbar", ->
70
85
  @toolbar = new Mercury.Toolbar({appendTo: '#test'})
71
86
 
72
87
  it "throws an exception when invalid options are passed", ->
73
- expect(=> @toolbar.buildButton('foo', false)).toThrow('Unknown button structure -- please provide an array, object, or string for foo.')
88
+ expect(=> @toolbar.buildButton('foo', false)).toThrow('Unknown button structure -- please provide an array, object, or string for "foo".')
74
89
 
75
90
  it "returns false if the name is _custom, or _regions", ->
76
91
  expect(@toolbar.buildButton('_custom', 'foo')).toEqual(false)
@@ -1,5 +1,3 @@
1
- require '/assets/mercury.js'
2
-
3
1
  describe "Mercury.tooltip", ->
4
2
 
5
3
  template 'mercury/tooltip.html'
@@ -35,7 +33,7 @@ describe "Mercury.tooltip", ->
35
33
 
36
34
  it "gets the document from the element passed in", ->
37
35
  Mercury.tooltip.show(@forElement, 'content')
38
- expect(Mercury.tooltip.document.get(0)).toEqual($(document).get(0))
36
+ expect(Mercury.tooltip.document).toEqual(document)
39
37
 
40
38
  it "calls initialize", ->
41
39
  Mercury.tooltip.show(@forElement, 'content')
@@ -113,13 +111,13 @@ describe "Mercury.tooltip", ->
113
111
 
114
112
  describe "document scrolling", ->
115
113
 
114
+ # untestable
116
115
  it "calls position if visible", ->
117
- # untestable
118
116
 
119
117
  describe "element mousedown", ->
120
118
 
119
+ # untestable
121
120
  it "stops the event", ->
122
- # untestable
123
121
 
124
122
 
125
123
  describe "#appear", ->
@@ -1,5 +1,3 @@
1
- require '/assets/mercury.js'
2
-
3
1
  describe "Mercury.uploader", ->
4
2
 
5
3
  template 'mercury/uploader.html'
@@ -241,7 +239,7 @@ describe "Mercury.uploader", ->
241
239
  describe "#upload", ->
242
240
 
243
241
  # todo: test this
244
- it "", ->
242
+ it "should build a multipart form and submit it", ->
245
243
 
246
244
 
247
245
  describe "#updateStatus", ->
@@ -256,7 +254,7 @@ describe "Mercury.uploader", ->
256
254
 
257
255
  it "updates the progress indicator width", ->
258
256
  Mercury.uploader.updateStatus('message', 512)
259
- expect($('#test .mercury-uploader-indicator div').css('width')).toEqual('50%')
257
+ expect($('#test .mercury-uploader-indicator div').css('width')).toEqual('50px')
260
258
 
261
259
  it "updates the progress indicator value", ->
262
260
  Mercury.uploader.updateStatus('message', 512)
@@ -274,27 +272,27 @@ describe "Mercury.uploader", ->
274
272
  @setTimeoutSpy.andCallFake(=>)
275
273
  Mercury.uploader.hide(1)
276
274
  expect(@setTimeoutSpy.callCount).toEqual(1)
277
- expect(@setTimeoutSpy.argsForCall[0][1]).toEqual(1000)
275
+ expect(@setTimeoutSpy.argsForCall[0][0]).toEqual(1000)
278
276
 
279
277
  it "hides the overlay and element", ->
280
- @setTimeoutSpy.andCallFake((callback) => callback())
278
+ @setTimeoutSpy.andCallFake((timeout, callback) => callback())
281
279
  Mercury.uploader.hide()
282
280
  expect($('#test .mercury-uploader').css('opacity')).toEqual('0')
283
281
  expect($('#test .mercury-uploader-overlay').css('opacity')).toEqual('0')
284
282
 
285
283
  it "calls reset", ->
286
- @setTimeoutSpy.andCallFake((callback) => callback())
284
+ @setTimeoutSpy.andCallFake((timeout, callback) => callback())
287
285
  spy = spyOn(Mercury.uploader, 'reset').andCallFake(=>)
288
286
  Mercury.uploader.hide()
289
287
  expect(spy.callCount).toEqual(1)
290
288
 
291
289
  it "sets visible to false", ->
292
- @setTimeoutSpy.andCallFake((callback) => callback())
290
+ @setTimeoutSpy.andCallFake((timeout, callback) => callback())
293
291
  Mercury.uploader.hide()
294
292
  expect(Mercury.uploader.visible).toEqual(false)
295
293
 
296
294
  it "focuses the frame", ->
297
- @setTimeoutSpy.andCallFake((callback) => callback())
295
+ @setTimeoutSpy.andCallFake((timeout, callback) => callback())
298
296
  spy = spyOn(Mercury, 'trigger').andCallFake(=>)
299
297
  Mercury.uploader.hide()
300
298
  expect(spy.callCount).toEqual(1)
@@ -363,11 +361,7 @@ describe "Mercury.uploader", ->
363
361
  it "updates the status to 'Successfully uploaded' and passes the total file size", ->
364
362
  @events.onload.call(Mercury.uploader)
365
363
  expect(@updateStatusSpy.callCount).toEqual(1)
366
- expect(@updateStatusSpy.argsForCall[0]).toEqual(['Successfully uploaded', 1024])
367
-
368
- it "calls hide", ->
369
- @events.onload.call(Mercury.uploader)
370
- expect(@hideSpy.callCount).toEqual(1)
364
+ expect(@updateStatusSpy.argsForCall[0]).toEqual(['Successfully uploaded...', 1024])
371
365
 
372
366
  describe ".onerror", ->
373
367
 
@@ -1,3 +1,4 @@
1
+ require('/assets/mercury.js');
1
2
 
2
3
  jasmine.simulate = {
3
4
 
@@ -19,6 +19,7 @@
19
19
  <form id="form3r" action="" target="_self"></form>
20
20
  <form id="form4r" action=""></form>
21
21
  </div>
22
+ <div id="region4" class="custom-region-class"></div>
22
23
 
23
24
  <a id="anchor1" href="#" target="_top">1</a>
24
25
  <a id="anchor2" href="#" target="_blank">2</a>
@@ -1,2 +1,2 @@
1
- <div id="region">contents</div>
2
- <div id="region_with_snippet">contents<div class="mercury-snippet" data-snippet="snippet_1" data-version="1">snippet</div></div>
1
+ <div id="region" data-scope="scope" data-version="1">contents</div>
2
+ <div id="region_with_snippet">contents<div class="mercury-snippet" data-snippet="snippet_1" data-version="1">snippet</div></div>
@@ -24,16 +24,31 @@
24
24
  *
25
25
  *= require_self
26
26
  *
27
+ * Minimum jQuery requirements are 1.7
28
+ *= require mercury/dependencies/jquery-1.7
29
+ *
30
+ * You can include the Rails jQuery ujs script here to get some nicer behaviors in modals, panels and lightviews when
31
+ * using :remote => true within the contents rendered in them.
32
+ * require jquery_ujs
33
+ *
34
+ * If you want to override Mercury functionality, you can do so in a custom file that binds to the mercury:loaded event,
35
+ * or do so at the end of the current file (mercury.js). There's an example that will help you get started.
36
+ * require mercury_overrides
37
+ *
27
38
  * Add all requires for the support libraries that integrate nicely with Mercury Editor.
28
39
  * require mercury/support/history
29
40
  *
30
41
  * Require Mercury Editor itself.
31
42
  *= require mercury/mercury
32
43
  *
44
+ * Require any localizations you wish to support
45
+ * Example: es.locale, or fr.locale -- regional dialects are in each language file so never en_US for instance.
46
+ * require mercury/locales/swedish_chef.locale
47
+ *
33
48
  * Add all requires for plugins that extend or change the behavior of Mercury Editor.
34
49
  * require mercury/plugins/save_as_xml/plugin.js
35
50
  */
36
- window.MercurySetup = {
51
+ window.Mercury = {
37
52
 
38
53
  // # Mercury Configuration
39
54
  config: {
@@ -58,35 +73,45 @@ window.MercurySetup = {
58
73
  //
59
74
  // ### The available button types are:
60
75
  //
61
- // - toggle: toggles on or off when clicked, otherwise behaves like a button
62
- // - modal: opens a modal window, expects the action to be one of:
76
+ // - toggle: toggles on or off when clicked, otherwise behaves like a button
77
+ // - modal: opens a modal window, expects the action to be one of:
63
78
  // 1. a string url
64
79
  // 2. a function that returns a string url
65
- // - panel: opens a panel dialog, expects the action to be one of:
80
+ // - lightview: opens a lightview window (like modal, but different UI), expects the action to be one of:
66
81
  // 1. a string url
67
82
  // 2. a function that returns a string url
68
- // - palette: opens a palette window, expects the action to be one of:
83
+ // - panel: opens a panel dialog, expects the action to be one of:
69
84
  // 1. a string url
70
85
  // 2. a function that returns a string url
71
- // - select: opens a pulldown style window, expects the action to be one of:
86
+ // - palette: opens a palette window, expects the action to be one of:
72
87
  // 1. a string url
73
88
  // 2. a function that returns a string url
74
- // - context: calls a callback function, expects the action to be:
89
+ // - select: opens a pulldown style window, expects the action to be one of:
90
+ // 1. a string url
91
+ // 2. a function that returns a string url
92
+ // - context: calls a callback function, expects the action to be:
75
93
  // 1. a function that returns a boolean to highlight the button
76
94
  // note: if a function isn't provided, the key will be passed to the contextHandler, in which case a default
77
95
  // context will be used (for more info read the Contexts section below)
78
- // - mode: toggle a given mode in the editor, expects the action to be:
96
+ // - mode: toggle a given mode in the editor, expects the action to be:
79
97
  // 1. a string, denoting the name of the mode
80
98
  // note: it's assumed that when a specific mode is turned on, all other modes will be turned off, which happens
81
99
  // automatically, thus putting the editor into a specific "state"
82
- // - regions: allows buttons to be enabled/disabled based on what region type has focus, expects the action to be:
100
+ // - regions: allows buttons to be enabled/disabled based on what region type has focus, expects the action to be:
83
101
  // 1. an array of region types (eg. ['editable', 'markupable'])
84
- // - preload: allows some dialog views to be loaded when the button is created instead of on first open, expects:
102
+ // - preload: allows some dialog views to be loaded when the button is created instead of on first open, expects:
85
103
  // 1. a boolean true / false
86
104
  // note: this is only used by panels, selects, and palettes
87
105
  //
88
106
  // Separators are any "button" that's not an array, and are expected to be a string. You can use two different
89
107
  // separator styles: line ('-'), and spacer (' ').
108
+ //
109
+ // ### Adding Contexts
110
+ //
111
+ // Contexts are used callback functions used for highlighting and disabling/enabling buttons and buttongroups. When
112
+ // the cursor enters an element within an html region for instance we want to disable or highlight buttons based on
113
+ // the properties of the given node. You can see examples of contexts in, and add your own to:
114
+ // `Mercury.Toolbar.Button.contexts` and `Mercury.Toolbar.ButtonGroup.contexts`
90
115
  toolbars: {
91
116
  primary: {
92
117
  save: ['Save', 'Save this page'],
@@ -148,8 +173,8 @@ window.MercurySetup = {
148
173
  sep: '-'
149
174
  },
150
175
  indent: {
151
- outdent: ['Decrease Indentation', null],
152
- indent: ['Increase Indentation', null],
176
+ outdent: ['Decrease Indentation'],
177
+ indent: ['Increase Indentation'],
153
178
  sep: '-'
154
179
  },
155
180
  table: {
@@ -183,24 +208,153 @@ window.MercurySetup = {
183
208
  snippetable: {
184
209
  _custom: true,
185
210
  actions: {
186
- editSnippet: ['Edit Snippet Settings', null],
211
+ editSnippet: ['Edit Snippet Settings'],
187
212
  sep1: ' ',
188
- removeSnippet: ['Remove Snippet', null]
213
+ removeSnippet: ['Remove Snippet']
189
214
  }
190
215
  }
191
216
  },
192
217
 
193
218
 
194
- // ## Hijacking Links & Forms
219
+ // ## Region Options
195
220
  //
196
- // Mercury will hijack links and forms that don't have a target set, or the target is set to _self and will set it
197
- // to _top. This is because the target must be set properly for Mercury to not get in the way of some
198
- // functionality, like proper page loads on form submissions etc. Mercury doesn't do this to links or forms that
199
- // are within editable regions because it doesn't want to impact the html that's saved. With that being explained,
200
- // you can add classes to links or forms that you don't want this behavior added to. Let's say you have links that
201
- // open a lightbox style window, and you don't want the targets of these to be set to _top. You can add classes to
202
- // this array, and they will be ignored when the hijacking is applied.
203
- nonHijackableClasses: [],
221
+ // You can customize some aspects of how regions are found, identified, and saved.
222
+ //
223
+ // className: Mercury identifies editable regions by a className. This classname has to be added in your HTML in
224
+ // advance, and is the only real code/naming exposed in the implementation of Mercury. To allow this to be as
225
+ // configurable as possible, you can set the name of the class. When switching to preview mode, this configuration
226
+ // is also used to generate a class to indicate that Mercury is in preview mode by appending it with '-preview' (so
227
+ // by default it would be mercury-region-preview)
228
+ //
229
+ // identifier: This is used as a unique identifier for any given region (and thus should be unique to the page).
230
+ // By default this is the id attribute but can be changed to a data attribute should you want to use something
231
+ // custom instead.
232
+ //
233
+ // dataAttributes: The dataAttributes is an array of data attributes that will be serialized and returned to the
234
+ // server upon saving. These attributes, when applied to a Mercury region element, will be automatically serialized
235
+ // and submitted with the AJAX request sent when a page is saved. These are expected to be HTML5 data attributes,
236
+ // and 'data-' will automatically be prepended to each item in this directive. (ex. ['scope', 'version'])
237
+ regions: {
238
+ className: 'mercury-region',
239
+ identifier: 'id',
240
+ dataAttributes: []
241
+ },
242
+
243
+
244
+ // ## Snippet Options / Preview
245
+ //
246
+ // When a user drags a snippet onto the page they'll be prompted to enter options for the given snippet. The server
247
+ // is expected to respond with a form. Once the user submits this form, an Ajax request is sent to the server with
248
+ // the options provided; this preview request is expected to respond with the rendered markup for the snippet.
249
+ //
250
+ // method: The HTTP method used when submitting both the options and the preview. We use POST by default because a
251
+ // snippet options form may contain large text inputs and we don't want that to be truncated when sent to the
252
+ // server.
253
+ //
254
+ // optionsUrl: The url that the options form will be loaded from.
255
+ //
256
+ // previewUrl: The url that the options will be submitted to, and will return the rendered snippet markup.
257
+ //
258
+ // **Note:** `:name` will be replaced with the snippet name in the urls (eg. /mercury/snippets/example/options.html)
259
+ snippets: {
260
+ method: 'POST',
261
+ optionsUrl: '/mercury/snippets/:name/options.html',
262
+ previewUrl: '/mercury/snippets/:name/preview.html'
263
+ },
264
+
265
+
266
+ // ## Image Uploading
267
+ //
268
+ // If you drag images from your desktop into regions that support it, it will be uploaded to the server and inserted
269
+ // into the region. You can disable or enable this feature, the accepted mime-types, file size restrictions, and
270
+ // other things related to uploading.
271
+ //
272
+ // **Note:** Image uploading is only supported in some region types, and some browsers.
273
+ //
274
+ // enabled: You can set this to true, or false if you want to disable the feature entirely.
275
+ //
276
+ // allowedMimeTypes: You can restrict the types of files that can be uploaded by providing a list of allowed mime
277
+ // types.
278
+ //
279
+ // maxFileSize: You can restrict large files by setting the maxFileSize (in bytes).
280
+ //
281
+ // inputName: When uploading, a form is generated and submitted to the server via Ajax. If your server would prefer
282
+ // a different name for how the image comes through, you can change the inputName.
283
+ //
284
+ // url: The url that the image upload will be submitted to.
285
+ //
286
+ // handler: You can use false to let Mercury handle it for you, or you can provide a handler function that can
287
+ // modify the response from the server. This can be useful if your server doesn't respond the way Mercury expects.
288
+ // The handler function should take the response from the server and return an object that matches:
289
+ // `{image: {url: '[your provided url]'}`
290
+ uploading: {
291
+ enabled: true,
292
+ allowedMimeTypes: ['image/jpeg', 'image/gif', 'image/png'],
293
+ maxFileSize: 1235242880,
294
+ inputName: 'image[image]',
295
+ url: '/mercury/images',
296
+ handler: false
297
+ },
298
+
299
+
300
+ // ## Localization / I18n
301
+ //
302
+ // Include the .locale files you want to support when loading Mercury. The files are always named by the language,
303
+ // and not the regional dialect (eg. en.locale.js) because the regional dialects are nested within the primary
304
+ // locale files.
305
+ //
306
+ // The client locale will be used first, and if no proper locale file is found for their language then the fallback
307
+ // preferredLocale configuration will be used. If one isn't provided, and the client locale isn't included, the
308
+ // strings will remain untranslated.
309
+ //
310
+ // enabled: Set to false to disable, true to enable.
311
+ //
312
+ // preferredLocale: If a client doesn't support the locales you've included, this is used as a fallback.
313
+ localization: {
314
+ enabled: false,
315
+ preferredLocale: 'swedish_chef-BORK'
316
+ },
317
+
318
+
319
+ // ## Behaviors
320
+ //
321
+ // Behaviors are used to change the default behaviors of a given region type when a given button is clicked. For
322
+ // example, you may prefer to add HR tags using an HR wrapped within a div with a classname (for styling). You
323
+ // can add your own complex behaviors here and they'll be shared across all regions.
324
+ //
325
+ // If you want to add behaviors to specific region types, you can mix them into the actions property of any region
326
+ // type.
327
+ //
328
+ // Mercury.Regions.Editable.actions.htmlEditor = function() {}
329
+ //
330
+ // You can see how the behavior matches up directly with the button names. It's also important to note that the
331
+ // callback functions are executed within the scope of the given region, so you have access to all it's methods.
332
+ behaviors: {
333
+ //foreColor: function(selection, options) { selection.wrap('<span style="color:' + options.value.toHex() + '">', true) },
334
+ htmlEditor: function() { Mercury.modal('/mercury/modals/htmleditor.html', { title: 'HTML Editor', fullHeight: true, handler: 'htmlEditor' }); }
335
+ },
336
+
337
+
338
+ // ## Global Behaviors
339
+ //
340
+ // Global behaviors are much like behaviors, but are more "global". Things like save, exit, etc. can be included
341
+ // here. They'll only be called once, and execute within the scope of whatever editor is instantiated (eg.
342
+ // PageEditor).
343
+ //
344
+ // An example of changing how saving works:
345
+ //
346
+ // save: function() {
347
+ // var data = top.JSON.stringify(this.serialize(), null, ' ');
348
+ // var content = '<textarea style="width:500px;height:200px" wrap="off">' + data + '</textarea>';
349
+ // Mercury.modal(null, {title: 'Saving', closeButton: true, content: content})
350
+ // }
351
+ //
352
+ // This is a nice way to add functionality, when the behaviors aren't region specific. These can be triggered by a
353
+ // button, or manually with `Mercury.trigger('action', {action: 'barrelRoll'})`
354
+ globalBehaviors: {
355
+ exit: function() { window.location.href = this.iframeSrc() },
356
+ barrelRoll: function() { $('body').css({webkitTransform: 'rotate(360deg)'}) }
357
+ },
204
358
 
205
359
 
206
360
  // ## Ajax and CSRF Headers
@@ -212,6 +366,23 @@ window.MercurySetup = {
212
366
  csrfSelector: 'meta[name="csrf-token"]',
213
367
  csrfHeader: 'X-CSRF-Token',
214
368
 
369
+ // ## Editor URLs
370
+ //
371
+ // When loading a given page, you may want to tweak this regex. It's to allow the url to differ from the page
372
+ // you're editing, and the url at which you access it.
373
+ editorUrlRegEx: /([http|https]:\/\/.[^\/]*)\/editor\/?(.*)/i,
374
+
375
+ // ## Hijacking Links & Forms
376
+ //
377
+ // Mercury will hijack links and forms that don't have a target set, or the target is set to _self and will set it
378
+ // to _parent. This is because the target must be set properly for Mercury to not get in the way of some
379
+ // functionality, like proper page loads on form submissions etc. Mercury doesn't do this to links or forms that
380
+ // are within editable regions because it doesn't want to impact the html that's saved. With that being explained,
381
+ // you can add classes to links or forms that you don't want this behavior added to. Let's say you have links that
382
+ // open a lightbox style window, and you don't want the targets of these to be set to _parent. You can add classes
383
+ // to this array, and they will be ignored when the hijacking is applied.
384
+ nonHijackableClasses: [],
385
+
215
386
 
216
387
  // ## Pasting & Sanitizing
217
388
  //
@@ -220,17 +391,15 @@ window.MercurySetup = {
220
391
  // desired feature or an annoyance, so you can enable various sanitizing methods to clean the content when it's
221
392
  // pasted.
222
393
  //
223
- // ### Sanitizing options:
394
+ // sanitize: Can be any of the following:
224
395
  // - false: no sanitizing is done, the content is pasted the exact same as it was copied by the user
225
396
  // - 'whitelist': content is cleaned using the settings specified in the tag white list (described below)
226
397
  // - 'text': all html is stripped before pasting, leaving only the raw text
227
398
  //
228
- // ### Using the whitelist configuration
229
- //
230
- // The white list allows you to specify tags and attributes that are allowed when pasting content. Each item in
231
- // this object should contain the allowed tag, and an array of attributes that are allowed on that tag. If the
232
- // allowed attributes array is empty, all attributes will be removed. If a tag is not present in this list, it will
233
- // be removed, but without removing any of the text or tags inside it.
399
+ // whitelist: The white list allows you to specify tags and attributes that are allowed when pasting content. Each
400
+ // item in this object should contain the allowed tag, and an array of attributes that are allowed on that tag. If
401
+ // the allowed attributes array is empty, all attributes will be removed. If a tag is not present in this list, it
402
+ // will be removed, but without removing any of the text or tags inside it.
234
403
  //
235
404
  // **Note:** Content is *always* sanitized if looks like it's from MS Word or similar editors regardless of this
236
405
  // configuration.
@@ -252,8 +421,11 @@ window.MercurySetup = {
252
421
  td: ['colspan', 'rowspan'],
253
422
  div: ['class'],
254
423
  span: ['class'],
424
+ ul: [],
425
+ ol: [],
426
+ li: [],
255
427
  b: [],
256
- bold: [],
428
+ strong: [],
257
429
  i: [],
258
430
  em: [],
259
431
  u: [],
@@ -267,90 +439,20 @@ window.MercurySetup = {
267
439
  },
268
440
 
269
441
 
270
- // ## Snippet Options and Preview
271
- //
272
- // When a user drags a snippet onto the page they'll be prompted to enter options for the given snippet. The server
273
- // is expected to respond with a form. Once the user submits this form, an Ajax request is sent to the server with
274
- // the options provided; this preview request is expected to respond with the rendered markup for the snippet.
275
- //
276
- // Name will be replaced with the snippet name (eg. example)
277
- snippets: {
278
- method: 'POST',
279
- optionsUrl: '/mercury/snippets/:name/options.html',
280
- previewUrl: '/mercury/snippets/:name/preview.html'
281
- },
282
-
283
-
284
- // ## Image Uploading
285
- //
286
- // If you drag images (while pressing shift) from your desktop into regions that support it, it will be uploaded
287
- // to the server and inserted into the region. This configuration allows you to specify if you want to
288
- // disable/enable this feature, the accepted mime-types, file size restrictions, and other things related to
289
- // uploading. You can optionally provide a handler function that takes the response from the server and returns an
290
- // object: {image: {url: '[your provided url]'}
291
- //
292
- // **Note:** Image uploading is only supported in some region types, and some browsers.
293
- uploading: {
294
- enabled: true,
295
- allowedMimeTypes: ['image/jpeg', 'image/gif', 'image/png'],
296
- maxFileSize: 1235242880,
297
- inputName: 'image[image]',
298
- url: '/images',
299
- handler: false
300
- },
301
-
302
-
303
- // ## Behaviors
304
- //
305
- // Behaviors are used to change the default behaviors of a given region type when a given button is clicked. For
306
- // example, you may prefer to add HR tags using an HR wrapped within a div with a classname (for styling). You
307
- // can add your own complex behaviors here.
308
- //
309
- // You can see how the behavior matches up directly with the button names. It's also important to note that the
310
- // callback functions are executed within the scope of the given region, so you have access to all it's methods.
311
- // Here's some examples to help you get started.
312
- behaviors: {
313
- //foreColor: function(selection, options) { selection.wrap('<span style="color:' + options.value.toHex() + '">', true) },
314
- htmlEditor: function() { Mercury.modal('/mercury/modals/htmleditor.html', { title: 'HTML Editor', fullHeight: true, handler: 'htmlEditor' }); }
315
- },
316
-
317
-
318
- // ## Contexts
319
- //
320
- // Contexts are used callback functions used for highlighting and disabling/enabling buttons and buttongroups.
321
- // When the cursor enters an element within an html region for instance we want to disable or highlight buttons
322
- // based on the properties of the given node. You can see some examples of contexts in:
323
- //
324
- // Mercury.Toolbar.Button.contexts
325
- // and
326
- // Mercury.Toolbar.ButtonGroup.contexts
327
-
328
-
329
- // ## Region Class
330
- //
331
- // Mercury identifies editable regions by a region class. This class has to be added in your HTML in advance, and
332
- // is the only real Mercury code/naming exposed in the implementation of Mercury. To allow this to be as
333
- // configurable as possible, you can set the name of the class here. When switching to preview mode, this
334
- // configuration is used to generate a class to indicate that Mercury is in preview mode -- which will be this
335
- // class with '-preview' appended (so, mercury-region-preview by default)
336
- regionClass: 'mercury-region',
337
-
338
-
339
- // ## Styles
442
+ // ## Injected Styles
340
443
  //
341
444
  // Mercury tries to stay as much out of your code as possible, but because regions appear within your document we
342
445
  // need to include a few styles to indicate regions, as well as the different states of them (eg. focused). These
343
- // styles are injected into your document, and as simple as they might be, you may want to change them. You can do
344
- // so here. {{regionClass}} will be automatically replaced with whatever you have set in the regionClass
345
- // configuration directive.
446
+ // styles are injected into your document, and as simple as they might be, you may want to change them.
447
+ //
448
+ // {{regionClass}} will be automatically replaced with whatever you have set in the regions.class config directive.
346
449
  injectedStyles: '' +
347
450
  '.{{regionClass}} { min-height: 10px; outline: 1px dotted #09F } ' +
348
451
  '.{{regionClass}}:focus, .{{regionClass}}.focus { outline: none; -webkit-box-shadow: 0 0 10px #09F, 0 0 1px #045; box-shadow: 0 0 10px #09F, 0 0 1px #045 }' +
349
452
  '.{{regionClass}}:after { content: "."; display: block; visibility: hidden; clear: both; height: 0; overflow: hidden; }' +
350
- '.{{regionClass}} table, .{{regionClass}} td, .{{regionClass}} th { border: 1px dotted red; }' +
351
- '.mercury-textarea { box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; resize: vertical; }' +
352
- '.mercury-textarea { min-height: 10px; outline: 1px dotted #09F }' +
353
- '.mercury-textarea:focus, .mercury-textarea.focus { outline: none; -webkit-box-shadow: 0 0 10px #09F, 0 0 1px #045; box-shadow: 0 0 10px #09F, 0 0 1px #045 }'
453
+ '.{{regionClass}} table, .{{regionClass}} td, .{{regionClass}} th { border: 1px dotted red; min-width: 6px; }' +
454
+ '.mercury-textarea { border: 0; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; resize: none; }' +
455
+ '.mercury-textarea:focus { outline: none; }'
354
456
  },
355
457
 
356
458
  // ## Silent Mode
@@ -361,9 +463,13 @@ window.MercurySetup = {
361
463
  // ## Debug Mode
362
464
  //
363
465
  // Turning debug mode on will log events and other various things (using console.debug if available).
364
- debug: false
466
+ debug: false,
365
467
 
366
- };
468
+ // The onload method is provided as a callback in case you want to override default Mercury Editor behavior. It will
469
+ // be called directly after the Mercury scripts have loaded, but before anything has been initialized. It's a good
470
+ // place to add or change functionality.
471
+ onload: function() {
472
+ //Mercury.PageEditor.prototype.iframeSrc = function(url) { return '/testing'; }
473
+ },
367
474
 
368
- if (!window.Mercury) window.Mercury = window.MercurySetup;
369
- else if (typeof(jQuery) !== 'undefined') jQuery.extend(window.Mercury, window.MercurySetup);
475
+ };