MDL-32843 import YUI 3.5.1
[moodle.git] / lib / yui / 3.5.1 / build / classnamemanager / classnamemanager.js
blobf0c4cebbe3112a3ca36bbe4403b2cd43410da615
1 /*
2 YUI 3.5.1 (build 22)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
7 YUI.add('classnamemanager', function(Y) {
9 /**
10 * Contains a singleton (ClassNameManager) that enables easy creation and caching of 
11 * prefixed class names.
12 * @module classnamemanager
15 /**
16  * A singleton class providing: 
17  * 
18  * <ul>
19  *    <li>Easy creation of prefixed class names</li>
20  *    <li>Caching of previously created class names for improved performance.</li>
21  * </ul>
22  * 
23  * @class ClassNameManager
24  * @static 
25  */
27 // String constants
28 var CLASS_NAME_PREFIX = 'classNamePrefix',
29         CLASS_NAME_DELIMITER = 'classNameDelimiter',
30     CONFIG = Y.config;
32 // Global config
34 /**
35  * Configuration property indicating the prefix for all CSS class names in this YUI instance.
36  *
37  * @property classNamePrefix
38  * @type {String}
39  * @default "yui"
40  * @static
41  */
42 CONFIG[CLASS_NAME_PREFIX] = CONFIG[CLASS_NAME_PREFIX] || 'yui3';
44 /**
45  * Configuration property indicating the delimiter used to compose all CSS class names in
46  * this YUI instance.
47  *
48  * @property classNameDelimiter
49  * @type {String}
50  * @default "-"
51  * @static
52  */
53 CONFIG[CLASS_NAME_DELIMITER] = CONFIG[CLASS_NAME_DELIMITER] || '-';
55 Y.ClassNameManager = function () {
57         var sPrefix    = CONFIG[CLASS_NAME_PREFIX],
58                 sDelimiter = CONFIG[CLASS_NAME_DELIMITER];
60         return {
62                 /**
63                  * Returns a class name prefixed with the the value of the 
64                  * <code>Y.config.classNamePrefix</code> attribute + the provided strings.
65                  * Uses the <code>Y.config.classNameDelimiter</code> attribute to delimit the 
66                  * provided strings. E.g. Y.ClassNameManager.getClassName('foo','bar'); // yui-foo-bar
67                  *
68                  * @method getClassName
69                  * @param {String}+ classnameSection one or more classname sections to be joined
70                  * @param {Boolean} skipPrefix If set to true, the classname will not be prefixed with the default Y.config.classNameDelimiter value.  
71                  */
72                 getClassName: Y.cached(function () {
74             var args = Y.Array(arguments);
76             if (args[args.length-1] !== true) {
77                 args.unshift(sPrefix);
78             } else {
79                 args.pop();
80             }
82                         return args.join(sDelimiter);
83                 })
85         };
87 }();
90 }, '3.5.1' ,{requires:['yui-base']});