mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Introduce PaperScope#setup(canvas), as a simple way to setup a standard project when not using PaperScript.
This commit is contained in:
parent
470360301c
commit
9f1f4d334e
2 changed files with 18 additions and 6 deletions
|
@ -140,6 +140,23 @@ var PaperScope = this.PaperScope = Base.extend(/** @scope _global_ */{
|
|||
return res;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets up the scope for a standard project, by creating an empty
|
||||
* {@link Project} object for us, along with a {@link View} for the passed
|
||||
* canvas, both linked to this scope.
|
||||
*/
|
||||
setup: function(canvas) {
|
||||
// We need to set the global paper reference to this scope,
|
||||
// since that will be used in the Project constructor to set
|
||||
// internal references.
|
||||
paper = this;
|
||||
new Project();
|
||||
if (canvas) {
|
||||
// Activate the newly created view straight away
|
||||
new View(canvas).activate();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Injects the paper scope into any other given scope. Can be used for
|
||||
* examle to inject the currently active PaperScope into the window's global
|
||||
|
|
|
@ -138,12 +138,7 @@ var PaperScript = this.PaperScript = new function() {
|
|||
// so the active project is defined.
|
||||
var canvas = PaperScript.getAttribute(code, 'canvas');
|
||||
if (canvas = canvas && document.getElementById(canvas)) {
|
||||
// Create an empty Project for this scope, and a view for the
|
||||
// canvas, both using the right paper scope
|
||||
paper = scope;
|
||||
new Project();
|
||||
// Activate the newly created view straight away
|
||||
new View(canvas).activate();
|
||||
scope.setup(canvas);
|
||||
}
|
||||
if (code.src) {
|
||||
// If we're loading from a source, request that first and then
|
||||
|
|
Loading…
Reference in a new issue