2
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.net/yui/license.txt
8
YUI.add('classnamemanager', function(Y) {
11
* Contains a singleton (ClassNameManager) that enables easy creation and caching of
12
* prefixed class names.
13
* @module classnamemanager
17
* A singleton class providing:
20
* <li>Easy creation of prefixed class names</li>
21
* <li>Caching of previously created class names for improved performance.</li>
24
* @class ClassNameManager
29
var CLASS_NAME_PREFIX = 'classNamePrefix',
30
CLASS_NAME_DELIMITER = 'classNameDelimiter',
36
* Configuration property indicating the prefix for all CSS class names in this YUI instance.
38
* @property Y.config.classNamePrefix
43
CONFIG[CLASS_NAME_PREFIX] = CONFIG[CLASS_NAME_PREFIX] || 'yui';
46
* Configuration property indicating the delimiter used to compose all CSS class names in
49
* @property Y.config.classNameDelimiter
54
CONFIG[CLASS_NAME_DELIMITER] = CONFIG[CLASS_NAME_DELIMITER] || '-';
56
Y.ClassNameManager = function () {
58
var sPrefix = CONFIG[CLASS_NAME_PREFIX],
59
sDelimiter = CONFIG[CLASS_NAME_DELIMITER];
64
* Returns a class name prefixed with the the value of the
65
* <code>Y.config.classNamePrefix</code> attribute + the provided strings.
66
* Uses the <code>Y.config.classNameDelimiter</code> attribute to delimit the
67
* provided strings. E.g. Y.ClassNameManager.getClassName('foo','bar'); // yui-foo-bar
69
* @method getClassName
70
* @param {String}+ one or more classname bits to be joined and prefixed
72
getClassName: Y.cached(function (c, x) {
74
var sClass = sPrefix + sDelimiter +
75
// ((x) ? Y.Array(arguments, 0, true).join(sDelimiter) : c);
76
((x) ? Array.prototype.join.call(arguments, sDelimiter) : c);
78
return sClass.replace(/\s/g, '');