diff options
| author | Christophe Matthieu <chm@odoo.com> | 2014-08-08 11:58:40 +0200 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2014-08-08 11:58:40 +0200 |
| commit | 777a082bfc8de9d3a4d3e7c144453c9efb14751c (patch) | |
| tree | 3068953a09822f72fe501b16cd1ee047c8e11f80 /addons/website/static/src/js/website.editor.js | |
| parent | eb23f30c7e3bcb1fa19c9a9f9d0291d802abe462 (diff) | |
[IMP] website: create customize theme application and color-picker; Create theme_bootswatch and use less files.
Diffstat (limited to 'addons/website/static/src/js/website.editor.js')
| -rw-r--r-- | addons/website/static/src/js/website.editor.js | 111 |
1 files changed, 108 insertions, 3 deletions
diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index 60076b9664b..9b86002626c 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -209,6 +209,111 @@ } }); + CKEDITOR.plugins.add('customColor', { + requires: 'panelbutton,floatpanel', + init: function (editor) { + function create_button (buttonID, label) { + var btnID = buttonID; + editor.ui.add(buttonID, CKEDITOR.UI_PANELBUTTON, { + label: label, + title: label, + modes: { wysiwyg: true }, + editorFocus: true, + context: 'font', + panel: { + css: [ '/web/css/web.assets_common/' + (new Date().getTime()), + '/web/css/website.assets_frontend/' + (new Date().getTime()), + '/web/css/website.assets_editor/' + (new Date().getTime())], + attributes: { 'role': 'listbox', 'aria-label': label }, + }, + enable: function () { + this.setState(CKEDITOR.TRISTATE_OFF); + }, + disable: function () { + this.setState(CKEDITOR.TRISTATE_DISABLED); + }, + onBlock: function (panel, block) { + var self = this; + var html = openerp.qweb.render('website.colorpicker'); + block.autoSize = true; + block.element.setHtml( html ); + $(block.element.$).on('click', 'button', function () { + self.clicked(this); + }); + if (btnID === "TextColor") { + $(".only-text", block.element.$).css("display", "block"); + $(".only-bg", block.element.$).css("display", "none"); + } + var $body = $(block.element.$).parents("body"); + setTimeout(function () { + $body.css('background-color', '#fff'); + }, 0); + }, + getClasses: function () { + var self = this; + var classes = []; + var id = this._.id; + var block = this._.panel._.panel._.blocks[id]; + var $root = $(block.element.$); + $root.find("button").map(function () { + var color = self.getClass(this); + if(color) classes.push( color ); + }); + return classes; + }, + getClass: function (button) { + var color = btnID === "BGColor" ? $(button).attr("class") : $(button).attr("class").replace(/^bg-/i, 'text-'); + return color.length && color; + }, + clicked: function (button) { + var className = this.getClass(button); + var ancestor = editor.getSelection().getCommonAncestor(); + + editor.focus(); + this._.panel.hide(); + editor.fire('saveSnapshot'); + + // remove style + var classes = []; + var $ancestor = $(ancestor.$); + var $fonts = $(ancestor.$).find('font'); + if (!ancestor.$.tagName) { + $ancestor = $ancestor.parent(); + } + if ($ancestor.is('font')) { + $fonts = $fonts.add($ancestor[0]); + } + + $fonts.filter("."+this.getClasses().join(",.")).map(function () { + var className = $(this).attr("class"); + if (classes.indexOf(className) === -1) { + classes.push(className); + } + }); + for (var k in classes) { + editor.removeStyle( new CKEDITOR.style({ + element: 'font', + attributes: { 'class': classes[k] }, + }) ); + } + + // add new style + if (className) { + editor.applyStyle( new CKEDITOR.style({ + element: 'font', + attributes: { 'class': className }, + }) ); + } + editor.fire('saveSnapshot'); + } + + }); + } + create_button("BGColor", "Background Color"); + create_button("TextColor", "Text Color"); + } + }); + CKEDITOR.plugins.add('oeref', { requires: 'widget', @@ -564,7 +669,7 @@ website.EditorBarCustomize = openerp.Widget.extend({ events: { 'mousedown a.dropdown-toggle': 'load_menu', - 'click ul a[data-action!=ace]': 'do_customize', + 'click li:not(#html_editor):not(#theme_customize):not(#install_apps) a': 'do_customize', }, start: function() { var self = this; @@ -868,7 +973,7 @@ fillEmptyBlocks: false, filebrowserImageUploadUrl: "/website/attach", // Support for sharedSpaces in 4.x - extraPlugins: 'sharedspace,customdialogs,tablebutton,oeref', + extraPlugins: 'customColor,sharedspace,customdialogs,tablebutton,oeref', // Place toolbar in controlled location sharedSpaces: { top: 'oe_rte_toolbar' }, toolbar: [{ @@ -900,7 +1005,7 @@ {name: "Heading 5", element: 'h5'}, {name: "Heading 6", element: 'h6'}, {name: "Formatted", element: 'pre'}, - {name: "Address", element: 'address'} + {name: "Address", element: 'address'}, ], }; }, |
