Add PaperScope#view and #layer as shortcuts to #document.activeView / activeLayer.

This commit is contained in:
Jürg Lehni 2011-05-16 10:59:45 +01:00
parent a601cfdd6d
commit 2773ef693a

View file

@ -19,12 +19,28 @@
* global paper object, which simply is a pointer to the currently active scope.
*/
var PaperScope = this.PaperScope = Base.extend({
beans: true,
initialize: function(id) {
this.document = null;
this.documents = [];
this.tools = [];
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) {
@ -56,14 +72,17 @@ var PaperScope = this.PaperScope = Base.extend({
remove: function() {
this.clear();
delete PaperScope.scopes[this.id];
delete PaperScope._scopes[this.id];
},
statics: {
scopes: {},
_scopes: {},
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;
}
}
});