mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Only create an empty Project for a PaperScope if a canvas was provided for it.
This commit is contained in:
parent
da6f923463
commit
c6cf4f9cf0
2 changed files with 11 additions and 10 deletions
|
@ -39,26 +39,24 @@
|
|||
var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
|
||||
|
||||
/**
|
||||
* Creates a PaperScope object and an empty {@link Project} for it. If a
|
||||
* canvas is provided, it also creates a {@link View} for it.
|
||||
* Both project and view are linked to this scope.
|
||||
* Creates a PaperScope object. If a canvas is provided, it also creates a
|
||||
* an empty {@link Project} and a {@link View} for it, both linked to this
|
||||
* scope.
|
||||
*
|
||||
* @name PaperScope#initialize
|
||||
* @function
|
||||
* @param {HTMLCanvasElement} canvas The canvas this scope should be
|
||||
* associated with.
|
||||
* associated with.
|
||||
*/
|
||||
initialize: function(canvas, script) {
|
||||
// script is only used internally, when creating scopes for PaperScript.
|
||||
// Whenever a PaperScope is created, it automatically becomes the active
|
||||
// one.
|
||||
paper = this;
|
||||
this.views = [];
|
||||
this.view = null;
|
||||
this.views = [];
|
||||
this.project = null;
|
||||
this.projects = [];
|
||||
// Since the global paper variable points to this PaperScope, the
|
||||
// created project and view are automatically associated with it.
|
||||
this.project = new Project();
|
||||
this.tool = null;
|
||||
this.tools = [];
|
||||
var obj = script || canvas;
|
||||
|
@ -72,6 +70,10 @@ var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
|
|||
script.setAttribute('id', this._id);
|
||||
PaperScope._scopes[this._id] = this;
|
||||
if (canvas) {
|
||||
// Create an empty project for the scope.
|
||||
// Since the global paper variable points to this PaperScope, the
|
||||
// created project and view are automatically associated with it.
|
||||
this.project = new Project();
|
||||
// Create a view for the canvas.
|
||||
this.view = new View(canvas);
|
||||
}
|
||||
|
|
|
@ -144,8 +144,7 @@ var PaperScript = this.PaperScript = new function() {
|
|||
|
||||
/**
|
||||
* Evaluates parsed PaperScript code in the passed {@link PaperScope}
|
||||
* object. It also handles canvas setup, tool creation and handlers
|
||||
* automatically for us.
|
||||
* object. It also installs handlers automatically for us.
|
||||
*
|
||||
* @name PaperScript.evaluate
|
||||
* @function
|
||||
|
|
Loading…
Reference in a new issue