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

    $.widget( "ui.remark_widget", {
        _init: function() {
            this.init();
        },

        init: function() {

            var me = this,
                widgetElement = $(me.element);

                me.widgetElement = widgetElement;

                widgetElement.on('click', '.remark-cancel', function() {
                    var editing = me.widgetElement.data('editing');
                    $.proxy(me.switchToView(), me);
                    return false;
                });

                widgetElement.on('click', '.remark-edit', function() {
                    var editing = me.widgetElement.data('editing');
                    $.proxy(me.switchToEdit(), me);
                    return false;
                });

                widgetElement.on('click', '.remark-save', function() {
                    $.proxy(me.save(), me);
                    return false;
                });

                widgetElement.on('click', '.remark-delete', function() {
                    $.proxy(me.delete(), me);
                    return false;
                });

        },

        switchToEdit: function() {

            var me = this,
                remark_id = me.widgetElement.data('remarkid'),
                id = me.widgetElement.data('id'),
                unique = me.widgetElement.data('unique');

            me.widgetElement.data('editing', 1);

            z_event('render_remark_'+unique, {'editing':1, 'remark_id': remark_id, 'id': id});

            return false;

        },

        switchToView: function() {

            var me = this,
                remark_id = me.widgetElement.data('remarkid'),
                id = me.widgetElement.data('id'),
                unique = me.widgetElement.data('unique');

            me.widgetElement.data('editing', '0');

            z_event('render_remark_' + unique, {'editing':0, 'remark_id': remark_id, 'id': id });

            return false;

        },

        setValues(remark_id) {

            var me = this;

            if (remark_id) {
                me.widgetElement.data('remarkid', remark_id);
            }

        },

        save: function() {

            var me = this,
                form = me.widgetElement.find('#rscform'),
                tinyname = form.data('tinyname'),
                contentText = tinymce.get(tinyname).getContent({'format':'text'}).trim(),
                title = $('input#title'),
                valid = true,
                re = /[a-z A-Z 0-1]+/i;

            $('.mce-tinymce').removeClass('is-error');
            title.closest('p').removeClass('is-error');

            if (!contentText || contentText == "") {
                $('.mce-tinymce').addClass('is-error');
                valid = false;
            }

            if (!re.test(title.val())) {
                title.closest('p').addClass('is-error');
                valid = false;
            }

            if (valid) {
                $('.remark-save').hide();
                $('.remark-cancel').hide();
                $(form).submit();
                return false;
            }

            return false;
        },

        afterSave: function() {

            var me = this;
            me.switchToView();
        },

        delete: function() {

            var me = this,
                remark_id = me.widgetElement.data('remarkid');<commit_msg>changed validation for remark field<commit_after>(function ($) {
   'use strict';

    $.widget( "ui.remark_widget", {
        _init: function() {
            this.init();
        },

        init: function() {

            var me = this,
                widgetElement = $(me.element);

                me.widgetElement = widgetElement;

                widgetElement.on('click', '.remark-cancel', function() {
                    var editing = me.widgetElement.data('editing');
                    $.proxy(me.switchToView(), me);
                    return false;
                });

                widgetElement.on('click', '.remark-edit', function() {
                    var editing = me.widgetElement.data('editing');
                    $.proxy(me.switchToEdit(), me);
                    return false;
                });

                widgetElement.on('click', '.remark-save', function() {
                    $.proxy(me.save(), me);
                    return false;
                });

                widgetElement.on('click', '.remark-delete', function() {
                    $.proxy(me.delete(), me);
                    return false;
                });

        },

        switchToEdit: function() {

            var me = this,
                remark_id = me.widgetElement.data('remarkid'),
                id = me.widgetElement.data('id'),
                unique = me.widgetElement.data('unique');

            me.widgetElement.data('editing', 1);

            z_event('render_remark_'+unique, {'editing':1, 'remark_id': remark_id, 'id': id});

            return false;

        },

        switchToView: function() {

            var me = this,
                remark_id = me.widgetElement.data('remarkid'),
                id = me.widgetElement.data('id'),
                unique = me.widgetElement.data('unique');

            me.widgetElement.data('editing', '0');

            z_event('render_remark_' + unique, {'editing':0, 'remark_id': remark_id, 'id': id });

            return false;

        },

        setValues(remark_id) {

            var me = this;

            if (remark_id) {
                me.widgetElement.data('remarkid', remark_id);
            }

        },

        save: function() {

            var me = this,
                form = me.widgetElement.find('#rscform'),
                tinyname = form.data('tinyname'),
                contentText = tinymce.get(tinyname).getContent({'format':'text'}).trim(),
                title = $('input#title'),
                valid = true,
                re = /[a-z A-Z 0-1]+/i;

            var rawContent = tinymce.get(tinyname).getContent({'format':'raw'});

            rawContent = rawContent.replace(/<img([^>])*>/gi, 'img').trim();
            rawContent = $(rawContent).text();

            $('.mce-tinymce').removeClass('is-error');
            title.closest('p').removeClass('is-error');

            if (!rawContent || rawContent == "") {
                $('.mce-tinymce').addClass('is-error');
                valid = false;
            }

            if (!re.test(title.val())) {
                title.closest('p').addClass('is-error');
                valid = false;
            }

            if (valid) {
                $('.remark-save').hide();
                $('.remark-cancel').hide();
                $(form).submit();
                return false;
            }

            return false;
        },

        afterSave: function() {

            var me = this;
            me.switchToView();
        },

        delete: function() {

            var me = this,
                remark_id = me.widgetElement.data('remarkid');
{'fraction_non_alphanumeric': 0.15087122821929452, 'fraction_numerical': 0.0016999575010624734, 'mean_word_length': 1.3200788695366414, 'pattern_counts': {'":': 0, '<': 4, '<?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': '2973605', 'n_tokens_mistral': 1940, 'n_tokens_neox': 1778, 'n_words': 323}