mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Revert back to PaperScope#setup() and keep #initialize0 simple.
This commit is contained in:
parent
6086165d1a
commit
6b6d5909c1
2 changed files with 25 additions and 18 deletions
|
@ -39,16 +39,12 @@
|
||||||
var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
|
var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a PaperScope object. If a canvas is provided, it also creates a
|
* Creates a PaperScope object.
|
||||||
* an empty {@link Project} and a {@link View} for it, both linked to this
|
|
||||||
* scope.
|
|
||||||
*
|
*
|
||||||
* @name PaperScope#initialize
|
* @name PaperScope#initialize
|
||||||
* @function
|
* @function
|
||||||
* @param {HTMLCanvasElement} canvas The canvas this scope should be
|
|
||||||
* associated with.
|
|
||||||
*/
|
*/
|
||||||
initialize: function(canvas, script) {
|
initialize: function(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.
|
||||||
|
@ -59,9 +55,9 @@ var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
|
||||||
this.projects = [];
|
this.projects = [];
|
||||||
this.tool = null;
|
this.tool = null;
|
||||||
this.tools = [];
|
this.tools = [];
|
||||||
var obj = script || canvas;
|
// Assign an id to this canvas that's either extracted from the script
|
||||||
this._id = obj && obj.getAttribute('id')
|
// or automatically generated.
|
||||||
|| script && script.src
|
this._id = script && (script.getAttribute('id') || script.src)
|
||||||
|| ('paperscope-' + (PaperScope._id++));
|
|| ('paperscope-' + (PaperScope._id++));
|
||||||
// Make sure the script tag also has this id now. If it already had an
|
// Make sure the script tag also has this id now. If it already had an
|
||||||
// id, we're not changing it, since it's the first option we're
|
// id, we're not changing it, since it's the first option we're
|
||||||
|
@ -69,14 +65,6 @@ var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
|
||||||
if (script)
|
if (script)
|
||||||
script.setAttribute('id', this._id);
|
script.setAttribute('id', this._id);
|
||||||
PaperScope._scopes[this._id] = this;
|
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);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -145,6 +133,24 @@ var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
|
||||||
}, scope);
|
}, scope);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up an empty project for us. If a canvas is provided, it also creates
|
||||||
|
* a {@link View} for it, both linked to this scope.
|
||||||
|
*
|
||||||
|
* @param {HTMLCanvasElement} canvas The canvas this scope should be
|
||||||
|
* associated with.
|
||||||
|
*/
|
||||||
|
setup: function(canvas) {
|
||||||
|
// Create an empty project for the scope.
|
||||||
|
// Make sure this is the active scope, so the created project and view
|
||||||
|
// are automatically associated with it.
|
||||||
|
paper = this;
|
||||||
|
this.project = new Project();
|
||||||
|
// Create a view for the canvas.
|
||||||
|
if (canvas)
|
||||||
|
this.view = new View(canvas);
|
||||||
|
},
|
||||||
|
|
||||||
clear: function() {
|
clear: function() {
|
||||||
// Remove all projects, views and tools.
|
// Remove all projects, views and tools.
|
||||||
for (var i = this.projects.length - 1; i >= 0; i--)
|
for (var i = this.projects.length - 1; i >= 0; i--)
|
||||||
|
|
|
@ -239,7 +239,8 @@ var PaperScript = this.PaperScript = new function() {
|
||||||
// so a project is created for it now.
|
// so a project is created for it now.
|
||||||
var canvas = PaperScript.getAttribute(script, 'canvas');
|
var canvas = PaperScript.getAttribute(script, 'canvas');
|
||||||
canvas = canvas && document.getElementById(canvas);
|
canvas = canvas && document.getElementById(canvas);
|
||||||
var scope = new PaperScope(canvas, script);
|
var scope = new PaperScope(script);
|
||||||
|
scope.setup(canvas);
|
||||||
if (script.src) {
|
if (script.src) {
|
||||||
// If we're loading from a source, request that first and then
|
// If we're loading from a source, request that first and then
|
||||||
// run later.
|
// run later.
|
||||||
|
|
Loading…
Reference in a new issue