mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-05-31 07:14:46 -04:00
Reuse scopes associated with canvases to support multiple scripts per canvas.
As described in #171.
This commit is contained in:
parent
8b4104fe19
commit
24a5016470
2 changed files with 8 additions and 2 deletions
src/core
|
@ -167,6 +167,8 @@ var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
|
|||
// are automatically associated with it.
|
||||
paper = this;
|
||||
this.project = new Project(canvas);
|
||||
// This is needed in PaperScript.load().
|
||||
return this;
|
||||
},
|
||||
|
||||
clear: function() {
|
||||
|
|
|
@ -278,8 +278,12 @@ var PaperScript = this.PaperScript = new function() {
|
|||
// retrieved through PaperScope.get().
|
||||
// If a canvas id is provided, pass it on to the PaperScope
|
||||
// so a project is created for it now.
|
||||
var scope = new PaperScope(script);
|
||||
scope.setup(PaperScript.getAttribute(script, 'canvas'));
|
||||
var canvas = PaperScript.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);
|
||||
if (script.src) {
|
||||
// If we're loading from a source, request that first and then
|
||||
// run later.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue