forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxObjectIdentity.js
More file actions
59 lines (54 loc) · 1.18 KB
/
mxObjectIdentity.js
File metadata and controls
59 lines (54 loc) · 1.18 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
/**
* $Id: mxObjectIdentity.js,v 1.1 2012/11/15 13:26:45 gaudenz Exp $
* Copyright (c) 2006-2010, JGraph Ltd
*/
var mxObjectIdentity =
{
/**
* Class: mxObjectIdentity
*
* Identity for JavaScript objects. This is implemented using a simple
* incremeting counter which is stored in each object under <ID_NAME>.
*
* The identity for an object does not change during its lifecycle.
*
* Variable: FIELD_NAME
*
* Name of the field to be used to store the object ID. Default is
* '_mxObjectId'.
*/
FIELD_NAME: 'mxObjectId',
/**
* Variable: counter
*
* Current counter for objects.
*/
counter: 0,
/**
* Function: get
*
* Returns the object id for the given object.
*/
get: function(obj)
{
if (typeof(obj) == 'object' &&
obj[mxObjectIdentity.FIELD_NAME] == null)
{
var ctor = mxUtils.getFunctionName(obj.constructor);
obj[mxObjectIdentity.FIELD_NAME] = ctor+'#'+mxObjectIdentity.counter++;
}
return obj[mxObjectIdentity.FIELD_NAME];
},
/**
* Function: clear
*
* Removes the object id from the given object.
*/
clear: function(obj)
{
if (typeof(obj) == 'object')
{
delete obj[mxObjectIdentity.FIELD_NAME];
}
}
};