| OLD | NEW |
| (Empty) | |
| 1 <!-- |
| 2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 6 Code distributed by Google as part of the polymer project is also |
| 7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 8 --> |
| 9 <!doctype html> |
| 10 <html> |
| 11 <head> |
| 12 <!-- |
| 13 TODO: remove style |
| 14 --> |
| 15 <style> |
| 16 body { |
| 17 position: relative; |
| 18 margin: 0; |
| 19 padding: 0; |
| 20 } |
| 21 #foo { |
| 22 position: absolute; |
| 23 background: #faa; |
| 24 box-sizing: border-box; |
| 25 } |
| 26 .static { |
| 27 height: 100px; |
| 28 background: blue; |
| 29 border: solid 1px black; |
| 30 box-sizing: border-box; |
| 31 } |
| 32 </style> |
| 33 </head> |
| 34 <body> |
| 35 <!-- |
| 36 TODO: remove content |
| 37 |
| 38 This is only here for demo / development until there's a way to load conte
nt into the frame. |
| 39 --> |
| 40 <div class="static"></div> |
| 41 <div class="static"></div> |
| 42 <div id="foo" style="top: 100px; left: 100px; height: 100px;width: 400px;">H
ello Designer</div> |
| 43 <div id="foo" style="top: 300px; left: 100px; height: 100px;width: 400px;">H
ello Designer</div> |
| 44 <script> |
| 45 (function() { |
| 46 currentElement = null; |
| 47 token = null; |
| 48 |
| 49 window.addEventListener("message", function(e) { |
| 50 switch (e.data.message_type) { |
| 51 case 'setToken': |
| 52 setToken(e); |
| 53 break; |
| 54 case 'selectElement': |
| 55 selectElement(e); |
| 56 break; |
| 57 case 'resizeElement': |
| 58 resizeElement(e); |
| 59 break; |
| 60 } |
| 61 }); |
| 62 |
| 63 function setToken(e) { |
| 64 if (token != null) { |
| 65 throw new Error('token already set'); |
| 66 } |
| 67 token = e.data.token; |
| 68 } |
| 69 |
| 70 function sendUpdateSelector(receiver, bounds) { |
| 71 receiver.postMessage({ |
| 72 message_type: 'updateSelector', |
| 73 token: token, |
| 74 bounds: { |
| 75 left: bounds.left, |
| 76 top: bounds.top, |
| 77 width: bounds.width, |
| 78 height: bounds.height |
| 79 } |
| 80 }, '*'); |
| 81 } |
| 82 |
| 83 function sendSelectedElement(receiver, element) { |
| 84 var style = window.getComputedStyle(element); |
| 85 var bounds = element.getBoundingClientRect(); |
| 86 receiver.postMessage({ |
| 87 message_type: 'seletedElement', |
| 88 token: token, |
| 89 tagName: element.tagName, |
| 90 display: style.display, |
| 91 position: style.position, |
| 92 bounds: { |
| 93 left: bounds.left, |
| 94 top: bounds.top, |
| 95 width: bounds.width, |
| 96 height: bounds.height |
| 97 } |
| 98 }, '*'); |
| 99 } |
| 100 |
| 101 function selectElement(e) { |
| 102 var data = e.data; |
| 103 currentElement = document.elementFromPoint(data.x, data.y); |
| 104 var bounds = currentElement.getBoundingClientRect(); |
| 105 sendSelectedElement(e.source, currentElement); |
| 106 } |
| 107 |
| 108 function resizeElement(e) { |
| 109 if (currentElement != null) { |
| 110 var bounds = e.data.bounds; |
| 111 currentElement.style.top = bounds.top + 'px'; |
| 112 currentElement.style.left = bounds.left + 'px'; |
| 113 currentElement.style.height = bounds.height + 'px'; |
| 114 currentElement.style.width = bounds.width + 'px'; |
| 115 sendUpdateSelector(e.source, bounds); |
| 116 } |
| 117 } |
| 118 })(); |
| 119 </script> |
| 120 </body> |
| 121 </html> |
| OLD | NEW |