Path: blob/trunk/third_party/closure/goog/ui/idgenerator.js
4135 views
/**1* @license2* Copyright The Closure Library Authors.3* SPDX-License-Identifier: Apache-2.04*/56/**7* @fileoverview Generator for unique element IDs.8*/910goog.provide('goog.ui.IdGenerator');11121314/**15* Creates a new id generator.16* @constructor17* @final18*/19goog.ui.IdGenerator = function() {};20goog.addSingletonGetter(goog.ui.IdGenerator);212223/**24* Next unique ID to use25* @type {number}26* @private27*/28goog.ui.IdGenerator.prototype.nextId_ = 0;293031/**32* Random ID prefix to help avoid collisions with other closure JavaScript on33* the same page that may initialize its own IdGenerator singleton.34* @type {string}35* @private36*/37goog.ui.IdGenerator.prototype.idPrefix_ = '';383940/**41* Sets the ID prefix for this singleton. This is a temporary workaround to be42* backwards compatible with code relying on the undocumented, but consistent,43* behavior. In the future this will be removed and the prefix will be set to44* a randomly generated string.45* @param {string} idPrefix46*/47goog.ui.IdGenerator.prototype.setIdPrefix = function(idPrefix) {48'use strict';49this.idPrefix_ = idPrefix;50};515253/**54* Gets the next unique ID.55* @return {string} The next unique identifier.56*/57goog.ui.IdGenerator.prototype.getNextUniqueId = function() {58'use strict';59return this.idPrefix_ + ':' + (this.nextId_++).toString(36);60};616263