Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/ui/idgenerator.js
4523 views
1
/**
2
* @license
3
* Copyright The Closure Library Authors.
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
/**
8
* @fileoverview Generator for unique element IDs.
9
*/
10
11
goog.provide('goog.ui.IdGenerator');
12
13
14
15
/**
16
* Creates a new id generator.
17
* @constructor
18
* @final
19
*/
20
goog.ui.IdGenerator = function() {};
21
goog.addSingletonGetter(goog.ui.IdGenerator);
22
23
24
/**
25
* Next unique ID to use
26
* @type {number}
27
* @private
28
*/
29
goog.ui.IdGenerator.prototype.nextId_ = 0;
30
31
32
/**
33
* Random ID prefix to help avoid collisions with other closure JavaScript on
34
* the same page that may initialize its own IdGenerator singleton.
35
* @type {string}
36
* @private
37
*/
38
goog.ui.IdGenerator.prototype.idPrefix_ = '';
39
40
41
/**
42
* Sets the ID prefix for this singleton. This is a temporary workaround to be
43
* backwards compatible with code relying on the undocumented, but consistent,
44
* behavior. In the future this will be removed and the prefix will be set to
45
* a randomly generated string.
46
* @param {string} idPrefix
47
*/
48
goog.ui.IdGenerator.prototype.setIdPrefix = function(idPrefix) {
49
'use strict';
50
this.idPrefix_ = idPrefix;
51
};
52
53
54
/**
55
* Gets the next unique ID.
56
* @return {string} The next unique identifier.
57
*/
58
goog.ui.IdGenerator.prototype.getNextUniqueId = function() {
59
'use strict';
60
return this.idPrefix_ + ':' + (this.nextId_++).toString(36);
61
};
62
63