summaryrefslogtreecommitdiff
path: root/addons/website/static/src
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2013-12-16 14:44:24 +0100
committerXavier Morel <xmo@openerp.com>2013-12-16 14:44:24 +0100
commit98c4e6b3d4023663e4fda1244d57dbf94219fd9d (patch)
treedc33117365aad6f60bb3407556c376fe5b040840 /addons/website/static/src
parentd15f3d2b8a420da788f741b933c429538fcbdaef (diff)
[IMP] editability criteria for links and images
if a link or image is an editing host (has @contenteditable=true), its body is editable *but* its attributes should not be considered editable: if the attributes come from a t-att-*, @contenteditable will be set on the node itself. such elements should be ignored by the link & image dialog handling thing, as editing their attributes has undesirable effects. bzr revid: xmo@openerp.com-20131216134424-fdqs03i9pidbmaqt
Diffstat (limited to 'addons/website/static/src')
-rw-r--r--addons/website/static/src/js/website.editor.js37
1 files changed, 26 insertions, 11 deletions
diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js
index 40b7820e89a..1e3ef0da66a 100644
--- a/addons/website/static/src/js/website.editor.js
+++ b/addons/website/static/src/js/website.editor.js
@@ -32,6 +32,27 @@
});
});
+ /**
+ * An editing host is an HTML element with @contenteditable=true, or the
+ * child of a document in designMode=on (but that one's not supported)
+ *
+ * https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#editing-host
+ */
+ function is_editing_host(element) {
+ return element.getAttribute('contentEditable') === 'true';
+ }
+ /**
+ * Checks that both the element's content *and the element itself* are
+ * editable: an editing host is considered non-editable because its content
+ * is editable but its attributes should not be considered editable
+ */
+ function is_editable_node(element) {
+ return !(element.data('oe-model') === 'ir.ui.view'
+ || element.data('cke-realelement')
+ || is_editing_host(element)
+ || element.isReadOnly());
+ }
+
function link_dialog(editor) {
return new website.editor.RTELinkDialog(editor).appendTo(document.body);
}
@@ -54,18 +75,13 @@
init: function (editor) {
editor.on('doubleclick', function (evt) {
var element = evt.data.element;
- if (element.is('img')
- && !element.data('cke-realelement')
- && !element.isReadOnly()
- && (element.data('oe-model') !== 'ir.ui.view')) {
+ if (element.is('img') && is_editable_node(element)) {
image_dialog(editor, element);
return;
}
element = get_selected_link(editor) || evt.data.element;
- if (element.isReadOnly()
- || !element.is('a')
- || element.data('oe-model')) {
+ if (!(element.is('a') && is_editable_node(element))) {
return;
}
@@ -360,7 +376,8 @@
});
$body.css('padding-top', '50px'); // Not working properly: editor.$el.outerHeight());
};
- /* ----- TOP EDITOR BAR FOR ADMIN ---- */
+
+ /* ----- TOP EDITOR BAR FOR ADMIN ---- */
website.EditorBar = openerp.Widget.extend({
template: 'website.editorbar',
events: {
@@ -597,9 +614,7 @@
if (previous && previous === this) { return; }
var selected = new CKEDITOR.dom.element(this);
- if (selected.data('oe-model') === 'ir.ui.view'
- || selected.data('cke-realelement')
- || selected.isReadOnly()) {
+ if (!is_editable_node(selected)) {
return;
}