| Index: dart/site/try/src/run.dart
|
| diff --git a/dart/site/try/src/run.dart b/dart/site/try/src/run.dart
|
| index 3eae69811d5db7a582956d5c1ba39618edca0376..e453a7015bccf9bdeb3f965dd7cb4299f0932392 100644
|
| --- a/dart/site/try/src/run.dart
|
| +++ b/dart/site/try/src/run.dart
|
| @@ -35,37 +35,37 @@ final String outputHelper =
|
|
|
| const String OUTPUT_HELPER = r'''
|
| function dartPrint(msg) {
|
| + // Send a message to the main Try Dart window.
|
| window.parent.postMessage(String(msg), "*");
|
| }
|
|
|
| function dartMainRunner(main) {
|
| - main();
|
| -}
|
| -
|
| -window.onerror = function (message, url, lineNumber) {
|
| - window.parent.postMessage(
|
| - ["error", {message: message, url: url, lineNumber: lineNumber}], "*");
|
| -};
|
| + // Store the current height (of an empty document). This implies that the
|
| + // main Try Dart application is only notified if the document is actually
|
| + // changed.
|
| + var previousScrollHeight = document.documentElement.scrollHeight;
|
|
|
| -(function () {
|
| + function postScrollHeight(mutations, observer) {
|
| + var scrollHeight = document.documentElement.scrollHeight;
|
| + if (scrollHeight !== previousScrollHeight) {
|
| + previousScrollHeight = scrollHeight;
|
| + window.parent.postMessage(["scrollHeight", scrollHeight], "*");
|
| + }
|
| + }
|
|
|
| -function postScrollHeight() {
|
| - window.parent.postMessage(
|
| - ["scrollHeight", document.documentElement.scrollHeight], "*");
|
| -}
|
| + var MutationObserver =
|
| + window.MutationObserver ||
|
| + window.WebKitMutationObserver ||
|
| + window.MozMutationObserver;
|
|
|
| -var observer = new (window.MutationObserver ||
|
| - window.WebKitMutationObserver ||
|
| - window.MozMutationObserver)(function(mutations) {
|
| - postScrollHeight()
|
| - window.setTimeout(postScrollHeight, 500);
|
| -});
|
| + // Listen to any changes to the DOM.
|
| + new MutationObserver(postScrollHeight).observe(
|
| + document.documentElement,
|
| + { attributes: true,
|
| + childList: true,
|
| + characterData: true,
|
| + subtree: true });
|
|
|
| -observer.observe(
|
| - document.body,
|
| - { attributes: true,
|
| - childList: true,
|
| - characterData: true,
|
| - subtree: true });
|
| -})();
|
| + main();
|
| +}
|
| ''';
|
|
|