<commit_before>(function (Shrike, encodeURIComponent) {

function addReadyStateChange(request, successHandlers, errorHandlers, elem) {
    request.onreadystatechange = function () {
        if (request.readyState != 4)
            return;
        var i, l, result;
        if (request.status == 200) {
            if (successHandlers.length == 0)
                elem.innerHTML = request.responseText;
            for (i = 0, l = successHandlers.length; i < l; ++i) {
                result = successHandlers[i](request, elem);
                if (typeof result == 'string' && elem) {
                    if (i == 0)
                        elem.innerHTML = '';
                    elem.innerHTML += result;
                }
            }
        }
        else {
            for (i = 0, l = errorHandlers.length; i < l; ++i)
                errorHandlers[i](request, elem);
        }
    };
}

Shrike.toQueryString = function toQueryString(obj, base) {
    var str = [], i, v;
    for (i in obj) {
        if (obj.hasOwnProperty(i)) {
            v = obj[i];
            if (base)
                i = base + '[' + i + ']';
            if (typeof v == 'object')
                str.push(toQueryString(v, i));
            else
                str.push(i + '=' + encodeURIComponent(v));
        }
    }
    return str.join('&');
};

Shrike.ajax = function (selectors, props) {
    var successHandlers = [], errorHandlers = [], options = {},
    ajax = {
        'url': function (_, url) {
            options.url = url;
        },
        
        'success': function (_, handler) {
            successHandlers.push(handler);
        },
        
        'error': function (_, handler) {
            errorHandlers.push(handler);
        },
        
        'get': function (elem, data) {
            var request = new XMLHttpRequest(); // I don't support IE 6 :-)
            request.open('GET', options.url + '?' + (typeof data == 'string' ? data :
                Shrike.toQueryString(data)), true);
            addReadyStateChange(request, successHandlers, errorHandlers, elem);
            request.send(null);
        },
    
        'post': function (elem, data) {
            var request = new XMLHttpRequest();
            request.open('POST', options.url, true);
            request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            addReadyStateChange(request, successHandlers, errorHandlers, elem);
            request.send(typeof data == 'string' ? data : Shrike.toQueryString(data));
        }
    };
    return Shrike.declaration(ajax, function () { })(selectors, props);
};

})(Shrike, encodeURIComponent);<commit_msg>rewrite the ajax module to something more normal<commit_after>(function (Shrike, XMLHttpRequest, encodeURIComponent, undefined) {

Shrike.toQueryString = function toQueryString(obj, base) {
    var str = [];
    Shrike.each(obj, function (val, key) {
        if (base)
            key = base + '[' + key + ']';
        if (typeof val == 'object')
            str.push(toQueryString(val, key));
        else
            str.push(key + '=' + encodeURIComponent(val));
    });
    return str.join('&');
};

Shrike.ajax = function (options) {
    var request = new XMLHttpRequest(), // I don't support IE 6 :)
    method = options.method ? options.method.toUpperCase() : 'GET',
    headers = options.headers || {},
    data = options.data || '',
    url = options.url + (options.method == 'GET' ? '?' + (
        typeof data == 'string' ? data : Shrike.toQueryString(data)
    ) : ''),
    success = typeof options.success == 'function' ? [options.success] : options.success || [],
    error = typeof options.error == 'function' ? [options.error] : options.error || [];
    if (method == 'POST' && !headers['Content-type'])
        headers['Content-type'] = 'application/x-www-form-urlencoded';
    request.open(method, url, true);
    Shrike.each(headers, function (value, header) {
        request.setRequestHeader(header, value);
    });
    request.onreadystatechange = function () {
        if (request.readyState != 4)
            return;
        Shrike.each(request.status == 200 ? success : error, function (callback) {
            callback(request);
        });
    };
    request.send(method == 'GET' ? undefined : typeof data == 'string' ? Shrike.toQueryString(data) : data)
    return request;
};

})(Shrike, XMLHttpRequest, encodeURIComponent);
{'fraction_non_alphanumeric': 0.14832427536231885, 'fraction_numerical': 0.003170289855072464, 'mean_word_length': 2.093137254901961, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '854979', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1257, 'n_words': 287}