<commit_before>(function () {
    'use strict';

    var website = openerp.website;
    var _t = openerp._t;

    website.add_template_file('/website/static/src/xml/website.editor.xml');
    website.dom_ready.done(function () {
        var is_smartphone = $(document.body)[0].clientWidth < 767;

        if (!is_smartphone) {
            website.ready().then(website.init_editor);
        }

        $(document).on('click', 'a.js_link2post', function (ev) {
            ev.preventDefault();
            website.form(this.pathname, 'POST');
        });

        $(document).on('hide.bs.dropdown', '.dropdown', function (ev) {
            // Prevent dropdown closing when a contenteditable children is focused
            if (ev.originalEvent
                    && $(ev.target).has(ev.originalEvent.target).length
                    && $(ev.originalEvent.target).is('[contenteditable]')) {
                ev.preventDefault();
            }
        });
    });

    function link_dialog(editor) {
        return new website.editor.RTELinkDialog(editor).appendTo(document.body);
    }
    function image_dialog(editor, image) {
        return new website.editor.RTEImageDialog(editor, image).appendTo(document.body);
    }

    // only enable editors manually
    CKEDITOR.disableAutoInline = true;
    // EDIT ALL THE THINGS
    CKEDITOR.dtd.$editable = $.extend(
        {}, CKEDITOR.dtd.$block, CKEDITOR.dtd.$inline);
    // Disable removal of empty elements on CKEDITOR activation. Empty
    // elements are used for e.g. support of FontAwesome icons
    CKEDITOR.dtd.$removeEmpty = {};

    website.init_editor = function () {
        CKEDITOR.plugins.add('customdialogs', {
//            requires: 'link,image',
            init: function (editor) {
                editor.on('doubleclick', function (evt) {
                    var element = evt.data.element;
                    if (element.is('img')
                            && !element.data('cke-realelement')
                            && !element.isReadOnly()
                            && (element.data('oe-model') !== 'ir.ui.view')) {
                        image_dialog(editor, element);
                        return;
                    }

                    element = get_selected_link(editor) || evt.data.element;
                    if (element.isReadOnly()
                        || !element.is('a')
                        || element.data('oe-model')) {
                        return;
                    }

                    editor.getSelection().selectElement(element);
                    link_dialog(editor);
                }, null, null, 500);

                var previousSelection;
                $(editor.element.$).on('mouseenter', 'img', function () {
                    if (previousSelection) { return; }
                    var selected = new CKEDITOR.dom.element(this);
                    if (!selected.is('img')
                            || selected.data('cke-realelement')
                            || selected.isReadOnly()
                            || selected.data('oe-model') === 'ir.ui.view') {
                        return;
                    }

                    // display button
                    var $el = $((previousSelection = selected).$);
                    var $btn = $('<button type="button" class="btn btn-primary image-edit-button" contenteditable="false">Edit</button>')
                        .insertAfter($el)
                        .click(function (e) {
                            e.preventDefault();
                            e.stopPropagation();
                            image_dialog(editor, selected);
                        });

                    var position = $el.position();
                    // http://bugs.jquery.com/ticket/5445#comment:6
                    // if the image has margin: x auto for centering, FF & IE
                    // will report top/left as the "correct" value and
                    // marginTop/marginLeft at "0px", webkit browsers will
                    // report top/left as 0-ish and set marginTop and
                    // marginLeft
                    var image_top = position.top + parseInt($el.css('marginTop'), 10);
                    var image_left = position.left + parseInt($el.css('marginLeft'), 10);
                    $btn.css({
                        position: 'absolute',
                        top: $el.height() / 2 + image_top - $btn.outerHeight() / 2,
                        left: $el.width() / 2 + image_left - $btn.outerWidth() / 2,
                    });
                }).on('mouseleave', 'img', function (e) {
                    if (!previousSelection) { return; }
                    var $previous = $(previousSelection.$);
                    var $button = $previous.next('button');
                    $button.css('visibility', 'hidden');
                    var el = document.elementFromPoint(e.clientX, e.clientY);
                    $button.css('visibility', '');
                    if (el === this) { return; }
                    $button.remove();
                    previousSelection = null;
                });
                editor.on('destroy', function () {
                    if (!previousSelection) { return; }
                    $('.image-edit-button').remove();
                });

                //noinspection JSValidateTypes
                editor.addCommand('link', {
                    exec: function (editor) {
                        link_dialog(editor);
                        return true;
                    },
                    canUndo: false,
                    editorFocus: true,
                });
                //noinspection JSValidateTypes
                editor.addCommand('image', {
                    exec: function (editor) {
                        image_dialog(editor);
                        return true;
                    },
                    canUndo: false,
                    editorFocus: true,
                });

                editor.ui.addButton('Link', {
                    label: 'Link',
                    command: 'link',
                    toolbar: 'links,10',
                });
                editor.ui.addButton('Image', {
                    label: 'Image',
                    command: 'image',
                    toolbar: 'insert,10',
                });

                editor.setKeystroke(CKEDITOR.CTRL + 76 /*L*/, 'link');
            }
        });
        CKEDITOR.plugins.add( 'tablebutton', {
            requires: 'panelbutton,floatpanel',
            init: function( editor ) {
                var label = "Table";

                editor.ui.add('TableButton', CKEDITOR.UI_PANELBUTTON, {
                    label: label,
                    title: label,
                    // use existing 'table' icon
                    icon: 'table',
                    modes: { wysiwyg: true },
                    editorFocus: true,
                    // panel opens in iframe, @css is CSS file <link>-ed within
                    // frame document, @attributes are set on iframe itself.
                    panel: {
                        css: '/website/static/src/css/editor.css',
                        attributes: { 'role': 'listbox', 'aria-label': label, },
                    },

                    onBlock: function (panel, block) {
                        block.autoSize = true;
                        block.element.setHtml(openerp.qweb.render('website.editor.table.panel', {
                            rows: 5,
                            cols: 5,
                        }));

                        var $table = $(block.element.$).on('mouseenter', 'td', function (e) {
                            var $e = $(e.target);
                            var y = $e.index() + 1;
                            var x = $e.closest('tr').index() + 1;

                            $table
                                .find('td').removeClass('selected').end()
                                .find('tr:lt(' + String(x) + ')')
                                .children().filter(function () { return $(this).index() < y; })
                                .addClass('selected');
                        }).on('click', 'td', function (e) {
                            var $e = $(e.target);

                            //noinspection JSPotentiallyInvalidConstructorUsage
                            var table = new CKEDITOR.dom.element(
                                $(openerp.qweb.render('website.editor.table', {
                                    rows: $e.closest('tr').index() + 1,
                                    cols: $e.index() + 1,
                                }))[0]);

                            editor.insertElement(table);
                            setTimeout(function () {
                                //noinspection JSPotentiallyInvalidConstructorUsage
                                var firstCell = new CKEDITOR.dom.element(table.$.rows[0].cells[0]);
                                var range = editor.createRange();
                                range.moveToPosition(firstCell, CKEDITOR.POSITION_AFTER_START);
                                range.select();
                            }, 0);
                        });

                        block.element.getDocument().getBody().setStyle('overflow', 'hidden');
                        CKEDITOR.ui.fire('ready', this);
                    },
                });
            }
        });

        CKEDITOR.plugins.add('linkstyle', {
            requires: 'panelbutton,floatpanel',
            init: function (editor) {
                var label = "Link Style";

                editor.ui.add('LinkStyle', CKEDITOR.UI_PANELBUTTON, {
                    label: label,
                    title: label,
                    icon: '/website/static/src/img/bglink.png',
                    modes: { wysiwyg: true },
                    editorFocus: true,
                    panel: {
                        css: '/website/static/lib/bootstrap/css/bootstrap.css',
                        attributes: { 'role': 'listbox', 'aria-label': label },
                    },

                    types: {
                        'btn-default': _t("Basic"),
                        'btn-primary': _t("Primary"),
                        'btn-success': _t("Success"),
                        'btn-info': _t("Info"),
                        'btn-warning': _t("Warning"),
                        'btn-danger': _t("Danger"),
                    },
                    sizes: {
                        'btn-xs': _t("Extra Small"),
                        'btn-sm': _t("Small"),
                        '': _t("Default"),
                        'btn-lg': _t("Large")
                    },

                    onRender: function () {
                        var self = this;
                        editor.on('selectionChange', function (e) {
                            var path = e.data.path, el;

                            if (!(e = path.contains('a')) || e.isReadOnly()) {
                                self.disable();
                                return;
                            }

                            self.enable();
                        });
                        // no hook where button is available, so wait
                        // "some time" after render.
                        setTimeout(function () {
                            self.disable();
                        }, 0)
                    },
                    enable: function () {
                        this.setState(CKEDITOR.TRISTATE_OFF);
                    },
                    disable: function () {
                        this.setState(CKEDITOR.TRISTATE_DISABLED);
                    },

                    onOpen: function () {
                        var link = get_selected_link(editor);
                        var id = this._.id;
                        var block = this._.panel._.panel._.blocks[id];
                        var $root = $(block.element.$);
                        $root.find('button').removeClass('active').removeProp('disabled');

                        // enable buttons matching link state
                        for (var type in this.types) {
                            if (!this.types.hasOwnProperty(type)) { continue; }
                            if (!link.hasClass(type)) { continue; }

                            $root.find('button[data-type=types].' + type)
                                 .addClass('active');
                        }
                        var found;
                        for (var size in this.sizes) {
                            if (!this.sizes.hasOwnProperty(size)) { continue; }
                            if (!size || !link.hasClass(size)) { continue; }
                            found = true;
                            $root.find('button[data-type=sizes].' + size)
                                 .addClass('active');
                        }
                        if (!found && link.hasClass('btn')) {
                            $root.find('button[data-type="sizes"][data-set-class=""]')
                                 .addClass('active');
                        }
                    },

                    onBlock: function (panel, block) {
                        var self = this;
                        block.autoSize = true;

                        var html = ['<div style="padding: 5px">'];
                        html.push('<div style="white-space: nowrap">');
                        _(this.types).each(function (label, key) {
                            html.push(_.str.sprintf(
                                '<button type="button" class="btn %s" ' +
                                        'data-type="types" data-set-class="%s">%s</button>',
                                key, key, label));
                        });
                        html.push('</div>');
                        html.push('<div style="white-space: nowrap; margin: 5px 0; text-align: center">');
                        _(this.sizes).each(function (label, key) {
                            html.push(_.str.sprintf(
                                '<button type="button" class="btn btn-default %s" ' +
                                        'data-type="sizes" data-set-class="%s">%s</button>',
                                key, key, label));
                        });
                        html.push('</div>');
                        html.push('<button type="button" class="btn btn-link btn-block" ' +
                                          'data-type="reset">Reset</button>');
                        html.push('</div>');

                        block.element.setHtml(html.join(' '));
                        var $panel = $(block.element.$);
                        $panel.on('click', 'button', function () {
                            self.clicked(this);
                        });
                    },
                    clicked: function (button) {
                        editor.focus();
                        editor.fire('saveSnapshot');

                        var $button = $(button),
                              $link = $(get_selected_link(editor).$);
                        if (!$link.hasClass('btn')) {
                            $link.addClass('btn btn-default');
                        }
                        switch($button.data('type')) {
                        case 'reset':
                            $link.removeClass('btn')
                                 .removeClass(_.keys(this.types).join(' '))
                                 .removeClass(_.keys(this.sizes).join(' '));
                            break;
                        case 'types':
                            $link.removeClass(_.keys(this.types).join(' '))
                                 .addClass($button.data('set-class'));
                            break;
                        case 'sizes':
                            $link.removeClass(_.keys(this.sizes).join(' '))
                                 .addClass($button.data('set-class'));
                        }
                        this._.panel.hide();

                        editor.fire('saveSnapshot');
                    },

                });
            }
        });

        CKEDITOR.plugins.add('oeref', {
            requires: 'widget',

            init: function (editor) {
                editor.widgets.add('oeref', {
                    editables: { text: '*' },

                    upcast: function (el) {
                        return el.attributes['data-oe-type']
                            && el.attributes['data-oe-type'] !== 'monetary';
                    },
                });
                editor.widgets.add('monetary', {
                    editables: { text: 'span.oe_currency_value' },

                    upcast: function (el) {
                        return el.attributes['data-oe-type'] === 'monetary';
                    }
                });
            }
        });

        var editor = new website.EditorBar();
        var $body = $(document.body);
        editor.prependTo($body).then(function () {
            if (location.search.indexOf("enable_editor") >= 0) {
                editor.edit();
            }
        });
        $body.css('padding-top', '50px'); // Not working properly: editor.$el.outerHeight());
    };
        /* ----- TOP EDITOR BAR FOR ADMIN ---- */
    website.EditorBar = openerp.Widget.extend({
        template: 'website.editorbar',
        events: {
            'click button[data-action=edit]': 'edit',
            'click button[data-action=save]': 'save',
            'click button[data-action=cancel]': 'cancel',
            'click a[data-action=new_page]': 'new_page',
        },
        container: 'body',
        customize_setup: function() {
            var self = this;
            var view_name = $(document.documentElement).data('view-xmlid');
            var menu = $('#customize-menu');
            this.$('#customize-menu-button').click(function(event) {
                menu.empty();
                openerp.jsonRpc('/website/customize_template_get', 'call', { 'xml_id': view_name }).then(
                    function(result) {
                        _.each(result, function (item) {
                            if (item.header) {
                                menu.append('<li class="dropdown-header">' + item.name + '</li>');
                            } else {
                                menu.append(_.str.sprintf('<li role="presentation"><a href="#" data-view-id="%s" role="menuitem"><strong class="icon-check%s"></strong> %s</a></li>',
                                    item.id, item.active ? '' : '-empty', item.name));
                            }
                        });<commit_msg>[FIX] website: customize: apply fontawesome to icons<commit_after>(function () {
    'use strict';

    var website = openerp.website;
    var _t = openerp._t;

    website.add_template_file('/website/static/src/xml/website.editor.xml');
    website.dom_ready.done(function () {
        var is_smartphone = $(document.body)[0].clientWidth < 767;

        if (!is_smartphone) {
            website.ready().then(website.init_editor);
        }

        $(document).on('click', 'a.js_link2post', function (ev) {
            ev.preventDefault();
            website.form(this.pathname, 'POST');
        });

        $(document).on('hide.bs.dropdown', '.dropdown', function (ev) {
            // Prevent dropdown closing when a contenteditable children is focused
            if (ev.originalEvent
                    && $(ev.target).has(ev.originalEvent.target).length
                    && $(ev.originalEvent.target).is('[contenteditable]')) {
                ev.preventDefault();
            }
        });
    });

    function link_dialog(editor) {
        return new website.editor.RTELinkDialog(editor).appendTo(document.body);
    }
    function image_dialog(editor, image) {
        return new website.editor.RTEImageDialog(editor, image).appendTo(document.body);
    }

    // only enable editors manually
    CKEDITOR.disableAutoInline = true;
    // EDIT ALL THE THINGS
    CKEDITOR.dtd.$editable = $.extend(
        {}, CKEDITOR.dtd.$block, CKEDITOR.dtd.$inline);
    // Disable removal of empty elements on CKEDITOR activation. Empty
    // elements are used for e.g. support of FontAwesome icons
    CKEDITOR.dtd.$removeEmpty = {};

    website.init_editor = function () {
        CKEDITOR.plugins.add('customdialogs', {
//            requires: 'link,image',
            init: function (editor) {
                editor.on('doubleclick', function (evt) {
                    var element = evt.data.element;
                    if (element.is('img')
                            && !element.data('cke-realelement')
                            && !element.isReadOnly()
                            && (element.data('oe-model') !== 'ir.ui.view')) {
                        image_dialog(editor, element);
                        return;
                    }

                    element = get_selected_link(editor) || evt.data.element;
                    if (element.isReadOnly()
                        || !element.is('a')
                        || element.data('oe-model')) {
                        return;
                    }

                    editor.getSelection().selectElement(element);
                    link_dialog(editor);
                }, null, null, 500);

                var previousSelection;
                $(editor.element.$).on('mouseenter', 'img', function () {
                    if (previousSelection) { return; }
                    var selected = new CKEDITOR.dom.element(this);
                    if (!selected.is('img')
                            || selected.data('cke-realelement')
                            || selected.isReadOnly()
                            || selected.data('oe-model') === 'ir.ui.view') {
                        return;
                    }

                    // display button
                    var $el = $((previousSelection = selected).$);
                    var $btn = $('<button type="button" class="btn btn-primary image-edit-button" contenteditable="false">Edit</button>')
                        .insertAfter($el)
                        .click(function (e) {
                            e.preventDefault();
                            e.stopPropagation();
                            image_dialog(editor, selected);
                        });

                    var position = $el.position();
                    // http://bugs.jquery.com/ticket/5445#comment:6
                    // if the image has margin: x auto for centering, FF & IE
                    // will report top/left as the "correct" value and
                    // marginTop/marginLeft at "0px", webkit browsers will
                    // report top/left as 0-ish and set marginTop and
                    // marginLeft
                    var image_top = position.top + parseInt($el.css('marginTop'), 10);
                    var image_left = position.left + parseInt($el.css('marginLeft'), 10);
                    $btn.css({
                        position: 'absolute',
                        top: $el.height() / 2 + image_top - $btn.outerHeight() / 2,
                        left: $el.width() / 2 + image_left - $btn.outerWidth() / 2,
                    });
                }).on('mouseleave', 'img', function (e) {
                    if (!previousSelection) { return; }
                    var $previous = $(previousSelection.$);
                    var $button = $previous.next('button');
                    $button.css('visibility', 'hidden');
                    var el = document.elementFromPoint(e.clientX, e.clientY);
                    $button.css('visibility', '');
                    if (el === this) { return; }
                    $button.remove();
                    previousSelection = null;
                });
                editor.on('destroy', function () {
                    if (!previousSelection) { return; }
                    $('.image-edit-button').remove();
                });

                //noinspection JSValidateTypes
                editor.addCommand('link', {
                    exec: function (editor) {
                        link_dialog(editor);
                        return true;
                    },
                    canUndo: false,
                    editorFocus: true,
                });
                //noinspection JSValidateTypes
                editor.addCommand('image', {
                    exec: function (editor) {
                        image_dialog(editor);
                        return true;
                    },
                    canUndo: false,
                    editorFocus: true,
                });

                editor.ui.addButton('Link', {
                    label: 'Link',
                    command: 'link',
                    toolbar: 'links,10',
                });
                editor.ui.addButton('Image', {
                    label: 'Image',
                    command: 'image',
                    toolbar: 'insert,10',
                });

                editor.setKeystroke(CKEDITOR.CTRL + 76 /*L*/, 'link');
            }
        });
        CKEDITOR.plugins.add( 'tablebutton', {
            requires: 'panelbutton,floatpanel',
            init: function( editor ) {
                var label = "Table";

                editor.ui.add('TableButton', CKEDITOR.UI_PANELBUTTON, {
                    label: label,
                    title: label,
                    // use existing 'table' icon
                    icon: 'table',
                    modes: { wysiwyg: true },
                    editorFocus: true,
                    // panel opens in iframe, @css is CSS file <link>-ed within
                    // frame document, @attributes are set on iframe itself.
                    panel: {
                        css: '/website/static/src/css/editor.css',
                        attributes: { 'role': 'listbox', 'aria-label': label, },
                    },

                    onBlock: function (panel, block) {
                        block.autoSize = true;
                        block.element.setHtml(openerp.qweb.render('website.editor.table.panel', {
                            rows: 5,
                            cols: 5,
                        }));

                        var $table = $(block.element.$).on('mouseenter', 'td', function (e) {
                            var $e = $(e.target);
                            var y = $e.index() + 1;
                            var x = $e.closest('tr').index() + 1;

                            $table
                                .find('td').removeClass('selected').end()
                                .find('tr:lt(' + String(x) + ')')
                                .children().filter(function () { return $(this).index() < y; })
                                .addClass('selected');
                        }).on('click', 'td', function (e) {
                            var $e = $(e.target);

                            //noinspection JSPotentiallyInvalidConstructorUsage
                            var table = new CKEDITOR.dom.element(
                                $(openerp.qweb.render('website.editor.table', {
                                    rows: $e.closest('tr').index() + 1,
                                    cols: $e.index() + 1,
                                }))[0]);

                            editor.insertElement(table);
                            setTimeout(function () {
                                //noinspection JSPotentiallyInvalidConstructorUsage
                                var firstCell = new CKEDITOR.dom.element(table.$.rows[0].cells[0]);
                                var range = editor.createRange();
                                range.moveToPosition(firstCell, CKEDITOR.POSITION_AFTER_START);
                                range.select();
                            }, 0);
                        });

                        block.element.getDocument().getBody().setStyle('overflow', 'hidden');
                        CKEDITOR.ui.fire('ready', this);
                    },
                });
            }
        });

        CKEDITOR.plugins.add('linkstyle', {
            requires: 'panelbutton,floatpanel',
            init: function (editor) {
                var label = "Link Style";

                editor.ui.add('LinkStyle', CKEDITOR.UI_PANELBUTTON, {
                    label: label,
                    title: label,
                    icon: '/website/static/src/img/bglink.png',
                    modes: { wysiwyg: true },
                    editorFocus: true,
                    panel: {
                        css: '/website/static/lib/bootstrap/css/bootstrap.css',
                        attributes: { 'role': 'listbox', 'aria-label': label },
                    },

                    types: {
                        'btn-default': _t("Basic"),
                        'btn-primary': _t("Primary"),
                        'btn-success': _t("Success"),
                        'btn-info': _t("Info"),
                        'btn-warning': _t("Warning"),
                        'btn-danger': _t("Danger"),
                    },
                    sizes: {
                        'btn-xs': _t("Extra Small"),
                        'btn-sm': _t("Small"),
                        '': _t("Default"),
                        'btn-lg': _t("Large")
                    },

                    onRender: function () {
                        var self = this;
                        editor.on('selectionChange', function (e) {
                            var path = e.data.path, el;

                            if (!(e = path.contains('a')) || e.isReadOnly()) {
                                self.disable();
                                return;
                            }

                            self.enable();
                        });
                        // no hook where button is available, so wait
                        // "some time" after render.
                        setTimeout(function () {
                            self.disable();
                        }, 0)
                    },
                    enable: function () {
                        this.setState(CKEDITOR.TRISTATE_OFF);
                    },
                    disable: function () {
                        this.setState(CKEDITOR.TRISTATE_DISABLED);
                    },

                    onOpen: function () {
                        var link = get_selected_link(editor);
                        var id = this._.id;
                        var block = this._.panel._.panel._.blocks[id];
                        var $root = $(block.element.$);
                        $root.find('button').removeClass('active').removeProp('disabled');

                        // enable buttons matching link state
                        for (var type in this.types) {
                            if (!this.types.hasOwnProperty(type)) { continue; }
                            if (!link.hasClass(type)) { continue; }

                            $root.find('button[data-type=types].' + type)
                                 .addClass('active');
                        }
                        var found;
                        for (var size in this.sizes) {
                            if (!this.sizes.hasOwnProperty(size)) { continue; }
                            if (!size || !link.hasClass(size)) { continue; }
                            found = true;
                            $root.find('button[data-type=sizes].' + size)
                                 .addClass('active');
                        }
                        if (!found && link.hasClass('btn')) {
                            $root.find('button[data-type="sizes"][data-set-class=""]')
                                 .addClass('active');
                        }
                    },

                    onBlock: function (panel, block) {
                        var self = this;
                        block.autoSize = true;

                        var html = ['<div style="padding: 5px">'];
                        html.push('<div style="white-space: nowrap">');
                        _(this.types).each(function (label, key) {
                            html.push(_.str.sprintf(
                                '<button type="button" class="btn %s" ' +
                                        'data-type="types" data-set-class="%s">%s</button>',
                                key, key, label));
                        });
                        html.push('</div>');
                        html.push('<div style="white-space: nowrap; margin: 5px 0; text-align: center">');
                        _(this.sizes).each(function (label, key) {
                            html.push(_.str.sprintf(
                                '<button type="button" class="btn btn-default %s" ' +
                                        'data-type="sizes" data-set-class="%s">%s</button>',
                                key, key, label));
                        });
                        html.push('</div>');
                        html.push('<button type="button" class="btn btn-link btn-block" ' +
                                          'data-type="reset">Reset</button>');
                        html.push('</div>');

                        block.element.setHtml(html.join(' '));
                        var $panel = $(block.element.$);
                        $panel.on('click', 'button', function () {
                            self.clicked(this);
                        });
                    },
                    clicked: function (button) {
                        editor.focus();
                        editor.fire('saveSnapshot');

                        var $button = $(button),
                              $link = $(get_selected_link(editor).$);
                        if (!$link.hasClass('btn')) {
                            $link.addClass('btn btn-default');
                        }
                        switch($button.data('type')) {
                        case 'reset':
                            $link.removeClass('btn')
                                 .removeClass(_.keys(this.types).join(' '))
                                 .removeClass(_.keys(this.sizes).join(' '));
                            break;
                        case 'types':
                            $link.removeClass(_.keys(this.types).join(' '))
                                 .addClass($button.data('set-class'));
                            break;
                        case 'sizes':
                            $link.removeClass(_.keys(this.sizes).join(' '))
                                 .addClass($button.data('set-class'));
                        }
                        this._.panel.hide();

                        editor.fire('saveSnapshot');
                    },

                });
            }
        });

        CKEDITOR.plugins.add('oeref', {
            requires: 'widget',

            init: function (editor) {
                editor.widgets.add('oeref', {
                    editables: { text: '*' },

                    upcast: function (el) {
                        return el.attributes['data-oe-type']
                            && el.attributes['data-oe-type'] !== 'monetary';
                    },
                });
                editor.widgets.add('monetary', {
                    editables: { text: 'span.oe_currency_value' },

                    upcast: function (el) {
                        return el.attributes['data-oe-type'] === 'monetary';
                    }
                });
            }
        });

        var editor = new website.EditorBar();
        var $body = $(document.body);
        editor.prependTo($body).then(function () {
            if (location.search.indexOf("enable_editor") >= 0) {
                editor.edit();
            }
        });
        $body.css('padding-top', '50px'); // Not working properly: editor.$el.outerHeight());
    };
        /* ----- TOP EDITOR BAR FOR ADMIN ---- */
    website.EditorBar = openerp.Widget.extend({
        template: 'website.editorbar',
        events: {
            'click button[data-action=edit]': 'edit',
            'click button[data-action=save]': 'save',
            'click button[data-action=cancel]': 'cancel',
            'click a[data-action=new_page]': 'new_page',
        },
        container: 'body',
        customize_setup: function() {
            var self = this;
            var view_name = $(document.documentElement).data('view-xmlid');
            var menu = $('#customize-menu');
            this.$('#customize-menu-button').click(function(event) {
                menu.empty();
                openerp.jsonRpc('/website/customize_template_get', 'call', { 'xml_id': view_name }).then(
                    function(result) {
                        _.each(result, function (item) {
                            if (item.header) {
                                menu.append('<li class="dropdown-header">' + item.name + '</li>');
                            } else {
                                menu.append(_.str.sprintf('<li role="presentation"><a href="#" data-view-id="%s" role="menuitem"><strong class="fa fa%s-square-o"></strong> %s</a></li>',
                                    item.id, item.active ? '' : '-check', item.name));
                            }
                        });
{'fraction_non_alphanumeric': 0.128453733873745, 'fraction_numerical': 0.0024371506529974303, 'mean_word_length': 1.0117239541699974, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7580774', 'n_tokens_mistral': 9240, 'n_tokens_neox': 8548, 'n_words': 1595}