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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59ebb7e9f3d9eaec6e6b965c250f083a696a53bd
4
- data.tar.gz: 7a5d40718af27c18be8f565cd860f01c4dd0c9be
3
+ metadata.gz: d091f0fb55963257f889a74ae1a259e712e0a23b
4
+ data.tar.gz: ea7a99033cfe56a742f8dbea909dd4f7ce8de9b7
5
5
  SHA512:
6
- metadata.gz: ef38499a2b63cc0f9f321844568748e0e0953335e2db4c4d2184715ed5d16f1ab6b5d909fee604e44096143a1381138eccec2b8b0a911f37023c9e2471eb56d0
7
- data.tar.gz: bcfe2eb6df4b024db66c4968b1e50552e7670a8baadf94d440aeea0115761391b30c2b9eeb16ecdf7e8651f9682b225dc1c8ad40fb243e017d7d554d1a47a378
6
+ metadata.gz: 9585b8d80d0b135fdb52d4b6d9a8fe62f11e5ee19a2b291a188250ebb9377d3a7315c0fcdc7c185bb79858b0d1a75315a69bd94524aa079737449f5d95dd6e62
7
+ data.tar.gz: c14e1f67537e6db4b697fd251465d7ece67ba7c570bf7efcc97e2ee866e20b69d51a80173e1b9c182811ebd6f49072ba6737785a3f08e176f995e51e82ae7a77
@@ -0,0 +1,41 @@
1
+ (function() {
2
+ var activate, showDeleteButton;
3
+
4
+ activate = function(element) {
5
+ var cmsField, container;
6
+ cmsField = $(element);
7
+ container = scrivito.editors._setup_binary_button_container(cmsField, 'scrivito-editor-binary-button-container');
8
+ scrivito.editors._file_dropzone(container, function(_, file) {
9
+ return cmsField.scrivito('save', file).then(function() {
10
+ return cmsField.scrivito('reload');
11
+ });
12
+ }, 'image-editor-dragover');
13
+ if (cmsField.scrivito('content') && cmsField.is('[data-scrivito-editors-allow-delete]')) {
14
+ return showDeleteButton(container, cmsField);
15
+ }
16
+ };
17
+
18
+ showDeleteButton = function(container, cmsField) {
19
+ if (container && container.find('.delete-binary').length === 0) {
20
+ return $("<a href='#' class='delete-binary editing-button'> <i class='editing-icon editing-icon-trash'></i></a>").prependTo(container).click(function() {
21
+ return cmsField.scrivito('save', null).then(function() {
22
+ return cmsField.scrivito('reload');
23
+ }) && false;
24
+ });
25
+ }
26
+ };
27
+
28
+ scrivito.editors.binary_editor = {
29
+ can_edit: function(element) {
30
+ return $(element).is('[data-scrivito-field-type=binary]');
31
+ },
32
+ activate: function(element) {
33
+ return activate(element);
34
+ }
35
+ };
36
+
37
+ scrivito.on('load', function() {
38
+ return scrivito.define_editor('binary', scrivito.editors.binary_editor);
39
+ });
40
+
41
+ }).call(this);
@@ -0,0 +1,66 @@
1
+ (function() {
2
+ var activate, onClose, onSelect, save, template;
3
+
4
+ template = function() {
5
+ return $('<input />').attr('type', 'text');
6
+ };
7
+
8
+ save = function(datetimepickerElement, dateTimeText, additionalDoneEvent) {
9
+ var cmsField, datetime;
10
+ cmsField = datetimepickerElement.data('cmsField');
11
+ datetime = datetimepickerElement.datetimepicker('getDate');
12
+ return cmsField.scrivito('save', datetime).done(function() {
13
+ cmsField.trigger('save.scrivito_editors');
14
+ if (additionalDoneEvent) {
15
+ return cmsField.trigger(additionalDoneEvent);
16
+ }
17
+ });
18
+ };
19
+
20
+ onClose = function(dateTimeText) {
21
+ return save($(this), dateTimeText, 'scrivito_editors:blur');
22
+ };
23
+
24
+ onSelect = function(dateTimeText) {
25
+ return save($(this), dateTimeText);
26
+ };
27
+
28
+ activate = function(element) {
29
+ var cmsField;
30
+ cmsField = $(element);
31
+ return cmsField.on('click', function(event) {
32
+ var content, dateFormat, options, timeFormat;
33
+ if (cmsField.is('.hasDatepicker')) {
34
+ return;
35
+ }
36
+ event.preventDefault();
37
+ content = cmsField.text().trim();
38
+ dateFormat = cmsField.data('scrivitoEditorsDateFormat');
39
+ timeFormat = cmsField.data('scrivitoEditorsTimeFormat');
40
+ options = {
41
+ onClose: onClose,
42
+ onSelect: onSelect
43
+ };
44
+ options.dateFormat = dateFormat || 'yy-mm-dd';
45
+ if (timeFormat) {
46
+ options.timeFormat = timeFormat;
47
+ }
48
+ template().data('cmsField', cmsField).insertAfter(cmsField).datetimepicker(options).datetimepicker('setDate', $(cmsField).scrivito('content')).focus();
49
+ return cmsField.hide();
50
+ });
51
+ };
52
+
53
+ scrivito.editors.date_editor = {
54
+ can_edit: function(element) {
55
+ return $(element).is('[data-scrivito-field-type=date]');
56
+ },
57
+ activate: function(element) {
58
+ return activate(element);
59
+ }
60
+ };
61
+
62
+ scrivito.on('load', function() {
63
+ return scrivito.define_editor('date', scrivito.editors.date_editor);
64
+ });
65
+
66
+ }).call(this);
@@ -0,0 +1,43 @@
1
+ (function() {
2
+ var COEXISTING_EDITORS, PRIMARY_EDITORS, default_editor;
3
+
4
+ PRIMARY_EDITORS = ['date_editor', 'enum_editor', 'html_editor', 'image_editor', 'link_editor', 'linklist_editor', 'multienum_editor', 'permalink_editor', 'reference_editor', 'referencelist_editor', 'string_editor', 'stringlist_editor'];
5
+
6
+ COEXISTING_EDITORS = ['binary_editor', 'image_drop_editor'];
7
+
8
+ default_editor = {
9
+ can_edit: function() {
10
+ return true;
11
+ },
12
+ activate: function(element) {
13
+ var editor, i, j, legacyApiEditor, len, len1, ref;
14
+ legacyApiEditor = $(element).data('editor');
15
+ if (legacyApiEditor) {
16
+ editor = legacyApiEditor + "_editor";
17
+ console.warn("data-editor is deprecated, please use scrivito_tag(tag, obj, html_options, editor: '" + legacyApiEditor + "')");
18
+ if ((ref = scrivito.editors[editor]) != null) {
19
+ ref.activate(element);
20
+ }
21
+ return;
22
+ }
23
+ for (i = 0, len = COEXISTING_EDITORS.length; i < len; i++) {
24
+ editor = COEXISTING_EDITORS[i];
25
+ if (scrivito.editors[editor].can_edit(element)) {
26
+ scrivito.editors[editor].activate(element);
27
+ }
28
+ }
29
+ for (j = 0, len1 = PRIMARY_EDITORS.length; j < len1; j++) {
30
+ editor = PRIMARY_EDITORS[j];
31
+ if (scrivito.editors[editor].can_edit(element)) {
32
+ scrivito.editors[editor].activate(element);
33
+ return;
34
+ }
35
+ }
36
+ }
37
+ };
38
+
39
+ scrivito.on('load', function() {
40
+ return scrivito.define_editor('default', default_editor);
41
+ });
42
+
43
+ }).call(this);
@@ -0,0 +1,44 @@
1
+ (function() {
2
+ var DATA_ATTRIBUTES, _deprecationLogged;
3
+
4
+ DATA_ATTRIBUTES = ['autosave', 'date-format', 'filter-context', 'filters', 'max', 'min', 'newlines', 'placeholder', 'reload', 'step', 'time-format', 'values'];
5
+
6
+ _deprecationLogged = [];
7
+
8
+ scrivito.on('content', function(element) {
9
+ var attribute, cmsElement, cmsField, cmsFields, i, len, newAttribute, results, value;
10
+ if (!scrivito.in_editable_view()) {
11
+ return;
12
+ }
13
+ cmsFields = $(element).addBack().find('[data-scrivito-field-type]');
14
+ results = [];
15
+ for (i = 0, len = cmsFields.length; i < len; i++) {
16
+ cmsElement = cmsFields[i];
17
+ cmsField = $(cmsElement);
18
+ results.push((function() {
19
+ var j, len1, results1;
20
+ results1 = [];
21
+ for (j = 0, len1 = DATA_ATTRIBUTES.length; j < len1; j++) {
22
+ attribute = DATA_ATTRIBUTES[j];
23
+ value = cmsField.data(attribute);
24
+ if (value !== void 0) {
25
+ newAttribute = attribute.replace('newlines', 'multiline');
26
+ cmsField.data("scrivito-editors-" + newAttribute, value);
27
+ cmsField.attr("data-scrivito-editors-" + newAttribute, cmsField.attr("data-" + attribute));
28
+ if (!_deprecationLogged[attribute]) {
29
+ _deprecationLogged[attribute] = true;
30
+ results1.push(console.warn("data-" + attribute + " is deprecated, please use data-scrivito-editors-" + newAttribute + "."));
31
+ } else {
32
+ results1.push(void 0);
33
+ }
34
+ } else {
35
+ results1.push(void 0);
36
+ }
37
+ }
38
+ return results1;
39
+ })());
40
+ }
41
+ return results;
42
+ });
43
+
44
+ }).call(this);
@@ -0,0 +1,68 @@
1
+ (function() {
2
+ var activate, clear, save, template,
3
+ indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
4
+
5
+ clear = '__scrivito_editors_enum_clear';
6
+
7
+ template = function(values) {
8
+ var element;
9
+ element = $('<select></select>').addClass('form-control');
10
+ $.each(values, function(index, value) {
11
+ var text;
12
+ if (value === clear) {
13
+ text = '';
14
+ } else {
15
+ text = value;
16
+ }
17
+ return $('<option></option>').attr('value', value).text(text).appendTo(element);
18
+ });
19
+ return element;
20
+ };
21
+
22
+ save = function(event) {
23
+ var cmsField, content, element;
24
+ element = $(event.currentTarget);
25
+ cmsField = element.data('cmsField');
26
+ content = element.val();
27
+ if (content === clear) {
28
+ content = null;
29
+ }
30
+ return cmsField.scrivito('save', content).done(function() {
31
+ return cmsField.trigger('save.scrivito_editors');
32
+ });
33
+ };
34
+
35
+ activate = function(element) {
36
+ var cmsField;
37
+ cmsField = $(element);
38
+ return cmsField.on('click', function() {
39
+ var content, selected, values;
40
+ content = cmsField.scrivito('content');
41
+ values = cmsField.scrivito('allowed_values');
42
+ if (indexOf.call(values, '') < 0) {
43
+ values.push(clear);
44
+ }
45
+ if (content) {
46
+ selected = content;
47
+ } else {
48
+ selected = clear;
49
+ }
50
+ template(values).data('cmsField', cmsField).val(selected).insertAfter(cmsField).change(save).focusout(save).focus();
51
+ return cmsField.hide();
52
+ });
53
+ };
54
+
55
+ scrivito.editors.enum_editor = {
56
+ can_edit: function(element) {
57
+ return $(element).is('[data-scrivito-field-type=enum]');
58
+ },
59
+ activate: function(element) {
60
+ return activate(element);
61
+ }
62
+ };
63
+
64
+ scrivito.on('load', function() {
65
+ return scrivito.define_editor('enum', scrivito.editors.enum_editor);
66
+ });
67
+
68
+ }).call(this);
@@ -0,0 +1,54 @@
1
+ (function() {
2
+ var extendDeepData, mergeFilterContexts,
3
+ hasProp = {}.hasOwnProperty;
4
+
5
+ extendDeepData = function(data, prefix) {
6
+ var i, key, len, name, obj, obj1, path, ref, results, value;
7
+ results = [];
8
+ for (key in data) {
9
+ if (!hasProp.call(data, key)) continue;
10
+ value = data[key];
11
+ if (!(key.search(prefix) === 0)) {
12
+ continue;
13
+ }
14
+ path = key.match(RegExp("([A-Z]|^" + prefix + ")[^A-Z]*", "g"));
15
+ if (path[0] === prefix) {
16
+ ref = path.slice(1).reverse();
17
+ for (i = 0, len = ref.length; i < len; i++) {
18
+ name = ref[i];
19
+ value = (
20
+ obj = {},
21
+ obj["" + (name.toLowerCase())] = value,
22
+ obj
23
+ );
24
+ }
25
+ results.push($.extend(true, data, (
26
+ obj1 = {},
27
+ obj1["" + prefix] = value,
28
+ obj1
29
+ )));
30
+ } else {
31
+ results.push(void 0);
32
+ }
33
+ }
34
+ return results;
35
+ };
36
+
37
+ mergeFilterContexts = function() {
38
+ var cmsFields;
39
+ cmsFields = $("[data-scrivito-field-type][data-scrivito-editors-filter-context],\n[data-scrivito-field-type^=\"html\"],\n[data-scrivito-field-type^=\"link\"],\n[data-scrivito-field-type^=\"reference\"]");
40
+ return cmsFields.each(function() {
41
+ var cmsField, data;
42
+ cmsField = $(this);
43
+ data = cmsField.data();
44
+ return extendDeepData(data, 'scrivitoEditorsFilterContext');
45
+ });
46
+ };
47
+
48
+ scrivito.on('content', function() {
49
+ if (scrivito.in_editable_view()) {
50
+ return mergeFilterContexts();
51
+ }
52
+ });
53
+
54
+ }).call(this);
@@ -0,0 +1,33 @@
1
+ (function() {
2
+ var setup;
3
+
4
+ scrivito.editors._file_dropzone = function(fields, callback) {
5
+ return fields.each(function() {
6
+ return setup($(this), callback);
7
+ });
8
+ };
9
+
10
+ setup = function(el, callback) {
11
+ el.on('dragenter', function() {
12
+ el.children().not('img').css({
13
+ pointerEvents: 'none'
14
+ });
15
+ return el.addClass('image-editor-dragover') && false;
16
+ });
17
+ el.on('dragleave', function() {
18
+ el.children().not('img').css({
19
+ pointerEvents: 'auto'
20
+ });
21
+ return el.removeClass('image-editor-dragover') && false;
22
+ });
23
+ return el.on('drop', function(e) {
24
+ var files, ref, ref1;
25
+ el.removeClass('image-editor-dragover');
26
+ if (((ref = (files = (ref1 = e.originalEvent.dataTransfer) != null ? ref1.files : void 0)) != null ? ref.length : void 0) === 1) {
27
+ callback(el, files[0]);
28
+ }
29
+ return false;
30
+ });
31
+ };
32
+
33
+ }).call(this);
@@ -0,0 +1,5 @@
1
+ (function() {
2
+ scrivito.editors._imgly_asset_path_resolver = function(path) {
3
+ return <%= ScrivitoEditors::Engine.imgly_assets { |file| image_path(file) }.to_json %>[path];
4
+ };
5
+ }).call(this);
@@ -0,0 +1,12 @@
1
+ (function() {
2
+ scrivito.editors._setup_binary_button_container = function(element, container_class) {
3
+ var container;
4
+ container = element.parent(".scrivito-editor-button-container");
5
+ if (container.length) {
6
+ return container.addClass(container_class);
7
+ } else {
8
+ return element.wrap("<div class='" + container_class + " scrivito-editor-button-container' />").parent();
9
+ }
10
+ };
11
+
12
+ }).call(this);
@@ -0,0 +1,15 @@
1
+ (function() {
2
+ scrivito.editors.html_editor = {
3
+ can_edit: function(element) {
4
+ return scrivito.editors.redactor_editor.can_edit(element);
5
+ },
6
+ activate: function(element) {
7
+ return scrivito.editors.redactor_editor.activate(element);
8
+ }
9
+ };
10
+
11
+ scrivito.on('load', function() {
12
+ return scrivito.define_editor('html', scrivito.editors.html_editor);
13
+ });
14
+
15
+ }).call(this);
@@ -0,0 +1,52 @@
1
+ (function() {
2
+ var activate, save;
3
+
4
+ activate = function(element) {
5
+ return scrivito.editors._file_dropzone($(element), save);
6
+ };
7
+
8
+ save = function(field, file) {
9
+ var objClass;
10
+ objClass = scrivito.default_obj_class_for_content_type(file.type);
11
+ return scrivito.create_obj({
12
+ blob: file,
13
+ _obj_class: objClass
14
+ }).then(function(obj) {
15
+ var type, value;
16
+ type = field.attr('data-scrivito-field-type');
17
+ value = (function() {
18
+ switch (type) {
19
+ case 'link':
20
+ return {
21
+ obj_id: obj.id
22
+ };
23
+ case 'linklist':
24
+ return [
25
+ {
26
+ obj_id: obj.id
27
+ }
28
+ ];
29
+ case 'reference':
30
+ return obj.id;
31
+ }
32
+ })();
33
+ return field.scrivito('save', value).then(function() {
34
+ return field.scrivito('reload');
35
+ });
36
+ });
37
+ };
38
+
39
+ scrivito.editors.image_drop_editor = {
40
+ can_edit: function(element) {
41
+ return $(element).is('img[data-scrivito-field-type=link],\nimg[data-scrivito-field-type=linklist],\nimg[data-scrivito-field-type=reference]');
42
+ },
43
+ activate: function(element) {
44
+ return activate(element);
45
+ }
46
+ };
47
+
48
+ scrivito.on('load', function() {
49
+ return scrivito.define_editor('image_drop', scrivito.editors.image_drop_editor);
50
+ });
51
+
52
+ }).call(this);
@@ -0,0 +1,114 @@
1
+ (function() {
2
+ var activate, open_image_editing_dialog, open_image_editing_dialog_options, save_edited_image, setup_edit_btn, setup_image_kit, setup_image_kit_container;
3
+
4
+ activate = function(element) {
5
+ return setup_edit_btn($(element));
6
+ };
7
+
8
+ setup_edit_btn = function(element) {
9
+ scrivito.editors._setup_binary_button_container(element, 'scrivito-editor-image-button-container');
10
+ if (element.scrivito('content')) {
11
+ return $("<a href='#' class='edit-image editing-button'> <i class='editing-icon editing-icon-edit'></i></a>").insertBefore(element).click(function(event) {
12
+ event.preventDefault();
13
+ return open_image_editing_dialog(element);
14
+ });
15
+ }
16
+ };
17
+
18
+ open_image_editing_dialog = function(element) {
19
+ var content, dialog;
20
+ content = $("<div class='image_kit_start' />");
21
+ dialog = scrivito.dialog(content, open_image_editing_dialog_options());
22
+ return setup_image_kit_container(element, dialog);
23
+ };
24
+
25
+ open_image_editing_dialog_options = function() {
26
+ var dialog_options;
27
+ return dialog_options = {
28
+ color: "dark",
29
+ confirm: {
30
+ title: "Confirm",
31
+ color: "green"
32
+ },
33
+ cancel: {
34
+ title: "Cancel",
35
+ color: "lightgrey"
36
+ }
37
+ };
38
+ };
39
+
40
+ setup_image_kit = function(image, container) {
41
+ return new ImglyKit({
42
+ renderer: "canvas",
43
+ assetsUrl: "imgly_sdk",
44
+ image: image,
45
+ versionCheck: false,
46
+ container: container[0],
47
+ ui: {
48
+ enabled: true,
49
+ assetPathResolver: scrivito.editors._imgly_asset_path_resolver
50
+ }
51
+ });
52
+ };
53
+
54
+ setup_image_kit_container = function(element, dialog) {
55
+ var container, fallbackUrl, image, url;
56
+ container = $(".image_kit_start");
57
+ image = new Image();
58
+ url = element.scrivito("content").url;
59
+ image.crossOrigin = "Anonymous";
60
+ image.src = url;
61
+ fallbackUrl = url;
62
+ if (url.indexOf("?") < 0) {
63
+ fallbackUrl = url + "?=" + new Date().getTime();
64
+ } else {
65
+ fallbackUrl = url + "&=" + new Date().getTime();
66
+ }
67
+ image.onerror = function() {
68
+ if (image.src === fallbackUrl) {
69
+ return $("<div style='padding:20px'>\n <h1>We're sorry,</h1>\n <p>Scrivito can't edit this image in your browser. What now?</p>\n <ul>\n <li>Check for browser updates</li>\n <li>Try using a different browser</li>\n <li>Contact us at\n <a href=\"https://scrivito.com/support\" target=\"_blank\">https://scrivito.com/support</a>\n </li>\n </ul>\n</div>").appendTo(container);
70
+ } else {
71
+ console.info("Scrivito detected a probable CORS browser cache mismatch, trying uncached load");
72
+ return image.src = fallbackUrl;
73
+ }
74
+ };
75
+ return image.onload = function() {
76
+ var kit;
77
+ kit = setup_image_kit(image, container);
78
+ kit.ui.selectOperations({
79
+ except: "stickers"
80
+ });
81
+ kit.run();
82
+ return dialog.when_closed.then((function(_this) {
83
+ return function() {
84
+ return save_edited_image(element, kit);
85
+ };
86
+ })(this));
87
+ };
88
+ };
89
+
90
+ save_edited_image = function(element, kit) {
91
+ return kit.render("blob", "image/jpeg").then(function(blob) {
92
+ return element.scrivito("save", scrivito.upload_binary({
93
+ blob: blob,
94
+ filename: element.scrivito("content").filename
95
+ })).then(function() {
96
+ return element.scrivito("reload");
97
+ });
98
+ });
99
+ };
100
+
101
+ scrivito.editors.image_editor = {
102
+ can_edit: function(element) {
103
+ return $(element).is('img[data-scrivito-field-type=binary]');
104
+ },
105
+ activate: function(element) {
106
+ return activate(element);
107
+ }
108
+ };
109
+
110
+ scrivito.on('load', function() {
111
+ return scrivito.define_editor('image', scrivito.editors.image_editor);
112
+ });
113
+
114
+ }).call(this);
@@ -0,0 +1,88 @@
1
+ (function() {
2
+ var activate, openContentBrowser, save, template;
3
+
4
+ scrivito.on('load', function() {
5
+ return scrivito.define_editor('link', scrivito.editors.link_editor);
6
+ });
7
+
8
+ scrivito.editors.link_editor = {
9
+ can_edit: function(element) {
10
+ return $(element).is('[data-scrivito-field-type=link]');
11
+ },
12
+ activate: function(element) {
13
+ return activate($(element));
14
+ }
15
+ };
16
+
17
+ activate = function(cmsField) {
18
+ var link, obj_id;
19
+ link = cmsField.scrivito('content') || {};
20
+ cmsField.html(template(link));
21
+ if (obj_id = link.obj_id) {
22
+ scrivito.description_for_editor([obj_id]).then(function(descriptions) {
23
+ var urlInput;
24
+ urlInput = cmsField.find('[name=url]');
25
+ if (!urlInput.is(':focus')) {
26
+ return urlInput.val(descriptions[0]);
27
+ }
28
+ });
29
+ }
30
+ cmsField.on('blur', 'li input', function() {
31
+ return save(cmsField);
32
+ }).on('click', 'a.scrivito_open_content_browser', function() {
33
+ return openContentBrowser(cmsField);
34
+ });
35
+ return cmsField.find('[name=url]').on('focus', function() {
36
+ var input, raw;
37
+ input = $(this);
38
+ raw = input.data('value');
39
+ if (raw) {
40
+ input.val(raw);
41
+ }
42
+ return input.data('value', null);
43
+ });
44
+ };
45
+
46
+ template = function(link) {
47
+ var obj_url;
48
+ obj_url = link.obj_id && ("/" + link.obj_id);
49
+ return $("<ul>\n <li data-id=\"" + link.obj_id + "\" 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 </div>\n </li>\n</ul>");
50
+ };
51
+
52
+ openContentBrowser = function(cmsField) {
53
+ var id, linkItem;
54
+ linkItem = cmsField.find('li');
55
+ id = linkItem.data('id');
56
+ scrivito.content_browser.open({
57
+ selection: id ? [id] : [],
58
+ selection_mode: 'single',
59
+ filters: cmsField.data('scrivitoEditorsFilters'),
60
+ filter_context: cmsField.data('scrivitoEditorsFilterContext')
61
+ }).done(function(selection) {
62
+ var url, val;
63
+ if (id = selection[0]) {
64
+ url = "/" + id;
65
+ val = "Content browser selection (" + url + ")";
66
+ linkItem.data('id', id).find('[name=url]').data('value', url).val(val);
67
+ return save(cmsField);
68
+ }
69
+ });
70
+ return false;
71
+ };
72
+
73
+ save = function(cmsField) {
74
+ var li, title, url, urlInput, value;
75
+ li = cmsField.find('li');
76
+ title = li.find('[name=title]').val();
77
+ urlInput = li.find('[name=url]');
78
+ url = urlInput.data('value') || urlInput.val();
79
+ value = url ? {
80
+ title: title,
81
+ url: url
82
+ } : null;
83
+ return cmsField.scrivito('save', value).done(function() {
84
+ return cmsField.trigger('save.scrivito_editors');
85
+ });
86
+ };
87
+
88
+ }).call(this);