react_editable_content 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.travis.yml +7 -0
  4. data/Gemfile +20 -0
  5. data/Gemfile.lock +129 -0
  6. data/Rakefile +20 -0
  7. data/Readme.md +44 -0
  8. data/app/assets/images/icon_edit.png +0 -0
  9. data/app/assets/javascripts/mercury.js +463 -0
  10. data/app/assets/javascripts/mercury/uploader.js.coffee +248 -0
  11. data/app/assets/stylesheets/mercury.css +23 -0
  12. data/app/controller/editable_content/editables_controller.rb +21 -0
  13. data/app/controller/mercury/images_controller.rb +24 -0
  14. data/app/helpers/editable_content/application_helper.rb +39 -0
  15. data/app/models/editable_content/editable.rb +6 -0
  16. data/app/models/mercury/image.rb +21 -0
  17. data/app/views/editable_content/_edit_link.html.erb +3 -0
  18. data/app/views/layouts/mercury.html.erb +23 -0
  19. data/config/routes.rb +9 -0
  20. data/lib/editable_content/engine.rb +17 -0
  21. data/lib/editable_content/railtie.rb +10 -0
  22. data/lib/generators/editable_content/install/install_generator.rb +22 -0
  23. data/lib/generators/editable_content/install/templates/create_editable_content_editables.rb +11 -0
  24. data/lib/generators/editable_content/install/templates/create_mercury_images.rb +8 -0
  25. data/lib/generators/editable_content/install/templates/lib/mercury/authentication.rb +9 -0
  26. data/lib/mercury/authentication.rb +9 -0
  27. data/lib/react_editable_content.rb +6 -0
  28. data/react_editable_content.gemspec +25 -0
  29. data/test/controllers/editable_content/editable_controller_test.rb +37 -0
  30. data/test/dummy/Rakefile +7 -0
  31. data/test/dummy/app/controllers/application_controller.rb +3 -0
  32. data/test/dummy/app/helpers/application_helper.rb +2 -0
  33. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  34. data/test/dummy/config.ru +4 -0
  35. data/test/dummy/config/application.rb +44 -0
  36. data/test/dummy/config/boot.rb +10 -0
  37. data/test/dummy/config/database.yml +22 -0
  38. data/test/dummy/config/environment.rb +5 -0
  39. data/test/dummy/config/environments/development.rb +25 -0
  40. data/test/dummy/config/environments/production.rb +49 -0
  41. data/test/dummy/config/environments/test.rb +35 -0
  42. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  43. data/test/dummy/config/initializers/inflections.rb +10 -0
  44. data/test/dummy/config/initializers/mime_types.rb +5 -0
  45. data/test/dummy/config/initializers/secret_token.rb +7 -0
  46. data/test/dummy/config/initializers/session_store.rb +8 -0
  47. data/test/dummy/config/locales/en.yml +5 -0
  48. data/test/dummy/config/routes.rb +58 -0
  49. data/test/dummy/db/migrate/20140908144759_create_editable_content_editables.rb +11 -0
  50. data/test/dummy/db/migrate/20140908144760_create_mercury_images.rb +8 -0
  51. data/test/dummy/db/schema.rb +33 -0
  52. data/test/dummy/db/test.sqlite3 +0 -0
  53. data/test/dummy/lib/mercury/authentication.rb +9 -0
  54. data/test/dummy/public/404.html +26 -0
  55. data/test/dummy/public/422.html +26 -0
  56. data/test/dummy/public/500.html +26 -0
  57. data/test/dummy/public/favicon.ico +0 -0
  58. data/test/dummy/public/javascripts/application.js +2 -0
  59. data/test/dummy/public/javascripts/controls.js +965 -0
  60. data/test/dummy/public/javascripts/dragdrop.js +974 -0
  61. data/test/dummy/public/javascripts/effects.js +1123 -0
  62. data/test/dummy/public/javascripts/prototype.js +6001 -0
  63. data/test/dummy/public/javascripts/rails.js +202 -0
  64. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  65. data/test/dummy/script/rails +6 -0
  66. data/test/dummy/test/fixtures/editables.yml +9 -0
  67. data/test/dummy/test/fixtures/rails.png +0 -0
  68. data/test/helpers/editables_helper_test.rb +78 -0
  69. data/test/test_helper.rb +27 -0
  70. metadata +167 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9dbaeda26e5658eb0778f0e3e3826b7e9032b608
4
+ data.tar.gz: 30d8de739ee6712705dee7ba829f415e463e72af
5
+ SHA512:
6
+ metadata.gz: 640962418dd2a0b4d055da56ada36c150aeeaa45cb56762163b7933abb476a7450cf6432a2a6d0ee7c8c3d2083d39001393f7489d681562a5b8c15925115ebd3
7
+ data.tar.gz: 33af6363a4debaa119604f31586515ef65eb525950387c209bb3a78c2311141fce8c0dca91ba0aea1dbb2b139e77ecfaf7907f9b38f7dc85f450064f2dcd76f3
@@ -0,0 +1,18 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore coverage
8
+ /coverage
9
+
10
+ # Ignore bundler config
11
+ /.bundle
12
+
13
+ # Ignore all logfiles and tempfiles.
14
+ /test/dummy/log/*.log
15
+ /test/dummy/tmp
16
+
17
+ .DS_Store
18
+ ._.DS_Store
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.1.1"
4
+ - "2.0.0"
5
+ - "1.9.3"
6
+ # uncomment this line if your project needs to run something other than `rake`:
7
+ # script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'coveralls', require: false
4
+ gem 'mercury-rails', git: 'https://github.com/jejacks0n/mercury.git', ref: '1cc637b'
5
+
6
+ # For dummy app
7
+ gem 'actionpack', '>= 4.1.1'
8
+ gem 'actionview', '>= 4.1.1'
9
+ gem 'activemodel', '>= 4.1.1'
10
+ gem 'activerecord', '>= 4.1.1'
11
+ gem 'activesupport', '>= 4.1.1'
12
+ gem 'railties', '>= 4.1.1'
13
+ gem 'sprockets-rails', '>= 2.0'
14
+
15
+ group :test do
16
+ gem 'sqlite3', '~> 1.3.9'
17
+ gem 'mocha', '>= 1.0.0'
18
+ end
19
+
20
+ gemspec
@@ -0,0 +1,129 @@
1
+ GIT
2
+ remote: https://github.com/jejacks0n/mercury.git
3
+ revision: 1cc637b0bccea19085f824d2881c6513ed5ee8ae
4
+ ref: 1cc637b
5
+ specs:
6
+ mercury-rails (0.9.0)
7
+ coffee-rails (>= 3.2.2)
8
+ railties (>= 3.0)
9
+
10
+ PATH
11
+ remote: .
12
+ specs:
13
+ react_editable_content (0.0.1)
14
+ paperclip (>= 4.1.1)
15
+
16
+ GEM
17
+ remote: https://rubygems.org/
18
+ specs:
19
+ actionpack (4.1.5)
20
+ actionview (= 4.1.5)
21
+ activesupport (= 4.1.5)
22
+ rack (~> 1.5.2)
23
+ rack-test (~> 0.6.2)
24
+ actionview (4.1.5)
25
+ activesupport (= 4.1.5)
26
+ builder (~> 3.1)
27
+ erubis (~> 2.7.0)
28
+ activemodel (4.1.5)
29
+ activesupport (= 4.1.5)
30
+ builder (~> 3.1)
31
+ activerecord (4.1.5)
32
+ activemodel (= 4.1.5)
33
+ activesupport (= 4.1.5)
34
+ arel (~> 5.0.0)
35
+ activesupport (4.1.5)
36
+ i18n (~> 0.6, >= 0.6.9)
37
+ json (~> 1.7, >= 1.7.7)
38
+ minitest (~> 5.1)
39
+ thread_safe (~> 0.1)
40
+ tzinfo (~> 1.1)
41
+ arel (5.0.1.20140414130214)
42
+ builder (3.2.2)
43
+ climate_control (0.0.3)
44
+ activesupport (>= 3.0)
45
+ cocaine (0.5.4)
46
+ climate_control (>= 0.0.3, < 1.0)
47
+ coffee-rails (4.0.1)
48
+ coffee-script (>= 2.2.0)
49
+ railties (>= 4.0.0, < 5.0)
50
+ coffee-script (2.3.0)
51
+ coffee-script-source
52
+ execjs
53
+ coffee-script-source (1.8.0)
54
+ coveralls (0.7.1)
55
+ multi_json (~> 1.3)
56
+ rest-client
57
+ simplecov (>= 0.7)
58
+ term-ansicolor
59
+ thor
60
+ docile (1.1.5)
61
+ erubis (2.7.0)
62
+ execjs (2.2.1)
63
+ hike (1.2.3)
64
+ i18n (0.6.11)
65
+ json (1.8.1)
66
+ metaclass (0.0.4)
67
+ mime-types (2.3)
68
+ minitest (5.4.1)
69
+ mocha (1.1.0)
70
+ metaclass (~> 0.0.1)
71
+ multi_json (1.10.1)
72
+ netrc (0.7.7)
73
+ paperclip (4.2.0)
74
+ activemodel (>= 3.0.0)
75
+ activesupport (>= 3.0.0)
76
+ cocaine (~> 0.5.3)
77
+ mime-types
78
+ rack (1.5.2)
79
+ rack-test (0.6.2)
80
+ rack (>= 1.0)
81
+ railties (4.1.5)
82
+ actionpack (= 4.1.5)
83
+ activesupport (= 4.1.5)
84
+ rake (>= 0.8.7)
85
+ thor (>= 0.18.1, < 2.0)
86
+ rake (10.3.2)
87
+ rest-client (1.7.2)
88
+ mime-types (>= 1.16, < 3.0)
89
+ netrc (~> 0.7)
90
+ simplecov (0.9.0)
91
+ docile (~> 1.1.0)
92
+ multi_json
93
+ simplecov-html (~> 0.8.0)
94
+ simplecov-html (0.8.0)
95
+ sprockets (2.12.2)
96
+ hike (~> 1.2)
97
+ multi_json (~> 1.0)
98
+ rack (~> 1.0)
99
+ tilt (~> 1.1, != 1.3.0)
100
+ sprockets-rails (2.1.4)
101
+ actionpack (>= 3.0)
102
+ activesupport (>= 3.0)
103
+ sprockets (~> 2.8)
104
+ sqlite3 (1.3.9)
105
+ term-ansicolor (1.3.0)
106
+ tins (~> 1.0)
107
+ thor (0.19.1)
108
+ thread_safe (0.3.4)
109
+ tilt (1.4.1)
110
+ tins (1.3.2)
111
+ tzinfo (1.2.2)
112
+ thread_safe (~> 0.1)
113
+
114
+ PLATFORMS
115
+ ruby
116
+
117
+ DEPENDENCIES
118
+ actionpack (>= 4.1.1)
119
+ actionview (>= 4.1.1)
120
+ activemodel (>= 4.1.1)
121
+ activerecord (>= 4.1.1)
122
+ activesupport (>= 4.1.1)
123
+ coveralls
124
+ mercury-rails!
125
+ mocha (>= 1.0.0)
126
+ railties (>= 4.1.1)
127
+ react_editable_content!
128
+ sprockets-rails (>= 2.0)
129
+ sqlite3 (~> 1.3.9)
@@ -0,0 +1,20 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+
11
+ require 'rake/testtask'
12
+
13
+ Rake::TestTask.new(:test) do |t|
14
+ t.libs << 'lib'
15
+ t.libs << 'test'
16
+ t.pattern = 'test/**/*_test.rb'
17
+ t.verbose = false
18
+ end
19
+
20
+ task :default => :test
@@ -0,0 +1,44 @@
1
+ # react_editable_content
2
+
3
+ This gem wraps the mercury-rails gem (a very cool full page wysiwyg text editor, check out [the demo](http://jejacks0n.github.com/mercury/)) to make it much easier to use with Rails.
4
+
5
+ [![Travis CI](http://img.shields.io/travis/rogeriochaves/react_editable_content/master.svg)](https://travis-ci.org/rogeriochaves/react_editable_content)
6
+ [![Coverage Status](https://img.shields.io/coveralls/rogeriochaves/react_editable_content.svg)](https://coveralls.io/r/rogeriochaves/react_editable_content)
7
+ [![Code Climate](https://codeclimate.com/github/rogeriochaves/react_editable_content/badges/gpa.svg)](https://codeclimate.com/github/rogeriochaves/react_editable_content)
8
+
9
+ The react_editable_content makes very simple to create an editable block of text or image. First, include this two gems on your Gemfile:
10
+
11
+ gem 'mercury-rails', github: 'jejacks0n/mercury', ref: '1cc637b'
12
+ gem 'react_editable_content', github: 'rogeriochaves/react_editable_content'
13
+
14
+ Then, run the following command to install the migrations and the authentication.rb file
15
+
16
+ rails generate editable_content:install
17
+
18
+ You can now run the migrations
19
+
20
+ rake db:migrate
21
+
22
+ The authentication.rb file is where you can control if the user is allowed to edit anything on the page, you may want to edit that file later.
23
+
24
+ Now, on your erb, define an editable block, like that:
25
+
26
+ <%= editable_content 'content-optional-identifier' do %>
27
+ <p>
28
+ Lorem ipsum dolor sit amet, edit me please
29
+ </p>
30
+ <% end %>
31
+
32
+ Create an editable image too, let's go:
33
+
34
+ <%= editable_image_tag("rails.png", size: "150x150") %>
35
+
36
+ Now, go to [http://localhost:3000/editor](http://localhost:3000/editor), you should already be able to change things around, and drag-and-drop images from your computer to upload, isn't that awesome!?
37
+
38
+ To add an edit link that gets the user to the /editor page on the top of the page (only if the user has permission), add this before the closing body tag on your application.html.erb
39
+
40
+ <%= render 'editable_content/edit_link' %>
41
+
42
+ One more thing, when using editable_image_tag you have to specify the size of the image, if your intention is to leave free for the user to upload images of any size, just use a regular image_tag inside an editable_content block, like we did with the Lorem ipsum.
43
+
44
+ Have fun ;)
@@ -0,0 +1,463 @@
1
+ /*!
2
+ * Mercury Editor is a CoffeeScript and jQuery based WYSIWYG editor. Documentation and other useful information can be
3
+ * found at https://github.com/jejacks0n/mercury
4
+ *
5
+ * Minimum jQuery requirements are 1.7
6
+ *= require_self
7
+ *
8
+ * You can include the Rails jQuery ujs script here to get some nicer behaviors in modals, panels and lightviews when
9
+ * using :remote => true within the contents rendered in them.
10
+ * require jquery_ujs
11
+ *
12
+ * Add any requires for the support libraries that integrate nicely with Mercury Editor.
13
+ * require mercury/support/history
14
+ *
15
+ * Require Mercury Editor itself.
16
+ *= require mercury/mercury
17
+ *
18
+ * Require any localizations you wish to support
19
+ * Example: es.locale, or fr.locale -- regional dialects are in each language file so never en_US for instance.
20
+ * Make sure you enable the localization feature in the configuration.
21
+ * require mercury/locales/swedish_chef.locale
22
+ *
23
+ * Add all requires for plugins that extend or change the behavior of Mercury Editor.
24
+ * require mercury/plugins/save_as_xml/plugin.js
25
+ *
26
+ * Require any files you want to use that either extend, or change the default Mercury behavior.
27
+ * require mercury_overrides
28
+ */
29
+ window.Mercury = {
30
+
31
+ // # Mercury Configuration
32
+ config: {
33
+ // ## Toolbars
34
+ //
35
+ // This is where you can customize the toolbars by adding or removing buttons, or changing them and their
36
+ // behaviors. Any top level object put here will create a new toolbar. Buttons are simply nested inside the
37
+ // toolbars, along with button groups.
38
+ //
39
+ // Some toolbars are custom (the snippets toolbar for instance), and to denote that use _custom: true. You can then
40
+ // build the toolbar yourself with it's own behavior.
41
+ //
42
+ // Buttons can be grouped, and a button group is simply a way to wrap buttons for styling -- they can also handle
43
+ // enabling or disabling all the buttons within it by using a context. The table button group is a good example of
44
+ // this.
45
+ //
46
+ // It's important to note that each of the button names (keys), in each toolbar object must be unique, regardless of
47
+ // if it's in a button group, or nested, etc. This is because styling is applied to them by name, and because their
48
+ // name is used in the event that's fired when you click on them.
49
+ //
50
+ // Button format: `[label, description, {type: action, type: action, etc}]`
51
+ //
52
+ // ### The available button types are:
53
+ //
54
+ // - toggle: toggles on or off when clicked, otherwise behaves like a button
55
+ // - modal: opens a modal window, expects the action to be one of:
56
+ // 1. a string url
57
+ // 2. a function that returns a string url
58
+ // - lightview: opens a lightview window (like modal, but different UI), expects the action to be one of:
59
+ // 1. a string url
60
+ // 2. a function that returns a string url
61
+ // - panel: opens a panel dialog, expects the action to be one of:
62
+ // 1. a string url
63
+ // 2. a function that returns a string url
64
+ // - palette: opens a palette window, expects the action to be one of:
65
+ // 1. a string url
66
+ // 2. a function that returns a string url
67
+ // - select: opens a pulldown style window, expects the action to be one of:
68
+ // 1. a string url
69
+ // 2. a function that returns a string url
70
+ // - context: calls a callback function, expects the action to be:
71
+ // 1. a function that returns a boolean to highlight the button
72
+ // note: if a function isn't provided, the key will be passed to the contextHandler, in which case a default
73
+ // context will be used (for more info read the Contexts section below)
74
+ // - mode: toggle a given mode in the editor, expects the action to be:
75
+ // 1. a string, denoting the name of the mode
76
+ // note: it's assumed that when a specific mode is turned on, all other modes will be turned off, which happens
77
+ // automatically, thus putting the editor into a specific "state"
78
+ // - regions: allows buttons to be enabled/disabled based on what region type has focus, expects:
79
+ // 1. an array of region types (eg. ['full', 'markdown'])
80
+ // - preload: allows some dialog views to be loaded when the button is created instead of on first open, expects:
81
+ // 1. a boolean true / false
82
+ // note: this is only used by panels, selects, and palettes
83
+ //
84
+ // Separators are any "button" that's not an array, and are expected to be a string. You can use two different
85
+ // separator styles: line ('-'), and spacer (' ').
86
+ //
87
+ // ### Adding Contexts
88
+ //
89
+ // Contexts are used callback functions used for highlighting and disabling/enabling buttons and buttongroups. When
90
+ // the cursor enters an element within an html region for instance we want to disable or highlight buttons based on
91
+ // the properties of the given node. You can see examples of contexts in, and add your own to:
92
+ // `Mercury.Toolbar.Button.contexts` and `Mercury.Toolbar.ButtonGroup.contexts`
93
+ toolbars: {
94
+ primary: {
95
+ save: ['Save', 'Save this page'],
96
+ preview: ['Preview', 'Preview this page', { toggle: true, mode: true }],
97
+ sep1: ' ',
98
+ undoredo: {
99
+ undo: ['Undo', 'Undo your last action'],
100
+ redo: ['Redo', 'Redo your last action'],
101
+ sep: ' '
102
+ },
103
+ insertLink: ['Link', 'Insert Link', { modal: '/mercury/modals/link.html', regions: ['full', 'markdown'] }],
104
+ insertMedia: ['Media', 'Insert Media (images and videos)', { modal: '/mercury/modals/media.html', regions: ['full', 'markdown'] }],
105
+ insertTable: ['Table', 'Insert Table', { modal: '/mercury/modals/table.html', regions: ['full', 'markdown'] }],
106
+ insertCharacter: ['Character', 'Special Characters', { modal: '/mercury/modals/character.html', regions: ['full', 'markdown'] }],
107
+ snippetPanel: ['Snippet', 'Snippet Panel', { panel: '/mercury/panels/snippets.html' }],
108
+ sep2: ' ',
109
+ historyPanel: ['History', 'Page Version History', { panel: '/mercury/panels/history.html' }],
110
+ sep3: ' ',
111
+ notesPanel: ['Notes', 'Page Notes', { panel: '/mercury/panels/notes.html' }]
112
+ },
113
+
114
+ editable: {
115
+ _regions: ['full', 'markdown'],
116
+ predefined: {
117
+ style: ['Style', null, { select: '/mercury/selects/style.html', preload: true }],
118
+ sep1: ' ',
119
+ formatblock: ['Block Format', null, { select: '/mercury/selects/formatblock.html', preload: true }],
120
+ sep2: '-'
121
+ },
122
+ colors: {
123
+ backColor: ['Background Color', null, { palette: '/mercury/palettes/backcolor.html', context: true, preload: true, regions: ['full'] }],
124
+ sep1: ' ',
125
+ foreColor: ['Text Color', null, { palette: '/mercury/palettes/forecolor.html', context: true, preload: true, regions: ['full'] }],
126
+ sep2: '-'
127
+ },
128
+ decoration: {
129
+ bold: ['Bold', null, { context: true }],
130
+ italic: ['Italicize', null, { context: true }],
131
+ overline: ['Overline', null, { context: true, regions: ['full'] }],
132
+ strikethrough: ['Strikethrough', null, { context: true, regions: ['full'] }],
133
+ underline: ['Underline', null, { context: true, regions: ['full'] }],
134
+ sep: '-'
135
+ },
136
+ script: {
137
+ subscript: ['Subscript', null, { context: true }],
138
+ superscript: ['Superscript', null, { context: true }],
139
+ sep: '-'
140
+ },
141
+ justify: {
142
+ justifyLeft: ['Align Left', null, { context: true, regions: ['full'] }],
143
+ justifyCenter: ['Center', null, { context: true, regions: ['full'] }],
144
+ justifyRight: ['Align Right', null, { context: true, regions: ['full'] }],
145
+ justifyFull: ['Justify Full', null, { context: true, regions: ['full'] }],
146
+ sep: '-'
147
+ },
148
+ list: {
149
+ insertUnorderedList: ['Unordered List', null, { context: true }],
150
+ insertOrderedList: ['Numbered List', null, { context: true }],
151
+ sep: '-'
152
+ },
153
+ indent: {
154
+ outdent: ['Decrease Indentation'],
155
+ indent: ['Increase Indentation'],
156
+ sep: '-'
157
+ },
158
+ table: {
159
+ _context: true,
160
+ insertRowBefore: ['Insert Table Row', 'Insert a table row before the cursor', { regions: ['full'] }],
161
+ insertRowAfter: ['Insert Table Row', 'Insert a table row after the cursor', { regions: ['full'] }],
162
+ deleteRow: ['Delete Table Row', 'Delete this table row', { regions: ['full'] }],
163
+ insertColumnBefore: ['Insert Table Column', 'Insert a table column before the cursor', { regions: ['full'] }],
164
+ insertColumnAfter: ['Insert Table Column', 'Insert a table column after the cursor', { regions: ['full'] }],
165
+ deleteColumn: ['Delete Table Column', 'Delete this table column', { regions: ['full'] }],
166
+ sep1: ' ',
167
+ increaseColspan: ['Increase Cell Columns', 'Increase the cells colspan'],
168
+ decreaseColspan: ['Decrease Cell Columns', 'Decrease the cells colspan and add a new cell'],
169
+ increaseRowspan: ['Increase Cell Rows', 'Increase the cells rowspan'],
170
+ decreaseRowspan: ['Decrease Cell Rows', 'Decrease the cells rowspan and add a new cell'],
171
+ sep2: '-'
172
+ },
173
+ rules: {
174
+ horizontalRule: ['Horizontal Rule', 'Insert a horizontal rule'],
175
+ sep1: '-'
176
+ },
177
+ formatting: {
178
+ removeFormatting: ['Remove Formatting', 'Remove formatting for the selection', { regions: ['full'] }],
179
+ sep2: ' '
180
+ },
181
+ editors: {
182
+ htmlEditor: ['Edit HTML', 'Edit the HTML content', { regions: ['full'] }]
183
+ }
184
+ },
185
+
186
+ snippets: {
187
+ _custom: true,
188
+ actions: {
189
+ editSnippet: ['Edit Snippet Settings'],
190
+ sep1: ' ',
191
+ removeSnippet: ['Remove Snippet']
192
+ }
193
+ }
194
+ },
195
+
196
+
197
+ // ## Region Options
198
+ //
199
+ // You can customize some aspects of how regions are found, identified, and saved.
200
+ //
201
+ // attribute: Mercury identifies editable regions by a data-mercury attribute. This attribute has to be added in
202
+ // your HTML in advance, and is the only real code/naming exposed in the implementation of Mercury. To allow this
203
+ // to be as configurable as possible, you can set the name of this attribute. If you change this, you should adjust
204
+ // the injected styles as well.
205
+ //
206
+ // identifier: This is used as a unique identifier for any given region (and thus should be unique to the page).
207
+ // By default this is the id attribute but can be changed to a data attribute should you want to use something
208
+ // custom instead.
209
+ //
210
+ // dataAttributes: The dataAttributes is an array of data attributes that will be serialized and returned to the
211
+ // server upon saving. These attributes, when applied to a Mercury region element, will be automatically serialized
212
+ // and submitted with the AJAX request sent when a page is saved. These are expected to be HTML5 data attributes,
213
+ // and 'data-' will automatically be prepended to each item in this directive. (ex. ['scope', 'version'])
214
+ //
215
+ // determineType: This function is called after checking the data-type attribute for the correct field type. Use
216
+ // it if you want to dynamically set the type based on inspection of the region.
217
+ regions: {
218
+ attribute: 'data-mercury',
219
+ identifier: 'id',
220
+ dataAttributes: []
221
+ // determineType: function(region){},
222
+ },
223
+
224
+
225
+ // ## Snippet Options / Preview
226
+ //
227
+ // When a user drags a snippet onto the page they'll be prompted to enter options for the given snippet. The server
228
+ // is expected to respond with a form. Once the user submits this form, an Ajax request is sent to the server with
229
+ // the options provided; this preview request is expected to respond with the rendered markup for the snippet.
230
+ //
231
+ // method: The HTTP method used when submitting both the options and the preview. We use POST by default because a
232
+ // snippet options form may contain large text inputs and we don't want that to be truncated when sent to the
233
+ // server.
234
+ //
235
+ // optionsUrl: The url that the options form will be loaded from.
236
+ //
237
+ // previewUrl: The url that the options will be submitted to, and will return the rendered snippet markup.
238
+ //
239
+ // **Note:** `:name` will be replaced with the snippet name in the urls (eg. /mercury/snippets/example/options.html)
240
+ snippets: {
241
+ method: 'POST',
242
+ optionsUrl: '/mercury/snippets/:name/options.html',
243
+ previewUrl: '/mercury/snippets/:name/preview.html'
244
+ },
245
+
246
+
247
+ // ## Image Uploading
248
+ //
249
+ // If you drag images from your desktop into regions that support it, it will be uploaded to the server and inserted
250
+ // into the region. You can disable or enable this feature, the accepted mime-types, file size restrictions, and
251
+ // other things related to uploading.
252
+ //
253
+ // **Note:** Image uploading is only supported in some region types, and some browsers.
254
+ //
255
+ // enabled: You can set this to true, or false if you want to disable the feature entirely.
256
+ //
257
+ // allowedMimeTypes: You can restrict the types of files that can be uploaded by providing a list of allowed mime
258
+ // types.
259
+ //
260
+ // maxFileSize: You can restrict large files by setting the maxFileSize (in bytes).
261
+ //
262
+ // inputName: When uploading, a form is generated and submitted to the server via Ajax. If your server would prefer
263
+ // a different name for how the image comes through, you can change the inputName.
264
+ //
265
+ // url: The url that the image upload will be submitted to.
266
+ //
267
+ // handler: You can use false to let Mercury handle it for you, or you can provide a handler function that can
268
+ // modify the response from the server. This can be useful if your server doesn't respond the way Mercury expects.
269
+ // The handler function should take the response from the server and return an object that matches:
270
+ // `{image: {url: '[your provided url]'}`
271
+ uploading: {
272
+ enabled: true,
273
+ allowedMimeTypes: ['image/jpeg', 'image/gif', 'image/png'],
274
+ maxFileSize: 1235242880,
275
+ inputName: 'image[image]',
276
+ url: '/mercury/images',
277
+ handler: false
278
+ },
279
+
280
+
281
+ // ## Localization / I18n
282
+ //
283
+ // Include the .locale files you want to support when loading Mercury. The files are always named by the language,
284
+ // and not the regional dialect (eg. en.locale.js) because the regional dialects are nested within the primary
285
+ // locale files.
286
+ //
287
+ // The client locale will be used first, and if no proper locale file is found for their language then the fallback
288
+ // preferredLocale configuration will be used. If one isn't provided, and the client locale isn't included, the
289
+ // strings will remain untranslated.
290
+ //
291
+ // enabled: Set to false to disable, true to enable.
292
+ //
293
+ // preferredLocale: If a client doesn't support the locales you've included, this is used as a fallback.
294
+ localization: {
295
+ enabled: false,
296
+ preferredLocale: 'swedish_chef-BORK'
297
+ },
298
+
299
+
300
+ // ## Behaviors
301
+ //
302
+ // Behaviors are used to change the default behaviors of a given region type when a given button is clicked. For
303
+ // example, you may prefer to add HR tags using an HR wrapped within a div with a classname (for styling). You
304
+ // can add your own complex behaviors here and they'll be shared across all regions.
305
+ //
306
+ // If you want to add behaviors to specific region types, you can mix them into the actions property of any region
307
+ // type.
308
+ //
309
+ // Mercury.Regions.Full.actions.htmlEditor = function() {}
310
+ //
311
+ // You can see how the behavior matches up directly with the button names. It's also important to note that the
312
+ // callback functions are executed within the scope of the given region, so you have access to all it's methods.
313
+ behaviors: {
314
+ //foreColor: function(selection, options) { selection.wrap('<span style="color:' + options.value.toHex() + '">', true) },
315
+ htmlEditor: function() { Mercury.modal('/mercury/modals/htmleditor.html', { title: 'HTML Editor', fullHeight: true, handler: 'htmlEditor' }); }
316
+ },
317
+
318
+
319
+ // ## Global Behaviors
320
+ //
321
+ // Global behaviors are much like behaviors, but are more "global". Things like save, exit, etc. can be included
322
+ // here. They'll only be called once, and execute within the scope of whatever editor is instantiated (eg.
323
+ // PageEditor).
324
+ //
325
+ // An example of changing how saving works:
326
+ //
327
+ // save: function() {
328
+ // var data = top.JSON.stringify(this.serialize(), null, ' ');
329
+ // var content = '<textarea style="width:500px;height:200px" wrap="off">' + data + '</textarea>';
330
+ // Mercury.modal(null, {title: 'Saving', closeButton: true, content: content})
331
+ // }
332
+ //
333
+ // This is a nice way to add functionality, when the behaviors aren't region specific. These can be triggered by a
334
+ // button, or manually with `Mercury.trigger('action', {action: 'barrelRoll'})`
335
+ globalBehaviors: {
336
+ exit: function() { window.location.href = this.iframeSrc() },
337
+ barrelRoll: function() { $('body').css({webkitTransform: 'rotate(360deg)'}) }
338
+ },
339
+
340
+
341
+ // ## Ajax and CSRF Headers
342
+ //
343
+ // Some server frameworks require that you provide a specific header for Ajax requests. The values for these CSRF
344
+ // tokens are typically stored in the rendered DOM. By default, Mercury will look for the Rails specific meta tag,
345
+ // and provide the X-CSRF-Token header on Ajax requests, but you can modify this configuration if the system you're
346
+ // using doesn't follow the same standard.
347
+ csrfSelector: 'meta[name="csrf-token"]',
348
+ csrfHeader: 'X-CSRF-Token',
349
+
350
+
351
+ // ## Editor URLs
352
+ //
353
+ // When loading a given page, you may want to tweak this regex. It's to allow the url to differ from the page
354
+ // you're editing, and the url at which you access it.
355
+ editorUrlRegEx: /([http|https]:\/\/.[^\/]*)\/editor\/?(.*)/i,
356
+
357
+
358
+ // ## Hijacking Links & Forms
359
+ //
360
+ // Mercury will hijack links and forms that don't have a target set, or the target is set to _self and will set it
361
+ // to _parent. This is because the target must be set properly for Mercury to not get in the way of some
362
+ // functionality, like proper page loads on form submissions etc. Mercury doesn't do this to links or forms that
363
+ // are within editable regions because it doesn't want to impact the html that's saved. With that being explained,
364
+ // you can add classes to links or forms that you don't want this behavior added to. Let's say you have links that
365
+ // open a lightbox style window, and you don't want the targets of these to be set to _parent. You can add classes
366
+ // to this array, and they will be ignored when the hijacking is applied.
367
+ nonHijackableClasses: [],
368
+
369
+
370
+ // ## Pasting & Sanitizing
371
+ //
372
+ // When pasting content into Mercury it may sometimes contain HTML tags and attributes. This markup is used to
373
+ // style the content and makes the pasted content look (and behave) the same as the original content. This can be a
374
+ // desired feature or an annoyance, so you can enable various sanitizing methods to clean the content when it's
375
+ // pasted.
376
+ //
377
+ // sanitize: Can be any of the following:
378
+ // - false: no sanitizing is done, the content is pasted the exact same as it was copied by the user
379
+ // - 'whitelist': content is cleaned using the settings specified in the tag white list (described below)
380
+ // - 'text': all html is stripped before pasting, leaving only the raw text
381
+ //
382
+ // whitelist: The white list allows you to specify tags and attributes that are allowed when pasting content. Each
383
+ // item in this object should contain the allowed tag, and an array of attributes that are allowed on that tag. If
384
+ // the allowed attributes array is empty, all attributes will be removed. If a tag is not present in this list, it
385
+ // will be removed, but without removing any of the text or tags inside it.
386
+ //
387
+ // **Note:** Content is *always* sanitized if looks like it's from MS Word or similar editors regardless of this
388
+ // configuration.
389
+ pasting: {
390
+ sanitize: 'whitelist',
391
+ whitelist: {
392
+ h1: [],
393
+ h2: [],
394
+ h3: [],
395
+ h4: [],
396
+ h5: [],
397
+ h6: [],
398
+ table: [],
399
+ thead: [],
400
+ tbody: [],
401
+ tfoot: [],
402
+ tr: [],
403
+ th: ['colspan', 'rowspan'],
404
+ td: ['colspan', 'rowspan'],
405
+ div: ['class'],
406
+ span: ['class'],
407
+ ul: [],
408
+ ol: [],
409
+ li: [],
410
+ b: [],
411
+ strong: [],
412
+ i: [],
413
+ em: [],
414
+ u: [],
415
+ strike: [],
416
+ br: [],
417
+ p: [],
418
+ hr: [],
419
+ a: ['href', 'target', 'title', 'name'],
420
+ img: ['src', 'title', 'alt']
421
+ }
422
+ },
423
+
424
+
425
+ // ## Injected Styles
426
+ //
427
+ // Mercury tries to stay as much out of your code as possible, but because regions appear within your document we
428
+ // need to include a few styles to indicate regions, as well as the different states of them (eg. focused). These
429
+ // styles are injected into your document, and as simple as they might be, you may want to change them.
430
+ injectedStyles: '' +
431
+ '[data-mercury] { min-height: 10px; outline: 1px dotted #09F } ' +
432
+ '[data-mercury]:focus { outline: none; -webkit-box-shadow: 0 0 10px #09F, 0 0 1px #045; box-shadow: 0 0 10px #09F, 0 0 1px #045 }' +
433
+ '[data-mercury].focus { outline: none; -webkit-box-shadow: 0 0 10px #09F, 0 0 1px #045; box-shadow: 0 0 10px #09F, 0 0 1px #045 }' +
434
+ '[data-mercury]:after { content: "."; display: block; visibility: hidden; clear: both; height: 0; overflow: hidden; }' +
435
+ '[data-mercury] table { border: 1px dotted red; min-width: 6px; }' +
436
+ '[data-mercury] th { border: 1px dotted red; min-width: 6px; }' +
437
+ '[data-mercury] td { border: 1px dotted red; min-width: 6px; }' +
438
+ '[data-mercury] .mercury-textarea { border: 0; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; resize: none; }' +
439
+ '[data-mercury] .mercury-textarea:focus { outline: none; -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; }'
440
+ },
441
+
442
+ // ## Silent Mode
443
+ //
444
+ // Turning silent mode on will disable asking about unsaved changes before leaving the page.
445
+ silent: false,
446
+
447
+ // ## Debug Mode
448
+ //
449
+ // Turning debug mode on will log events and other various things (using console.debug if available).
450
+ debug: false
451
+
452
+ };
453
+
454
+ $(window).bind('mercury:ready', function() {
455
+ $('#mercury_iframe').contents().find('#edit-link').remove();
456
+ $('#mercury_iframe').contents().find("[data-size]").each(function(){
457
+ $(this).before('<div style="position: absolute; font-size:13px; padding:5px; background:rgba(0,0,0,.5); border-radius: 10px; color:#FFF">'+$(this).data('size')+'</div>')
458
+ });
459
+ });
460
+
461
+ $(window).bind('mercury:saved', function() {
462
+ window.location = window.location.href.replace(/\/editor/i, '/');
463
+ });