source: Dev/trunk/src/client/dojo/tests/io/scriptJsonp.js @ 485

Last change on this file since 485 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 1.3 KB
Line 
1function getJsonpCallback(url){
2        var result = null;
3        var idMatch = url.match(/jsonp=(.*?)(&|$)/);
4        if(idMatch){
5                result = idMatch[1];
6        }else{
7                //jsonp didn't match, so maybe it is the jsonCallback thing.
8                idMatch = url.match(/callback=(.*?)(&|$)/);
9                if(idMatch){
10                        result = idMatch[1];
11                }
12        }
13       
14        if(result){
15                result = decodeURIComponent(result);
16        }
17        return result;
18}
19
20function findJsonpDone(){
21        var result = false;
22        var scriptUrls = getScriptUrls();
23       
24        for(var i = 0; i < scriptUrls.length; i++){
25                var jsonp = getJsonpCallback(scriptUrls[i]);
26                if(jsonp){
27                        eval(jsonp + "({animalType: 'mammal'});");
28                        result = true;
29                        break;
30                }
31        }
32        return result;
33}
34
35function getScriptUrls(){
36        //Get the script tags in the page to figure what state we are in.
37        var scripts = document.getElementsByTagName('script');
38        var scriptUrls = new Array();
39        for(var i = 0; scripts && i < scripts.length; i++){
40                var scriptTag = scripts[i];
41                if(scriptTag.id.indexOf("dojo_request_script") == 0){
42                        scriptUrls.push(scriptTag.src);
43                }
44        }
45
46        return scriptUrls;
47}
48
49function doJsonpCallback(){
50        if(!findJsonpDone()){
51                 alert('ERROR: Could not jsonp callback!');
52        }
53}
54
55//Set a timeout to do the callback check, since MSIE won't see the SCRIPT tag until
56//we complete processing of this page.
57setTimeout(function(){doJsonpCallback();}, 300);
Note: See TracBrowser for help on using the repository browser.