OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset="utf-8"> |
| 5 <title>Base source for injecting into an iframe for tests</title> |
| 6 <script src="../../webcomponentsjs/webcomponents.js"></script> |
| 7 <link rel='import' href='./initialization-cases.html'> |
| 8 </head> |
| 9 <body> |
| 10 <script> |
| 11 window.addEventListener("message", messageReceived, false); |
| 12 |
| 13 window.addEventListener('WebComponentsReady', function() { |
| 14 window.parent.postMessage({ |
| 15 'type': 'ready' |
| 16 }, '*'); |
| 17 }); |
| 18 |
| 19 var appendBodyReceived = false; |
| 20 function messageReceived(msg) { |
| 21 if (!msg.data) { |
| 22 console.error('got invalid msg?'); |
| 23 } |
| 24 // the parent can (at any time) ask for our URL. |
| 25 if (msg.data.type === 'urlQuery') { |
| 26 msg.source.postMessage({ |
| 27 'type': 'urlQueryResponse', |
| 28 'href': window.location.href, |
| 29 'pathname': window.location.pathname, |
| 30 'hash': window.location.hash, |
| 31 'search': window.location.search |
| 32 }, '*'); |
| 33 } else if (msg.data.type === 'appendBody') { |
| 34 if (appendBodyReceived) { |
| 35 throw new Error('should only receive at most one appendBody call'); |
| 36 } |
| 37 var element = document.createElement(msg.data.tagName); |
| 38 document.body.appendChild(element); |
| 39 appendBodyReceived = true; |
| 40 } |
| 41 } |
| 42 |
| 43 window.addEventListener('error', function(e) { |
| 44 window.parent.postMessage({ |
| 45 'type': 'error', |
| 46 'error': e.message |
| 47 }, '*'); |
| 48 }); |
| 49 </script> |
| 50 </body> |
| 51 </html> |
OLD | NEW |