From 1e9ce28f7b3244d5c88ac5e78caaaf27fd5116cc Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 1 Dec 2015 17:31:37 +0100 Subject: [FIX] website, web_editor: open in new window The field `isNewWindow` is used to open a link in a new tab. In this case, the field newWindow was used, and therefore the property was not applied. opw-657510 --- addons/web_editor/static/src/js/widgets.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_editor/static/src/js') diff --git a/addons/web_editor/static/src/js/widgets.js b/addons/web_editor/static/src/js/widgets.js index 97c171f0950..7e13a27f8e5 100644 --- a/addons/web_editor/static/src/js/widgets.js +++ b/addons/web_editor/static/src/js/widgets.js @@ -1079,7 +1079,7 @@ var LinkDialog = Dialog.extend({ return this.get_data() .then(function (url, new_window, label, classes) { self.data.url = url; - self.data.newWindow = new_window; + self.data.isNewWindow = new_window; self.data.text = label; self.data.className = classes.replace(/\s+/gi, ' ').replace(/^\s+|\s+$/gi, ''); -- cgit v1.2.3 From d1af67bf28d24fe8471c2f43132488535d4f6a63 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 30 Nov 2015 15:53:21 +0100 Subject: [FIX] web_editor: img classname is removed when change the url --- addons/web_editor/static/src/js/widgets.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'addons/web_editor/static/src/js') diff --git a/addons/web_editor/static/src/js/widgets.js b/addons/web_editor/static/src/js/widgets.js index 7e13a27f8e5..165f0b0e914 100644 --- a/addons/web_editor/static/src/js/widgets.js +++ b/addons/web_editor/static/src/js/widgets.js @@ -171,12 +171,9 @@ var MediaDialog = Dialog.extend({ var self = this; if (self.media) { this.media.innerHTML = ""; - if (this.active !== this.imageDialog) { + if (this.active !== this.imageDialog && this.active !== this.documentDialog) { this.imageDialog.clear(); } - if (this.active !== this.documentDialog) { - this.documentDialog.clear(); - } // if not mode only_images if (this.iconDialog && this.active !== this.iconDialog) { this.iconDialog.clear(); @@ -355,7 +352,7 @@ var ImageDialog = Widget.extend({ return this.media; }, clear: function () { - this.media.className = this.media.className.replace(/(^|\s+)(img(\s|$)|img-(?!circle|rounded|thumbnail)[^\s]*)/g, ' '); + this.media.className = this.media.className.replace(/(^|\s+)((img(\s|$)|img-(?!circle|rounded|thumbnail))[^\s]*)/g, ' '); }, cancel: function () { this.trigger('cancel'); -- cgit v1.2.3 From 512ae81920727a104355553204482c3feebda6ea Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 2 Dec 2015 13:29:06 +0100 Subject: [FIX] web_editor: add code view in debug mode to allow jinja insertion --- addons/web_editor/static/src/js/backend.js | 6 +- addons/web_editor/static/src/js/iframe.js | 10 +++ addons/web_editor/static/src/js/rte.summernote.js | 99 +++++++++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) (limited to 'addons/web_editor/static/src/js') diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js index 2c7c86466c1..0cd7541c7e2 100644 --- a/addons/web_editor/static/src/js/backend.js +++ b/addons/web_editor/static/src/js/backend.js @@ -25,7 +25,7 @@ var FieldTextHtmlSimple = widget.extend({ template: 'web_editor.FieldTextHtmlSimple', _config: function () { var self = this; - return { + var config = { 'focus': false, 'height': 180, 'toolbar': [ @@ -46,6 +46,10 @@ var FieldTextHtmlSimple = widget.extend({ self.trigger('changed_value'); } }; + if (session.debug) { + config.toolbar.splice(7, 0, ['view', ['codeview']]); + } + return config; }, start: function() { var def = this._super.apply(this, arguments); diff --git a/addons/web_editor/static/src/js/iframe.js b/addons/web_editor/static/src/js/iframe.js index c6913bb39d9..2f494cd041c 100644 --- a/addons/web_editor/static/src/js/iframe.js +++ b/addons/web_editor/static/src/js/iframe.js @@ -59,6 +59,16 @@ snippet_editor.Class.include({ } }); +rte.Class.include({ + config: function ($editable) { + var config = this._super($editable); + if ($.deparam($.param.querystring()).debug !== undefined) { + config.airPopover.splice(7, 0, ['view', ['codeview']]); + } + return config; + } +}); + translator.Class.include({ start: function () { var res = this._super(); diff --git a/addons/web_editor/static/src/js/rte.summernote.js b/addons/web_editor/static/src/js/rte.summernote.js index 4e4af30f5aa..ca7d97ffd82 100644 --- a/addons/web_editor/static/src/js/rte.summernote.js +++ b/addons/web_editor/static/src/js/rte.summernote.js @@ -427,6 +427,105 @@ $.summernote.pluginEvents.visible = function (event, editor, layoutInfo) { return res; }; +function prettify_html(html) { + html = html.trim(); + var result = '', + level = 0, + get_space = function (level) { + var i = level, space = ''; + while (i--) space += ' '; + return space; + }, + reg = /^<\/?(a|span|font|strong|u|i|strong|b)(\s|>)/i, + inline_level = Infinity, + tokens = _.compact(_.flatten(_.map(html.split(//); + value[0] = /\S/.test(value[0]) ? '<' + value[0] + '>' : ''; + return value; + }))); + + // reduce => merge inline style + text + + for (var i = 0, l = tokens.length; i < l; i++) { + var token = tokens[i]; + var inline_tag = reg.test(token); + var inline = inline_tag || inline_level <= level; + + if (token[0] === '<' && token[1] === '/') { + if (inline_tag && inline_level === level) { + inline_level = Infinity; + } + level--; + } + + if (!inline && !/\S/.test(token)) { + continue; + } + if (!inline || (token[1] !== '/' && inline_level > level)) { + result += get_space(level); + } + + if (token[0] === '<' && token[1] !== '/') { + level++; + if (inline_tag && inline_level > level) { + inline_level = level; + } + } + + if (token.match(/^<(img|hr|br)/)) { + level--; + } + + result += token.trim().replace(/\s+/, ' '); + + if (inline_level > level) { + result += '\n'; + } + } + return result; +} +$.summernote.pluginEvents.codeview = function (event, editor, layoutInfo) { + if (layoutInfo.toolbar) { + return eventHandler.modules.codeview.toggle(layoutInfo); + } else { + var $editor = layoutInfo.editor(); + var $textarea = $editor.prev('textarea'); + + if (!$textarea.length) { + // init and create texarea + var html = prettify_html($editor.prop("innerHTML")); + $editor.parent().css({ + 'position': 'absolute', + 'top': 0, + 'bottom': 0, + 'left': 0, + 'right': 0 + }); + $textarea = $('