diff options
author | mensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f> | 2008-11-13 09:49:11 +0000 |
---|---|---|
committer | mensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f> | 2008-11-13 09:49:11 +0000 |
commit | e44a7e37b6c7b5961adaffc62b9042b8d442938e (patch) | |
tree | 95b67c356e93163467db2451f2b8cce84ed5d582 /includes/js/dojo/tests/io/scriptJsonp.js | |
parent | a62b9742ee5e28bcec6872d88f50f25b820914f6 (diff) | |
download | semanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.gz semanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.bz2 |
New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'includes/js/dojo/tests/io/scriptJsonp.js')
-rw-r--r-- | includes/js/dojo/tests/io/scriptJsonp.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/includes/js/dojo/tests/io/scriptJsonp.js b/includes/js/dojo/tests/io/scriptJsonp.js new file mode 100644 index 0000000..ad1a196 --- /dev/null +++ b/includes/js/dojo/tests/io/scriptJsonp.js @@ -0,0 +1,57 @@ +function getJsonpCallback(url){ + var result = null; + var idMatch = url.match(/jsonp=(.*?)(&|$)/); + if(idMatch){ + result = idMatch[1]; + }else{ + //jsonp didn't match, so maybe it is the jsonCallback thing. + idMatch = url.match(/callback=(.*?)(&|$)/); + if(idMatch){ + result = idMatch[1]; + } + } + + if(result){ + result = decodeURIComponent(result); + } + return result; +} + +function findJsonpDone(){ + var result = false; + var scriptUrls = getScriptUrls(); + + for(var i = 0; i < scriptUrls.length; i++){ + var jsonp = getJsonpCallback(scriptUrls[i]); + if(jsonp){ + eval(jsonp + "({animalType: 'mammal'});"); + result = true; + break; + } + } + return result; +} + +function getScriptUrls(){ + //Get the script tags in the page to figure what state we are in. + var scripts = document.getElementsByTagName('script'); + var scriptUrls = new Array(); + for(var i = 0; scripts && i < scripts.length; i++){ + var scriptTag = scripts[i]; + if(scriptTag.id.indexOf("dojoIoScript") == 0){ + scriptUrls.push(scriptTag.src); + } + } + + return scriptUrls; +} + +function doJsonpCallback(){ + if(!findJsonpDone()){ + alert('ERROR: Could not jsonp callback!'); + } +} + +//Set a timeout to do the callback check, since MSIE won't see the SCRIPT tag until +//we complete processing of this page. +setTimeout(function(){doJsonpCallback();}, 300); |