<commit_before>// XXX: this could/should be merged with form-state and ajax be an
// option of form-state
define([
    "jquery",
    "../registry",
    "../lib/ajax"
], function($, registry, ajax) {
    var _ = {
        name: "ajax",
        trigger: "form.pat-ajax",
        init: function($el, opts) {
            // process matches single-file
            if ($el.length > 1)
                return $el.each(function() { _.init($(this), opts); });

            // remember initial state of the form and after
            // successfull submission
            _.saveState.call($el);
            $el.on('pat-ajax-success', _.saveState);

            // setup listeners for form to be handled via ajax
            $el.on('submit.pat-ajax', _.submit);

            // enable chaining
            return $el;
        },
        saveState: function() {
            var $el = $(this);
            $el.data('pat-ajax.previous-state', $el.data('pat-ajax.state'));
            $el.data('pat-ajax.state', $el.serializeArray());
        },
        submit: function(event) {
            if (event)
                event.preventDefault();
            ajax($(this));
        }
    };

    registry.register(_);
    return _;
});<commit_msg>ajax pattern is handling forms<commit_after>// XXX: this could/should be merged with form-state and ajax be an
// option of form-state
define([
    "jquery",
    "../registry",
    "../lib/ajax"
], function($, registry, ajax) {
    var _ = {
        name: "ajax",
        trigger: "form.pat-ajax",
        init: function($form, opts) {
            // process matches single-file
            if ($form.length > 1)
                return $form.each(function() { _.init($(this), opts); });

            // remember initial state of the form and after
            // successfull submission
            _.saveState.call($form);
            $form.on('pat-ajax-success', _.saveState);

            // setup listeners for form to be handled via ajax
            $form.on('submit.pat-ajax', _.submit);

            // enable chaining
            return $form;
        },
        saveState: function() {
            var $form = $(this);
            $form.data('pat-ajax.previous-state', $form.data('pat-ajax.state'));
            $form.data('pat-ajax.state', $form.serializeArray());
        },
        submit: function(event) {
            if (event)
                event.preventDefault();
            ajax($(this));
        }
    };

    registry.register(_);
    return _;
});
{'fraction_non_alphanumeric': 0.15286114445778312, 'fraction_numerical': 0.0008003201280512205, 'mean_word_length': 1.6511134676564156, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6303808', 'n_tokens_mistral': 697, 'n_tokens_neox': 680, 'n_words': 174}