summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js/rte.summernote.js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2016-08-29 18:43:55 +0200
committerqsm-odoo <qsm@odoo.com>2016-08-31 16:37:20 +0200
commit0659d94d7fcf3ba601703e86806a5d46bafae2aa (patch)
tree24353c8e6df28c22471bc90c33911f0b260abb5c /addons/web_editor/static/src/js/rte.summernote.js
parent323c949ec4388930cfda021f4adb2bdca6ce366c (diff)
[IMP] web_editor: open link dialog on double click on a link
(Also refactore the code so that the implementation is the same for the media dialog opening on double click on an image).
Diffstat (limited to 'addons/web_editor/static/src/js/rte.summernote.js')
-rw-r--r--addons/web_editor/static/src/js/rte.summernote.js61
1 files changed, 40 insertions, 21 deletions
diff --git a/addons/web_editor/static/src/js/rte.summernote.js b/addons/web_editor/static/src/js/rte.summernote.js
index 26c2938b1b2..36310c89335 100644
--- a/addons/web_editor/static/src/js/rte.summernote.js
+++ b/addons/web_editor/static/src/js/rte.summernote.js
@@ -722,31 +722,27 @@ function summernote_ie_fix (event, pred) {
var fn_attach = eventHandler.attach;
eventHandler.attach = function (oLayoutInfo, options) {
fn_attach.call(this, oLayoutInfo, options);
+
oLayoutInfo.editor().on('dragstart', 'img', function (e) { e.preventDefault(); });
- $(document).on('mousedown', summernote_mousedown);
- $(document).on('mouseup', summernote_mouseup);
+ $(document).on('mousedown', summernote_mousedown).on('mouseup', summernote_mouseup);
oLayoutInfo.editor().off('click').on('click', function (e) {e.preventDefault();}); // if the content editable is a link
- var imageSelector = 'img, .media_iframe_video, span.fa, i.fa, span.fa, a.o_image';
- var show_tooltip = true;
- oLayoutInfo.editor().on('dblclick', imageSelector, function (event) {
- show_tooltip = false;
- if (!$(event.target).closest(".note-toolbar").length) { // prevent icon edition of top bar for default summernote
- new widgets.MediaDialog(null, {}, oLayoutInfo.editor(), event.target).open();
- }
+
+ /**
+ * Open Media Dialog on double click on an image/video/icon.
+ * Shows a tooltip on click to say to the user he can double click.
+ */
+ create_dblclick_feature("img, .media_iframe_video, i.fa, span.fa, a.o_image", function () {
+ eventHandler.modules.imageDialog.show(oLayoutInfo);
});
- oLayoutInfo.editor().on('click', imageSelector, function (event) {
- if (!$(event.target).closest(".note-toolbar").length) { // prevent icon edition of top bar for default summernote
- setTimeout(function () {
- if (show_tooltip) {
- $(event.target).tooltip({title: _t('Double-click to edit'), trigger: 'manuel', container: 'body'}).tooltip('show');
- setTimeout(function () {
- $(event.target).tooltip('destroy');
- }, 800);
- }
- }, 400);
- show_tooltip = true;
- }
+
+ /**
+ * Open Link Dialog on double click on a link/button.
+ * Shows a tooltip on click to say to the user he can double click.
+ */
+ create_dblclick_feature("a[href], .btn", function () {
+ eventHandler.modules.linkDialog.show(oLayoutInfo);
});
+
if(oLayoutInfo.editor().is('[data-oe-model][data-oe-type="image"]')) {
oLayoutInfo.editor().on('click', 'img', function (event) {
$(event.target).trigger("dblclick");
@@ -813,6 +809,29 @@ eventHandler.attach = function (oLayoutInfo, options) {
$('button[data-event="undo"]', $toolbar).attr('disabled', !oLayoutInfo.editable().data('NoteHistory').hasUndo());
$('button[data-event="redo"]', $toolbar).attr('disabled', !oLayoutInfo.editable().data('NoteHistory').hasRedo());
});
+
+ function create_dblclick_feature(selector, callback) {
+ var show_tooltip = true;
+
+ oLayoutInfo.editor().on("dblclick", selector, function (e) {
+ if ($(e.target).closest(".note-toolbar").length) return; // prevent icon edition of top bar for default summernote
+ show_tooltip = false;
+ callback();
+ });
+
+ oLayoutInfo.editor().on("click", selector, function (e) {
+ var $target = $(e.target);
+ if ($target.closest(".note-toolbar").length) return; // prevent icon edition of top bar for default summernote
+ show_tooltip = true;
+ setTimeout(function () {
+ if (!show_tooltip) return;
+ $target.tooltip({title: _t('Double-click to edit'), trigger: 'manuel', container: 'body'}).tooltip('show');
+ setTimeout(function () {
+ $target.tooltip('destroy');
+ }, 800);
+ }, 400);
+ });
+ }
};
var fn_detach = eventHandler.detach;
eventHandler.detach = function (oLayoutInfo, options) {