mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -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# */{
|
var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a PaperScope object and an empty {@link Project} for it. If a
|
* Creates a PaperScope object. If a canvas is provided, it also creates a
|
||||||
* canvas is provided, it also creates a {@link View} for it.
|
* an empty {@link Project} and a {@link View} for it, both linked to this
|
||||||
* Both project and view are linked to this scope.
|
* scope.
|
||||||
*
|
*
|
||||||
* @name PaperScope#initialize
|
* @name PaperScope#initialize
|
||||||
* @function
|
* @function
|
||||||
* @param {HTMLCanvasElement} canvas The canvas this scope should be
|
* @param {HTMLCanvasElement} canvas The canvas this scope should be
|
||||||
* associated with.
|
* associated with.
|
||||||
*/
|
*/
|
||||||
initialize: function(canvas, script) {
|
initialize: function(canvas, script) {
|
||||||
// script is only used internally, when creating scopes for PaperScript.
|
// script is only used internally, when creating scopes for PaperScript.
|
||||||
// Whenever a PaperScope is created, it automatically becomes the active
|
// Whenever a PaperScope is created, it automatically becomes the active
|
||||||
// one.
|
// one.
|
||||||
paper = this;
|
paper = this;
|
||||||
this.views = [];
|
|
||||||
this.view = null;
|
this.view = null;
|
||||||
|
this.views = [];
|
||||||
|
this.project = null;
|
||||||
this.projects = [];
|
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.tool = null;
|
||||||
this.tools = [];
|
this.tools = [];
|
||||||
var obj = script || canvas;
|
var obj = script || canvas;
|
||||||
|
@ -72,6 +70,10 @@ var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
|
||||||
script.setAttribute('id', this._id);
|
script.setAttribute('id', this._id);
|
||||||
PaperScope._scopes[this._id] = this;
|
PaperScope._scopes[this._id] = this;
|
||||||
if (canvas) {
|
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.
|
// Create a view for the canvas.
|
||||||
this.view = new View(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}
|
* Evaluates parsed PaperScript code in the passed {@link PaperScope}
|
||||||
* object. It also handles canvas setup, tool creation and handlers
|
* object. It also installs handlers automatically for us.
|
||||||
* automatically for us.
|
|
||||||
*
|
*
|
||||||
* @name PaperScript.evaluate
|
* @name PaperScript.evaluate
|
||||||
* @function
|
* @function
|
||||||
|
|
Loading…
Reference in a new issue