summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2017-03-17 17:57:52 +0100
committerChristophe Simonis <chs@odoo.com>2017-03-17 17:57:52 +0100
commitb2fa9f2ad1dac059c365e854cc1078b45eccdd85 (patch)
treed92287b0652b68b46882b6acd14be0232a4efaf4 /addons/web_editor/static/src/js
parentcee15f7d90956b3e004f27f1e91e02ab59c450d1 (diff)
parent31ebb077734a4fda87df8eb19a88c0591f7e79e2 (diff)
[MERGE] forward port branch 10.0 up to 31ebb077734
Diffstat (limited to 'addons/web_editor/static/src/js')
-rw-r--r--addons/web_editor/static/src/js/summernote.js18
-rw-r--r--addons/web_editor/static/src/js/transcoder.js36
2 files changed, 35 insertions, 19 deletions
diff --git a/addons/web_editor/static/src/js/summernote.js b/addons/web_editor/static/src/js/summernote.js
index 9d7304caf75..71647828cc6 100644
--- a/addons/web_editor/static/src/js/summernote.js
+++ b/addons/web_editor/static/src/js/summernote.js
@@ -2313,11 +2313,19 @@ eventHandler.modules.popover.update = function ($popover, oStyle, isAirMode) {
eventHandler.modules.clipboard.attach = function(layoutInfo) {
var $editable = layoutInfo.editable();
$editable.on('paste', function(e) {
- e.preventDefault();
- $editable.data('NoteHistory').recordUndo($editable);
- var pastedText = ((e.originalEvent || e).clipboardData || window.clipboardData).getData('Text');
- var formattedText = pastedText.replace(/([^.!?:;])\r?\n/g, "$1").trim(); // Remove linebreaks which are not at the end of a sentence
- document.execCommand("insertText", false, formattedText);
+ var clipboardData = ((e.originalEvent || e).clipboardData || window.clipboardData);
+ // Change nothing if pasting html (copy from text editor / web / ...) or
+ // if clipboardData is not available (IE / ...)
+ if (clipboardData && clipboardData.types && clipboardData.types.length === 1 && clipboardData.types[0] === "text/plain") {
+ e.preventDefault();
+ $editable.data('NoteHistory').recordUndo($editable); // FIXME
+ var pastedText = clipboardData.getData("text/plain");
+ // Try removing linebreaks which are not really linebreaks (in a PDF,
+ // when a sentence goes over the next line, copying it considers it
+ // a linebreak for example).
+ var formattedText = pastedText.replace(/([\w-])\r?\n([\w-])/g, "$1 $2").trim();
+ document.execCommand("insertText", false, formattedText);
+ }
});
};
diff --git a/addons/web_editor/static/src/js/transcoder.js b/addons/web_editor/static/src/js/transcoder.js
index 20d4f5844af..fa7b4023377 100644
--- a/addons/web_editor/static/src/js/transcoder.js
+++ b/addons/web_editor/static/src/js/transcoder.js
@@ -98,20 +98,28 @@ var getMatchedCSSRules = function (a) {
if (style.display === 'block') {
delete style.display;
}
- if (style['margin-top']) {
- style.margin = (style['margin-top'] || 0) + ' ' + (style['margin-right'] || 0) + ' ' + (style['margin-bottom'] || 0) + ' ' + (style['margin-left'] || 0);
- delete style['margin-top'];
- delete style['margin-right'];
- delete style['margin-bottom'];
- delete style['margin-left'];
- }
- if (style['padding-top']) {
- style.padding = (style['padding-top'] || 0) + ' ' + (style['padding-right'] || 0) + ' ' + (style['padding-bottom'] || 0) + ' ' + (style['padding-left'] || 0);
- delete style['padding-top'];
- delete style['padding-right'];
- delete style['padding-bottom'];
- delete style['padding-left'];
- }
+
+ _.each(['margin', 'padding'], function(p) {
+ if (style[p+'-top'] || style[p+'-right'] || style[p+'-bottom'] || style[p+'-left']) {
+ if (style[p+'-top'] === style[p+'-right'] && style[p+'-top'] === style[p+'-bottom'] && style[p+'-top'] === style[p+'-left']) {
+ // keep => property: [top/right/bottom/left value];
+ style[p] = style[p+'-top'];
+ }
+ else {
+ // keep => property: [top value] [right value] [bottom value] [left value];
+ style[p] = (style[p+'-top'] || 0) + ' ' + (style[p+'-right'] || 0) + ' ' + (style[p+'-bottom'] || 0) + ' ' + (style[p+'-left'] || 0);
+ if (style[p].indexOf('inherit') !== -1 || style[p].indexOf('initial') !== -1) {
+ // keep => property-top: [top value]; property-right: [right value]; property-bottom: [bottom value]; property-left: [left value];
+ delete style[p];
+ return;
+ }
+ }
+ delete style[p+'-top'];
+ delete style[p+'-right'];
+ delete style[p+'-bottom'];
+ delete style[p+'-left'];
+ }
+ });
return style;
};