lib/assets/javascripts/scrivito_editing.js in scrivito_sdk-0.14.0 vs lib/assets/javascripts/scrivito_editing.js in scrivito_sdk-0.15.0
- old
+ new
@@ -9680,18 +9680,56 @@
});
return this.ScrivitoHandlebarsTemplates["element_overlay"];
}).call(this);
(function() {
this.ScrivitoHandlebarsTemplates || (this.ScrivitoHandlebarsTemplates = {});
- this.ScrivitoHandlebarsTemplates["inplace_menu"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
+ this.ScrivitoHandlebarsTemplates["inplace_marker"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [3,'>= 1.0.0-rc.4'];
helpers = helpers || Handlebars.helpers; data = data || {};
var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;
function program1(depth0,data) {
var buffer = "", stack1;
+ buffer += "\n <span class=\"scrivito_editing_marker_title\">";
+ if (stack1 = helpers.description) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0.description; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + "</span>\n ";
+ return buffer;
+ }
+
+ buffer += "<span class=\"scrivito_editing_marker ";
+ if (stack1 = helpers.css_classes) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0.css_classes; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + "\" title=\"";
+ if (stack1 = helpers.tooltip) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0.tooltip; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + "\">\n <i class=\"scrivito_icon\">";
+ if (stack1 = helpers.icon) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0.icon; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + "</i>\n ";
+ stack1 = helpers['if'].call(depth0, depth0.description, {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
+ if(stack1 || stack1 === 0) { buffer += stack1; }
+ buffer += "\n</span>\n";
+ return buffer;
+ });
+ return this.ScrivitoHandlebarsTemplates["inplace_marker"];
+}).call(this);
+(function() {
+ this.ScrivitoHandlebarsTemplates || (this.ScrivitoHandlebarsTemplates = {});
+ this.ScrivitoHandlebarsTemplates["menu"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
+ this.compilerInfo = [3,'>= 1.0.0-rc.4'];
+helpers = helpers || Handlebars.helpers; data = data || {};
+ var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;
+
+function program1(depth0,data) {
+
+ var buffer = "", stack1;
buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.is_present, {hash:{},inverse:self.noop,fn:self.program(2, program2, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n ";
return buffer;
@@ -9740,66 +9778,20 @@
if (stack1 = helpers.reason_for_being_disabled) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.reason_for_being_disabled; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
return escapeExpression(stack1);
}
- buffer += "<div id=\"";
- if (stack1 = helpers.id) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0.id; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "\" class=\"scrivito_editing_marker_menu\">\n <ul class=\"scrivito_menu_box scrivito_right\">\n ";
+ buffer += "<div class=\"scrivito_editing_marker_menu\">\n <ul class=\"scrivito_menu_box scrivito_right\">\n ";
stack1 = helpers.each.call(depth0, depth0.commands, {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n </ul>\n</div>\n";
return buffer;
});
- return this.ScrivitoHandlebarsTemplates["inplace_menu"];
+ return this.ScrivitoHandlebarsTemplates["menu"];
}).call(this);
(function() {
this.ScrivitoHandlebarsTemplates || (this.ScrivitoHandlebarsTemplates = {});
- this.ScrivitoHandlebarsTemplates["inplace_menu_marker"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
- this.compilerInfo = [3,'>= 1.0.0-rc.4'];
-helpers = helpers || Handlebars.helpers; data = data || {};
- var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;
-
-function program1(depth0,data) {
-
- var buffer = "", stack1;
- buffer += "\n <span class=\"scrivito_editing_marker_title\">";
- if (stack1 = helpers.description) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0.description; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "</span>\n ";
- return buffer;
- }
-
- buffer += "<span class=\"scrivito_editing_marker ";
- if (stack1 = helpers.css_classes) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0.css_classes; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "\" id=\"";
- if (stack1 = helpers.id) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0.id; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "\" title=\"";
- if (stack1 = helpers.tooltip) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0.tooltip; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "\">\n <i class=\"scrivito_icon\">";
- if (stack1 = helpers.icon) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0.icon; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "</i>\n ";
- stack1 = helpers['if'].call(depth0, depth0.description, {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
- if(stack1 || stack1 === 0) { buffer += stack1; }
- buffer += "\n</span>\n";
- return buffer;
- });
- return this.ScrivitoHandlebarsTemplates["inplace_menu_marker"];
-}).call(this);
-(function() {
- this.ScrivitoHandlebarsTemplates || (this.ScrivitoHandlebarsTemplates = {});
this.ScrivitoHandlebarsTemplates["menu_bar"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [3,'>= 1.0.0-rc.4'];
helpers = helpers || Handlebars.helpers; data = data || {};
@@ -9957,11 +9949,11 @@
if (stack1 = helpers.icon) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.icon; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "</i>";
options = {hash:{},data:data};
- buffer += escapeExpression(((stack1 = helpers.translate),stack1 ? stack1.call(depth0, "inplace_menus.sort_items", options) : helperMissing.call(depth0, "translate", "inplace_menus.sort_items", options)))
+ buffer += escapeExpression(((stack1 = helpers.translate),stack1 ? stack1.call(depth0, "inplace_marker.sort_items", options) : helperMissing.call(depth0, "translate", "inplace_marker.sort_items", options)))
+ "</h3>\n </div>\n\n <div class=\"scrivito_modal_body scrivito_auto_height\">\n <ul id=\"scrivito_obj_sorting_sortable\">\n ";
stack2 = helpers.each.call(depth0, depth0.child_list, {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
if(stack2 || stack2 === 0) { buffer += stack2; }
buffer += "\n </ul>\n </div>\n\n <div class=\"scrivito_modal_footer\">\n <a href=\"#\" class=\"scrivito_button scrivito_cancel\">";
options = {hash:{},data:data};
@@ -10349,11 +10341,14 @@
'commands.sort_items.tooltip': 'Reihenfolge der Elemente unterhalb $1 bearbeiten',
'commands.sort_items.auto_sort': 'Diese Navigation wird automatisch sortiert.',
'commands.sort_items.too_less_children': 'Die Navigation kann nicht sortiert werden, weil sie weniger als zwei Elemente enthält.',
'commands.add_widget.title': 'Widget einfügen',
+
'commands.widget_details.title': 'Widget-Eigenschaften',
+ 'commands.widget_details.no_details_view': 'Dieses Widget hat keine Eigenschaften',
+
'commands.save_widget_to_clipboard.title': 'Widget zum Kopieren markieren',
'commands.copy_widget_from_clipboard.title': 'Markiertes Widget hierher kopieren',
'commands.copy_widget_from_clipboard.paste_forbidden': 'Aufgrund ihres Typs kann das Widget hier nicht eingefügt werden. Nur Widgets der folgenden Typen können hierher verschoben oder kopiert werden: $1',
@@ -10498,11 +10493,14 @@
'commands.sort_items.tooltip': 'Edit order of items underneath $1',
'commands.sort_items.auto_sort': 'This navigation is sorted automatically.',
'commands.sort_items.too_less_children': 'This navigation cannot be sorted because it consists of less than two items.',
'commands.add_widget.title': 'Insert widget',
+
'commands.widget_details.title': 'Widget properties',
+ 'commands.widget_details.no_details_view': 'This widget has no properties',
+
'commands.save_widget_to_clipboard.title': 'Mark widget for copying',
'commands.copy_widget_from_clipboard.title': 'Copy marked widget here',
'commands.copy_widget_from_clipboard.paste_forbidden': 'Due to its type, the widget cannot be moved or copied here. Only widgets of the following types can be inserted here: $1',
@@ -10664,21 +10662,39 @@
window.console.warn(message);
},
on: function(event, callback) {
if (event === 'editing') {
+ scrivito.deprecation_warning('scrivito.on("editing", ...)',
+ 'scrivito.on("load", ...) && scrivito.in_editable_view()');
scrivito.gui.on('editing', function() {
if (scrivito.editing_context.visible_workspace.is_editable()) {
callback();
}
});
} else if (event === 'new_content') {
+ scrivito.deprecation_warning('scrivito.on("new_content", ...)',
+ 'scrivito.on("content", ...)');
scrivito.gui.on('new_content', function(dom_element) {
- if (dom_element) {
- callback(dom_element);
- }
+ callback(dom_element);
});
+ } else if (event === 'load') {
+ scrivito.gui.on('open', function() {
+ callback();
+ });
+
+ if (scrivito.gui.is_started()) {
+ callback();
+ }
+ } else if (event === 'content') {
+ scrivito.on('load', function() {
+ callback(window.document);
+ });
+
+ scrivito.gui.on('content', function(dom_element) {
+ callback(dom_element);
+ });
} else {
$.error('Unknown event "' + event + '"');
}
},
@@ -10708,31 +10724,28 @@
} else {
$.error('Unknown event "' + event_name + '"');
}
},
- open_resource_dialog: function(obj_id) {
- var title = scrivito.i18n.translate('resource');
+ in_editable_view: function() {
+ return scrivito.editing_context.display_mode === 'editing' &&
+ scrivito.editing_context.visible_workspace.is_editable();
+ },
- var obj = scrivito.obj.create_instance({
- id: obj_id
- });
- var fetch_markup = function() {
- return obj.fetch_details_markup();
- };
-
- return scrivito.details_dialog.open(title, fetch_markup, '');
+ open_resource_dialog: function(obj_id) {
+ return scrivito.resource_dialog.open(obj_id);
},
init: function(config) {
scrivito.config = config;
scrivito.editing_context.init(config.editing_context);
scrivito.i18n.init(config.i18n);
scrivito.obj.init(config.obj);
+ scrivito.resource_dialog.init(config.open_resource_dialog);
- scrivito.inplace_menus.init();
+ scrivito.inplace_marker.init();
scrivito.menu_bar_saving_indicator.init();
scrivito.menu_bar_toggle.init();
scrivito.menu_bar_dropdown.init();
scrivito.workspace_select.init();
scrivito.menu_bar.init();
@@ -10874,20 +10887,26 @@
if (dom_element) {
callback(dom_element);
}
});
}
+
+ if (callbacks.content) {
+ _.each(callbacks.content, function(callback) {
+ if (dom_element) {
+ callback(dom_element);
+ }
+ });
+ }
};
$.extend(scrivito, {
gui: {
start: function() {
$('body').attr('data-scrivito-display-mode', scrivito.editing_context.display_mode);
-
- run_open_callbacks();
-
$('body').append('<div id="ip-editing"></div>');
+ run_open_callbacks();
},
new_content: function(dom_element) {
run_new_content_callbacks(dom_element);
},
@@ -10901,10 +10920,14 @@
},
// for testing purposes only
reset_callbacks: function() {
callbacks = {};
+ },
+
+ is_started: function() {
+ return !!$('body').attr('data-scrivito-display-mode');
}
}
});
}());
(function() {
@@ -11589,22 +11612,11 @@
var obj_id = element.attr('data-scrivito-private-changes-list-obj-id');
var obj_modification = element.attr(
'data-scrivito-private-changes-list-obj-modification');
var obj_is_binary = element.attr('data-scrivito-private-changes-list-obj-is-binary');
- if (!!obj_is_binary) {
- scrivito.open_resource_dialog(obj_id);
- } else {
- if (obj_modification === 'deleted') {
- scrivito.change_location('/' + obj_id + '?_scrivito_display_mode=deleted');
- } else if (obj_modification === 'new' &&
- scrivito.editing_context.is_deleted_mode()) {
- scrivito.change_location('/' + obj_id + '?_scrivito_display_mode=added');
- } else {
- scrivito.change_location('/' + obj_id);
- }
- }
+ scrivito.changes_dialog.redirect_to_obj(obj_id, obj_modification, obj_is_binary);
return false;
});
});
};
@@ -11627,10 +11639,30 @@
}).then(function() {
scrivito.dialog.adjust(view);
});
return scrivito.with_dialog_behaviour(deferred, {escape: cancel});
+ },
+
+ redirect_to_obj: function(obj_id, modification, is_binary) {
+ var base_url = '/';
+ var query_params = {};
+
+ if (!!is_binary) {
+ base_url = '/__scrivito/details_page/';
+ query_params.return_to = document.URL;
+ }
+
+ if (modification === 'deleted' && !scrivito.editing_context.is_deleted_mode()) {
+ query_params._scrivito_display_mode = 'deleted';
+ }
+
+ if (modification === 'new' && scrivito.editing_context.is_deleted_mode()) {
+ query_params._scrivito_display_mode = 'added';
+ }
+
+ scrivito.change_location(base_url + obj_id + '?' + $.param( query_params ));
}
}
});
var batch;
@@ -11867,10 +11899,23 @@
return dom_element;
},
equals: function(cms_element) {
return cms_element.dom_element().get(0) === that.dom_element().get(0);
+ },
+
+ menu: function() {
+ var menu = dom_element.data('scrivito-menu');
+ if (!menu) {
+ menu = [];
+ that.set_menu(menu);
+ }
+ return menu;
+ },
+
+ set_menu: function(menu) {
+ dom_element.data('scrivito-menu', menu);
}
};
return that;
},
@@ -12516,10 +12561,14 @@
container_modification: function() {
return options.container_modification;
},
+ description_for_editor: function() {
+ return options.description_for_editor;
+ },
+
is_modified: function() {
return !!(that.modification() || that.container_modification());
},
save: function(widget_attributes) {
@@ -12567,17 +12616,20 @@
if (cms_element.dom_element().attr('data-scrivito-private-widget-id')) {
var that = cms_element;
$.extend(that, {
widget: function() {
+ var dom_element = that.dom_element();
return scrivito.widget.create_instance(that.widget_field().obj(),
- that.dom_element().attr('data-scrivito-private-widget-id'),
- that.dom_element().attr('data-scrivito-widget-obj-class'),
+ dom_element.attr('data-scrivito-private-widget-id'),
+ dom_element.attr('data-scrivito-widget-obj-class'),
{
- modification: that.dom_element().attr('data-scrivito-private-widget-modification'),
- container_modification: that.dom_element().attr(
- 'data-scrivito-private-widget-container-modification')
+ modification: dom_element.attr('data-scrivito-private-widget-modification'),
+ container_modification: dom_element.attr(
+ 'data-scrivito-private-widget-container-modification'),
+ description_for_editor: dom_element.attr(
+ 'data-scrivito-private-widget-description-for-editor')
}
);
},
widget_field: function() {
@@ -12622,11 +12674,12 @@
return widget_element.widget().id();
});
},
widget_elements: function() {
- var widget_elements_dom = that.dom_element().children('[data-scrivito-private-widget-id]');
+ var widget_elements_dom = that.dom_element()
+ .children('[data-scrivito-private-widget-id]');
var widget_elements = _.map(widget_elements_dom, function(widget_element_dom) {
return scrivito.cms_element.from_dom_element($(widget_element_dom));
});
return widget_elements;
},
@@ -12679,11 +12732,12 @@
});
var add_widget = function(widget_spec, widget_element) {
var position;
if (widget_element) {
- position = widget_element.dom_element().index() + 1;
+ position = widget_element.dom_element()
+ .prevAll('[data-scrivito-private-widget-id]').length + 1;
} else {
position = that.widget_elements().length;
}
var content = that.content();
@@ -13362,15 +13416,21 @@
target.hide();
spinner.show();
fetch_markup().then(function(markup) {
target.html(markup);
- var modal_size = $(markup).attr('data-scrivito-modal-size');
- var valid_sizes = ['small', 'medium', 'large'];
- if ($.inArray(modal_size, valid_sizes) !== -1) {
+
+ var size_attr = 'data-scrivito-modal-size';
+ var modal_size = $(markup).attr(size_attr) ||
+ $(markup).find('[' + size_attr + ']').attr(size_attr);
+ if (_.contains(['small', 'medium', 'large'], modal_size)) {
view.removeClass('scrivito_modal_medium');
- view.addClass('scrivito_modal_' + modal_size);
+ scrivito.transition(view, function() {
+ view.addClass('scrivito_modal_' + modal_size);
+ }).then(function() {
+ scrivito.dialog.adjust(view);
+ });
}
spinner.hide();
target.show();
@@ -13410,184 +13470,162 @@
}
}
});
}());
(function() {
- var menu_define_callbacks = [];
- var dom_elements_with_menus = [];
- var dom_elements_with_marker = [];
- var fade_time = 500;
-
$.extend(scrivito, {
- inplace_menus: {
- define: function(menu_define_callback) {
- menu_define_callbacks.push(menu_define_callback);
- },
+ menus: {
+ open: function(dom_element, commands) {
+ scrivito.menus.close_all();
- refresh_positions: function() {
- _.each($('.scrivito_editing_marker_menu'), function(menu_dom) {
- var menu = $(menu_dom);
- var marker = $('#' + menu.data('scrivito-private-menu-marker-id'));
- menu.offset(marker.offset());
- });
- },
+ var menu = $(scrivito.template.render('menu', {commands: commands}));
- reset_menu_define_callbacks: function() {
- menu_define_callbacks = [];
- },
+ menu.data('scrivito-private-menus-target', dom_element);
+ dom_element.data('scrivito-private-menus-menu', menu);
- init: function() {
- scrivito.gui.on('open', function() {
- scrivito.inplace_menus.refresh();
+ _.each(commands, function(command) {
+ menu.find('.scrivito_menu_item.' + command.id()).on('click', function() {
+ if (command.is_enabled()) {
+ close(menu);
+ }
+ command.execute();
+ return false;
+ });
});
- scrivito.gui.on('new_content', function() {
- scrivito.inplace_menus.refresh();
- });
+ menu.appendTo($('body'));
+ menu.offset(dom_element.offset()); // Bugfix IE: offset can not be set before append.
+ menu.find('.scrivito_menu_box').fadeIn(500);
},
- close_all_menus: function() {
- remove_menus();
- },
-
- refresh: function() {
- if (!scrivito.editing_context.is_view_mode()) {
- remove_markers_and_menus();
- collect_menu_items();
- render_menu_items();
- scrivito.inplace_menus.refresh_positions();
+ toggle: function(dom_element, commands) {
+ var menu = dom_element.data('scrivito-private-menus-menu');
+ if (menu) {
+ close(menu);
+ } else {
+ scrivito.menus.open(dom_element, commands);
}
- }
- }
- });
-
- var collect_menu_items = function() {
- var menu = {
- add_item: function(dom_element, command) {
- dom_element = $(dom_element);
- var commands = dom_element.data('scrivito-private-menu-commands') || [];
- commands.push(command);
- dom_elements_with_menus.push(dom_element);
- if (command.is_present()) {
- dom_elements_with_marker.push(dom_element);
- }
- dom_element.data('scrivito-private-menu-commands', commands);
},
- set_icon: function(dom_element, icon) {
- $(dom_element).attr('data-scrivito-private-menu-icon', icon);
+ close_all: function() {
+ each_menu(function(menu) {
+ close(menu);
+ });
},
- set_description: function(dom_element, description) {
- $(dom_element).attr('data-scrivito-private-menu-description', description);
- },
-
- set_tooltip: function(dom_element, tooltip) {
- $(dom_element).attr('data-scrivito-private-menu-tooltip', tooltip);
- },
-
- set_css_classes: function(dom_element, css_classes) {
- $(dom_element).attr('data-scrivito-private-menu-css-classes', css_classes);
+ refresh_positions: function() {
+ each_menu(function(menu) {
+ menu.offset(menu.data('scrivito-private-menus-target').offset());
+ });
}
- };
+ }
+ });
- _.each($(menu_define_callbacks), function(menu_define_callback) {
- menu_define_callback(menu);
+ var each_menu = function(callback) {
+ _.each($('.scrivito_editing_marker_menu'), function(menu) {
+ callback($(menu));
});
};
- var fade_out_and_remove_menus = function(menus) {
- menus.fadeOut(fade_time, function() {
- menus.remove();
+ var close = function(menu) {
+ menu.data('scrivito-private-menus-target').removeData('scrivito-private-menus-menu');
+ menu.fadeOut(500, function() {
+ menu.remove();
});
};
+}());
- var render_menu_items = function() {
- _.each($(dom_elements_with_marker), function(dom_element, i) {
- if (dom_element.children('.scrivito_editing_marker').length === 0) {
- var menu_id = 'scrivito_private_menu_' + i;
- var marker_id = 'scrivito_private_menu_marker_' + i;
+$(window).on('resize', function() {
+ scrivito.menus.refresh_positions();
+});
- var icon = dom_element.attr('data-scrivito-private-menu-icon') || '\uf000';
- var description = dom_element.attr('data-scrivito-private-menu-description');
- var tooltip = dom_element.attr('data-scrivito-private-menu-tooltip');
- var css_classes = dom_element.attr('data-scrivito-private-menu-css-classes');
- var commands = dom_element.data('scrivito-private-menu-commands');
+$(window).on('load', function() {
+ scrivito.menus.refresh_positions();
+});
+(function() {
+ var callbacks = [];
- var marker = $(scrivito.template.render('inplace_menu_marker', {
- id: marker_id,
- icon: icon,
- description: description,
- tooltip: tooltip,
- css_classes: css_classes
- }));
+ $.extend(scrivito, {
+ inplace_marker: {
+ init: function() {
+ scrivito.on('load', function() {
+ scrivito.inplace_marker.refresh();
+ });
+ scrivito.on('content', function() {
+ scrivito.inplace_marker.refresh();
+ });
+ },
- marker.data('scrivito-private-menu-id', marker_id);
+ define: function(callback) {
+ callbacks.push(callback);
+ },
- marker.on('click.ip-menu-open', function(e) {
- e.preventDefault();
+ refresh: function() {
+ if (!scrivito.editing_context.is_view_mode()) {
+ $('.scrivito_editing_marker').remove();
- var menu = $('#' + menu_id);
+ _.each(callbacks, function(callback) {
+ callback(builder);
+ });
- var remove_menu = function() {
- fade_out_and_remove_menus(menu);
- };
+ scrivito.menus.refresh_positions();
+ }
+ },
- if (menu.length === 0) {
- fade_out_and_remove_menus($('.scrivito_editing_marker_menu').not(menu));
+ // For test purpose only.
+ reset_callbacks: function() {
+ callbacks = [];
+ }
+ }
+ });
- menu = $(scrivito.template.render('inplace_menu', {id: menu_id, commands: commands}));
+ var builder = {
+ activate_for: function(cms_element, options) {
+ var marker = $(scrivito.template.render('inplace_marker',
+ $.extend({icon: '\uf000'}, options || {})));
- _.each(commands, function(command) {
- menu.find('.scrivito_menu_item.' + command.id()).click(function() {
- if (command.is_enabled()) {
- remove_menu();
- }
- command.execute();
- return false;
- });
- });
+ marker.on('click', function() {
+ scrivito.menus.toggle(marker, cms_element.menu());
+ return false;
+ });
- menu.data('scrivito-private-menu-marker-id', marker_id);
+ marker.prependTo(cms_element.dom_element());
+ }
+ };
+}());
+(function() {
+ $.extend(scrivito, {
+ resource_dialog: {
+ init: function(config) {
+ if (config) {
+ scrivito.gui.on('open', function() {
+ scrivito.resource_dialog.open_and_redirect_on_close(config.obj_id, config.redirect_to);
+ });
+ }
+ },
- $('body').append(menu);
+ open: function(obj_id) {
+ var title = scrivito.i18n.translate('resource');
- // Bugfix IE: offset can not be set before append.
- menu.offset(marker.offset());
- menu.find('.scrivito_menu_box').fadeIn(fade_time);
- } else {
- remove_menu();
- }
+ var obj = scrivito.obj.create_instance({
+ id: obj_id
});
+ var fetch_markup = function() {
+ return obj.fetch_details_markup();
+ };
- dom_element.prepend(marker);
- }
- });
- };
+ return scrivito.details_dialog.open(title, fetch_markup, '');
+ },
- var remove_markers_and_menus = function() {
- $('.scrivito_editing_marker').remove();
- remove_menus();
- };
-
- var remove_menus = function() {
- fade_out_and_remove_menus($('.scrivito_editing_marker_menu'));
- _.each($(dom_elements_with_menus), function(element) {
- element.removeData('scrivito-private-menu-commands');
- });
- dom_elements_with_menus = [];
- dom_elements_with_marker = [];
- };
+ open_and_redirect_on_close: function(obj_id, redirect_to) {
+ scrivito.resource_dialog.open(obj_id).done(function() {
+ return scrivito.redirect_to(redirect_to);
+ });
+ }
+ }
+ });
}());
-
-$(window).on('resize', function() {
- scrivito.inplace_menus.refresh_positions();
-});
-
-$(window).on('load', function() {
- scrivito.inplace_menus.refresh_positions();
-});
(function() {
$.extend(scrivito, {
add_subpage_command: function(child_list_element) {
return scrivito.command.create_instance({
id: 'add_subpage',
@@ -13629,15 +13667,17 @@
}
},
execute: function() {
var selection = widget_field_element.fetch_widget_class_selection();
- return scrivito.choose_obj_class_dialog(selection, 'add_widget').then(function(obj_class) {
+ var choose_widget_obj_class = scrivito.choose_obj_class_dialog(selection, 'add_widget');
+ return choose_widget_obj_class.then(function(obj_class) {
return scrivito.with_saving_overlay(
widget_field_element.create_widget(obj_class, widget_element).then(function(widget) {
return widget.fetch_show_markup().then(function(widget_markup) {
- var dom_element = widget_field_element.append_widget_markup(widget_markup);
+ var dom_element = widget_field_element
+ .append_widget_markup(widget_markup, widget_element);
scrivito.ensure_fully_visible_within_window(dom_element);
scrivito.widget_sorting.update_placeholder(widget_field_element);
});
})
);
@@ -13711,14 +13751,15 @@
var obj_id = widget.obj().id();
var copy_widget = widget_field_element.copy_widget(obj_id, widget_id, widget_element);
return scrivito.with_saving_overlay(copy_widget.then(function(widget) {
return widget.fetch_show_markup().then(function(widget_markup) {
- var dom_element = widget_field_element.append_widget_markup(widget_markup);
+ var dom_element = widget_field_element
+ .append_widget_markup(widget_markup, widget_element);
scrivito.ensure_fully_visible_within_window(dom_element);
scrivito.widget_sorting.update_placeholder(widget_field_element);
- scrivito.inplace_menus.refresh();
+ scrivito.inplace_marker.refresh();
});
}));
}
});
}
@@ -13753,10 +13794,14 @@
color: 'red',
confirm_button_text: scrivito.i18n.translate('commands.delete_obj.dialog.confirm'),
confirm_button_color: 'red'
}).then(function() {
return scrivito.with_saving_overlay(obj.destroy().then(function() {
+ if (scrivito.obj_clipboard.is_present() &&
+ scrivito.obj_clipboard.obj().id() === obj.id()) {
+ scrivito.obj_clipboard.clear();
+ }
return scrivito.redirect_to('/');
}));
});
}
});
@@ -13786,17 +13831,22 @@
}).then(function() {
var widget = widget_element.widget();
widget_element.dom_element().remove();
if (widget_field_element.widget_elements().length === 0) {
- scrivito.inplace_menus.refresh();
+ scrivito.inplace_marker.refresh();
}
scrivito.widget_sorting.update_placeholder(widget_field_element);
return widget_field_element.save().then(function() {
- return widget.destroy();
+ return widget.destroy().then(function() {
+ if (scrivito.widget_clipboard.is_present() &&
+ scrivito.widget_clipboard.widget().id() === widget.id()) {
+ scrivito.widget_clipboard.clear();
+ }
+ });
});
});
}
});
}
@@ -14011,11 +14061,10 @@
}
},
execute: function() {
scrivito.obj_clipboard.save_obj(obj);
- scrivito.inplace_menus.refresh();
}
});
}
});
}());
@@ -14031,11 +14080,10 @@
return scrivito.editing_context.is_editing_mode();
},
execute: function() {
scrivito.widget_clipboard.save_widget(widget_element.widget());
- scrivito.inplace_menus.refresh();
}
});
}
});
}());
@@ -14079,14 +14127,20 @@
id: 'widget_details',
title: scrivito.i18n.translate('commands.widget_details.title'),
icon: '',
present: function() {
- return widget_element.has_details_view() &&
- (scrivito.editing_context.is_editing_mode() || widget_element.widget().is_modified());
+ return scrivito.editing_context.is_editing_mode() ||
+ widget_element.widget().is_modified();
},
+ disabled: function() {
+ if (!widget_element.has_details_view()) {
+ return scrivito.i18n.translate('commands.widget_details.no_details_view');
+ }
+ },
+
execute: function() {
var dialog_title = widget_element.widget().widget_class_name();
var fetch_markup = function() {
return widget_element.fetch_details_markup();
};
@@ -14103,117 +14157,122 @@
}());
(function() {
$.extend(scrivito, {
widget_menus: {
init: function() {
- scrivito.inplace_menus.define(function(menu) {
+ scrivito.inplace_marker.define(function(inplace_marker) {
if (scrivito.editing_context.selected_workspace.is_editable()) {
_.each(scrivito.widget_field_element.all(), function(widget_field_element) {
- var widget_field_dom_element = widget_field_element.dom_element();
- _.each([
+ widget_field_element.set_menu([
scrivito.add_widget_command(widget_field_element),
scrivito.copy_widget_from_clipboard_command(widget_field_element)
- ], function(command) {
- menu.add_item(widget_field_dom_element, command);
- });
+ ]);
+ if (scrivito.editing_context.is_editing_mode() &&
+ widget_field_element.widget_elements().length === 0) {
+ inplace_marker.activate_for(widget_field_element);
+ }
+
_.each(widget_field_element.widget_elements(), function(widget_element) {
- var widget_dom_element = widget_element.dom_element();
- _.each([
+ widget_element.set_menu([
scrivito.add_widget_command(widget_field_element, widget_element),
scrivito.widget_details_command(widget_element),
scrivito.save_widget_to_clipboard_command(widget_element),
scrivito.copy_widget_from_clipboard_command(widget_field_element, widget_element),
scrivito.delete_widget_command(widget_field_element, widget_element)
- ], function(command) {
- menu.add_item(widget_dom_element, command);
- });
+ ]);
- var description = widget_element.widget().widget_class_name();
- menu.set_description(widget_dom_element, description);
-
- if (widget_element.has_details_view() &&
- scrivito.editing_context.is_comparing_mode()) {
- var options = menu_options(widget_element);
- if (options) {
- var tooltip = scrivito.i18n.translate('widget_menus.' + options.key);
- menu.set_tooltip(widget_dom_element, tooltip);
- menu.set_icon(widget_dom_element, options.icon);
- menu.set_css_classes(widget_dom_element, options.css_class);
- }
+ var modification = widget_element.widget().modification() ||
+ widget_element.widget().container_modification();
+ if (scrivito.editing_context.is_editing_mode() ||
+ scrivito.editing_context.is_comparing_mode() && !!modification) {
+ inplace_marker.activate_for(widget_element,
+ inplace_marker_options(widget_element));
}
});
});
}
});
}
}
});
- var menu_options = function(widget_element) {
- var modification = widget_element.widget().modification();
- var container_modification = widget_element.widget().container_modification();
+ var inplace_marker_options = function(widget_element) {
+ var options = {};
- var icon;
- switch (modification) {
- case 'new':
- return {icon: '\uf022', key: 'widget_is_new'};
- case 'deleted':
- return {icon: '\uf018', key: 'widget_is_deleted'};
- case 'edited':
- icon = '\uf035';
- switch (container_modification) {
- case 'new':
- return {
- icon: icon,
- key: 'widget_is_edited_and_dragged_here',
- css_class: 'scrivito_widget_moved_icon'
- };
- case 'deleted':
- return {
- icon: icon,
- key: 'widget_is_edited_and_dragged_away',
- css_class: 'scrivito_widget_moved_icon'
- };
- default:
- return {icon: icon, key: 'widget_is_edited'};
- }
- break;
- default:
- icon = '\uf03c';
- switch (container_modification) {
- case 'new':
- return {icon: icon, key: 'widget_is_dragged_here'};
- case 'deleted':
- return {icon: icon, key: 'widget_is_dragged_away'};
- }
+ if (scrivito.editing_context.is_comparing_mode()) {
+ var tooltip_translation_key;
+ var modification = widget_element.widget().modification();
+ var container_modification = widget_element.widget().container_modification();
+
+ switch (modification) {
+ case 'new':
+ tooltip_translation_key = 'widget_is_new';
+ options.icon = '\uf022';
+ break;
+ case 'deleted':
+ tooltip_translation_key = 'widget_is_deleted';
+ options.icon = '\uf018';
+ break;
+ case 'edited':
+ options.icon = '\uf035';
+ switch (container_modification) {
+ case 'new':
+ tooltip_translation_key = 'widget_is_edited_and_dragged_here';
+ options.css_classes = 'scrivito_widget_moved_icon';
+ break;
+ case 'deleted':
+ tooltip_translation_key = 'widget_is_edited_and_dragged_away';
+ options.css_classes = 'scrivito_widget_moved_icon';
+ break;
+ default:
+ tooltip_translation_key = 'widget_is_edited';
+ }
+ break;
+ default:
+ options.icon = '\uf03c';
+ switch (container_modification) {
+ case 'new':
+ tooltip_translation_key = 'widget_is_dragged_here';
+ break;
+ case 'deleted':
+ tooltip_translation_key = 'widget_is_dragged_away';
+ break;
+ }
+ }
+
+ if (tooltip_translation_key) {
+ options.tooltip = scrivito.i18n.translate('widget_menus.' + tooltip_translation_key);
+ }
}
+
+ options.description = widget_element.widget().description_for_editor();
+
+ return options;
};
}());
(function() {
$.extend(scrivito, {
widget_reloading: {
init: function() {
- activate_for_all_beneath($('body'));
+ scrivito.on('content', function(dom_element) {
+ if (scrivito.in_editable_view()) {
+ var jquery_object = $(dom_element);
- scrivito.on('new_content', function(dom_element) {
- var jquery_object = $(dom_element);
- if (jquery_object.attr('data-scrivito-private-widget-id')) {
- activate_for(jquery_object);
+ if (jquery_object.attr('data-scrivito-private-widget-id')) {
+ activate_for(jquery_object);
+ }
+
+ _.each(jquery_object.find('[data-scrivito-private-widget-id]'), function(dom_element) {
+ activate_for($(dom_element));
+ });
}
- activate_for_all_beneath(jquery_object);
});
}
}
});
- var activate_for_all_beneath = function(jquery_object) {
- _.each(jquery_object.find('[data-scrivito-private-widget-id]'), function(dom_element) {
- activate_for($(dom_element));
- });
- };
-
var activate_for = function(jquery_object) {
jquery_object.on('scrivito_reload', function() {
var widget_element = scrivito.cms_element.from_dom_element(jquery_object);
scrivito.with_element_overlay(jquery_object,
@@ -14230,19 +14289,25 @@
}());
(function() {
$.extend(scrivito, {
widget_sorting: {
init: function() {
- scrivito.gui.on('editing', create);
- scrivito.gui.on('new_content', create);
+ scrivito.on('load', function() {
+ if (scrivito.in_editable_view()) {
+ create();
+ }
+ });
+ scrivito.on('content', function() {
+ create();
+ });
},
start: function(event, ui) {
$('body').addClass('scrivito_widget_dragging_active');
var marker = ui.item.find('.scrivito_editing_marker');
- scrivito.inplace_menus.close_all_menus();
+ scrivito.menus.close_all();
var widget_element = scrivito.cms_element.from_dom_element(ui.item);
var widget_class_name = widget_element.widget().widget_class_name();
_.each(widget_field_elements, function(widget_field_element) {
var dom_element = widget_field_element.dom_element();
@@ -14258,11 +14323,11 @@
},
stop: function() {
$('body').removeClass('scrivito_widget_dragging_active');
- scrivito.inplace_menus.refresh();
+ scrivito.inplace_marker.refresh();
_.each(widget_field_dom_elements, function(dom_element) {
dom_element.removeClass('scrivito_widget_drop_allowed');
if (dom_element.data('ui-sortable')) {
$(dom_element).sortable('enable');
@@ -14350,26 +14415,24 @@
}());
(function() {
$.extend(scrivito, {
child_list_menus: {
init: function() {
- scrivito.inplace_menus.define(function(menu) {
+ scrivito.inplace_marker.define(function(inplace_marker) {
if (scrivito.editing_context.visible_workspace.is_editable() &&
scrivito.editing_context.is_editing_mode()) {
_.each(scrivito.child_list_element.all(), function(child_list_element) {
- var dom_element = child_list_element.dom_element();
- var description = child_list_element.obj().description_for_editor();
- menu.set_description(dom_element,
- scrivito.i18n.translate('child_list_menu.description', description));
- _.each([
+ child_list_element.set_menu([
scrivito.add_subpage_command(child_list_element),
scrivito.copy_page_from_clipboard_command(child_list_element),
scrivito.move_page_from_clipboard_command(child_list_element),
scrivito.sort_items_command(child_list_element)
- ], function(command) {
- menu.add_item(dom_element, command);
- });
+ ]);
+
+ var description = scrivito.i18n.translate('child_list_menu.description',
+ child_list_element.obj().description_for_editor());
+ inplace_marker.activate_for(child_list_element, {description: description});
});
}
});
}
}
@@ -14410,13 +14473,15 @@
(function() {
$.extend(scrivito, {
image_upload: {
init: function() {
- scrivito.on('editing', function() {
- activate_for_field_type('linklist');
- activate_for_field_type('reference');
+ scrivito.on('load', function() {
+ if (scrivito.in_editable_view()) {
+ activate_for_field_type('linklist');
+ activate_for_field_type('reference');
+ }
});
// Disable DnD for all elements by default to prevent the user
// from accidentally opening an image in browser.
$('body').on('dragover', function(e) { return false; });
@@ -14701,9 +14766,11 @@
var data = scrivito.storage.get(storage_key);
return data || {};
};
})();
+
+