forked from paperjs/paper.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaperScopeItem.js
More file actions
62 lines (57 loc) · 1.65 KB
/
Copy pathPaperScopeItem.js
File metadata and controls
62 lines (57 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
/**
* @name PaperScopeItem
*
* @class A private base class for all classes that have lists and references in
* the {@link PaperScope} ({@link Project}, {@link View}, {@link Tool}), so
* functionality can be shared.
*
* @private
*/
var PaperScopeItem = Base.extend(Callback, /** @lends PaperScopeItem# */{
/**
* Creates a PaperScopeItem object.
*/
initialize: function(activate) {
// Store reference to the currently active global paper scope:
this._scope = paper;
// Push it onto this._scope[this._list] and set _index:
this._index = this._scope[this._list].push(this) - 1;
// If the project has no active reference, activate this one
if (activate || !this._scope[this._reference])
this.activate();
},
activate: function() {
if (!this._scope)
return false;
var prev = this._scope[this._reference];
if (prev && prev != this)
prev.fire('deactivate');
this._scope[this._reference] = this;
this.fire('activate', prev);
return true;
},
isActive: function() {
return this._scope[this._reference] === this;
},
remove: function() {
if (this._index == null)
return false;
Base.splice(this._scope[this._list], null, this._index, 1);
// Clear the active tool reference if it was pointint to this.
if (this._scope[this._reference] == this)
this._scope[this._reference] = null;
this._scope = null;
return true;
}
});