<commit_before>/**
 * Imcms Events addon, has no dependencies and is cross-browser
 * Event can be fired in one place and catch in other
 *
 * @author <NAME> from Ubrainians for imCode
 */
Imcms.Events = {
    /**
     * All events
     */
    all: [],

    /**
     * Fires event by name
     * @param name event's name
     */
    fire: function (name) {
        var callback = Imcms.Events.getCallback(name);
        if (callback) {
            callback.call();
        }
    },

    /**
     * Set handler on event by name
     * @param name event's name
     * @param callback function that will be called when event fires
     */
    on: function (name, callback) {
        var data = {}; // data object can be added in future and use in callback as 1st_arg.data
        Imcms.Events.all.push({
            name: name,
            data: data,
            callback: callback
        })
    },

    /**
     * Returns callback of event if such exists
     * @param name event's name
     * @returns {*|callback|null}
     */
    getCallback: function (name) {
        var event = Imcms.Events.all.find(function (event) {
            return event.name == name;
        });

        if (event && event.callback) {
            return event.callback;
        }
    },

    /**
     * Returns callback of event if such exists or specified function
     * @param name event's name
     * @param orFunc - function that will be returned if there are no any handler for event
     */
    getCallbackOr: function (name, orFunc) {
        var callback = Imcms.Events.getCallback(name);

        return (callback) ? callback : orFunc;
    }
};
<commit_msg>IMCMS-150 - Rewrite js hell in imCMS and use AMD mechanism: - Events module refactored.<commit_after>(function (Imcms) {
    /**
     * Imcms Events addon, has no dependencies and is cross-browser
     * Event can be fired in one place and catch in other
     *
     * @author <NAME> from Ubrainians for imCode
     */
    return Imcms.Events = {
        /**
         * All events
         */
        events: [],

        /**
         * Fires event by name
         * @param name event's name
         */
        fire: function (name) {
            var callback = Imcms.Events.getCallback(name);
            if (callback) {
                callback.call();
            }
        },

        /**
         * Set handler on event by name
         * @param name event's name
         * @param callback function that will be called when event fires
         */
        on: function (name, callback) {
            var data = {}; // data object can be added in future and use in callback as 1st_arg.data
            Imcms.Events.events.push({
                name: name,
                data: data,
                callback: callback
            })
        },

        /**
         * Returns callback of event if such exists
         * @param name event's name
         * @returns {*|callback|null}
         */
        getCallback: function (name) {
            var event = Imcms.Events.events.find(function (event) {
                return event.name == name;
            });

            if (event && event.callback) {
                return event.callback;
            }
        },

        /**
         * Returns callback of event if such exists or specified function
         * @param name event's name
         * @param orFunc - function that will be returned if there are no any handler for event
         */
        getCallbackOr: function (name, orFunc) {
            var callback = Imcms.Events.getCallback(name);

            return (callback) ? callback : orFunc;
        }
    };
})(Imcms);

{'fraction_non_alphanumeric': 0.09876543209876543, 'fraction_numerical': 0.0013717421124828531, 'mean_word_length': 1.6154949784791965, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5205801', 'n_tokens_mistral': 996, 'n_tokens_neox': 945, 'n_words': 339}