From 950d7cdff98551cf3da3f7caef10cbbfe47e8bc7 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Sat, 10 Aug 2013 11:20:19 +0100 Subject: [PATCH] Fixed #720. The run button now sets requested/withAlerts Also tidying up some code and removing old files. Note that the rejig of order in live.js is because the renderLivePreview needs to assigned before we create a throttled version of the code. --- public/js/chrome/navigation.js | 2 +- public/js/render/infinite-loop-test-worker.js | 33 ------------------- public/js/render/live.js | 23 ++++++++----- 3 files changed, 15 insertions(+), 43 deletions(-) delete mode 100644 public/js/render/infinite-loop-test-worker.js diff --git a/public/js/chrome/navigation.js b/public/js/chrome/navigation.js index 6bc7bbb1..c1476eac 100644 --- a/public/js/chrome/navigation.js +++ b/public/js/chrome/navigation.js @@ -185,7 +185,7 @@ $('#runwithalerts').click(function () { }); $('#runconsole').click(function () { - editors.console.render(); + editors.console.render(true); return false; }); diff --git a/public/js/render/infinite-loop-test-worker.js b/public/js/render/infinite-loop-test-worker.js deleted file mode 100644 index 98695f9d..00000000 --- a/public/js/render/infinite-loop-test-worker.js +++ /dev/null @@ -1,33 +0,0 @@ -// fake objects to help detect those infinite loops -var noop = function () {}; -var document = { - createElement: function () { - return document; - }, - appendChild: noop, - addEventListener: noop - }, - alert = noop, - console = { - log: noop, - dir: noop - }, - window = { - document: document, - console: console - }; - - -this.addEventListener('message', function(e) { - this.postMessage({ code: 'READY' }); - setTimeout(function () { - try { - eval(e.data); - } catch (e) { - this.postMessage({ code: 'ERROR', msg: e.toString() }); // 3 is excpetion and don't run - return; - } - - this.postMessage({ code: 'DONE' }); - }, 10); -}, false); \ No newline at end of file diff --git a/public/js/render/live.js b/public/js/render/live.js index 9141aaef..6c072796 100644 --- a/public/js/render/live.js +++ b/public/js/render/live.js @@ -1,3 +1,6 @@ +var $live = $('#live'), + showlive = $('#showlive')[0]; + /** * Defer callable. Kinda tricky to explain. Basically: * "Don't make newFn callable until I tell you via this trigger callback." @@ -48,11 +51,6 @@ var deferCallable = function (newFn, trigger) { * ============================================================================= */ -var $live = $('#live'), - showlive = $('#showlive')[0], - throttledPreview = throttle(renderLivePreview, 200), - liveScrollTop = null; - function sendReload() { if (saveChecksum) { $.ajax({ @@ -67,8 +65,6 @@ function sendReload() { } } -var deferredLiveRender = null; - function codeChangeLive(event, data) { clearTimeout(deferredLiveRender); @@ -101,8 +97,6 @@ function codeChangeLive(event, data) { } } -$document.bind('codeChange.live', codeChangeLive); - /** ============================================================================ * JS Bin Renderer * Messages to and from the runner. @@ -336,3 +330,14 @@ var renderLivePreview = (function () { }()); + +// this needs to be after renderLivePreview is set (as it's defined using +// var instead of a first class function). +var throttledPreview = throttle(renderLivePreview, 200), + liveScrollTop = null; + +// timer value: used in the delayed render (because iframes don't have +// innerHeight/Width) in Chrome & WebKit +var deferredLiveRender = null; + +$document.bind('codeChange.live', codeChangeLive);