summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/lib/summernote/src/js/module
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2015-09-25 10:53:08 +0200
committerNicolas Lempereur <nle@odoo.com>2015-09-25 10:53:08 +0200
commiteed63c793a55140b036bf807914e93c2a8bb37ad (patch)
tree6a205e37eeac6c60f84f58191392b95457e1afac /addons/web_editor/static/lib/summernote/src/js/module
parent15d2778f0f1f2fbdbe829530c82929b1efb51f5f (diff)
Revert "[IMP] web_editor: update summernote up to 2015-08-31"
Revert till several issues are solved.
Diffstat (limited to 'addons/web_editor/static/lib/summernote/src/js/module')
-rw-r--r--addons/web_editor/static/lib/summernote/src/js/module/Button.js40
-rw-r--r--addons/web_editor/static/lib/summernote/src/js/module/Clipboard.js90
-rw-r--r--addons/web_editor/static/lib/summernote/src/js/module/Codeview.js137
-rw-r--r--addons/web_editor/static/lib/summernote/src/js/module/Dialog.js158
-rw-r--r--addons/web_editor/static/lib/summernote/src/js/module/DragAndDrop.js98
-rw-r--r--addons/web_editor/static/lib/summernote/src/js/module/Editor.js861
-rw-r--r--addons/web_editor/static/lib/summernote/src/js/module/Fullscreen.js51
-rw-r--r--addons/web_editor/static/lib/summernote/src/js/module/Handle.js61
-rw-r--r--addons/web_editor/static/lib/summernote/src/js/module/HelpDialog.js35
-rw-r--r--addons/web_editor/static/lib/summernote/src/js/module/ImageDialog.js110
-rw-r--r--addons/web_editor/static/lib/summernote/src/js/module/LinkDialog.js129
-rw-r--r--addons/web_editor/static/lib/summernote/src/js/module/Popover.js37
-rw-r--r--addons/web_editor/static/lib/summernote/src/js/module/Statusbar.js44
-rw-r--r--addons/web_editor/static/lib/summernote/src/js/module/Toolbar.js47
14 files changed, 183 insertions, 1715 deletions
diff --git a/addons/web_editor/static/lib/summernote/src/js/module/Button.js b/addons/web_editor/static/lib/summernote/src/js/module/Button.js
index b7a1614d4db..512822aeba8 100644
--- a/addons/web_editor/static/lib/summernote/src/js/module/Button.js
+++ b/addons/web_editor/static/lib/summernote/src/js/module/Button.js
@@ -1,10 +1,7 @@
define([
- 'summernote/core/list',
- 'summernote/core/agent'
-], function (list, agent) {
+ 'summernote/core/list'
+], function (list) {
/**
- * @class module.Button
- *
* Button
*/
var Button = function () {
@@ -31,7 +28,6 @@ define([
/**
* update button state(active or not).
*
- * @private
* @param {String} selector
* @param {Function} pred
*/
@@ -44,30 +40,30 @@ define([
var $img = $(styleInfo.image);
btnState('button[data-event="imageShape"][data-value="img-rounded"]', function () {
- return $img.hasClass('img-rounded');
+ return $img.hasClass("img-rounded");
});
btnState('button[data-event="imageShape"][data-value="img-circle"]', function () {
- return $img.hasClass('img-circle');
+ return $img.hasClass("img-circle");
});
btnState('button[data-event="imageShape"][data-value="img-thumbnail"]', function () {
- return $img.hasClass('img-thumbnail');
+ return $img.hasClass("img-thumbnail");
});
btnState('button[data-event="imageShape"]:not([data-value])', function () {
- return !$img.is('.img-rounded, .img-circle, .img-thumbnail');
+ return !$img.is(".img-rounded, .img-circle, .img-thumbnail");
});
- var imgFloat = $img.css('float');
+ var imgFloat = $img.css("float");
btnState('button[data-event="floatMe"][data-value="left"]', function () {
- return imgFloat === 'left';
+ return imgFloat === "left";
});
btnState('button[data-event="floatMe"][data-value="right"]', function () {
- return imgFloat === 'right';
+ return imgFloat === "right";
});
btnState('button[data-event="floatMe"][data-value="none"]', function () {
- return imgFloat !== 'left' && imgFloat !== 'right';
+ return imgFloat !== "left" && imgFloat !== "right";
});
- var style = $img.attr('style');
+ var style = $img.attr("style");
btnState('button[data-event="resize"][data-value="1"]', function () {
return !!/(^|\s)(max-)?width\s*:\s*100%/.test(style);
});
@@ -85,18 +81,10 @@ define([
if ($fontname.length) {
var selectedFont = styleInfo['font-family'];
if (!!selectedFont) {
-
- var list = selectedFont.split(',');
- for (var i = 0, len = list.length; i < len; i++) {
- selectedFont = list[i].replace(/[\'\"]/g, '').replace(/\s+$/, '').replace(/^\s+/, '');
- if (agent.isFontInstalled(selectedFont)) {
- break;
- }
- }
-
+ selectedFont = list.head(selectedFont.split(','));
+ selectedFont = selectedFont.replace(/\'/g, '');
$fontname.find('.note-current-fontname').text(selectedFont);
checkDropdownMenu($fontname, selectedFont);
-
}
}
@@ -152,7 +140,7 @@ define([
*
* @param {Node} button
* @param {String} eventName
- * @param {Mixed} value
+ * @param {value} value
*/
this.updateRecentColor = function (button, eventName, value) {
var $color = $(button).closest('.note-color');
diff --git a/addons/web_editor/static/lib/summernote/src/js/module/Clipboard.js b/addons/web_editor/static/lib/summernote/src/js/module/Clipboard.js
deleted file mode 100644
index e2d234c9dbb..00000000000
--- a/addons/web_editor/static/lib/summernote/src/js/module/Clipboard.js
+++ /dev/null
@@ -1,90 +0,0 @@
-define([
- 'summernote/core/list',
- 'summernote/core/dom',
- 'summernote/core/key',
- 'summernote/core/agent'
-], function (list, dom, key, agent) {
- var Clipboard = function (handler) {
- var $paste;
-
- this.attach = function (layoutInfo) {
- // [workaround] getting image from clipboard
- // - IE11 and Firefox: CTRL+v hook
- // - Webkit: event.clipboardData
- if ((agent.isMSIE && agent.browserVersion > 10) || agent.isFF) {
- $paste = $('<div />').attr('contenteditable', true).css({
- position : 'absolute',
- left : -100000,
- opacity : 0
- });
-
- layoutInfo.editable().on('keydown', function (e) {
- if (e.ctrlKey && e.keyCode === key.code.V) {
- handler.invoke('saveRange', layoutInfo.editable());
- $paste.focus();
-
- setTimeout(function () {
- pasteByHook(layoutInfo);
- }, 0);
- }
- });
-
- layoutInfo.editable().before($paste);
- } else {
- layoutInfo.editable().on('paste', pasteByEvent);
- }
- };
-
- var pasteByHook = function (layoutInfo) {
- var $editable = layoutInfo.editable();
- var node = $paste[0].firstChild;
-
- if (dom.isImg(node)) {
- var dataURI = node.src;
- var decodedData = atob(dataURI.split(',')[1]);
- var array = new Uint8Array(decodedData.length);
- for (var i = 0; i < decodedData.length; i++) {
- array[i] = decodedData.charCodeAt(i);
- }
-
- var blob = new Blob([array], { type : 'image/png' });
- blob.name = 'clipboard.png';
-
- handler.invoke('restoreRange', $editable);
- handler.invoke('focus', $editable);
- handler.insertImages(layoutInfo, [blob]);
- } else {
- var pasteContent = $('<div />').html($paste.html()).html();
- handler.invoke('restoreRange', $editable);
- handler.invoke('focus', $editable);
-
- if (pasteContent) {
- handler.invoke('pasteHTML', $editable, pasteContent);
- }
- }
-
- $paste.empty();
- };
-
- /**
- * paste by clipboard event
- *
- * @param {Event} event
- */
- var pasteByEvent = function (event) {
- var clipboardData = event.originalEvent.clipboardData;
- var layoutInfo = dom.makeLayoutInfo(event.currentTarget || event.target);
- var $editable = layoutInfo.editable();
-
- if (clipboardData && clipboardData.items && clipboardData.items.length) {
- var item = list.head(clipboardData.items);
- if (item.kind === 'file' && item.type.indexOf('image/') !== -1) {
- handler.insertImages(layoutInfo, [item.getAsFile()]);
- }
- handler.invoke('editor.afterCommand', $editable);
- }
- };
- };
-
- return Clipboard;
-});
diff --git a/addons/web_editor/static/lib/summernote/src/js/module/Codeview.js b/addons/web_editor/static/lib/summernote/src/js/module/Codeview.js
deleted file mode 100644
index 46f3d96ab12..00000000000
--- a/addons/web_editor/static/lib/summernote/src/js/module/Codeview.js
+++ /dev/null
@@ -1,137 +0,0 @@
-define([
- 'summernote/core/agent',
- 'summernote/core/dom'
-], function (agent, dom) {
-
- var CodeMirror;
- if (agent.hasCodeMirror) {
- if (agent.isSupportAmd) {
- require(['CodeMirror'], function (cm) {
- CodeMirror = cm;
- });
- } else {
- CodeMirror = window.CodeMirror;
- }
- }
-
- /**
- * @class Codeview
- */
- var Codeview = function (handler) {
-
- this.sync = function (layoutInfo) {
- var isCodeview = handler.invoke('codeview.isActivated', layoutInfo);
- if (isCodeview && agent.hasCodeMirror) {
- layoutInfo.codable().data('cmEditor').save();
- }
- };
-
- /**
- * @param {Object} layoutInfo
- * @return {Boolean}
- */
- this.isActivated = function (layoutInfo) {
- var $editor = layoutInfo.editor();
- return $editor.hasClass('codeview');
- };
-
- /**
- * toggle codeview
- *
- * @param {Object} layoutInfo
- */
- this.toggle = function (layoutInfo) {
- if (this.isActivated(layoutInfo)) {
- this.deactivate(layoutInfo);
- } else {
- this.activate(layoutInfo);
- }
- };
-
- /**
- * activate code view
- *
- * @param {Object} layoutInfo
- */
- this.activate = function (layoutInfo) {
- var $editor = layoutInfo.editor(),
- $toolbar = layoutInfo.toolbar(),
- $editable = layoutInfo.editable(),
- $codable = layoutInfo.codable(),
- $popover = layoutInfo.popover(),
- $handle = layoutInfo.handle();
-
- var options = $editor.data('options');
-
- $codable.val(dom.html($editable, options.prettifyHtml));
- $codable.height($editable.height());
-
- handler.invoke('toolbar.updateCodeview', $toolbar, true);
- handler.invoke('popover.hide', $popover);
- handler.invoke('handle.hide', $handle);
-
- $editor.addClass('codeview');
-
- $codable.focus();
-
- // activate CodeMirror as codable
- if (agent.hasCodeMirror) {
- var cmEditor = CodeMirror.fromTextArea($codable[0], options.codemirror);
-
- // CodeMirror TernServer
- if (options.codemirror.tern) {
- var server = new CodeMirror.TernServer(options.codemirror.tern);
- cmEditor.ternServer = server;
- cmEditor.on('cursorActivity', function (cm) {
- server.updateArgHints(cm);
- });
- }
-
- // CodeMirror hasn't Padding.
- cmEditor.setSize(null, $editable.outerHeight());
- $codable.data('cmEditor', cmEditor);
- }
- };
-
- /**
- * deactivate code view
- *
- * @param {Object} layoutInfo
- */
- this.deactivate = function (layoutInfo) {
- var $holder = layoutInfo.holder(),
- $editor = layoutInfo.editor(),
- $toolbar = layoutInfo.toolbar(),
- $editable = layoutInfo.editable(),
- $codable = layoutInfo.codable();
-
- var options = $editor.data('options');
-
- // deactivate CodeMirror as codable
- if (agent.hasCodeMirror) {
- var cmEditor = $codable.data('cmEditor');
- $codable.val(cmEditor.getValue());
- cmEditor.toTextArea();
- }
-
- var value = dom.value($codable, options.prettifyHtml) || dom.emptyPara;
- var isChange = $editable.html() !== value;
-
- $editable.html(value);
- $editable.height(options.height ? $codable.height() : 'auto');
- $editor.removeClass('codeview');
-
- if (isChange) {
- handler.bindCustomEvent(
- $holder, $editable.data('callbacks'), 'change'
- )($editable.html(), $editable);
- }
-
- $editable.focus();
-
- handler.invoke('toolbar.updateCodeview', $toolbar, false);
- };
- };
-
- return Codeview;
-});
diff --git a/addons/web_editor/static/lib/summernote/src/js/module/Dialog.js b/addons/web_editor/static/lib/summernote/src/js/module/Dialog.js
new file mode 100644
index 00000000000..8e7cf07b323
--- /dev/null
+++ b/addons/web_editor/static/lib/summernote/src/js/module/Dialog.js
@@ -0,0 +1,158 @@
+define('summernote/module/Dialog', function () {
+ /**
+ * Dialog
+ *
+ * @class
+ */
+ var Dialog = function () {
+
+ /**
+ * toggle button status
+ *
+ * @param {jQuery} $btn
+ * @param {Boolean} isEnable
+ */
+ var toggleBtn = function ($btn, isEnable) {
+ $btn.toggleClass('disabled', !isEnable);
+ $btn.attr('disabled', !isEnable);
+ };
+
+ /**
+ * show image dialog
+ *
+ * @param {jQuery} $editable
+ * @param {jQuery} $dialog
+ * @return {Promise}
+ */
+ this.showImageDialog = function ($editable, $dialog) {
+ return $.Deferred(function (deferred) {
+ var $imageDialog = $dialog.find('.note-image-dialog');
+
+ var $imageInput = $dialog.find('.note-image-input'),
+ $imageUrl = $dialog.find('.note-image-url'),
+ $imageBtn = $dialog.find('.note-image-btn');
+
+ $imageDialog.one('shown.bs.modal', function () {
+ // Cloning imageInput to clear element.
+ $imageInput.replaceWith($imageInput.clone()
+ .on('change', function () {
+ deferred.resolve(this.files || this.value);
+ $imageDialog.modal('hide');
+ })
+ .val('')
+ );
+
+ $imageBtn.click(function (event) {
+ event.preventDefault();
+
+ deferred.resolve($imageUrl.val());
+ $imageDialog.modal('hide');
+ });
+
+ $imageUrl.on('keyup paste', function (event) {
+ var url;
+
+ if (event.type === 'paste') {
+ url = event.originalEvent.clipboardData.getData('text');
+ } else {
+ url = $imageUrl.val();
+ }
+
+ toggleBtn($imageBtn, url);
+ }).val('').trigger('focus');
+ }).one('hidden.bs.modal', function () {
+ $imageInput.off('change');
+ $imageUrl.off('keyup paste');
+ $imageBtn.off('click');
+
+ if (deferred.state() === 'pending') {
+ deferred.reject();
+ }
+ }).modal('show');
+ });
+ };
+
+ /**
+ * Show link dialog and set event handlers on dialog controls.
+ *
+ * @param {jQuery} $dialog
+ * @param {Object} linkInfo
+ * @return {Promise}
+ */
+ this.showLinkDialog = function ($editable, $dialog, linkInfo) {
+ return $.Deferred(function (deferred) {
+ var $linkDialog = $dialog.find('.note-link-dialog');
+
+ var $linkText = $linkDialog.find('.note-link-text'),
+ $linkUrl = $linkDialog.find('.note-link-url'),
+ $linkBtn = $linkDialog.find('.note-link-btn'),
+ $openInNewWindow = $linkDialog.find('input[type=checkbox]');
+
+ $linkDialog.one('shown.bs.modal', function () {
+ $linkText.val(linkInfo.text);
+
+ $linkText.on('input', function () {
+ // if linktext was modified by keyup,
+ // stop cloning text from linkUrl
+ linkInfo.text = $linkText.val();
+ });
+
+ // if no url was given, copy text to url
+ if (!linkInfo.url) {
+ linkInfo.url = linkInfo.text;
+ toggleBtn($linkBtn, linkInfo.text);
+ }
+
+ $linkUrl.on('input', function () {
+ toggleBtn($linkBtn, $linkUrl.val());
+ // display same link on `Text to display` input
+ // when create a new link
+ if (!linkInfo.text) {
+ $linkText.val($linkUrl.val());
+ }
+ }).val(linkInfo.url).trigger('focus').trigger('select');
+
+ $openInNewWindow.prop('checked', linkInfo.newWindow);
+
+ $linkBtn.one('click', function (event) {
+ event.preventDefault();
+
+ deferred.resolve({
+ range: linkInfo.range,
+ url: $linkUrl.val(),
+ text: $linkText.val(),
+ newWindow: $openInNewWindow.is(':checked')
+ });
+ $linkDialog.modal('hide');
+ });
+ }).one('hidden.bs.modal', function () {
+ // detach events
+ $linkText.off('input');
+ $linkUrl.off('input');
+ $linkBtn.off('click');
+
+ if (deferred.state() === 'pending') {
+ deferred.reject();
+ }
+ }).modal('show');
+ }).promise();
+ };
+
+ /**
+ * show help dialog
+ *
+ * @param {jQuery} $dialog
+ */
+ this.showHelpDialog = function ($editable, $dialog) {
+ return $.Deferred(function (deferred) {
+ var $helpDialog = $dialog.find('.note-help-dialog');
+
+ $helpDialog.one('hidden.bs.modal', function () {
+ deferred.resolve();
+ }).modal('show');
+ }).promise();
+ };
+ };
+
+ return Dialog;
+});
diff --git a/addons/web_editor/static/lib/summernote/src/js/module/DragAndDrop.js b/addons/web_editor/static/lib/summernote/src/js/module/DragAndDrop.js
deleted file mode 100644
index b8871599c6f..00000000000
--- a/addons/web_editor/static/lib/summernote/src/js/module/DragAndDrop.js
+++ /dev/null
@@ -1,98 +0,0 @@
-define([
- 'summernote/core/dom'
-], function (dom) {
- var DragAndDrop = function (handler) {
- var $document = $(document);
-
- /**
- * attach Drag and Drop Events
- *
- * @param {Object} layoutInfo - layout Informations
- * @param {Object} options
- */
- this.attach = function (layoutInfo, options) {
- if (options.airMode || options.disableDragAndDrop) {
- // prevent default drop event
- $document.on('drop', function (e) {
- e.preventDefault();
- });
- } else {
- this.attachDragAndDropEvent(layoutInfo, options);
- }
- };
-
- /**
- * attach Drag and Drop Events
- *
- * @param {Object} layoutInfo - layout Informations
- * @param {Object} options
- */
- this.attachDragAndDropEvent = function (layoutInfo, options) {
- var collection = $(),
- $editor = layoutInfo.editor(),
- $dropzone = layoutInfo.dropzone(),
- $dropzoneMessage = $dropzone.find('.note-dropzone-message');
-
- // show dropzone on dragenter when dragging a object to document
- // -but only if the editor is visible, i.e. has a positive width and height
- $document.on('dragenter', function (e) {
- var isCodeview = handler.invoke('codeview.isActivated', layoutInfo);
- var hasEditorSize = $editor.width() > 0 && $editor.height() > 0;
- if (!isCodeview && !collection.length && hasEditorSize) {
- $editor.addClass('dragover');
- $dropzone.width($editor.width());
- $dropzone.height($editor.height());
- $dropzoneMessage.text(options.langInfo.image.dragImageHere);
- }
- collection = collection.add(e.target);
- }).on('dragleave', function (e) {
- collection = collection.not(e.target);
- if (!collection.length) {
- $editor.removeClass('dragover');
- }
- }).on('drop', function () {
- collection = $();
- $editor.removeClass('dragover');
- });
-
- // change dropzone's message on hover.
- $dropzone.on('dragenter', function () {
- $dropzone.addClass('hover');
- $dropzoneMessage.text(options.langInfo.image.dropImage);
- }).on('dragleave', function () {
- $dropzone.removeClass('hover');
- $dropzoneMessage.text(options.langInfo.image.dragImageHere);
- });
-
- // attach dropImage
- $dropzone.on('drop', function (event) {
-
- var dataTransfer = event.originalEvent.dataTransfer;
- var layoutInfo = dom.makeLayoutInfo(event.currentTarget || event.target);
-
- if (dataTransfer && dataTransfer.files && dataTransfer.files.length) {
- event.preventDefault();
- layoutInfo.editable().focus();
- handler.insertImages(layoutInfo, dataTransfer.files);
- } else {
- var insertNodefunc = function () {
- layoutInfo.holder().summernote('insertNode', this);
- };
-
- for (var i = 0, len = dataTransfer.types.length; i < len; i++) {
- var type = dataTransfer.types[i];
- var content = dataTransfer.getData(type);
-
- if (type.toLowerCase().indexOf('text') > -1) {
- layoutInfo.holder().summernote('pasteHTML', content);
- } else {
- $(content).each(insertNodefunc);
- }
- }
- }
- }).on('dragover', false); // prevent default dragover event
- };
- };
-
- return DragAndDrop;
-});
diff --git a/addons/web_editor/static/lib/summernote/src/js/module/Editor.js b/addons/web_editor/static/lib/summernote/src/js/module/Editor.js
deleted file mode 100644
index 732072b5d24..00000000000
--- a/addons/web_editor/static/lib/summernote/src/js/module/Editor.js
+++ /dev/null
@@ -1,861 +0,0 @@
-define([
- 'summernote/core/agent',
- 'summernote/core/func',
- 'summernote/core/list',
- 'summernote/core/dom',
- 'summernote/core/range',
- 'summernote/core/async',
- 'summernote/editing/Style',
- 'summernote/editing/Typing',
- 'summernote/editing/Table',
- 'summernote/editing/Bullet'
-], function (agent, func, list, dom, range, async,
- Style, Typing, Table, Bullet) {
-
- var KEY_BOGUS = 'bogus';
-
- /**
- * @class editing.Editor
- *
- * Editor
- *
- */
- var Editor = function (handler) {
-
- var self = this;
- var style = new Style();
- var table = new Table();
- var typing = new Typing();
- var bullet = new Bullet();
-
- this.style = style; // ODOO: allow access for override
- this.table = table; // ODOO: allow access for override
- this.typing = typing; // ODOO: allow access for override
- this.bullet = bullet; // ODOO: allow access for override
-
- /**
- * @method createRange
- *
- * create range
- *
- * @param {jQuery} $editable
- * @return {WrappedRange}
- */
- this.createRange = function ($editable) {
- this.focus($editable);
- return range.create();
- };
-
- /**
- * @method saveRange
- *
- * save current range
- *
- * @param {jQuery} $editable
- * @param {Boolean} [thenCollapse=false]
- */
- this.saveRange = function ($editable, thenCollapse) {
- // ODOO: scroll to top when click on input in editable m (start_modification
- // this.focus($editable);
- var r = range.create();
- if (!r || ($editable[0] !== r.sc && !$.contains($editable[0], r.sc))) {
- $editable.focus();
- }
- // ODOO: end_modication)
- $editable.data('range', range.create());
- if (thenCollapse) {
- range.create().collapse().select();
- }
- };
-
- /**
- * @method saveRange
- *
- * save current node list to $editable.data('childNodes')
- *
- * @param {jQuery} $editable
- */
- this.saveNode = function ($editable) {
- // copy child node reference
- var copy = [];
- for (var key = 0, len = $editable[0].childNodes.length; key < len; key++) {
- copy.push($editable[0].childNodes[key]);
- }
- $editable.data('childNodes', copy);
- };
-
- /**
- * @method restoreRange
- *
- * restore lately range
- *
- * @param {jQuery} $editable
- */
- this.restoreRange = function ($editable) {
- var rng = $editable.data('range');
- if (rng) {
- rng.select();
- this.focus($editable);
- }
- };
-
- /**
- * @method restoreNode
- *
- * restore lately node list
- *
- * @param {jQuery} $editable
- */
- this.restoreNode = function ($editable) {
- $editable.html('');
- var child = $editable.data('childNodes');
- for (var index = 0, len = child.length; index < len; index++) {
- $editable[0].appendChild(child[index]);
- }
- };
-
- /**
- * @method currentStyle
- *
- * current style
- *
- * @param {Node} target
- * @return {Object|Boolean} unfocus
- */
- this.currentStyle = function (target) {
- var rng = range.create();
- var styleInfo = rng && rng.isOnEditable() ? style.current(rng.normalize()) : {};
- if (dom.isImg(target)) {
- styleInfo.image = target;
- }
- return styleInfo;
- };
-
- /**
- * style from node
- *
- * @param {jQuery} $node
- * @return {Object}
- */
- this.styleFromNode = function ($node) {
- return style.fromNode($node);
- };
-
- var triggerOnBeforeChange = function ($editable) {
- var $holder = dom.makeLayoutInfo($editable).holder();
- handler.bindCustomEvent(
- $holder, $editable.data('callbacks'), 'before.command'
- )($editable.html(), $editable);
- };
-
- var triggerOnChange = function ($editable) {
- var $holder = dom.makeLayoutInfo($editable).holder();
- handler.bindCustomEvent(
- $holder, $editable.data('callbacks'), 'change'
- )($editable.html(), $editable);
- };
-
- /**
- * @method undo
- * undo
- * @param {jQuery} $editable
- */
- this.undo = function ($editable) {
- triggerOnBeforeChange($editable);
- $editable.data('NoteHistory').undo();
- triggerOnChange($editable);
- };
-
- /**
- * @method redo
- * redo
- * @param {jQuery} $editable
- */
- this.redo = function ($editable) {
- triggerOnBeforeChange($editable);
- $editable.data('NoteHistory').redo();
- triggerOnChange($editable);
- };
-
- /**
- * @method beforeCommand
- * before command
- * @param {jQuery} $editable
- */
- var beforeCommand = this.beforeCommand = function ($editable) {
- triggerOnBeforeChange($editable);
- // keep focus on editable before command execution
- self.focus($editable);
- };
-
- /**
- * @method afterCommand
- * after command
- * @param {jQuery} $editable
- * @param {Boolean} isPreventTrigger
- */
- var afterCommand = this.afterCommand = function ($editable, isPreventTrigger) {
- $editable.data('NoteHistory').recordUndo();
- if (!isPreventTrigger) {
- triggerOnChange($editable);
- }
- };
-
- /**
- * @method bold
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method italic
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method underline
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method strikethrough
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method formatBlock
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method superscript
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method subscript
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method justifyLeft
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method justifyCenter
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method justifyRight
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method justifyFull
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method formatBlock
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method removeFormat
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method backColor
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method foreColor
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method insertHorizontalRule
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /**
- * @method fontName
- *
- * change font name
- *
- * @param {jQuery} $editable
- * @param {Mixed} value
- */
-
- /* jshint ignore:start */
- // native commands(with execCommand), generate function for execCommand
- var commands = ['bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript',
- 'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull',
- 'formatBlock', 'removeFormat',
- 'backColor', 'foreColor', 'fontName'];
-
- for (var idx = 0, len = commands.length; idx < len; idx ++) {
- this[commands[idx]] = (function (sCmd) {
- return function ($editable, value) {
- beforeCommand($editable);
-
- document.execCommand(sCmd, false, value);
-
- afterCommand($editable, true);
- };
- })(commands[idx]);
- }
- /* jshint ignore:end */
-
- /**
- * @method tab
- *
- * handle tab key
- *
- * @param {jQuery} $editable
- * @param {Object} options
- */
- this.tab = function ($editable, options) {
- var rng = this.createRange($editable);
- if (rng.isCollapsed() && rng.isOnCell()) {
- table.tab(rng);
- } else {
- beforeCommand($editable);
- typing.insertTab($editable, rng, options.tabsize);
- afterCommand($editable);
- }
- };
-
- /**
- * @method untab
- *
- * handle shift+tab key
- *
- */
- this.untab = function ($editable) {
- var rng = this.createRange($editable);
- if (rng.isCollapsed() && rng.isOnCell()) {
- table.tab(rng, true);
- }
- };
-
- /**
- * @method insertParagraph
- *
- * insert paragraph
- *
- * @param {Node} $editable
- */
- this.insertParagraph = function ($editable) {
- beforeCommand($editable);
- typing.insertParagraph($editable);
- afterCommand($editable);
- };
-
- /**
- * @method insertOrderedList
- *
- * @param {jQuery} $editable
- */
- this.insertOrderedList = function ($editable) {
- beforeCommand($editable);
- bullet.insertOrderedList($editable);
- afterCommand($editable);
- };
-
- /**
- * @param {jQuery} $editable
- */
- this.insertUnorderedList = function ($editable) {
- beforeCommand($editable);
- bullet.insertUnorderedList($editable);
- afterCommand($editable);
- };
-
- /**
- * @param {jQuery} $editable
- */
- this.indent = function ($editable) {
- beforeCommand($editable);
- bullet.indent($editable);
- afterCommand($editable);
- };
-
- /**
- * @param {jQuery} $editable
- */
- this.outdent = function ($editable) {
- beforeCommand($editable);
- bullet.outdent($editable);
- afterCommand($editable);
- };
-
- /**
- * insert image
- *
- * @param {jQuery} $editable
- * @param {String} sUrl
- */
- this.insertImage = function ($editable, sUrl, filename) {
- async.createImage(sUrl, filename).then(function ($image) {
- beforeCommand($editable);
- $image.css({
- display: '',
- width: Math.min($editable.width(), $image.width())
- });
- range.create().insertNode($image[0]);
- range.createFromNodeAfter($image[0]).select();
- afterCommand($editable);
- }).fail(function () {
- var $holder = dom.makeLayoutInfo($editable).holder();
- handler.bindCustomEvent(
- $holder, $editable.data('callbacks'), 'image.upload.error'
- )();
- });
- };
-
- /**
- * @method insertNode
- * insert node
- * @param {Node} $editable
- * @param {Node} node
- */
- this.insertNode = function ($editable, node) {
- beforeCommand($editable);
- range.create().insertNode(node);
- range.createFromNodeAfter(node).select();
- afterCommand($editable);
- };
-
- /**
- * insert text
- * @param {Node} $editable
- * @param {String} text
- */
- this.insertText = function ($editable, text) {
- beforeCommand($editable);
- var textNode = range.create().insertNode(dom.createText(text));
- range.create(textNode, dom.nodeLength(textNode)).select();
- afterCommand($editable);
- };
-
- /**
- * paste HTML
- * @param {Node} $editable
- * @param {String} markup
- */
- this.pasteHTML = function ($editable, markup) {
- beforeCommand($editable);
- var contents = range.create().pasteHTML(markup);
- range.createFromNodeAfter(list.last(contents)).select();
- afterCommand($editable);
- };
-
- /**
- * formatBlock
- *
- * @param {jQuery} $editable
- * @param {String} tagName
- */
- this.formatBlock = function ($editable, tagName) {
- beforeCommand($editable);
- // [workaround] for MSIE, IE need `<`
- tagName = agent.isMSIE ? '<' + tagName + '>' : tagName;
- document.execCommand('FormatBlock', false, tagName);
- afterCommand($editable);
- };
-
- this.formatPara = function ($editable) {
- beforeCommand($editable);
- this.formatBlock($editable, 'P');
- afterCommand($editable);
- };
-
- /* jshint ignore:start */
- for (var idx = 1; idx <= 6; idx ++) {
- this['formatH' + idx] = function (idx) {
- return function ($editable) {
- this.formatBlock($editable, 'H' + idx);
- };
- }(idx);
- };
- /* jshint ignore:end */
-
- /**
- * fontSize
- *
- * @param {jQuery} $editable
- * @param {String} value - px
- */
- this.fontSize = function ($editable, value) {
- var rng = range.create();
-
- if (rng.isCollapsed()) {
- var spans = style.styleNodes(rng);
- var firstSpan = list.head(spans);
-
- $(spans).css({
- 'font-size': value + 'px'
- });
-
- // [workaround] added styled bogus span for style
- // - also bogus character needed for cursor position
- if (firstSpan && !dom.nodeLength(firstSpan)) {
- firstSpan.innerHTML = dom.ZERO_WIDTH_NBSP_CHAR;
- range.createFromNodeAfter(firstSpan.firstChild).select();
- $editable.data(KEY_BOGUS, firstSpan);
- }
- } else {
- beforeCommand($editable);
- $(style.styleNodes(rng)).css({
- 'font-size': value + 'px'
- });
- afterCommand($editable);
- }
- };
-
- /**
- * insert horizontal rule
- * @param {jQuery} $editable
- */
- this.insertHorizontalRule = function ($editable) {
- beforeCommand($editable);
-
- var rng = range.create();
- var hrNode = rng.insertNode($('<HR/>')[0]);
- if (hrNode.nextSibling) {
- range.create(hrNode.nextSibling, 0).normalize().select();
- }
-
- afterCommand($editable);
- };
-
- /**
- * remove bogus node and character
- */
- this.removeBogus = function ($editable) {
- var bogusNode = $editable.data(KEY_BOGUS);
- if (!bogusNode) {
- return;
- }
-
- var textNode = list.find(list.from(bogusNode.childNodes), dom.isText);
-
- var bogusCharIdx = textNode.nodeValue.indexOf(dom.ZERO_WIDTH_NBSP_CHAR);
- if (bogusCharIdx !== -1) {
- textNode.deleteData(bogusCharIdx, 1);
- }
-
- if (dom.isEmpty(bogusNode)) {
- dom.remove(bogusNode);
- }
-
- $editable.removeData(KEY_BOGUS);
- };
-
- /**
- * lineHeight
- * @param {jQuery} $editable
- * @param {String} value
- */
- this.lineHeight = function ($editable, value) {
- beforeCommand($editable);
- style.stylePara(range.create(), {
- lineHeight: value
- });
- afterCommand($editable);
- };
-
- /**
- * unlink
- *
- * @type command
- *
- * @param {jQuery} $editable
- */
- this.unlink = function ($editable) {
- var rng = this.createRange($editable);
- if (rng.isOnAnchor()) {
- var anchor = dom.ancestor(rng.sc, dom.isAnchor);
- rng = range.createFromNode(anchor);
- rng.select();
-
- beforeCommand($editable);
- document.execCommand('unlink');
- afterCommand($editable);
- }
- };
-
- /**
- * create link (command)
- *
- * @param {jQuery} $editable
- * @param {Object} linkInfo
- * @param {Object} options
- */
- this.createLink = function ($editable, linkInfo, options) {
- var linkUrl = linkInfo.url;
- var linkText = linkInfo.text;
- var isNewWindow = linkInfo.isNewWindow;
- var className = linkInfo.className || null; // ODOO: addition
- var rng = linkInfo.range || this.createRange($editable);
- var isTextChanged = rng.toString() !== linkText;
-
- options = options || dom.makeLayoutInfo($editable).editor().data('options');
-
- beforeCommand($editable);
-
- if (options.onCreateLink) {
- linkUrl = options.onCreateLink(linkUrl);
- }
-
- var anchors = [];
- if (isTextChanged) {
- // Create a new link when text changed.
- var anchor = rng.insertNode($('<A>' + linkText + '</A>')[0]);
- anchors.push(anchor);
- } else {
- anchors = style.styleNodes(rng, {
- nodeName: 'A',
- expandClosestSibling: true,
- onlyPartialContains: true
- });
- }
-
- $.each(anchors, function (idx, anchor) {
- $(anchor).attr('href', linkUrl);
- $(anchor).attr('class', className); // ODOO: addition
- if (isNewWindow) {
- $(anchor).attr('target', '_blank');
- } else {
- $(anchor).removeAttr('target');
- }
- });
-
- var startRange = range.createFromNodeBefore(list.head(anchors));
- var startPoint = startRange.getStartPoint();
- var endRange = range.createFromNodeAfter(list.last(anchors));
- var endPoint = endRange.getEndPoint();
-
- range.create(
- startPoint.node,
- startPoint.offset,
- endPoint.node,
- endPoint.offset
- ).select();
-
- afterCommand($editable);
- };
-
- /**
- * returns link info
- *
- * @return {Object}
- * @return {WrappedRange} return.range
- * @return {String} return.text
- * @return {Boolean} [return.isNewWindow=true]
- * @return {String} [return.url=""]
- */
- this.getLinkInfo = function ($editable) {
- this.focus($editable);
-
- var rng = range.create().expand(dom.isAnchor);
-
- // Get the first anchor on range(for edit).
- var $anchor = $(list.head(rng.nodes(dom.isAnchor)));
-
- return {
- range: rng,
- text: rng.toString(),
- isNewWindow: $anchor.length ? $anchor.attr('target') === '_blank' : false,
- url: $anchor.length ? $anchor.attr('href') : ''
- };
- };
-
- /**
- * setting color
- *
- * @param {Node} $editable
- * @param {Object} sObjColor color code
- * @param {String} sObjColor.foreColor foreground color
- * @param {String} sObjColor.backColor background color
- */
- this.color = function ($editable, sObjColor) {
- var oColor = JSON.parse(sObjColor);
- var foreColor = oColor.foreColor, backColor = oColor.backColor;
-
- beforeCommand($editable);
-
- if (foreColor) { document.execCommand('foreColor', false, foreColor); }
- if (backColor) { document.execCommand('backColor', false, backColor); }
-
- afterCommand($editable);
- };
-
- /**
- * insert Table
- *
- * @param {Node} $editable
- * @param {String} sDim dimension of table (ex : "5x5")
- */
- this.insertTable = function ($editable, sDim) {
- var dimension = sDim.split('x');
- beforeCommand($editable);
-
- var rng = range.create().deleteContents();
- rng.insertNode(table.createTable(dimension[0], dimension[1]));
- afterCommand($editable);
- };
-
- /**
- * float me
- *
- * @param {jQuery} $editable
- * @param {String} value
- * @param {jQuery} $target
- */
- this.floatMe = function ($editable, value, $target) {
- beforeCommand($editable);
- // bootstrap
- $target.removeClass('pull-left pull-right');
- if (value && value !== 'none') {
- $target.addClass('pull-' + value);
- }
-
- // fallback for non-bootstrap
- $target.css('float', value);
- afterCommand($editable);
- };
-
- /**
- * change image shape
- *
- * @param {jQuery} $editable
- * @param {String} value css class
- * @param {Node} $target
- */
- this.imageShape = function ($editable, value, $target) {
- beforeCommand($editable);
-
- $target.removeClass('img-rounded img-circle img-thumbnail');
-
- if (value) {
- $target.addClass(value);
- }
-
- afterCommand($editable);
- };
-
- /**
- * resize overlay element
- * @param {jQuery} $editable
- * @param {String} value
- * @param {jQuery} $target - target element
- */
- this.resize = function ($editable, value, $target) {
- beforeCommand($editable);
-
- $target.css({
- width: value * 100 + '%',
- height: ''
- });
-
- afterCommand($editable);
- };
-
- /**
- * @param {Position} pos
- * @param {jQuery} $target - target element
- * @param {Boolean} [bKeepRatio] - keep ratio
- */
- this.resizeTo = function (pos, $target, bKeepRatio) {
- var imageSize;
- if (bKeepRatio) {
- var newRatio = pos.y / pos.x;
- var ratio = $target.data('ratio');
- imageSize = {
- width: ratio > newRatio ? pos.x : pos.y / ratio,
- height: ratio > newRatio ? pos.x * ratio : pos.y
- };
- } else {
- imageSize = {
- width: pos.x,
- height: pos.y
- };
- }
-
- $target.css(imageSize);
- };
-
- /**
- * remove media object
- *
- * @param {jQuery} $editable
- * @param {String} value - dummy argument (for keep interface)
- * @param {jQuery} $target - target element
- */
- this.removeMedia = function ($editable, value, $target) {
- beforeCommand($editable);
- $target.detach();
-
- handler.bindCustomEvent(
- $(), $editable.data('callbacks'), 'media.delete'
- )($target, $editable);
-
- afterCommand($editable);
- };
-
- /**
- * set focus
- *
- * @param $editable
- */
- this.focus = function ($editable) {
- $editable.focus();
-
- // [workaround] for firefox bug http://goo.gl/lVfAaI
- if (agent.isFF) {
- var rng = range.create();
- if (!rng || rng.isOnEditable()) {
- return;
- }
-
- range.createFromNode($editable[0])
- .normalize()
- .collapse()
- .select();
- }
- };
-
- /**
- * returns whether contents is empty or not.
- *
- * @param {jQuery} $editable
- * @return {Boolean}
- */
- this.isEmpty = function ($editable) {
- return dom.isEmpty($editable[0]) || dom.emptyPara === $editable.html();
- };
- };
-
- return Editor;
-});
diff --git a/addons/web_editor/static/lib/summernote/src/js/module/Fullscreen.js b/addons/web_editor/static/lib/summernote/src/js/module/Fullscreen.js
deleted file mode 100644
index fd837483b3b..00000000000
--- a/addons/web_editor/static/lib/summernote/src/js/module/Fullscreen.js
+++ /dev/null
@@ -1,51 +0,0 @@
-define([], function () { // ODOO: remove error from Odoo define
- var Fullscreen = function (handler) {
- var $window = $(window);
- var $scrollbar = $('html, body');
-
- /**
- * toggle fullscreen
- *
- * @param {Object} layoutInfo
- */
- this.toggle = function (layoutInfo) {
-
- var $editor = layoutInfo.editor(),
- $toolbar = layoutInfo.toolbar(),
- $editable = layoutInfo.editable(),
- $codable = layoutInfo.codable();
-
- var resize = function (size) {
- $editable.css('height', size.h);
- $codable.css('height', size.h);
- if ($codable.data('cmeditor')) {
- $codable.data('cmeditor').setsize(null, size.h);
- }
- };
-
- $editor.toggleClass('fullscreen');
- var isFullscreen = $editor.hasClass('fullscreen');
- if (isFullscreen) {
- $editable.data('orgheight', $editable.css('height'));
-
- $window.on('resize', function () {
- resize({
- h: $window.height() - $toolbar.outerHeight()
- });
- }).trigger('resize');
-
- $scrollbar.css('overflow', 'hidden');
- } else {
- $window.off('resize');
- resize({
- h: $editable.data('orgheight')
- });
- $scrollbar.css('overflow', 'visible');
- }
-
- handler.invoke('toolbar.updateFullscreen', $toolbar, isFullscreen);
- };
- };
-
- return Fullscreen;
-});
diff --git a/addons/web_editor/static/lib/summernote/src/js/module/Handle.js b/addons/web_editor/static/lib/summernote/src/js/module/Handle.js
index 3b62304d706..375428faa32 100644
--- a/addons/web_editor/static/lib/summernote/src/js/module/Handle.js
+++ b/addons/web_editor/static/lib/summernote/src/js/module/Handle.js
@@ -1,60 +1,8 @@
-define([
- 'summernote/core/dom'
-], function (dom) {
+define('summernote/module/Handle', function () {
/**
- * @class module.Handle
- *
* Handle
*/
- var Handle = function (handler) {
- var $document = $(document);
-
- /**
- * `mousedown` event handler on $handle
- * - controlSizing: resize image
- *
- * @param {MouseEvent} event
- */
- var hHandleMousedown = function (event) {
- if (dom.isControlSizing(event.target)) {
- event.preventDefault();
- event.stopPropagation();
-
- var layoutInfo = dom.makeLayoutInfo(event.target),
- $handle = layoutInfo.handle(),
- $popover = layoutInfo.popover(),
- $editable = layoutInfo.editable(),
- $editor = layoutInfo.editor();
-
- var target = $handle.find('.note-control-selection').data('target'),
- $target = $(target), posStart = $target.offset(),
- scrollTop = $document.scrollTop();
-
- var isAirMode = $editor.data('options').airMode;
-
- $document.on('mousemove', function (event) {
- handler.invoke('editor.resizeTo', {
- x: event.clientX - posStart.left,
- y: event.clientY - (posStart.top - scrollTop)
- }, $target, !event.shiftKey);
-
- handler.invoke('handle.update', $handle, {image: target}, isAirMode);
- handler.invoke('popover.update', $popover, {image: target}, isAirMode);
- }).one('mouseup', function () {
- $document.off('mousemove');
- handler.invoke('editor.afterCommand', $editable);
- });
-
- if (!$target.data('ratio')) { // original ratio.
- $target.data('ratio', $target.height() / $target.width());
- }
- }
- };
-
- this.attach = function (layoutInfo) {
- layoutInfo.handle().on('mousedown', hHandleMousedown);
- };
-
+ var Handle = function () {
/**
* update handle
* @param {jQuery} $handle
@@ -87,11 +35,6 @@ define([
}
};
- /**
- * hide
- *
- * @param {jQuery} $handle
- */
this.hide = function ($handle) {
$handle.children().hide();
};
diff --git a/addons/web_editor/static/lib/summernote/src/js/module/HelpDialog.js b/addons/web_editor/static/lib/summernote/src/js/module/HelpDialog.js
deleted file mode 100644
index e4ff7b775ed..00000000000
--- a/addons/web_editor/static/lib/summernote/src/js/module/HelpDialog.js
+++ /dev/null
@@ -1,35 +0,0 @@
-define([], function () { // ODOO: remove error from Odoo define
- var HelpDialog = function (handler) {
- /**
- * show help dialog
- *
- * @param {jQuery} $editable
- * @param {jQuery} $dialog
- * @return {Promise}
- */
- this.showHelpDialog = function ($editable, $dialog) {
- return $.Deferred(function (deferred) {
- var $helpDialog = $dialog.find('.note-help-dialog');
-
- $helpDialog.one('hidden.bs.modal', function () {
- deferred.resolve();
- }).modal('show');
- }).promise();
- };
-
- /**
- * @param {Object} layoutInfo
- */
- this.show = function (layoutInfo) {
- var $dialog = layoutInfo.dialog(),
- $editable = layoutInfo.editable();
-
- handler.invoke('editor.saveRange', $editable, true);
- this.showHelpDialog($editable, $dialog).then(function () {
- handler.invoke('editor.restoreRange', $editable);
- });
- };
- };
-
- return HelpDialog;
-});
diff --git a/addons/web_editor/static/lib/summernote/src/js/module/ImageDialog.js b/addons/web_editor/static/lib/summernote/src/js/module/ImageDialog.js
deleted file mode 100644
index 042921183cc..00000000000
--- a/addons/web_editor/static/lib/summernote/src/js/module/ImageDialog.js
+++ /dev/null
@@ -1,110 +0,0 @@
-define([
- 'summernote/core/key'
-], function (key) {
- var ImageDialog = function (handler) {
- /**
- * toggle button status
- *
- * @private
- * @param {jQuery} $btn
- * @param {Boolean} isEnable
- */
- var toggleBtn = function ($btn, isEnable) {
- $btn.toggleClass('disabled', !isEnable);
- $btn.attr('disabled', !isEnable);
- };
-
- /**
- * bind enter key
- *
- * @private
- * @param {jQuery} $input
- * @param {jQuery} $btn
- */
- var bindEnterKey = function ($input, $btn) {
- $input.on('keypress', function (event) {
- if (event.keyCode === key.code.ENTER) {
- $btn.trigger('click');
- }
- });
- };
-
- this.show = function (layoutInfo) {
- var $dialog = layoutInfo.dialog(),
- $editable = layoutInfo.editable();
-
- handler.invoke('editor.saveRange', $editable);
- this.showImageDialog($editable, $dialog).then(function (data) {
- handler.invoke('editor.restoreRange', $editable);
-
- if (typeof data === 'string') {
- // image url
- handler.invoke('editor.insertImage', $editable, data);
- } else {
- // array of files
- handler.insertImages(layoutInfo, data);
- }
- }).fail(function () {
- handler.invoke('editor.restoreRange', $editable);
- });
- };
-
- /**
- * show image dialog
- *
- * @param {jQuery} $editable
- * @param {jQuery} $dialog
- * @return {Promise}
- */
- this.showImageDialog = function ($editable, $dialog) {
- return $.Deferred(function (deferred) {
- var $imageDialog = $dialog.find('.note-image-dialog');
-
- var $imageInput = $dialog.find('.note-image-input'),
- $imageUrl = $dialog.find('.note-image-url'),
- $imageBtn = $dialog.find('.note-image-btn');
-
- $imageDialog.one('shown.bs.modal', function () {
- // Cloning imageInput to clear element.
- $imageInput.replaceWith($imageInput.clone()
- .on('change', function () {
- deferred.resolve(this.files || this.value);
- $imageDialog.modal('hide');
- })
- .val('')
- );
-
- $imageBtn.click(function (event) {
- event.preventDefault();
-
- deferred.resolve($imageUrl.val());
- $imageDialog.modal('hide');
- });
-
- $imageUrl.on('keyup paste', function (event) {
- var url;
-
- if (event.type === 'paste') {
- url = event.originalEvent.clipboardData.getData('text');
- } else {
- url = $imageUrl.val();
- }
-
- toggleBtn($imageBtn, url);
- }).val('').trigger('focus');
- bindEnterKey($imageUrl, $imageBtn);
- }).one('hidden.bs.modal', function () {
- $imageInput.off('change');
- $imageUrl.off('keyup paste keypress');
- $imageBtn.off('click');
-
- if (deferred.state() === 'pending') {
- deferred.reject();
- }
- }).modal('show');
- });
- };
- };
-
- return ImageDialog;
-});
diff --git a/addons/web_editor/static/lib/summernote/src/js/module/LinkDialog.js b/addons/web_editor/static/lib/summernote/src/js/module/LinkDialog.js
deleted file mode 100644
index 045119ee68a..00000000000
--- a/addons/web_editor/static/lib/summernote/src/js/module/LinkDialog.js
+++ /dev/null
@@ -1,129 +0,0 @@
-define([
- 'summernote/core/key'
-], function (key) {
- var LinkDialog = function (handler) {
-
- /**
- * toggle button status
- *
- * @private
- * @param {jQuery} $btn
- * @param {Boolean} isEnable
- */
- var toggleBtn = function ($btn, isEnable) {
- $btn.toggleClass('disabled', !isEnable);
- $btn.attr('disabled', !isEnable);
- };
-
- /**
- * bind enter key
- *
- * @private
- * @param {jQuery} $input
- * @param {jQuery} $btn
- */
- var bindEnterKey = function ($input, $btn) {
- $input.on('keypress', function (event) {
- if (event.keyCode === key.code.ENTER) {
- $btn.trigger('click');
- }
- });
- };
-
- /**
- * Show link dialog and set event handlers on dialog controls.
- *
- * @param {jQuery} $editable
- * @param {jQuery} $dialog
- * @param {Object} linkInfo
- * @return {Promise}
- */
- this.showLinkDialog = function ($editable, $dialog, linkInfo) {
- return $.Deferred(function (deferred) {
- var $linkDialog = $dialog.find('.note-link-dialog');
-
- var $linkText = $linkDialog.find('.note-link-text'),
- $linkUrl = $linkDialog.find('.note-link-url'),
- $linkBtn = $linkDialog.find('.note-link-btn'),
- $openInNewWindow = $linkDialog.find('input[type=checkbox]');
-
- $linkDialog.one('shown.bs.modal', function () {
- $linkText.val(linkInfo.text);
-
- $linkText.on('input', function () {
- toggleBtn($linkBtn, $linkText.val() && $linkUrl.val());
- // if linktext was modified by keyup,
- // stop cloning text from linkUrl
- linkInfo.text = $linkText.val();
- });
-
- // if no url was given, copy text to url
- if (!linkInfo.url) {
- linkInfo.url = linkInfo.text || 'http://';
- toggleBtn($linkBtn, linkInfo.text);
- }
-
- $linkUrl.on('input', function () {
- toggleBtn($linkBtn, $linkText.val() && $linkUrl.val());
- // display same link on `Text to display` input
- // when create a new link
- if (!linkInfo.text) {
- $linkText.val($linkUrl.val());
- }
- }).val(linkInfo.url).trigger('focus').trigger('select');
-
- bindEnterKey($linkUrl, $linkBtn);
- bindEnterKey($linkText, $linkBtn);
-
- $openInNewWindow.prop('checked', linkInfo.isNewWindow);
-
- $linkBtn.one('click', function (event) {
- event.preventDefault();
-
- deferred.resolve({
- range: linkInfo.range,
- url: $linkUrl.val(),
- text: $linkText.val(),
- isNewWindow: $openInNewWindow.is(':checked')
- });
- $linkDialog.modal('hide');
- });
- }).one('hidden.bs.modal', function () {
- // detach events
- $linkText.off('input keypress');
- $linkUrl.off('input keypress');
- $linkBtn.off('click');
-
- if (deferred.state() === 'pending') {
- deferred.reject();
- }
- }).modal('show');
- }).promise();
- };
-
- /**
- * @param {Object} layoutInfo
- */
- this.show = function (layoutInfo) {
- var $editor = layoutInfo.editor(),
- $dialog = layoutInfo.dialog(),
- $editable = layoutInfo.editable(),
- $popover = layoutInfo.popover(),
- linkInfo = handler.invoke('editor.getLinkInfo', $editable);
-
- var options = $editor.data('options');
-
- handler.invoke('editor.saveRange', $editable);
- this.showLinkDialog($editable, $dialog, linkInfo).then(function (linkInfo) {
- handler.invoke('editor.restoreRange', $editable);
- handler.invoke('editor.createLink', $editable, linkInfo, options);
- // hide popover after creating link
- handler.invoke('popover.hide', $popover);
- }).fail(function () {
- handler.invoke('editor.restoreRange', $editable);
- });
- };
- };
-
- return LinkDialog;
-});
diff --git a/addons/web_editor/static/lib/summernote/src/js/module/Popover.js b/addons/web_editor/static/lib/summernote/src/js/module/Popover.js
index f669569f6ba..e0531f06c45 100644
--- a/addons/web_editor/static/lib/summernote/src/js/module/Popover.js
+++ b/addons/web_editor/static/lib/summernote/src/js/module/Popover.js
@@ -4,32 +4,22 @@ define([
'summernote/module/Button'
], function (func, list, Button) {
/**
- * @class module.Popover
- *
* Popover (http://getbootstrap.com/javascript/#popovers)
- *
*/
var Popover = function () {
var button = new Button();
- this.button = button; // ODOO: allow access for override
+ this.button = button; // odoo change for overwrite
/**
* returns position from placeholder
- *
- * @private
* @param {Node} placeholder
- * @param {Object} options
- * @param {Boolean} options.isAirMode
- * @return {Position}
+ * @param {Boolean} isAirMode
*/
- var posFromPlaceholder = function (placeholder, options) {
- var isAirMode = options && options.isAirMode;
- var isLeftTop = options && options.isLeftTop;
-
+ var posFromPlaceholder = function (placeholder, isAirMode) {
var $placeholder = $(placeholder);
var pos = isAirMode ? $placeholder.offset() : $placeholder.position();
- var height = isLeftTop ? 0 : $placeholder.outerHeight(true); // include margin
+ var height = $placeholder.outerHeight(true); // include margin
// popover below placeholder.
return {
@@ -40,8 +30,6 @@ define([
/**
* show popover
- *
- * @private
* @param {jQuery} popover
* @param {Position} pos
*/
@@ -68,32 +56,21 @@ define([
if (styleInfo.anchor) {
var $anchor = $linkPopover.find('a');
var href = $(styleInfo.anchor).attr('href');
- var target = $(styleInfo.anchor).attr('target');
$anchor.attr('href', href).html(href);
- if (!target) {
- $anchor.removeAttr('target');
- } else {
- $anchor.attr('target', '_blank');
- }
- showPopover($linkPopover, posFromPlaceholder(styleInfo.anchor, {
- isAirMode: isAirMode
- }));
+ showPopover($linkPopover, posFromPlaceholder(styleInfo.anchor, isAirMode));
} else {
$linkPopover.hide();
}
var $imagePopover = $popover.find('.note-image-popover');
if (styleInfo.image) {
- showPopover($imagePopover, posFromPlaceholder(styleInfo.image, {
- isAirMode: isAirMode,
- isLeftTop: true
- }));
+ showPopover($imagePopover, posFromPlaceholder(styleInfo.image, isAirMode));
} else {
$imagePopover.hide();
}
var $airPopover = $popover.find('.note-air-popover');
- if (isAirMode && styleInfo.range && !styleInfo.range.isCollapsed()) {
+ if (isAirMode && !styleInfo.range.isCollapsed()) {
var rect = list.last(styleInfo.range.getClientRects());
if (rect) {
var bnd = func.rect2bnd(rect);
diff --git a/addons/web_editor/static/lib/summernote/src/js/module/Statusbar.js b/addons/web_editor/static/lib/summernote/src/js/module/Statusbar.js
deleted file mode 100644
index b50fce458eb..00000000000
--- a/addons/web_editor/static/lib/summernote/src/js/module/Statusbar.js
+++ /dev/null
@@ -1,44 +0,0 @@
-define([
- 'summernote/core/dom'
-], function (dom) {
- var EDITABLE_PADDING = 24;
-
- var Statusbar = function () {
- var $document = $(document);
-
- this.attach = function (layoutInfo, options) {
- if (!options.disableResizeEditor) {
- layoutInfo.statusbar().on('mousedown', hStatusbarMousedown);
- }
- };
-
- /**
- * `mousedown` event handler on statusbar
- *
- * @param {MouseEvent} event
- */
- var hStatusbarMousedown = function (event) {
- event.preventDefault();
- event.stopPropagation();
-
- var $editable = dom.makeLayoutInfo(event.target).editable();
- var editableTop = $editable.offset().top - $document.scrollTop();
-
- var layoutInfo = dom.makeLayoutInfo(event.currentTarget || event.target);
- var options = layoutInfo.editor().data('options');
-
- $document.on('mousemove', function (event) {
- var nHeight = event.clientY - (editableTop + EDITABLE_PADDING);
-
- nHeight = (options.minHeight > 0) ? Math.max(nHeight, options.minHeight) : nHeight;
- nHeight = (options.maxHeight > 0) ? Math.min(nHeight, options.maxHeight) : nHeight;
-
- $editable.height(nHeight);
- }).one('mouseup', function () {
- $document.off('mousemove');
- });
- };
- };
-
- return Statusbar;
-});
diff --git a/addons/web_editor/static/lib/summernote/src/js/module/Toolbar.js b/addons/web_editor/static/lib/summernote/src/js/module/Toolbar.js
index 5e5e5721b63..832b7c4c561 100644
--- a/addons/web_editor/static/lib/summernote/src/js/module/Toolbar.js
+++ b/addons/web_editor/static/lib/summernote/src/js/module/Toolbar.js
@@ -1,17 +1,14 @@
define([
'summernote/core/list',
- 'summernote/core/dom',
'summernote/module/Button'
-], function (list, dom, Button) {
+], function (list, Button) {
/**
- * @class module.Toolbar
- *
* Toolbar
*/
var Toolbar = function () {
var button = new Button();
- this.button = button; // ODOO: allow access for override
+ this.button = button; // odoo change for overwrite
this.update = function ($toolbar, styleInfo) {
button.update($toolbar, styleInfo);
@@ -46,54 +43,14 @@ define([
.addClass('disabled');
};
- /**
- * @param {jQuery} $container
- * @param {Boolean} [bFullscreen=false]
- */
this.updateFullscreen = function ($container, bFullscreen) {
var $btn = $container.find('button[data-event="fullscreen"]');
$btn.toggleClass('active', bFullscreen);
};
- /**
- * @param {jQuery} $container
- * @param {Boolean} [isCodeview=false]
- */
this.updateCodeview = function ($container, isCodeview) {
var $btn = $container.find('button[data-event="codeview"]');
$btn.toggleClass('active', isCodeview);
-
- if (isCodeview) {
- this.deactivate($container);
- } else {
- this.activate($container);
- }
- };
-
- /**
- * get button in toolbar
- *
- * @param {jQuery} $editable
- * @param {String} name
- * @return {jQuery}
- */
- this.get = function ($editable, name) {
- var $toolbar = dom.makeLayoutInfo($editable).toolbar();
-
- return $toolbar.find('[data-name=' + name + ']');
- };
-
- /**
- * set button state
- * @param {jQuery} $editable
- * @param {String} name
- * @param {Boolean} [isActive=true]
- */
- this.setButtonState = function ($editable, name, isActive) {
- isActive = (isActive === false) ? false : true;
-
- var $button = this.get($editable, name);
- $button.toggleClass('active', isActive);
};
};