scrivito_editors 0.71.2 → 0.90.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/scrivito_editors/binary_editor.js +41 -0
  3. data/app/assets/javascripts/scrivito_editors/date_editor.js +66 -0
  4. data/app/assets/javascripts/scrivito_editors/default_editor.js +43 -0
  5. data/app/assets/javascripts/scrivito_editors/deprecated_data_attrs.js +44 -0
  6. data/app/assets/javascripts/scrivito_editors/enum_editor.js +68 -0
  7. data/app/assets/javascripts/scrivito_editors/filter_context.js +54 -0
  8. data/app/assets/javascripts/scrivito_editors/helpers/file_dropzone.js +33 -0
  9. data/app/assets/javascripts/scrivito_editors/helpers/imgly_assets.js.erb +5 -0
  10. data/app/assets/javascripts/scrivito_editors/helpers/setup_binary_button_container.js +12 -0
  11. data/app/assets/javascripts/scrivito_editors/html_editor.js +15 -0
  12. data/app/assets/javascripts/scrivito_editors/image_drop_editor.js +52 -0
  13. data/app/assets/javascripts/scrivito_editors/image_editor.js +114 -0
  14. data/app/assets/javascripts/scrivito_editors/link_editor.js +88 -0
  15. data/app/assets/javascripts/scrivito_editors/linklist_editor.js +187 -0
  16. data/app/assets/javascripts/scrivito_editors/medium_editor.js +97 -0
  17. data/app/assets/javascripts/scrivito_editors/multienum_editor.js +48 -0
  18. data/app/assets/javascripts/scrivito_editors/permalink_editor.js +124 -0
  19. data/app/assets/javascripts/scrivito_editors/placeholder.js +37 -0
  20. data/app/assets/javascripts/scrivito_editors/redactor_editor.js +155 -0
  21. data/app/assets/javascripts/scrivito_editors/redactor_plugins/scrivito_editors_image_manager.js +41 -0
  22. data/app/assets/javascripts/scrivito_editors/redactor_plugins/scrivito_editors_link_manager.js +56 -0
  23. data/app/assets/javascripts/scrivito_editors/reference_editor.js +60 -0
  24. data/app/assets/javascripts/scrivito_editors/referencelist_editor.js +120 -0
  25. data/app/assets/javascripts/scrivito_editors/reload.js +14 -0
  26. data/app/assets/javascripts/scrivito_editors/slider_editor.js +62 -0
  27. data/app/assets/javascripts/scrivito_editors/string_editor.js +156 -0
  28. data/app/assets/javascripts/scrivito_editors/stringlist_editor.js +22 -0
  29. data/app/assets/javascripts/scrivito_editors.js +3 -0
  30. data/app/assets/stylesheets/scrivito_editors/editors/medium_editor.css +20 -0
  31. data/app/assets/stylesheets/scrivito_editors/editors/{html_editor.css → redactor_editor.css} +0 -0
  32. data/app/assets/stylesheets/scrivito_editors/editors/referencelist_editor.css +4 -0
  33. data/app/assets/stylesheets/scrivito_editors/placeholder.css +14 -3
  34. data/app/helpers/scrivito_editors/scrivito_tag_helper.rb +40 -135
  35. data/lib/scrivito_editors/engine.rb +0 -1
  36. data/vendor/assets/javascripts/medium-editor.js +6445 -0
  37. data/{app → vendor}/assets/javascripts/redactor.js +0 -0
  38. data/{app/assets/javascripts/scrivito_editors → vendor/assets/javascripts}/redactor_plugins/table.js +0 -0
  39. data/vendor/assets/stylesheets/medium-editor-themes/flat.css +58 -0
  40. data/vendor/assets/stylesheets/medium-editor.css +214 -0
  41. metadata +78 -56
  42. data/app/assets/javascripts/scrivito_editors/binary_editor.js.coffee +0 -25
  43. data/app/assets/javascripts/scrivito_editors/date_editor.js.coffee +0 -59
  44. data/app/assets/javascripts/scrivito_editors/enum_editor.js.coffee +0 -41
  45. data/app/assets/javascripts/scrivito_editors/filter_context.js.coffee +0 -26
  46. data/app/assets/javascripts/scrivito_editors/helpers/file_dropzone.js.coffee +0 -16
  47. data/app/assets/javascripts/scrivito_editors/helpers/setup_binary_button_container.js.coffee +0 -6
  48. data/app/assets/javascripts/scrivito_editors/html_editor.js.coffee +0 -138
  49. data/app/assets/javascripts/scrivito_editors/image_drop_editor.js.coffee +0 -19
  50. data/app/assets/javascripts/scrivito_editors/image_editor.js.coffee.erb +0 -96
  51. data/app/assets/javascripts/scrivito_editors/link_editor.js.coffee +0 -141
  52. data/app/assets/javascripts/scrivito_editors/linklist_editor.js.coffee +0 -197
  53. data/app/assets/javascripts/scrivito_editors/multienum_editor.js.coffee +0 -42
  54. data/app/assets/javascripts/scrivito_editors/permalink_editor.js.coffee +0 -111
  55. data/app/assets/javascripts/scrivito_editors/placeholder.js.coffee +0 -22
  56. data/app/assets/javascripts/scrivito_editors/redactor_plugins/scrivito_editors_image_manager.js.coffee +0 -22
  57. data/app/assets/javascripts/scrivito_editors/redactor_plugins/scrivito_editors_link_manager.js.coffee +0 -49
  58. data/app/assets/javascripts/scrivito_editors/reference_editor.js.coffee +0 -33
  59. data/app/assets/javascripts/scrivito_editors/referencelist_editor.js.coffee +0 -113
  60. data/app/assets/javascripts/scrivito_editors/reload.js.coffee +0 -12
  61. data/app/assets/javascripts/scrivito_editors/slider_editor.js.coffee +0 -41
  62. data/app/assets/javascripts/scrivito_editors/string_editor.js.coffee +0 -136
  63. data/app/assets/javascripts/scrivito_editors/stringlist_editor.js.coffee +0 -13
  64. data/app/helpers/scrivito_editors/cms_tag_helper.rb +0 -36
@@ -0,0 +1,187 @@
1
+ (function() {
2
+ var activate, addLink, attachHandlers, attachLinkHandlers, fetchDescriptions, linkTemplate, openContentBrowser, removeLink, render, save, storeLastSaved;
3
+
4
+ scrivito.on('load', function() {
5
+ return scrivito.define_editor('linklist', scrivito.editors.linklist_editor);
6
+ });
7
+
8
+ scrivito.editors.linklist_editor = {
9
+ can_edit: function(element) {
10
+ return $(element).is('[data-scrivito-field-type=linklist]');
11
+ },
12
+ activate: function(element) {
13
+ return activate($(element));
14
+ }
15
+ };
16
+
17
+ activate = function(cmsField) {
18
+ var linklist;
19
+ linklist = cmsField.scrivito('content');
20
+ render(cmsField, linklist);
21
+ fetchDescriptions(cmsField, linklist);
22
+ attachHandlers(cmsField);
23
+ return storeLastSaved(cmsField, linklist);
24
+ };
25
+
26
+ render = function(cmsField, linklist) {
27
+ var j, len, link, ul;
28
+ ul = $('<ul></ul>');
29
+ for (j = 0, len = linklist.length; j < len; j++) {
30
+ link = linklist[j];
31
+ ul.append(linkTemplate(link));
32
+ }
33
+ cmsField.html(ul);
34
+ return cmsField.append('<button class="editing-button editing-green add-link">\n <i class="editing-icon editing-icon-plus"></i>\n</button>');
35
+ };
36
+
37
+ fetchDescriptions = function(cmsField, linklist) {
38
+ var link, obj_ids;
39
+ obj_ids = (function() {
40
+ var j, len, results;
41
+ results = [];
42
+ for (j = 0, len = linklist.length; j < len; j++) {
43
+ link = linklist[j];
44
+ if (link.obj_id) {
45
+ results.push(link.obj_id);
46
+ }
47
+ }
48
+ return results;
49
+ })();
50
+ if (obj_ids.length) {
51
+ return scrivito.description_for_editor(obj_ids).then(function(descriptions) {
52
+ var i, j, len, obj_id, results, urlInput;
53
+ results = [];
54
+ for (i = j = 0, len = obj_ids.length; j < len; i = ++j) {
55
+ obj_id = obj_ids[i];
56
+ urlInput = cmsField.find("[data-id='" + obj_id + "'] [name=url]");
57
+ if (!urlInput.is(':focus')) {
58
+ results.push(urlInput.val(descriptions[i]));
59
+ } else {
60
+ results.push(void 0);
61
+ }
62
+ }
63
+ return results;
64
+ });
65
+ }
66
+ };
67
+
68
+ attachHandlers = function(cmsField) {
69
+ var j, len, li, ref, results, ul;
70
+ ul = cmsField.find('ul');
71
+ ul.sortable({
72
+ update: function() {
73
+ return save(cmsField);
74
+ }
75
+ });
76
+ cmsField.on('blur', 'li input', function() {
77
+ return save(cmsField);
78
+ }).on('click', 'button.add-link', function() {
79
+ return addLink(cmsField);
80
+ });
81
+ ref = ul.find('li');
82
+ results = [];
83
+ for (j = 0, len = ref.length; j < len; j++) {
84
+ li = ref[j];
85
+ results.push(attachLinkHandlers(cmsField, $(li)));
86
+ }
87
+ return results;
88
+ };
89
+
90
+ attachLinkHandlers = function(cmsField, li) {
91
+ return li.on('click', 'a.scrivito_open_content_browser', function() {
92
+ return openContentBrowser(cmsField, li);
93
+ }).on('click', 'a.delete', function() {
94
+ return removeLink(cmsField, li);
95
+ }).find('[name=url]').on('focus', function() {
96
+ var input, raw;
97
+ input = $(this);
98
+ raw = input.data('value');
99
+ if (raw) {
100
+ input.val(raw);
101
+ }
102
+ return input.data('value', null);
103
+ });
104
+ };
105
+
106
+ linkTemplate = function(link) {
107
+ var obj_url;
108
+ obj_url = link.obj_id && ("/" + link.obj_id);
109
+ return $("<li " + (link.obj_id ? "data-id='" + link.obj_id + "'" : void 0) + " data-title=\"" + link.title + "\" data-url=\"" + link.url + "\">\n <input type=\"text\" name=\"title\" value=\"" + (link.title || '') + "\" placeholder=\"Title\" />\n <input type=\"text\" name=\"url\" value=\"" + (link.url || obj_url || '') + "\"\n data-value=\"" + (link.url || obj_url || '') + "\" placeholder=\"Url\" class=\"editing-url\" />\n <div class=\"actions\">\n <a href=\"#\" class=\"scrivito_open_content_browser editing-button editing-green\">\n <i class=\"editing-icon editing-icon-search\" />\n </a>\n <a href=\"#\" class=\"editing-button editing-red delete\">\n <i class=\"editing-icon editing-icon-trash\" />\n </a>\n </div>\n</li>");
110
+ };
111
+
112
+ save = function(cmsField) {
113
+ var input, lastSaved, li, title, url, value;
114
+ value = (function() {
115
+ var j, len, ref, results;
116
+ ref = $(cmsField).find('li');
117
+ results = [];
118
+ for (j = 0, len = ref.length; j < len; j++) {
119
+ li = ref[j];
120
+ li = $(li);
121
+ title = li.find('[name=title]').val();
122
+ input = li.find('[name=url]');
123
+ url = input.data('value') || input.val();
124
+ if (url) {
125
+ results.push({
126
+ title: title,
127
+ url: url
128
+ });
129
+ } else {
130
+ results.push(null);
131
+ }
132
+ }
133
+ return results;
134
+ })();
135
+ value = $.grep(value, function(n) {
136
+ return n;
137
+ });
138
+ lastSaved = cmsField.data('scrivito-editors-linklist-last-saved');
139
+ if (JSON.stringify(value) !== JSON.stringify(lastSaved)) {
140
+ return cmsField.scrivito('save', value).done(function() {
141
+ cmsField.trigger('save.scrivito_editors');
142
+ return storeLastSaved(cmsField, value);
143
+ });
144
+ }
145
+ };
146
+
147
+ addLink = function(cmsField) {
148
+ var li;
149
+ li = linkTemplate({});
150
+ li.appendTo(cmsField.find('ul'));
151
+ attachLinkHandlers(cmsField, li);
152
+ return false;
153
+ };
154
+
155
+ openContentBrowser = function(cmsField, li) {
156
+ var id;
157
+ id = li.data('id');
158
+ scrivito.content_browser.open({
159
+ selection: id ? [id] : [],
160
+ selection_mode: 'single',
161
+ filters: cmsField.data('scrivitoEditorsFilters'),
162
+ filter_context: cmsField.data('scrivitoEditorsFilterContext')
163
+ }).done((function(_this) {
164
+ return function(selection) {
165
+ var url, val;
166
+ if (id = selection[0]) {
167
+ url = "/" + id;
168
+ val = "Content browser selection (" + url + ")";
169
+ li.data('id', id).find('[name=url]').data('value', url).val(val);
170
+ return save(cmsField);
171
+ }
172
+ };
173
+ })(this));
174
+ return false;
175
+ };
176
+
177
+ removeLink = function(cmsField, li) {
178
+ li.remove();
179
+ save(cmsField);
180
+ return false;
181
+ };
182
+
183
+ storeLastSaved = function(cmsField, lastSaved) {
184
+ return cmsField.data('scrivito-editors-linklist-last-saved', lastSaved);
185
+ };
186
+
187
+ }).call(this);
@@ -0,0 +1,97 @@
1
+ (function() {
2
+ var ScrivitoAnchor, activate, editorOptions;
3
+
4
+ ScrivitoAnchor = MediumEditor.extensions.anchor.extend({
5
+ name: 'scrivito_anchor',
6
+ contentDefault: '<i class="scrivito_customer_icon sci_link"></i>',
7
+ handleClick: function(event) {
8
+ var firstTextElement, linkElement, linkValue, selectedParent, selectionRange;
9
+ if (!this.isDisplayed()) {
10
+ selectionRange = MediumEditor.selection.getSelectionRange(this.document);
11
+ selectedParent = MediumEditor.selection.getSelectedParentElement(selectionRange);
12
+ firstTextElement = MediumEditor.util.getFirstTextNode(selectedParent);
13
+ linkElement = MediumEditor.util.getClosestTag(firstTextElement, 'a');
14
+ linkValue = $(linkElement).attr('href');
15
+ this.showForm(linkValue);
16
+ }
17
+ return false;
18
+ },
19
+ getTemplate: function() {
20
+ return "<i class='medium-editor-toolbar-browse scrivito_customer_icon sci_collection'></i>" + ("<input type='text' class='medium-editor-toolbar-input' placeholder='" + this.placeholderText + "'>") + "<i class='medium-editor-toolbar-save scrivito_customer_icon sci_check'></i>" + "<i class='medium-editor-toolbar-close scrivito_customer_icon sci_cross'></i>";
21
+ },
22
+ attachFormEvents: function(form) {
23
+ var input;
24
+ MediumEditor.extensions.anchor.prototype.attachFormEvents.call(this, form);
25
+ form = $(form);
26
+ input = form.find('.medium-editor-toolbar-input');
27
+ return form.find('.medium-editor-toolbar-browse').on('click', (function(_this) {
28
+ return function() {
29
+ var cmsField, matches, selection;
30
+ matches = input.val().match(/\b([a-f0-9]{16})\b/);
31
+ selection = matches != null ? [matches[1]] : [];
32
+ cmsField = $(_this.base.origElements);
33
+ scrivito.content_browser.open({
34
+ filter: cmsField.data('scrivitoEditorsFilter'),
35
+ filter_context: cmsField.data('scrivitoEditorsFilterContext'),
36
+ selection: selection,
37
+ selection_mode: 'single'
38
+ }).always(function() {
39
+ return input.focus();
40
+ }).done(function(selection) {
41
+ return input.val(selection);
42
+ });
43
+ return false;
44
+ };
45
+ })(this));
46
+ },
47
+ completeFormSave: function(opts) {
48
+ this.base.restoreSelection();
49
+ if (opts.url) {
50
+ this.execAction(this.action, opts);
51
+ } else {
52
+ this.execAction('unlink');
53
+ }
54
+ return this.base.checkSelection();
55
+ }
56
+ });
57
+
58
+ editorOptions = function(toolbarOptions) {
59
+ var options;
60
+ options = {
61
+ anchorPreview: false,
62
+ extensions: {
63
+ scrivito_anchor: new ScrivitoAnchor
64
+ },
65
+ toolbar: {
66
+ buttons: ['h1', 'h2', 'h3', 'bold', 'italic', 'scrivito_anchor', 'underline', 'orderedlist', 'unorderedlist', 'indent', 'outdent', 'justifyLeft', 'justifyCenter', 'justifyFull']
67
+ }
68
+ };
69
+ if (toolbarOptions) {
70
+ options.toolbar = toolbarOptions;
71
+ }
72
+ options.toolbar.standardizeSelectionStart = true;
73
+ return options;
74
+ };
75
+
76
+ activate = function(element) {
77
+ var cmsField;
78
+ cmsField = $(element);
79
+ return new MediumEditor(cmsField, editorOptions(cmsField.data('medium-editor-toolbar'))).subscribe('editableInput', function() {
80
+ return cmsField.scrivito('save', cmsField.html());
81
+ });
82
+ };
83
+
84
+ scrivito.editors.medium_editor = {
85
+ can_edit: function(element) {
86
+ return $(element).is('[data-scrivito-field-type=html]');
87
+ },
88
+ activate: function(element) {
89
+ return activate(element);
90
+ }
91
+ };
92
+
93
+ scrivito.on('load', function() {
94
+ return scrivito.define_editor('medium', scrivito.editors.medium_editor);
95
+ });
96
+
97
+ }).call(this);
@@ -0,0 +1,48 @@
1
+ (function() {
2
+ var activate, save, template;
3
+
4
+ template = function(values) {
5
+ var element;
6
+ element = $('<select></select>').attr('multiple', 'true');
7
+ $.each(values, function(index, value) {
8
+ return $('<option></option>').attr('value', value).text(value).appendTo(element);
9
+ });
10
+ return element;
11
+ };
12
+
13
+ save = function(event) {
14
+ var cmsField, content, element, ref;
15
+ element = $(event.currentTarget);
16
+ cmsField = element.data('cmsField');
17
+ content = (ref = element.val()) != null ? ref : [];
18
+ return cmsField.scrivito('save', content).done(function() {
19
+ return cmsField.trigger('save.scrivito_editors');
20
+ });
21
+ };
22
+
23
+ activate = function(element) {
24
+ var cmsField;
25
+ cmsField = $(element);
26
+ return cmsField.on('click', function() {
27
+ var selected, values;
28
+ selected = cmsField.scrivito('content');
29
+ values = cmsField.scrivito('allowed_values');
30
+ template(values).data('cmsField', cmsField).val(selected).insertAfter(cmsField).change(save).focusout(save).focus();
31
+ return cmsField.hide();
32
+ });
33
+ };
34
+
35
+ scrivito.editors.multienum_editor = {
36
+ can_edit: function(element) {
37
+ return $(element).is('[data-scrivito-field-type=multienum]');
38
+ },
39
+ activate: function(element) {
40
+ return activate(element);
41
+ }
42
+ };
43
+
44
+ scrivito.on('load', function() {
45
+ return scrivito.define_editor('multienum', scrivito.editors.multienum_editor);
46
+ });
47
+
48
+ }).call(this);
@@ -0,0 +1,124 @@
1
+ (function() {
2
+ var activate, render;
3
+
4
+ activate = function(element) {
5
+ var button, clear, disableSaveButton, editor, enableSaveButton, error, field, hideError, hideSaving, input, save, showError, showSaving, trySave;
6
+ field = $(element);
7
+ editor = field.html(render(field.scrivito('content') || ''));
8
+ input = editor.find('input');
9
+ button = editor.find('a');
10
+ error = editor.find('div.scrivito_error');
11
+ clear = editor.find('.scrivito_clear');
12
+ input.on('input', function() {
13
+ var permalink;
14
+ permalink = input.val();
15
+ if (permalink === field.scrivito('content')) {
16
+ hideError();
17
+ return disableSaveButton();
18
+ } else if (permalink.match(/^([\w._-]+[\/\w._-]*)?$/)) {
19
+ hideError();
20
+ return enableSaveButton();
21
+ } else {
22
+ showError('The permalink may only contain letters from A to Z, periods, hyphens, and underscores.');
23
+ return disableSaveButton();
24
+ }
25
+ });
26
+ clear.on('click', function() {
27
+ input.val('');
28
+ hideError();
29
+ if (!field.scrivito('content')) {
30
+ disableSaveButton();
31
+ } else {
32
+ enableSaveButton();
33
+ }
34
+ return false;
35
+ });
36
+ button.on('click', function() {
37
+ trySave();
38
+ return false;
39
+ });
40
+ editor.on('keyup', function(event) {
41
+ switch (event.keyCode) {
42
+ case 13:
43
+ return trySave();
44
+ case 27:
45
+ input.val(field.scrivito('content'));
46
+ hideError();
47
+ disableSaveButton();
48
+ return input.blur();
49
+ }
50
+ });
51
+ trySave = function() {
52
+ var permalink;
53
+ if (button.hasClass('scrivito_disabled')) {
54
+ return false;
55
+ }
56
+ showSaving();
57
+ permalink = input.val();
58
+ if (permalink) {
59
+ return scrivito.obj_where('_permalink', 'equals', permalink).size().then(function(total) {
60
+ if (total > 0) {
61
+ hideSaving();
62
+ showError('Permalink already taken.');
63
+ disableSaveButton();
64
+ return input.focus();
65
+ } else {
66
+ return save(permalink);
67
+ }
68
+ });
69
+ } else {
70
+ return save(null);
71
+ }
72
+ };
73
+ disableSaveButton = function() {
74
+ return button.addClass('scrivito_disabled');
75
+ };
76
+ enableSaveButton = function() {
77
+ return button.removeClass('scrivito_disabled scrivito_saving');
78
+ };
79
+ showError = function(message) {
80
+ disableSaveButton();
81
+ input.addClass('scrivito_error');
82
+ error.text(message);
83
+ return error.show();
84
+ };
85
+ hideError = function() {
86
+ input.removeClass('scrivito_error');
87
+ return error.hide();
88
+ };
89
+ showSaving = function() {
90
+ input.attr('disabled', 'disabled');
91
+ disableSaveButton();
92
+ button.addClass('scrivito_saving');
93
+ return button.find('span').text('Saving...');
94
+ };
95
+ hideSaving = function() {
96
+ input.removeAttr('disabled');
97
+ enableSaveButton();
98
+ return button.find('span').text('Save');
99
+ };
100
+ return save = function(permalink) {
101
+ return field.scrivito('save', permalink).then(function() {
102
+ return activate(field);
103
+ });
104
+ };
105
+ };
106
+
107
+ render = function(content) {
108
+ return "<div class=\"scrivito_permalink_editor\">\n <input type=\"text\" value=\"" + content + "\" />\n <span class=\"scrivito_clear\"></span>\n <a href=\"#\" class=\"scrivito_editing_button scrivito_disabled\">\n <span>Save</span>\n </a>\n <div class=\"scrivito_error\"></div>\n</div>";
109
+ };
110
+
111
+ scrivito.editors.permalink_editor = {
112
+ can_edit: function(element) {
113
+ return $(element).is('[data-scrivito-field-name=_permalink]');
114
+ },
115
+ activate: function(element) {
116
+ return activate(element);
117
+ }
118
+ };
119
+
120
+ scrivito.on('load', function() {
121
+ return scrivito.define_editor('permalink', scrivito.editors.permalink_editor);
122
+ });
123
+
124
+ }).call(this);
@@ -0,0 +1,37 @@
1
+ (function() {
2
+ var addPlaceholder, applyBrowserWorkarounds;
3
+
4
+ addPlaceholder = function() {
5
+ var cmsFields;
6
+ cmsFields = $('[data-scrivito-field-type]').not('[data-scrivito-field-type=widgetlist]');
7
+ return cmsFields.each(function() {
8
+ var cmsField, defaultPlaceholder, fieldName, placeholder;
9
+ cmsField = $(this);
10
+ fieldName = cmsField.attr('data-scrivito-field-name');
11
+ defaultPlaceholder = "Click to edit the “" + fieldName + "” attribute ...";
12
+ placeholder = cmsField.attr('data-scrivito-editors-placeholder') || defaultPlaceholder;
13
+ cmsField.attr('data-scrivito-editors-placeholder', placeholder);
14
+ return applyBrowserWorkarounds(cmsField);
15
+ });
16
+ };
17
+
18
+ applyBrowserWorkarounds = function(cmsField) {
19
+ return cmsField.on('focus', (function(_this) {
20
+ return function() {
21
+ if (cmsField.is(':empty')) {
22
+ cmsField.text('_');
23
+ window.getSelection().selectAllChildren(cmsField[0]);
24
+ cmsField.text('');
25
+ return window.getSelection().collapseToStart(cmsField[0]);
26
+ }
27
+ };
28
+ })(this));
29
+ };
30
+
31
+ scrivito.on('content', function() {
32
+ if (scrivito.in_editable_view()) {
33
+ return addPlaceholder();
34
+ }
35
+ });
36
+
37
+ }).call(this);
@@ -0,0 +1,155 @@
1
+ (function() {
2
+ var activate, closeEditor, defaultOptions, getCurrentContent, getOptions, saveContents;
3
+
4
+ this.RedactorPlugins || (this.RedactorPlugins = {});
5
+
6
+ RedactorPlugins.scrivito_editors_close = function() {
7
+ return {
8
+ init: function() {
9
+ var button;
10
+ button = this.button.addFirst('close', 'Close');
11
+ return this.button.addCallback(button, function() {
12
+ return closeEditor(this);
13
+ });
14
+ }
15
+ };
16
+ };
17
+
18
+ defaultOptions = {
19
+ buttons: ['formatting', 'bold', 'italic', 'deleted', 'underline', 'unorderedlist', 'orderedlist', 'table', 'image', 'link', 'html'],
20
+ buttonSource: true,
21
+ cleanSpaces: false,
22
+ cleanOnPaste: false,
23
+ convertLinks: false,
24
+ imageUpload: true,
25
+ linkTooltip: false,
26
+ paragraphize: false,
27
+ placeholder: false,
28
+ plugins: ['scrivito_editors_close', 'scrivito_editors_image_manager', 'scrivito_editors_link_manager', 'table'],
29
+ replaceDivs: false,
30
+ tabifier: false,
31
+ blurCallback: function() {
32
+ if (this._everHadFocus) {
33
+ return closeEditor(this);
34
+ }
35
+ },
36
+ changeCallback: function() {
37
+ return saveContents(this);
38
+ },
39
+ destroyCallback: function() {
40
+ return saveContents(this);
41
+ },
42
+ dropdownShowCallback: function() {
43
+ return saveContents(this);
44
+ },
45
+ focusCallback: function() {
46
+ if (this._isInitialized) {
47
+ return this._everHadFocus = true;
48
+ }
49
+ },
50
+ modalOpenedCallback: function() {
51
+ return saveContents(this);
52
+ },
53
+ keyupCallback: function(event) {
54
+ var key;
55
+ key = event.keyCode || event.which;
56
+ if (key === 27) {
57
+ event.stopPropagation();
58
+ return closeEditor(this);
59
+ } else {
60
+ return saveContents(this);
61
+ }
62
+ },
63
+ initCallback: function() {
64
+ var cmsField, content, html, htmlWithSelection;
65
+ cmsField = $(this.$element);
66
+ content = cmsField.scrivito('content');
67
+ this._initialScrivitoContent = content;
68
+ this.selection.selectAll();
69
+ htmlWithSelection = this.selection.getHtml();
70
+ this.selection.removeMarkers();
71
+ html = this.selection.getHtml();
72
+ if (html !== content) {
73
+ this.code.set(content);
74
+ this.selection.selectAll();
75
+ html = this.selection.getHtml();
76
+ this.focus.setEnd();
77
+ } else {
78
+ this.code.set(htmlWithSelection);
79
+ this.selection.restore();
80
+ }
81
+ this._initialRedactorContent = html;
82
+ return this._isInitialized = true;
83
+ },
84
+ startCallback: function() {
85
+ this._everHadFocus = void 0;
86
+ this._initialRedactorContent = void 0;
87
+ this._initialScrivitoContent = void 0;
88
+ this._isInitialized = void 0;
89
+ if (document.getSelection().anchorNode) {
90
+ return this.insert.node(this.selection.getMarker(), false);
91
+ }
92
+ }
93
+ };
94
+
95
+ closeEditor = function(editor) {
96
+ var cmsField;
97
+ cmsField = $(editor.$element);
98
+ editor.core.destroy();
99
+ cmsField.removeClass('scrivito_editors_redactor');
100
+ return cmsField.trigger('scrivito_editors:blur');
101
+ };
102
+
103
+ saveContents = function(editor) {
104
+ var cmsField, content;
105
+ cmsField = editor.$element;
106
+ content = getCurrentContent(editor);
107
+ if (content !== cmsField.scrivito('content')) {
108
+ return cmsField.scrivito('save', content).done(function() {
109
+ return cmsField.trigger('save.scrivito_editors');
110
+ });
111
+ } else {
112
+ return $.Deferred().resolve();
113
+ }
114
+ };
115
+
116
+ getCurrentContent = function(editor) {
117
+ var content;
118
+ content = editor.code.get();
119
+ if (content === editor._initialRedactorContent) {
120
+ content = editor._initialScrivitoContent;
121
+ }
122
+ return content;
123
+ };
124
+
125
+ getOptions = function() {
126
+ return $.extend({}, scrivito.editors.redactor_editor.default_options, scrivito.editors.redactor_editor.options);
127
+ };
128
+
129
+ activate = function(element) {
130
+ var cmsField;
131
+ cmsField = $(element);
132
+ return cmsField.on('click', function(event) {
133
+ event.preventDefault();
134
+ if (!cmsField.hasClass('scrivito_editors_redactor')) {
135
+ return cmsField.redactor(getOptions()).addClass('scrivito_editors_redactor');
136
+ }
137
+ });
138
+ };
139
+
140
+ scrivito.editors.redactor_editor = {
141
+ can_edit: function(element) {
142
+ return $(element).is('[data-scrivito-field-type=html]');
143
+ },
144
+ activate: function(element) {
145
+ return activate(element);
146
+ },
147
+ default_options: defaultOptions,
148
+ options: {}
149
+ };
150
+
151
+ scrivito.on('load', function() {
152
+ return scrivito.define_editor('redactor', scrivito.editors.redactor_editor);
153
+ });
154
+
155
+ }).call(this);
@@ -0,0 +1,41 @@
1
+ (function() {
2
+ if (this.RedactorPlugins == null) {
3
+ this.RedactorPlugins = {};
4
+ }
5
+
6
+ RedactorPlugins.scrivito_editors_image_manager = function() {
7
+ var self;
8
+ return self = {
9
+ init: function() {
10
+ return this.modal.addCallback('image', self.browse);
11
+ },
12
+ browse: function() {
13
+ var filterContext;
14
+ filterContext = $.extend({
15
+ _image: true
16
+ }, this.$element.data('scrivitoEditorsFilterContext'));
17
+ return scrivito.content_browser.open({
18
+ filter: this.$element.data('scrivitoEditorsFilter'),
19
+ filter_context: filterContext,
20
+ selection_mode: 'single'
21
+ }).done((function(_this) {
22
+ return function(selection) {
23
+ var id;
24
+ id = selection[0];
25
+ if (id != null) {
26
+ return self.insert(id);
27
+ }
28
+ };
29
+ })(this)).always((function(_this) {
30
+ return function() {
31
+ return _this.modal.close();
32
+ };
33
+ })(this));
34
+ },
35
+ insert: function(id) {
36
+ return this.image.insert("<img src='/" + id + "'>");
37
+ }
38
+ };
39
+ };
40
+
41
+ }).call(this);