      1 (function(){
      2
      3   function addParamToUrl(url, param) {
      4     return url + (/\?/.test(url) ? '&' : '?') + param;
      5   }
      6
      7   var makeXHR = (function() {
      8     var factories = [
      9       function() { return new ActiveXObject("Microsoft.XMLHTTP"); },
     10       function() { return new ActiveXObject("Msxml2.XMLHTTP"); },
     11       function() { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); },
     12       function() { return new XMLHttpRequest(); }
     13     ];
     14     for (var i = factories.length; i--; ) {
     15       try {
     16         var req = factories[i]();
     17         if (req) {
     18           return factories[i];
     19         }
     20       }
     21       catch (err) { }
     22     }
     23   })();
     24
     25   function emptyFn() { };
     26
     27   function request(url, options) {
     28
     29     options || (options = { });
     30
     31     var method = options.method ? options.method.toUpperCase() : 'GET',
     32         onComplete = options.onComplete || function() { },
     33         request = makeXHR(),
     34         body;
     35
     36     /** @ignore */
     37     request.onreadystatechange = function() {
     38       if (request.readyState === 4) {
     39         onComplete(request);
     40         request.onreadystatechange = emptyFn;
     41       }
     42     };
     43
     44     if (method === 'GET') {
     45       body = null;
     46       if (typeof options.parameters == 'string') {
     47         url = addParamToUrl(url, options.parameters);
     48       }
     49     }
     50
     51     request.open(method, url, true);
     52
     53     if (method === 'POST' || method === 'PUT') {
     54       request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
     55     }
     56
     57     request.send(body);
     58     return request;
     59   };
     60
     61   fabric.util.request = request;
     62 })();