soyjavi 14 lat temu
rodzic
commit
97565b5120
1 zmienionych plików z 117 dodań i 23 usunięć
  1. 117 23
      src/lib/QuoJS.js

+ 117 - 23
src/lib/QuoJS.js

@@ -1,9 +1,8 @@
 /*
-    QuoJS 2.0.2
+    QuoJS 2.0.3
     http://quojs.tapquo.com
-    Copyright (C) 2011,2012 Javi Jiménez Villar (@soyjavi)
 
-    Generated by CoffeeScript 1.3.2
+    Copyright (C) 2011,2012 Javi Jiménez Villar (@soyjavi)
 
     Permission is hereby granted, free of charge, to any person obtaining a
     copy of this software and associated documentation files (the "Software"),
@@ -65,6 +64,14 @@
   "$$" in window || (window.$$ = Quo);
 
 }).call(this);
+// Generated by CoffeeScript 1.3.3
+
+/*
+  QuoJS 2.0
+  (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
+  http://quojs.tapquo.com
+*/
+
 
 (function() {
 
@@ -186,6 +193,14 @@
   })(Quo);
 
 }).call(this);
+// Generated by CoffeeScript 1.3.3
+
+/*
+  QuoJS 2.0
+  (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
+  http://quojs.tapquo.com
+*/
+
 
 (function() {
 
@@ -251,6 +266,14 @@
   })(Quo);
 
 }).call(this);
+// Generated by CoffeeScript 1.3.3
+
+/*
+  QuoJS 2.0
+  (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
+  http://quojs.tapquo.com
+*/
+
 
 (function() {
 
@@ -319,6 +342,13 @@
   })(Quo);
 
 }).call(this);
+// Generated by CoffeeScript 1.3.3
+
+/*
+  QuoJS 2.0
+  (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
+  http://quojs.tapquo.com
+*/
 
 
 (function() {
@@ -381,6 +411,13 @@
   })(Quo);
 
 }).call(this);
+// Generated by CoffeeScript 1.3.3
+
+/*
+  QuoJS 2.0
+  (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
+  http://quojs.tapquo.com
+*/
 
 
 (function() {
@@ -483,6 +520,14 @@
   })(Quo);
 
 }).call(this);
+// Generated by CoffeeScript 1.3.3
+
+/*
+  QuoJS 2.0
+  (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
+  http://quojs.tapquo.com
+*/
+
 
 (function() {
 
@@ -536,11 +581,19 @@
   })(Quo);
 
 }).call(this);
+// Generated by CoffeeScript 1.3.3
+
+/*
+  QuoJS 2.0.3
+  (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
+  http://quojs.tapquo.com
+*/
+
 
 (function() {
 
   (function($$) {
-    var DEFAULT, JSONP_ID, MIME_TYPES, _isJsonP, _parseResponse, _xhrError, _xhrHeaders, _xhrStatus, _xhrSuccess, _xhrTimeout;
+    var DEFAULT, JSONP_ID, MIME_TYPES, _isJsonP, _parseResponse, _xhrError, _xhrForm, _xhrHeaders, _xhrStatus, _xhrSuccess, _xhrTimeout;
     DEFAULT = {
       TYPE: "GET",
       MIME: "json"
@@ -570,6 +623,11 @@
     $$.ajax = function(options) {
       var abortTimeout, settings, xhr;
       settings = $$.mix($$.ajaxSettings, options);
+      if (settings.type === DEFAULT.TYPE) {
+        settings.url += $$.serializeParameters(settings.data, "?");
+      } else {
+        settings.data = $$.serializeParameters(settings.data);
+      }
       if (_isJsonP(settings.url)) {
         return $$.jsonp(settings);
       }
@@ -623,47 +681,49 @@
         }
         return xhr;
       } else {
-        return console.error("ERROR: Unable to make jsonp synchronous call.");
+        return console.error("QuoJS.ajax: Unable to make jsonp synchronous call.");
       }
     };
     $$.get = function(url, data, success, dataType) {
-      url += $$.serializeParameters(data);
       return $$.ajax({
         url: url,
+        data: data,
         success: success,
         dataType: dataType
       });
     };
     $$.post = function(url, data, success, dataType) {
-      return $$.ajax({
-        type: "POST",
-        url: url,
-        data: data,
-        success: success,
-        dataType: dataType,
-        contentType: "application/x-www-form-urlencoded"
-      });
+      return _xhrForm("POST", url, data, success, dataType);
+    };
+    $$.put = function(url, data, success, dataType) {
+      return _xhrForm("PUT", url, data, success, dataType);
+    };
+    $$["delete"] = function(url, data, success, dataType) {
+      return _xhrForm("DELETE", url, data, success, dataType);
     };
     $$.json = function(url, data, success) {
-      url += $$.serializeParameters(data);
       return $$.ajax({
         url: url,
+        data: data,
         success: success,
         dataType: DEFAULT.MIME
       });
     };
-    $$.serializeParameters = function(parameters) {
+    $$.serializeParameters = function(parameters, character) {
       var parameter, serialize;
-      serialize = "?";
+      if (character == null) {
+        character = "";
+      }
+      serialize = character;
       for (parameter in parameters) {
         if (parameters.hasOwnProperty(parameter)) {
-          if (serialize !== "?") {
+          if (serialize !== character) {
             serialize += "&";
           }
           serialize += parameter + "=" + parameters[parameter];
         }
       }
-      if (serialize === "?") {
+      if (serialize === character) {
         return "";
       } else {
         return serialize;
@@ -675,7 +735,7 @@
           _xhrSuccess(_parseResponse(xhr, settings), xhr, settings);
         }
       } else {
-        _xhrError("QuoJS » $$.ajax", xhr, settings);
+        _xhrError("QuoJS.ajax: Unsuccesful request", xhr, settings);
       }
     };
     _xhrSuccess = function(response, xhr, settings) {
@@ -699,7 +759,17 @@
     _xhrTimeout = function(xhr, settings) {
       xhr.onreadystatechange = {};
       xhr.abort();
-      _xhrError("QuoJS » $$.ajax : timeout exceeded", xhr, settings);
+      _xhrError("QuoJS.ajax: Timeout exceeded", xhr, settings);
+    };
+    _xhrForm = function(method, url, data, success, dataType) {
+      return $$.ajax({
+        type: method,
+        url: url,
+        data: data,
+        success: success,
+        dataType: dataType,
+        contentType: "application/x-www-form-urlencoded"
+      });
     };
     _parseResponse = function(xhr, settings) {
       var response;
@@ -710,7 +780,7 @@
             response = JSON.parse(response);
           } catch (error) {
             response = error;
-            _xhrError("Parse Error", xhr, settings);
+            _xhrError("QuoJS.ajax: Parse Error", xhr, settings);
           }
         } else {
           if (settings.dataType === "xml") {
@@ -726,6 +796,14 @@
   })(Quo);
 
 }).call(this);
+// Generated by CoffeeScript 1.3.3
+
+/*
+  QuoJS 2.0
+  (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
+  http://quojs.tapquo.com
+*/
+
 
 (function() {
 
@@ -770,6 +848,14 @@
   })(Quo);
 
 }).call(this);
+// Generated by CoffeeScript 1.3.3
+
+/*
+    QuoJS 2.0
+    (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
+    http://quojs.tapquo.com
+*/
+
 
 (function() {
 
@@ -934,6 +1020,14 @@
   })(Quo);
 
 }).call(this);
+// Generated by CoffeeScript 1.3.3
+
+/*
+  QuoJS 2.0
+  (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
+  http://quojs.tapquo.com
+*/
+
 
 (function() {
 
@@ -1064,4 +1158,4 @@
     };
   })(Quo);
 
-}).call(this);
+}).call(this);