|
27 | 27 | |
28 | 28 | var body = document.getElementsByTagName('body'); |
29 | 29 | body[0].onclick = function() { |
30 | | - parent.postMessage( { "bodyclick":"bodyclick" }, window.location.protocol+"//"+window.location.host) |
| 30 | + var targetOrigin = (window.location.protocol == "file:") ? "*" : window.location.protocol+"//"+window.location.host; |
| 31 | + parent.postMessage( { "bodyclick":"bodyclick" }, targetOrigin) |
31 | 32 | }; |
32 | 33 | |
33 | 34 | var els = document.getElementsByClassName("patternLink"); |
34 | 35 | for (i in els) { |
35 | 36 | els[i].onclick = function() { |
36 | | - parent.postMessage( { "patternpartial": this.getAttribute("data-patternpartial") }, window.location.protocol+"//"+window.location.host); |
| 37 | + var targetOrigin = (window.location.protocol == "file:") ? "*" : window.location.protocol+"//"+window.location.host; |
| 38 | + parent.postMessage( { "patternpartial": this.getAttribute("data-patternpartial"), "path": "foo" }, targetOrigin); |
37 | 39 | return false; |
38 | 40 | } |
39 | 41 | } |
40 | 42 | |
41 | 43 | // alert the iframe parent that the pattern has loaded. for page follow. |
42 | | - parent.postMessage( { "url": window.location.host, "patternpartial": "{{ patternPartial }}" },window.location.protocol+"//"+window.location.host); |
| 44 | + var targetOrigin = (window.location.protocol == "file:") ? "*" : window.location.protocol+"//"+window.location.host; |
| 45 | + parent.postMessage( { "patternpartial": "{{ patternPartial }}", "path": window.location.toString() }, targetOrigin); |
| 46 | + |
| 47 | + // watch the iframe source so that it can be sent back to everyone else. |
| 48 | + function receiveIframeMessage(event) { |
| 49 | + |
| 50 | + // does the origin sending the message match the current host? if not dev/null the request |
| 51 | + if ((window.location.protocol != "file:") && (event.origin !== window.location.protocol+"//"+window.location.host)) { |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + if (event.data.path != undefined) { |
| 56 | + var re = /patterns\/(.*)$/; |
| 57 | + var path = window.location.protocol+"//"+window.location.host+window.location.pathname.replace(re,'')+event.data.path; |
| 58 | + window.location.replace(path); |
| 59 | + } else if (event.data.reload != undefined) { |
| 60 | + window.location.reload(); |
| 61 | + } |
| 62 | + |
| 63 | + } |
| 64 | + window.addEventListener("message", receiveIframeMessage, false); |
43 | 65 | |
44 | 66 | </script> |
45 | 67 | </body> |
|
0 commit comments