[483] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
---|
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> |
---|
| 3 | <html> |
---|
| 4 | <head> |
---|
| 5 | <title>Testing dojo.io.script</title> |
---|
| 6 | <style type="text/css"> |
---|
| 7 | @import "../../resources/dojo.css"; |
---|
| 8 | </style> |
---|
| 9 | <script type="text/javascript" src="../../dojo.js" data-dojo-config="isDebug:true"></script> |
---|
| 10 | <script type="text/javascript"> |
---|
| 11 | require(["dojo", "doh", "dojo/io/script"], function(dojo, doh){ |
---|
| 12 | doh.register("t", [ |
---|
| 13 | function ioScriptLoad(t){ |
---|
| 14 | //t.is("undefined", typeof(scriptLoad)); |
---|
| 15 | var d = new doh.Deferred(); |
---|
| 16 | var td = dojo.io.script.get({ |
---|
| 17 | url: "scriptLoad.js" |
---|
| 18 | }); |
---|
| 19 | td.addBoth(function(res){ |
---|
| 20 | if(typeof(scriptLoad) != "undefined" |
---|
| 21 | && t.is("loaded", scriptLoad)){ |
---|
| 22 | d.callback(true); |
---|
| 23 | }else{ |
---|
| 24 | d.errback(false); |
---|
| 25 | } |
---|
| 26 | }); |
---|
| 27 | return d; |
---|
| 28 | }, |
---|
| 29 | function ioScriptSimple(t){ |
---|
| 30 | var d = new doh.Deferred(); |
---|
| 31 | var td = dojo.io.script.get({ |
---|
| 32 | url: "scriptSimple.js", |
---|
| 33 | checkString: "myTasks" |
---|
| 34 | }); |
---|
| 35 | td.addBoth(function(res){ |
---|
| 36 | if(typeof(myTasks) != "undefined" |
---|
| 37 | && t.is("Do dishes.", myTasks[1])){ |
---|
| 38 | d.callback(true); |
---|
| 39 | }else{ |
---|
| 40 | d.errback(false); |
---|
| 41 | } |
---|
| 42 | }); |
---|
| 43 | return d; |
---|
| 44 | }, |
---|
| 45 | function ioScriptJsonp(t){ |
---|
| 46 | var d = new doh.Deferred(); |
---|
| 47 | var td = dojo.io.script.get({ |
---|
| 48 | url: "scriptJsonp.js", |
---|
| 49 | content: { foo: "bar" }, |
---|
| 50 | jsonp: "callback" |
---|
| 51 | }); |
---|
| 52 | td.addBoth(function(res){ |
---|
| 53 | if(!(res instanceof Error) && |
---|
| 54 | t.is("mammal", res.animalType)){ |
---|
| 55 | d.callback(true); |
---|
| 56 | }else{ |
---|
| 57 | d.errback(false); |
---|
| 58 | } |
---|
| 59 | }); |
---|
| 60 | return d; |
---|
| 61 | }, |
---|
| 62 | function ioScriptJsonpTimeout(t){ |
---|
| 63 | var d = new doh.Deferred(); |
---|
| 64 | var td = dojo.io.script.get({ |
---|
| 65 | url: "../_base/timeout.php", |
---|
| 66 | callbackParamName: "callback", |
---|
| 67 | content: {Foo: 'Bar'}, |
---|
| 68 | timeout: 500, |
---|
| 69 | handleAs: "json", |
---|
| 70 | preventCache: true, |
---|
| 71 | handle: function(response, ioArgs){ |
---|
| 72 | if(response instanceof Error && response.dojoType == "timeout"){ |
---|
| 73 | console.debug("FOO OK TEST"); |
---|
| 74 | d.callback(true); |
---|
| 75 | }else{ |
---|
| 76 | console.debug("FOO FAIL TEST"); |
---|
| 77 | d.errback(false); |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | }); |
---|
| 81 | return d; |
---|
| 82 | } |
---|
| 83 | ]); |
---|
| 84 | doh.runOnLoad(); |
---|
| 85 | /* |
---|
| 86 | // for watching in the debugger... |
---|
| 87 | dojo.addOnLoad(function(){ |
---|
| 88 | td = dojo.io.script.get({ |
---|
| 89 | url: "scriptSimple.js", |
---|
| 90 | checkString: "myTasks" |
---|
| 91 | }); |
---|
| 92 | td.addCallback(function(res){ |
---|
| 93 | alert(myTasks); |
---|
| 94 | alert(myTasks[1]); |
---|
| 95 | if(typeof(myTasks) != "undefined" |
---|
| 96 | && "Do dishes." == myTasks[1]){ |
---|
| 97 | alert("yeah"); |
---|
| 98 | }else{ |
---|
| 99 | alert("boo"); |
---|
| 100 | } |
---|
| 101 | }); |
---|
| 102 | }); |
---|
| 103 | */ |
---|
| 104 | }); |
---|
| 105 | </script> |
---|
| 106 | </head> |
---|
| 107 | <body> |
---|
| 108 | <h1>dojo.io.script test</h1> |
---|
| 109 | </body> |
---|
| 110 | </html> |
---|