Show
Ignore:
Timestamp:
12/07/07 13:12:07 (13 months ago)
Author:
cho45
Message:

lang/javascript/jsdeferred/trunk/Rakefile,
lang/javascript/jsdeferred/trunk/jsdeferred.mini.js,
lang/javascript/jsdeferred/trunk/jsdeferred.jquery.js,
lang/javascript/jsdeferred/trunk/jsdeferred.js,
lang/javascript/jsdeferred/trunk/jsdeferred.nodoc.js,
lang/javascript/jsdeferred/trunk/binding/userscript.js,
lang/javascript/jsdeferred/trunk/jsdeferred.userscript.js:

define() が Deferred をかえすように。
userscript 用に http のユーティリティを追加

Location:
lang/javascript/jsdeferred/trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/jsdeferred/trunk/Rakefile

    r2760 r2761  
    9090file "jsdeferred.userscript.js" => ["jsdeferred.js", "binding/userscript.js"] do |t| 
    9191        File.open(t.name, "w") {|f| 
    92                 f.puts "// Usage:: D().define();" 
     92                f.puts "// Usage:: var Deferred = D().define();" 
    9393                f << File.read("binding/userscript.js").sub("/*include JSDeferred*/", mini(File.read("jsdeferred.js"), true)) 
    9494        } 
  • lang/javascript/jsdeferred/trunk/binding/userscript.js

    r2759 r2761  
     1/* function xhttp (opts) //=> Deferred 
     2 * Cross site version of `http`. 
     3 */ 
     4/* function xhttp.get (url) //=> Deferred 
     5 */ 
     6/* function xhttp.post (url, data) //=> Deferred 
     7 */ 
     8function xhttp (opts) { 
     9        var d = Deferred(); 
     10        if (opts.onload)  d = d.next(opts.onload); 
     11        if (opts.onerror) d = d.error(opts.onerror); 
     12        opts.onload = function (res) { 
     13                d.call(res); 
     14        }; 
     15        opts.onerror = function (res) { 
     16                d.fail(res); 
     17        }; 
     18        GM_xmlhttpRequest(opts); 
     19        return d; 
     20} 
     21xhttp.get  = function (url)       { return xhttp({method:"get", url:url}) } 
     22xhttp.post = function (url, data) { return xhttp({method:"post", url:url, data:data}) } 
     23 
     24/* function http (opts) //=> Deferred 
     25 * Sample: 
     26 *     http.get("http://example.com/hogehoge") 
     27 *     .next(function (a) { 
     28 *         log(a.responseText); 
     29 *     }) 
     30 *     .error(function (e) { 
     31 *         log("error", e); 
     32 *     }); 
     33 */ 
     34/* function http.get (url) //=> Deferred 
     35 */ 
     36/* function http.post (url, data) //=> Deferred 
     37 */ 
     38function http (opts) { 
     39        var d = Deferred(); 
     40        var req = new XMLHttpRequest(); 
     41        req.open(opts.method, opts.url, true); 
     42        req.onreadystatechange = function () { 
     43                if (req.readyState == 4) d.call(req); 
     44        }; 
     45        req.send(opts.data || null); 
     46        return d; 
     47} 
     48http.get  = function (url)       { return http({method:"get", url:url}) } 
     49http.post = function (url, data) { return http({method:"post", url:url, data:data}) } 
     50 
    151function D () { 
    252 
  • lang/javascript/jsdeferred/trunk/jsdeferred.jquery.js

    r2651 r2761  
    6969if(!list)list=["parallel","wait","next","call","loop"];if(!obj)obj=(function(){return this})();for(var i=0;i<list.length;i++){ 
    7070var n=list[i];obj[n]=Deferred[n];} 
    71 };(function($){ 
     71return Deferred;};(function($){ 
    7272$.deferred=Deferred;$.each(["get","getJSON","post"],function(n,i){ 
    7373var orig=$[i];$[i]=function(url,data,callback){ 
  • lang/javascript/jsdeferred/trunk/jsdeferred.js

    r2691 r2761  
    340340                obj[n] = Deferred[n]; 
    341341        } 
    342 }; 
    343  
     342        return Deferred; 
     343}; 
     344 
  • lang/javascript/jsdeferred/trunk/jsdeferred.mini.js

    r2647 r2761  
    6969if(!list)list=["parallel","wait","next","call","loop"];if(!obj)obj=(function(){return this})();for(var i=0;i<list.length;i++){ 
    7070var n=list[i];obj[n]=Deferred[n];} 
    71 }; 
     71return Deferred;}; 
  • lang/javascript/jsdeferred/trunk/jsdeferred.nodoc.js

    r2659 r2761  
    156156                obj[n] = Deferred[n]; 
    157157        } 
     158        return Deferred; 
    158159}; 
  • lang/javascript/jsdeferred/trunk/jsdeferred.userscript.js

    r2760 r2761  
    1 // Usage:: D().define(); 
     1// Usage:: var Deferred = D().define(); 
     2/* function xhttp (opts) //=> Deferred 
     3 * Cross site version of `http`. 
     4 */ 
     5/* function xhttp.get (url) //=> Deferred 
     6 */ 
     7/* function xhttp.post (url, data) //=> Deferred 
     8 */ 
     9function xhttp (opts) { 
     10        var d = Deferred(); 
     11        if (opts.onload)  d = d.next(opts.onload); 
     12        if (opts.onerror) d = d.error(opts.onerror); 
     13        opts.onload = function (res) { 
     14                d.call(res); 
     15        }; 
     16        opts.onerror = function (res) { 
     17                d.fail(res); 
     18        }; 
     19        GM_xmlhttpRequest(opts); 
     20        return d; 
     21} 
     22xhttp.get  = function (url)       { return xhttp({method:"get", url:url}) } 
     23xhttp.post = function (url, data) { return xhttp({method:"post", url:url, data:data}) } 
     24 
     25/* function http (opts) //=> Deferred 
     26 * Sample: 
     27 *     http.get("http://example.com/hogehoge") 
     28 *     .next(function (a) { 
     29 *         log(a.responseText); 
     30 *     }) 
     31 *     .error(function (e) { 
     32 *         log("error", e); 
     33 *     }); 
     34 */ 
     35/* function http.get (url) //=> Deferred 
     36 */ 
     37/* function http.post (url, data) //=> Deferred 
     38 */ 
     39function http (opts) { 
     40        var d = Deferred(); 
     41        var req = new XMLHttpRequest(); 
     42        req.open(opts.method, opts.url, true); 
     43        req.onreadystatechange = function () { 
     44                if (req.readyState == 4) d.call(req); 
     45        }; 
     46        req.send(opts.data || null); 
     47        return d; 
     48} 
     49http.get  = function (url)       { return http({method:"get", url:url}) } 
     50http.post = function (url, data) { return http({method:"post", url:url, data:data}) } 
     51 
    252function D () { 
    353 
     
    159209                obj[n] = Deferred[n]; 
    160210        } 
     211        return Deferred; 
    161212}; 
    162213