From a3a211eead85a062499a7a510310e08e6231beca Mon Sep 17 00:00:00 2001 From: Yuval Greenfield Date: Wed, 2 Jan 2013 01:57:30 +0200 Subject: [PATCH] Late load of paperjs should still run paperscripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See this problem html http://stackoverflow.com/questions/14110205/dynamically-loading-a-script-changes-its-behaviour/14114337 and note how jquery handle this at https://github.com/jquery/jquery/blob/master/src/core.js#L768 --- src/core/PaperScript.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index a77686c9..5179f22a 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -298,7 +298,13 @@ var PaperScript = this.PaperScript = new function() { } } - DomEvent.add(window, { load: load }); + // Catch cases where paperjs is loaded after the browser event has already occurred. + if ( document.readyState === "complete" ) { + // Handle it asynchronously + setTimeout( load ); + } else { + DomEvent.add(window, { load: load }); + } // Produces helpers to e.g. check for both 'canvas' and 'data-paper-canvas' // attributes: