2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.net/yui/license.txt
7
YUI.add('classnamemanager', function(Y) {
10
* Contains a singleton (ClassNameManager) that enables easy creation and caching of
11
* prefixed class names.
12
* @module classnamemanager
16
* A singleton class providing:
19
* <li>Easy creation of prefixed class names</li>
20
* <li>Caching of previously created class names for improved performance.</li>
23
* @class ClassNameManager
28
var CLASS_NAME_PREFIX = 'classNamePrefix',
29
CLASS_NAME_DELIMITER = 'classNameDelimiter';
35
* Configuration property indicating the prefix for all CSS class names in this YUI instance.
37
* @property Y.config.classNamePrefix
42
Y.config[CLASS_NAME_PREFIX] = Y.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
Y.config[CLASS_NAME_DELIMITER] = Y.config[CLASS_NAME_DELIMITER] || '-';
57
Y.ClassNameManager = function () {
59
var sPrefix = Y.config[CLASS_NAME_PREFIX],
60
sDelimiter = Y.config[CLASS_NAME_DELIMITER],
66
* Returns a class name prefixed with the the value of the
67
* <code>Y.config.classNamePrefix</code> attribute + the provided strings.
68
* Uses the <code>Y.config.classNameDelimiter</code> attribute to delimit the
69
* provided strings. E.g. Y.ClassNameManager.getClassName('foo','bar'); // yui-foo-bar
72
* @method getClassName
73
* @param {String}+ one or more classname bits to be joined and prefixed
75
getClassName: function (c,x) {
77
// Test for multiple classname bits
79
c = Y.Array(arguments,0,true).join(sDelimiter);
82
// memoize in classNames map
83
return classNames[c] || (classNames[c] = sPrefix + sDelimiter + c);