genia.likes.science@gmail.com | c5f82a2 | 2013-05-08 02:44:35 -0700 | [diff] [blame^] | 1 | <!doctype html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>easyXDM</title> |
| 5 | <script type="text/javascript" src="../easyXDM.debug.js"> |
| 6 | </script> |
| 7 | <script type="text/javascript"> |
| 8 | /** |
| 9 | * Request the use of the JSON object |
| 10 | */ |
| 11 | easyXDM.DomHelper.requiresJSON("../json2.js"); |
| 12 | </script> |
| 13 | <script type="text/javascript"> |
| 14 | var win, remoteapp; // reference to the popups window |
| 15 | var proxy = new easyXDM.Rpc(/** The configuration */{ |
| 16 | local: "../name.html", |
| 17 | swf: "../easyxdm.swf" |
| 18 | }, { |
| 19 | local: { |
| 20 | /** |
| 21 | * This is used to open up the popup. A popup with the given name should already be opened |
| 22 | * in the user click handler. |
| 23 | */ |
| 24 | open: function(name){ |
| 25 | remoteapp = null; |
| 26 | // we now open the window, passing the name of this window (includes the channel name) |
| 27 | // in case it has to look us up using the framename |
| 28 | win = window.open('remoteapp.html' + '#easyXDM_' + easyXDM.query.xdm_c + '_provider', name, "width=400, height=400"); |
| 29 | }, |
| 30 | /** |
| 31 | * This is where we receive the data |
| 32 | * @param {Object} data The data |
| 33 | */ |
| 34 | postMessage: function(data){ |
| 35 | if (win.closed) { |
| 36 | alert("the popup has been closed - please open it again"); |
| 37 | return; |
| 38 | } |
| 39 | var div = remoteapp.document.createElement("div"); |
| 40 | div.innerHTML = "data from '" + proxy.origin + "'"; |
| 41 | if (remoteapp) { |
| 42 | remoteapp.document.body.appendChild(div); |
| 43 | for (var key in data) { |
| 44 | if (data.hasOwnProperty(key)) { |
| 45 | div = remoteapp.document.createElement("div"); |
| 46 | div.innerHTML = key + "=" + data[key]; |
| 47 | remoteapp.document.body.appendChild(div); |
| 48 | } |
| 49 | } |
| 50 | remoteapp.focus(); |
| 51 | } |
| 52 | } |
| 53 | }, |
| 54 | remote: { |
| 55 | postMessage: {} |
| 56 | } |
| 57 | }); |
| 58 | |
| 59 | |
| 60 | /** |
| 61 | * The popup must use this window to register itself |
| 62 | * @param {DOMWindow} app The window object of the popup |
| 63 | */ |
| 64 | function setApp(app){ |
| 65 | remoteapp = app; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * The popup must use this method to send data. This clones the object in order to |
| 70 | * work around a but in IE |
| 71 | * @param {Object} data The data to send |
| 72 | */ |
| 73 | function sendData(data){ |
| 74 | var copy = {}; |
| 75 | // copy the object in order to avoid the JSON serialization bug |
| 76 | easyXDM.apply(copy, data); |
| 77 | proxy.postMessage(copy); |
| 78 | } |
| 79 | </script> |
| 80 | </head> |
| 81 | <body> |
| 82 | </body> |
| 83 | </html> |