Rev | Line | |
---|
[483] | 1 | function 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 | |
---|
| 20 | function 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 | |
---|
| 35 | function 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 | |
---|
| 49 | function 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. |
---|
| 57 | setTimeout(function(){doJsonpCallback();}, 300); |
---|
Note: See
TracBrowser
for help on using the repository browser.