Reuse PaperScope objects when associating multiple scripts with the same canvas.

Closes #504.
This commit is contained in:
Jürg Lehni 2014-07-26 12:03:34 +02:00
parent e0ec2bf2c3
commit 0198f4c45f
3 changed files with 88 additions and 91 deletions

View file

@ -443,12 +443,13 @@ Base.exports.PaperScript = (function() {
// If a canvas id is provided, pass it on to the PaperScope
// so a project is created for it now.
var canvas = PaperScope.getAttribute(script, 'canvas'),
// See if there already is a scope for this canvas and reuse
// it, to support multiple scripts per canvas. Otherwise
// create a new one.
scope = PaperScope.get(canvas)
|| new PaperScope(script).setup(canvas),
src = script.src;
canvas = document.getElementById(canvas) || canvas;
// See if there already is a scope for this canvas and reuse
// it, to support multiple scripts per canvas. Otherwise
// create a new one.
var scope = PaperScope.get(canvas)
|| new PaperScope().setup(canvas);
if (src) {
// If we're loading from a source, request that first and
// then run later.