<commit_before>/**
 * Create a JSONP request
 *
 * @param {String} url
 * @param {Object} options
 */

function ajaxJSONP(url, options) {
  var name = (name = /callback\=([A-Za-z0-9\-\.]+)/.exec(url)) ? name[1] : 'jsonp' + (+new Date())
    , elm = document.createElement('script');

  elm.onerror = function () {
    tire(elm).remove();
    try { delete window[name]; }
    catch (e) { window[name] = undefined; }
    if (tire.isFun(options.error)) options.error('abort');
  };
  
  window[name] = function (data) {
    tire(elm).remove();
    try { delete window[name]; }
    catch (e) { window[name] = undefined; }
    ajaxSuccess(data, null, options);
  };
  
  options.data = tire.param(options.data);
  elm.src = url.replace(/\=\?/, '=' + name);
  tire('head')[0].appendChild(elm);
}

/**
 * Ajax success. Check if the dataType is JSON and try to parse it or just return the response text/xml.
 *
 * @param {Object} data
 * @param {Object} xhr
 * @param {Object} options
 * @return {Object}
 */

function ajaxSuccess(data, xhr, options) {
  var res;
  if (xhr) {
    if ((options.dataType === 'json' || false) && (res = tire.parseJSON(xhr.responseText)) === null) res = xhr.responseText;
    if (options.dataType === 'xml') res = xhr.responseXML;
    res = res || xhr.responseText;
  }
  if (!res && data) res = data;
  if (tire.isFunction(options.success)) options.success(res);
}
        
tire.fn.extend({
  
  /**
   * Ajax method to create ajax request with XMLHTTPRequest (or ActiveXObject).
   * Supports JSONP, no cross domain yet.
   *
   * @param {String|Object} url
   * @param {Object|Function} options
   * @return {Object}
   */
  
  ajax: function (url, options) {
    options = options || {};
    
    if (tire.isObject(url)) {
      if (tire.isFunction(options)) {
        url.success = url.success || options;
      }
      options = url;
      url = options.url;
    }
    
    if (tire.isFunction(options)) options = { success: options };
    
    options.dataType = (options.dataType || '').toLowerCase();
        
    // won't do anything without a url
    if (!url) return;
    
    var self = this
      , method = (options.type || 'GET').toUpperCase()
      , params = options.data || null
      , jsonp = options.dataType === 'jsonp' || false
      , xhr
      , mime = { // support for script needed
          html: 'text/html',
          text: 'text/plain',
          xml: 'application/xml, text/xml',
          json: 'application/json'
      };
    
    if (window.XMLHttpRequest) {
      xhr = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // < IE 9
      xhr = new ActiveXObject('Microsoft.XMLHTTP');
    }
    
    for (var k in mime) {
      if (url.indexOf('.' + k) !== -1 && !options.dataType) options.dataType = k;
    }
    
    // test for jsonp
    if (jsonp || /\=\?|callback\=/.test(url)) {
      if (/\=\?/.test(url)) url = (url + '&callback=?').replace(/[&?]{1,2}/, '?');
      ajaxJSONP(url, options);
      return this;
    }
    
    if (xhr) {
      xhr.queryString = params;<commit_msg>JSONP callback fix<commit_after>/**
 * Create a JSONP request
 *
 * @param {String} url
 * @param {Object} options
 */

function ajaxJSONP(url, options) {
  var name = (name = /callback\=([A-Za-z0-9\-\.]+)/.exec(url)) ? name[1] : 'jsonp' + (+new Date())
    , elm = document.createElement('script');

  elm.onerror = function () {
    tire(elm).remove();
    try { delete window[name]; }
    catch (e) { window[name] = undefined; }
    if (tire.isFun(options.error)) options.error('abort');
  };
  
  window[name] = function (data) {
    tire(elm).remove();
    try { delete window[name]; }
    catch (e) { window[name] = undefined; }
    ajaxSuccess(data, null, options);
  };
  
  options.data = tire.param(options.data);
  elm.src = url.replace(/\=\?/, '=' + name);
  tire('head')[0].appendChild(elm);
}

/**
 * Ajax success. Check if the dataType is JSON and try to parse it or just return the response text/xml.
 *
 * @param {Object} data
 * @param {Object} xhr
 * @param {Object} options
 * @return {Object}
 */

function ajaxSuccess(data, xhr, options) {
  var res;
  if (xhr) {
    if ((options.dataType === 'json' || false) && (res = tire.parseJSON(xhr.responseText)) === null) res = xhr.responseText;
    if (options.dataType === 'xml') res = xhr.responseXML;
    res = res || xhr.responseText;
  }
  if (!res && data) res = data;
  if (tire.isFunction(options.success)) options.success(res);
}
        
tire.fn.extend({
  
  /**
   * Ajax method to create ajax request with XMLHTTPRequest (or ActiveXObject).
   * Supports JSONP, no cross domain yet.
   *
   * @param {String|Object} url
   * @param {Object|Function} options
   * @return {Object}
   */
  
  ajax: function (url, options) {
    options = options || {};
    
    if (tire.isObject(url)) {
      if (tire.isFunction(options)) {
        url.success = url.success || options;
      }
      options = url;
      url = options.url;
    }
    
    if (tire.isFunction(options)) options = { success: options };
    
    options.dataType = (options.dataType || '').toLowerCase();
        
    // won't do anything without a url
    if (!url) return;
    
    var self = this
      , method = (options.type || 'GET').toUpperCase()
      , params = options.data || null
      , jsonp = options.dataType === 'jsonp' || false
      , xhr
      , mime = { // support for script needed
          html: 'text/html',
          text: 'text/plain',
          xml: 'application/xml, text/xml',
          json: 'application/json'
      };
    
    if (window.XMLHttpRequest) {
      xhr = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // < IE 9
      xhr = new ActiveXObject('Microsoft.XMLHTTP');
    }
    
    for (var k in mime) {
      if (url.indexOf('.' + k) !== -1 && !options.dataType) options.dataType = k;
    }
    
    // test for jsonp
    if (jsonp || /\=\?|callback\=/.test(url)) {
      if (!/\=\?/.test(url)) url = (url + '&callback=?').replace(/[&?]{1,2}/, '?');
      ajaxJSONP(url, options);
      return this;
    }
    
    if (xhr) {
      xhr.queryString = params;
{'fraction_non_alphanumeric': 0.17582597317631665, 'fraction_numerical': 0.0026169447170428526, 'mean_word_length': 2.4764070494599206, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '6560230', 'n_tokens_mistral': 2088, 'n_tokens_neox': 2068, 'n_words': 503}