<commit_before>odoo.define('web_editor.wysiwyg.multizone', function (require) {
'use strict';
var concurrency = require('web.concurrency');
var core = require('web.core');
var DropzonePlugin = require('web_editor.wysiwyg.plugin.dropzone');
var HelperPlugin = require('web_editor.wysiwyg.plugin.helper');
var TextPlugin = require('web_editor.wysiwyg.plugin.text');
var HistoryPlugin = require('web_editor.wysiwyg.plugin.history');
var Wysiwyg = require('web_editor.wysiwyg.snippets');

var _t = core._t;

HistoryPlugin.include({
    /**
     * @override
     */
    applySnapshot: function () {
        this.trigger_up('content_will_be_destroyed', {
            $target: this.$editable,
        });
        this._super.apply(this, arguments);
        this.trigger_up('content_was_recreated', {
            $target: this.$editable,
        });
        $('.oe_overlay').remove();
        $('.note-control-selection').hide();
        this.$editable.trigger('content_changed');
    },
});

HelperPlugin.include({
    /**
     * Returns true if range is on or within a field that is not of type 'html'.
     *
     * @returns {Boolean}
     */
    isOnNonHTMLField: function () {
        var range = this.context.invoke('editor.createRange');
        return !!$.summernote.dom.ancestor(range.sc, function (node) {
            return $(node).data('oe-type') && $(node).data('oe-type') !== 'html';
        });
    },
});

TextPlugin.include({
    /**
     * Paste text only if on non-HTML field.
     *
     * @override
     */
    pasteNodes: function (nodes, textOnly) {
        textOnly = textOnly || this.context.invoke('HelperPlugin.isOnNonHTMLField');
        this._super.apply(this, [nodes, textOnly]);
    },
});

DropzonePlugin.include({
    /**
     * Prevent dropping images in non-HTML fields.
     *
     * @override
     */
    _canDropHere: function (dataTransfer) {
        if (this.context.invoke('HelperPlugin.isOnNonHTMLField') && dataTransfer.files.length) {
            return false;
        }
        return this._super();
    },
});



/**
 * HtmlEditor
 * Intended to edit HTML content. This widget uses the Wysiwyg editor
 * improved by odoo.
 *
 * class editable: o_editable
 * class non editable: o_not_editable
 *
 */
var WysiwygMultizone = Wysiwyg.extend({
    events: _.extend({}, Wysiwyg.prototype.events, {
        'keyup *': function (ev) {
            if ((ev.keyCode === 8 || ev.keyCode === 46)) {
                var $target = $(ev.target).closest('.o_editable');
                if (!$target.is(':has(*:not(p):not(br))') && !$target.text().match(/\S/)) {
                    $target.empty();
                }
            }
            if (ev.key.length === 1) {
                this._onChange();
            }
        },
        'click .note-editable': function (ev) {
            ev.preventDefault();
        },
        'submit .note-editable form .btn': function (ev) {
            ev.preventDefault(); // Disable form submition in editable mode
        },
        '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();
            }
        },
    }),
    custom_events: _.extend({}, Wysiwyg.prototype.custom_events, {
        activate_snippet:  '_onActivateSnippet',
        drop_images: '_onDropImages',
    }),
    /**
     * @override
     * @param {Object} options.context - the context to use for the saving rpc
     * @param {boolean} [options.withLang=false]
     *        false if the lang must be omitted in the context (saving "master"
     *        page element)
     */
    init: function (parent, options) {
        options = options || {};
        options.addDropSelector = ':o_editable';
        this.savingMutex = new concurrency.Mutex();
        this._super(parent, options);
    },
    /**
     * Prevent some default features for the editable area.
     *
     * @override
     */
    start: function () {
        var self = this;
        return this._super().then(function () {
            // Unload preserve
            var flag = false;
            window.onbeforeunload = function (event) {
                if (self.isDirty() && !flag) {
                    flag = true;
                    _.defer(function () {
                        flag = false;
                    });
                    return _t('Changes you made may not be saved.');
                }
            };
            // firefox & IE fix
            try {
                document.execCommand('enableObjectResizing', false, false);
                document.execCommand('enableInlineTableEditing', false, false);
                document.execCommand('2D-position', false, false);
            } catch (e) { /* */ }
            document.body.addEventListener('resizestart', function (evt) {
                evt.preventDefault();<commit_msg>[FIX] web_editor: speeder edition of field char on website_blog<commit_after>odoo.define('web_editor.wysiwyg.multizone', function (require) {
'use strict';
var concurrency = require('web.concurrency');
var core = require('web.core');
var DropzonePlugin = require('web_editor.wysiwyg.plugin.dropzone');
var HelperPlugin = require('web_editor.wysiwyg.plugin.helper');
var TextPlugin = require('web_editor.wysiwyg.plugin.text');
var HistoryPlugin = require('web_editor.wysiwyg.plugin.history');
var Wysiwyg = require('web_editor.wysiwyg.snippets');

var _t = core._t;

HistoryPlugin.include({
    /**
     * @override
     */
    applySnapshot: function () {
        this.trigger_up('content_will_be_destroyed', {
            $target: this.$editable,
        });
        this._super.apply(this, arguments);
        this.trigger_up('content_was_recreated', {
            $target: this.$editable,
        });
        $('.oe_overlay').remove();
        $('.note-control-selection').hide();
        this.$editable.trigger('content_changed');
    },
});

HelperPlugin.include({
    /**
     * Returns true if range is on or within a field that is not of type 'html'.
     *
     * @returns {Boolean}
     */
    isOnNonHTMLField: function () {
        var range = this.context.invoke('editor.createRange');
        return !!$.summernote.dom.ancestor(range.sc, function (node) {
            return $(node).data('oe-type') && $(node).data('oe-type') !== 'html';
        });
    },
});

TextPlugin.include({
    /**
     * Paste text only if on non-HTML field.
     *
     * @override
     */
    pasteNodes: function (nodes, textOnly) {
        textOnly = textOnly || this.context.invoke('HelperPlugin.isOnNonHTMLField');
        this._super.apply(this, [nodes, textOnly]);
    },
});

DropzonePlugin.include({
    /**
     * Prevent dropping images in non-HTML fields.
     *
     * @override
     */
    _canDropHere: function (dataTransfer) {
        if (this.context.invoke('HelperPlugin.isOnNonHTMLField') && dataTransfer.files.length) {
            return false;
        }
        return this._super();
    },
});



/**
 * HtmlEditor
 * Intended to edit HTML content. This widget uses the Wysiwyg editor
 * improved by odoo.
 *
 * class editable: o_editable
 * class non editable: o_not_editable
 *
 */
var WysiwygMultizone = Wysiwyg.extend({
    events: _.extend({}, Wysiwyg.prototype.events, {
        'keyup *': function (ev) {
            if ((ev.keyCode === 8 || ev.keyCode === 46)) {
                var $target = $(ev.target).closest('.o_editable');
                if (!$target.is(':has(*:not(p):not(br))') && !$target.text().match(/\S/)) {
                    $target.empty();
                }
            }
            if (ev.key.length === 1) {
                this._onChangeThrottled();
            }
        },
        'click .note-editable': function (ev) {
            ev.preventDefault();
        },
        'submit .note-editable form .btn': function (ev) {
            ev.preventDefault(); // Disable form submition in editable mode
        },
        '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();
            }
        },
    }),
    custom_events: _.extend({}, Wysiwyg.prototype.custom_events, {
        activate_snippet:  '_onActivateSnippet',
        drop_images: '_onDropImages',
    }),
    /**
     * @override
     * @param {Object} options.context - the context to use for the saving rpc
     * @param {boolean} [options.withLang=false]
     *        false if the lang must be omitted in the context (saving "master"
     *        page element)
     */
    init: function (parent, options) {
        options = options || {};
        options.addDropSelector = ':o_editable';
        this.savingMutex = new concurrency.Mutex();
        this._super(parent, options);
        this._onChangeThrottled = _.throttle(this._onChange.bind(this), 300);
    },
    /**
     * Prevent some default features for the editable area.
     *
     * @override
     */
    start: function () {
        var self = this;
        return this._super().then(function () {
            // Unload preserve
            var flag = false;
            window.onbeforeunload = function (event) {
                if (self.isDirty() && !flag) {
                    flag = true;
                    _.defer(function () {
                        flag = false;
                    });
                    return _t('Changes you made may not be saved.');
                }
            };
            // firefox & IE fix
            try {
                document.execCommand('enableObjectResizing', false, false);
                document.execCommand('enableInlineTableEditing', false, false);
                document.execCommand('2D-position', false, false);
            } catch (e) { /* */ }
            document.body.addEventListener('resizestart', function (evt) {
                evt.preventDefault();
{'fraction_non_alphanumeric': 0.14122695796352286, 'fraction_numerical': 0.0012679215839266557, 'mean_word_length': 2.0238867590681213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '527764', 'n_tokens_mistral': 2953, 'n_tokens_neox': 2904, 'n_words': 618}