genia.likes.science@gmail.com | c5f82a2 | 2013-05-08 02:44:35 -0700 | [diff] [blame] | 1 | var myBookmark = (function(){
|
| 2 | var s1, s2, isLoaded = false, xhr, head = document.getElementsByTagName('head')[0];
|
| 3 | var scripts = document.getElementsByTagName("script");
|
| 4 | var REMOTE = (function(){
|
| 5 | var remote = location.href;
|
| 6 | switch (location.host) {
|
| 7 | case "provider.easyxdm.net":
|
| 8 | location.href = remote.replace("provider", "consumer");
|
| 9 | break;
|
| 10 | case "xdm1":
|
| 11 | remote = remote.replace("xdm1", "xdm2");
|
| 12 | break;
|
| 13 | default:
|
| 14 | remote = "http://provider.easyxdm.net/current/example/";
|
| 15 | }
|
| 16 | return remote.substring(0, remote.lastIndexOf("/"));
|
| 17 | }());
|
| 18 |
|
| 19 | function run(){
|
| 20 | if (typeof xhr === "undefined") {
|
| 21 | return;
|
| 22 | }
|
| 23 | xhr.post("example/glossary.php", {
|
| 24 | param1: "a",
|
| 25 | param2: "b"
|
| 26 | }, function(json){
|
| 27 | alert(json.glossary.title);
|
| 28 | });
|
| 29 | }
|
| 30 |
|
| 31 | function scriptOnLoad(){
|
| 32 | if (isLoaded || typeof easyXDM === "undefined" || typeof JSON === "undefined") {
|
| 33 | return;
|
| 34 | }
|
| 35 | isLoaded = true;
|
| 36 | xhr = new easyXDM.Rpc({
|
| 37 | remote: REMOTE + "/../xhr.html",
|
| 38 | onReady: function(){
|
| 39 | run();
|
| 40 | }
|
| 41 | }, {
|
| 42 | remote: {
|
| 43 | post: {}
|
| 44 | }
|
| 45 | });
|
| 46 |
|
| 47 | }
|
| 48 | s1 = document.createElement("script");
|
| 49 | s1.type = "text/javascript";
|
| 50 | s1.src = REMOTE + "/../easyXDM.debug.js";
|
| 51 | s1.onreadystatechange = function(){
|
| 52 | if (this.readyState === "complete" || this.readyState === "loaded") {
|
| 53 | scriptOnLoad();
|
| 54 | }
|
| 55 | };
|
| 56 | s1.onload = scriptOnLoad;
|
| 57 | head.appendChild(s1);
|
| 58 |
|
| 59 | if (typeof JSON === "undefined" || !JSON) {
|
| 60 | s2 = document.createElement("script");
|
| 61 | s2.type = "text/javascript";
|
| 62 | s2.src = REMOTE + "/../json2.js";
|
| 63 | s2.onreadystatechange = function(){
|
| 64 | if (this.readyState === "complete" || this.readyState === "loaded") {
|
| 65 | scriptOnLoad();
|
| 66 | }
|
| 67 | };
|
| 68 | s2.onload = scriptOnLoad;
|
| 69 | head.appendChild(s2);
|
| 70 | }
|
| 71 | return {
|
| 72 | run: run
|
| 73 | };
|
| 74 | })();
|