gtkhotkey-0.2.1-patched.tgz
[gitlive] / XMLHttpRequest.js
index 1f46ad2..381b759 100644 (file)
@@ -42,7 +42,7 @@ XMLHttpRequest.prototype = {
     _async   : false,
     
     // request
-     open : function ( method,  url, async, user, password)
+    open : function ( method,  url, async, user, password)
     {
         async = async || false;
         user = user || false;
@@ -87,6 +87,12 @@ XMLHttpRequest.prototype = {
     send  : function(data)
     {
         data = data|| false;
+        
+        if (typeof(data) == 'object') {
+            // params..
+            data = this.urlEncode(data);
+        }
+        
         if (data) {
             this._message.set_request('application/x-www-form-urlencoded', Soup.MemoryUse.COPY, data, data.length)
         }
@@ -97,6 +103,8 @@ XMLHttpRequest.prototype = {
                 
                 //print("got queue callback");
                 //_t._session.unpause_message(this._message);
+                //print("queue message");
+                //print(_t._message.response_body.data)
                 _t.responseText = _t._message.response_body.data;
                 _t.status = 4;
             
@@ -139,7 +147,31 @@ XMLHttpRequest.prototype = {
     getAllResponseHeaders : function ()
     {
         
-    }
-   
+    },
+    urlEncode : function(o){
+        if(!o){
+            return "";
+        }
+        var buf = [];
+        for(var key in o){
+            var ov = o[key], k = encodeURIComponent(key);
+            var type = typeof ov;
+            if(type == 'undefined'){
+                buf.push(k, "=&");
+            }else if(type != "function" && type != "object"){
+                buf.push(k, "=", encodeURIComponent(ov), "&");
+            }else if(ov instanceof Array){
+                if (ov.length) {
+                    for(var i = 0, len = ov.length; i < len; i++) {
+                        buf.push(k, "=", encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&");
+                    }
+                } else {
+                    buf.push(k, "=&");
+                }
+            }
+        }
+        buf.pop();
+        return buf.join("");
+    },
     
 };