]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/classnamemanager/classnamemanager.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / classnamemanager / classnamemanager.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('classnamemanager', function(Y) {
9
10 /**
11 * Contains a singleton (ClassNameManager) that enables easy creation and caching of 
12 * prefixed class names.
13 * @module classnamemanager
14 */
15
16 /**
17  * A singleton class providing: 
18  * 
19  * <ul>
20  *    <li>Easy creation of prefixed class names</li>
21  *    <li>Caching of previously created class names for improved performance.</li>
22  * </ul>
23  * 
24  * @class ClassNameManager
25  * @static 
26  */
27
28 // String constants
29 var CLASS_NAME_PREFIX = 'classNamePrefix',
30         CLASS_NAME_DELIMITER = 'classNameDelimiter',
31     CONFIG = Y.config;
32
33 // Global config
34
35 /**
36  * Configuration property indicating the prefix for all CSS class names in this YUI instance.
37  *
38  * @property Y.config.classNamePrefix
39  * @type {String}
40  * @default "yui"
41  * @static
42  */
43 CONFIG[CLASS_NAME_PREFIX] = CONFIG[CLASS_NAME_PREFIX] || 'yui3';
44
45 /**
46  * Configuration property indicating the delimiter used to compose all CSS class names in
47  * this YUI instance.
48  *
49  * @property Y.config.classNameDelimiter
50  * @type {String}
51  * @default "-"
52  * @static
53  */
54 CONFIG[CLASS_NAME_DELIMITER] = CONFIG[CLASS_NAME_DELIMITER] || '-';
55
56 Y.ClassNameManager = function () {
57
58         var sPrefix    = CONFIG[CLASS_NAME_PREFIX],
59                 sDelimiter = CONFIG[CLASS_NAME_DELIMITER];
60
61         return {
62
63                 /**
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
68                  *
69                  * @method getClassName
70                  * @param {String}+ classnameSection one or more classname sections to be joined
71                  * @param {Boolean} skipPrefix If set to true, the classname will not be prefixed with the default Y.config.classNameDelimiter value.  
72                  */
73                 getClassName: Y.cached(function () {
74
75             var args = Y.Array(arguments);
76
77             if (args[args.length-1] !== true) {
78                 args.unshift(sPrefix);
79             } else {
80                 args.pop();
81             }
82
83                         return args.join(sDelimiter);
84                 })
85
86         };
87
88 }();
89
90
91 }, '3.3.0' );