| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library trydart.run; | |
| 6 | |
| 7 import 'dart:html' show | |
| 8 Blob, | |
| 9 IFrameElement, | |
| 10 Url; | |
| 11 | |
| 12 makeOutputFrame(String scriptUrl) { | |
| 13 final String outputHtml = ''' | |
| 14 <!DOCTYPE html> | |
| 15 <html lang="en"> | |
| 16 <head> | |
| 17 <title>JavaScript output</title> | |
| 18 <meta http-equiv="Content-type" content="text/html;charset=UTF-8"> | |
| 19 </head> | |
| 20 <body> | |
| 21 <script type="application/javascript" src="$outputHelper"></script> | |
| 22 <script type="application/javascript" src="$scriptUrl"></script> | |
| 23 </body> | |
| 24 </html> | |
| 25 '''; | |
| 26 | |
| 27 return new IFrameElement() | |
| 28 ..src = Url.createObjectUrl(new Blob([outputHtml], "text/html")) | |
| 29 ..style.width = '100%' | |
| 30 ..style.height = '0px'; | |
| 31 } | |
| 32 | |
| 33 final String outputHelper = | |
| 34 Url.createObjectUrl(new Blob([OUTPUT_HELPER], 'application/javascript')); | |
| 35 | |
| 36 const String OUTPUT_HELPER = r''' | |
| 37 function dartPrint(msg) { | |
| 38 // Send a message to the main Try Dart window. | |
| 39 window.parent.postMessage(String(msg), "*"); | |
| 40 } | |
| 41 | |
| 42 function dartMainRunner(main) { | |
| 43 // Store the current height (of an empty document). This implies that the | |
| 44 // main Try Dart application is only notified if the document is actually | |
| 45 // changed. | |
| 46 var previousScrollHeight = document.documentElement.scrollHeight; | |
| 47 | |
| 48 function postScrollHeight(mutations, observer) { | |
| 49 var scrollHeight = document.documentElement.scrollHeight; | |
| 50 if (scrollHeight !== previousScrollHeight) { | |
| 51 previousScrollHeight = scrollHeight; | |
| 52 window.parent.postMessage(["scrollHeight", scrollHeight], "*"); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 var MutationObserver = | |
| 57 window.MutationObserver || | |
| 58 window.WebKitMutationObserver || | |
| 59 window.MozMutationObserver; | |
| 60 | |
| 61 // Listen to any changes to the DOM. | |
| 62 new MutationObserver(postScrollHeight).observe( | |
| 63 document.documentElement, | |
| 64 { attributes: true, | |
| 65 childList: true, | |
| 66 characterData: true, | |
| 67 subtree: true }); | |
| 68 | |
| 69 main(); | |
| 70 } | |
| 71 '''; | |
| OLD | NEW |