From 7082d7a3d6bd6afc28f5bce39568da979e198237 Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 21 Jul 2025 23:42:35 +0200 Subject: [PATCH] Mon 21 Jul 22:43:21 CEST 2025 --- js/ui/mxgraph/src/js/util/mxObjectIdentity.js | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 js/ui/mxgraph/src/js/util/mxObjectIdentity.js diff --git a/js/ui/mxgraph/src/js/util/mxObjectIdentity.js b/js/ui/mxgraph/src/js/util/mxObjectIdentity.js new file mode 100644 index 0000000..457eee8 --- /dev/null +++ b/js/ui/mxgraph/src/js/util/mxObjectIdentity.js @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2006-2015, JGraph Ltd + * Copyright (c) 2006-2015, Gaudenz Alder + */ +var mxObjectIdentity = +{ + /** + * Class: mxObjectIdentity + * + * Identity for JavaScript objects and functions. This is implemented using + * a simple incrementing counter which is stored in each object under + * . + * + * 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. + */ + counter: 0, + + /** + * Function: get + * + * Returns the ID for the given object or function or null if no object + * is specified. + */ + get: function(obj) + { + if (obj != null) + { + if (obj[mxObjectIdentity.FIELD_NAME] == null) + { + if (typeof obj === 'object') + { + var ctor = mxUtils.getFunctionName(obj.constructor); + obj[mxObjectIdentity.FIELD_NAME] = ctor + '#' + mxObjectIdentity.counter++; + } + else if (typeof obj === 'function') + { + obj[mxObjectIdentity.FIELD_NAME] = 'Function#' + mxObjectIdentity.counter++; + } + } + + return obj[mxObjectIdentity.FIELD_NAME]; + } + + return null; + }, + + /** + * Function: clear + * + * Deletes the ID from the given object or function. + */ + clear: function(obj) + { + if (typeof(obj) === 'object' || typeof obj === 'function') + { + delete obj[mxObjectIdentity.FIELD_NAME]; + } + } + +};