diff options
Diffstat (limited to 'addons/web_editor/static/src/js')
| -rw-r--r-- | addons/web_editor/static/src/js/backend.js | 6 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/iframe.js | 10 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/rte.summernote.js | 99 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/widgets.js | 9 |
4 files changed, 117 insertions, 7 deletions
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(/</), function (value) { + value = value.replace(/\s+/g, ' ').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 = $('<textarea/>').css({ + 'margin': '0 -4px', + 'padding': '0 4px', + 'border': 0, + 'top': '51px', + 'left': '620px', + 'width': '100%', + 'font-family': 'sans-serif', + 'font-size': '13px', + 'height': '98%', + 'white-space': 'pre', + 'word-wrap': 'normal' + }).val(html).data('init', html); + $editor.before($textarea); + $editor.hide(); + } else { + // save changes + $editor.prop('innerHTML', $textarea.val().replace(/\s*\n\s*/g, '')).trigger('content_changed'); + $textarea.remove(); + $editor.show(); + } + } +}; + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// /* fix ie and re-range to don't break snippet*/ diff --git a/addons/web_editor/static/src/js/widgets.js b/addons/web_editor/static/src/js/widgets.js index 97c171f0950..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'); @@ -1079,7 +1076,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, ''); |
