<commit_before>( function( $, Object, window, signals ) {
    "use strict";
    var _commands = { 
            testMode: false,
            useSignals: false
        },
        _defaultOptions = { 
            type: 'GET',  
            dataType: 'JSON', 
            mock: { wasSuccess: true }
        },
        _isFunction,
        _checkArg = {},
        _bindCommandToSignals,
        Command;

    _checkArg.required = function( obj, message ) {
        if( !obj ) {
            throw message;
        }
    };
    
    _checkArg.required( $, 'jQuery is required' );

    Command = function( key, options ) {
        var self = this;
        this.key = key;
        this.options = options;
        this.send = this.execute = function( data ) {
            if( data && !data.currentTarget ) {
                options.data = data;
            }
            if( !_commands.testMode ) {
                $.ajax( self.options ).success( self.success ).always( self.always ).error( self.error );    
            } else {
                if( self.options.mock.wasSuccess ) {
                    self.success( self.options.mock.responseData );
                } else {
                    self.error( self.options.mock.responseData );
                }
                self.always( self.options.responseData );
            }
        };
    };

    _commands.register = function( key, options ) {
        _checkArg.required( key, 'Please provide a key to register' );
        _checkArg.required( options, 'You must provide an options object with a URL property' );
        if( typeof options === 'string' ) {
            options = { url: options };
        }
        
        var command = new Command( key, $.extend( options, _defaultOptions ) );
        _commands[key] = command;
        if( _commands.useSignals ) { 
            _bindCommandToSignals( key, command );
        }
        return command;
    };

    Command.fn = Command.prototype;

    Command.fn.bind = function( selectors, events, func ) {
        var self = this,
            data = self.options.data;
        $( 'body' ).on( events, selectors, function( evt ) {
            evt.preventDefault();
            data = ( _isFunction( func ) ) ? func.apply(this, arguments) : data;<commit_msg>added general support in .bind for forms. If the selected el is a form, we will  serialize the form and auto set it as the data prop. We will also check for jQuery validation and stop the request if the form is not valid.<commit_after>( function( $, Object, window, signals ) {
    "use strict";
    var _commands = { 
            testMode: false,
            useSignals: false
        },
        _defaultOptions = { 
            type: 'GET',  
            dataType: 'JSON', 
            mock: { wasSuccess: true }
        },
        _isFunction,
        _checkArg = {},
        _bindCommandToSignals,
        Command;

    _checkArg.required = function( obj, message ) {
        if( !obj ) {
            throw message;
        }
    };
    
    _checkArg.required( $, 'jQuery is required' );

    Command = function( key, options ) {
        var self = this;
        this.key = key;
        this.options = options;
        this.send = this.execute = function( data ) {
            if( data && !data.currentTarget ) {
                options.data = data;
            }
            if( !_commands.testMode ) {
                $.ajax( self.options ).success( self.success ).always( self.always ).error( self.error );    
            } else {
                if( self.options.mock.wasSuccess ) {
                    self.success( self.options.mock.responseData );
                } else {
                    self.error( self.options.mock.responseData );
                }
                self.always( self.options.responseData );
            }
        };
    };

    _commands.register = function( key, options ) {
        _checkArg.required( key, 'Please provide a key to register' );
        _checkArg.required( options, 'You must provide an options object with a URL property' );
        if( typeof options === 'string' ) {
            options = { url: options };
        }
        
        var command = new Command( key, $.extend( options, _defaultOptions ) );
        _commands[key] = command;
        if( _commands.useSignals ) { 
            _bindCommandToSignals( key, command );
        }
        return command;
    };

    Command.fn = Command.prototype;

    Command.fn.bind = function( selectors, events, func ) {
        var self = this,
            data = self.options.data,
            $form,
            shouldProcess = true;
        $( 'body' ).on( events, selectors, function( evt ) {
            evt.preventDefault();
            
            //if the selected element is a form, wrap it with jQuery and set the $form variable
            if( this.action && this.method ) {
                $form = $( this );
            }
            //if the form is using jQuery validation, ensure the form is valid
            if( $form && $form.valid ) {
                shouldProcess = !$form.valid();
            }
            
            //if the form is not valid, we should return
            if( !shouldProcess ) return;

            //if the selected element is a form, serialize it and set to the Ajax requests data
            if( $form ) {
                data = $form.serialize();
            }

            data = ( _isFunction( func ) ) ? func.apply(this, arguments) : data;
{'fraction_non_alphanumeric': 0.10842047330764998, 'fraction_numerical': 0.0, 'mean_word_length': 1.5322805387830933, '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': '1311793', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1411, 'n_words': 415}