mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Add PaperScope#view and #layer as shortcuts to #document.activeView / activeLayer.
This commit is contained in:
parent
a601cfdd6d
commit
2773ef693a
1 changed files with 23 additions and 4 deletions
|
@ -19,12 +19,28 @@
|
||||||
* global paper object, which simply is a pointer to the currently active scope.
|
* global paper object, which simply is a pointer to the currently active scope.
|
||||||
*/
|
*/
|
||||||
var PaperScope = this.PaperScope = Base.extend({
|
var PaperScope = this.PaperScope = Base.extend({
|
||||||
|
beans: true,
|
||||||
|
|
||||||
initialize: function(id) {
|
initialize: function(id) {
|
||||||
this.document = null;
|
this.document = null;
|
||||||
this.documents = [];
|
this.documents = [];
|
||||||
this.tools = [];
|
this.tools = [];
|
||||||
this.id = id;
|
this.id = id;
|
||||||
PaperScope.scopes[id] = this;
|
PaperScope._scopes[id] = this;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A short-cut to the currently active view of the active document.
|
||||||
|
*/
|
||||||
|
getView: function() {
|
||||||
|
return this.document.activeView;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A short-cut to the currently active layer of the active document.
|
||||||
|
*/
|
||||||
|
getLayer: function() {
|
||||||
|
return this.document.activeLayer;
|
||||||
},
|
},
|
||||||
|
|
||||||
evaluate: function(code) {
|
evaluate: function(code) {
|
||||||
|
@ -56,14 +72,17 @@ var PaperScope = this.PaperScope = Base.extend({
|
||||||
|
|
||||||
remove: function() {
|
remove: function() {
|
||||||
this.clear();
|
this.clear();
|
||||||
delete PaperScope.scopes[this.id];
|
delete PaperScope._scopes[this.id];
|
||||||
},
|
},
|
||||||
|
|
||||||
statics: {
|
statics: {
|
||||||
scopes: {},
|
_scopes: {},
|
||||||
|
|
||||||
get: function(id) {
|
get: function(id) {
|
||||||
return this.scopes[id] || null;
|
// If a script tag is passed, get the id from it.
|
||||||
|
if (typeof id === 'object')
|
||||||
|
id = id.getAttribute('id');
|
||||||
|
return this._scopes[id] || null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue