classnamemanager.js revision 6af74f0f13ff81f220d9f945488e4f4c00c934f0
2N/A/**
2N/A* Contains a singleton (ClassNameManager) that enables easy creation and caching of
2N/A* prefixed class names.
2N/A* @module classnamemanager
2N/A*/
2N/A
2N/A/**
2N/A * A singleton class providing:
2N/A *
2N/A * <ul>
2N/A * <li>Easy creation of prefixed class names</li>
2N/A * <li>Caching of previously created class names for improved performance.</li>
2N/A * </ul>
2N/A *
2N/A * @class ClassNameManager
2N/A * @static
2N/A */
2N/A
2N/A// String constants
2N/Avar CLASS_NAME_PREFIX = 'classNamePrefix',
2N/A CLASS_NAME_DELIMITER = 'classNameDelimiter';
2N/A
2N/A
2N/A// Global config
2N/A
2N/A/**
2N/A * Configuration property indicating the prefix for all CSS class names in this YUI instance.
2N/A *
2N/A * @property Y.config.classNamePrefix
2N/A * @type {String}
2N/A * @default "yui"
2N/A * @static
2N/A */
2N/AY.config[CLASS_NAME_PREFIX] = Y.config[CLASS_NAME_PREFIX] || 'yui';
2N/A
2N/A
2N/A/**
2N/A * Configuration property indicating the delimiter used to compose all CSS class names in
2N/A * this YUI instance.
2N/A *
2N/A * @property Y.config.classNameDelimiter
2N/A * @type {String}
2N/A * @default "-"
2N/A * @static
2N/A */
2N/AY.config[CLASS_NAME_DELIMITER] = Y.config[CLASS_NAME_DELIMITER] || '-';
2N/A
2N/A
2N/AY.ClassNameManager = function () {
2N/A
2N/A var sPrefix = Y.config[CLASS_NAME_PREFIX],
2N/A sDelimiter = Y.config[CLASS_NAME_DELIMITER],
2N/A classNames = {};
2N/A
2N/A return {
2N/A
2N/A /**
2N/A * Returns a class name prefixed with the the value of the
2N/A * <code>Y.config.classNamePrefix</code> attribute + the provided strings.
2N/A * Uses the <code>Y.config.classNameDelimiter</code> attribute to delimit the
2N/A * provided strings. E.g. Y.ClassNameManager.getClassName('foo','bar'); // yui-foo-bar
2N/A *
2N/A *
2N/A * @method getClassName
2N/A * @param {String}+ one or more classname bits to be joined and prefixed
2N/A */
2N/A getClassName: function (c,x) {
2N/A
2N/A // Test for multiple classname bits
2N/A if (x) {
2N/A c = Y.Array(arguments,0,true).join(sDelimiter);
2N/A }
2N/A
2N/A // memoize in classNames map
2N/A return classNames[c] || (classNames[c] = sPrefix + sDelimiter + c);
2N/A
2N/A }
2N/A
2N/A };
2N/A
2N/A}();