/loggerhead/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerhead/trunk

« back to all changes in this revision

Viewing changes to loggerhead/static/javascript/yui/build/classnamemanager/classnamemanager.js

  • Committer: Colin Watson
  • Date: 2020-06-08 09:55:03 UTC
  • mfrom: (498.2.2 jquery)
  • Revision ID: cjwatson@canonical.com-20200608095503-n387xggxud2khqsw
[r=cjwatson] Port loggerhead from YUI to jQuery.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3
 
Code licensed under the BSD License:
4
 
http://developer.yahoo.net/yui/license.txt
5
 
version: 3.0.0pr2
6
 
*/
7
 
YUI.add('classnamemanager', function(Y) {
8
 
 
9
 
/**
10
 
* Contains a singleton (ClassNameManager) that enables easy creation and caching of 
11
 
* prefixed class names.
12
 
* @module classnamemanager
13
 
*/
14
 
 
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
 
 */
26
 
 
27
 
// String constants
28
 
var CLASS_NAME_PREFIX = 'classNamePrefix',
29
 
        CLASS_NAME_DELIMITER = 'classNameDelimiter';
30
 
 
31
 
 
32
 
// Global config
33
 
 
34
 
/**
35
 
 * Configuration property indicating the prefix for all CSS class names in this YUI instance.
36
 
 *
37
 
 * @property Y.config.classNamePrefix
38
 
 * @type {String}
39
 
 * @default "yui"
40
 
 * @static
41
 
 */
42
 
Y.config[CLASS_NAME_PREFIX] = Y.config[CLASS_NAME_PREFIX] || 'yui';
43
 
 
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
 
Y.config[CLASS_NAME_DELIMITER] = Y.config[CLASS_NAME_DELIMITER] || '-';
55
 
 
56
 
 
57
 
Y.ClassNameManager = function () {
58
 
 
59
 
        var sPrefix = Y.config[CLASS_NAME_PREFIX],
60
 
                sDelimiter = Y.config[CLASS_NAME_DELIMITER],
61
 
                classNames = {};
62
 
 
63
 
        return {
64
 
 
65
 
                /**
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
70
 
                 * 
71
 
                 * 
72
 
                 * @method getClassName
73
 
                 * @param {String}+ one or more classname bits to be joined and prefixed
74
 
                 */
75
 
                getClassName: function (c,x) {
76
 
        
77
 
                        // Test for multiple classname bits
78
 
                        if (x) {
79
 
                                c = Y.Array(arguments,0,true).join(sDelimiter);
80
 
                        }
81
 
                
82
 
                        // memoize in classNames map
83
 
                        return classNames[c] || (classNames[c] = sPrefix + sDelimiter + c);
84
 
        
85
 
                }
86
 
        
87
 
        };
88
 
 
89
 
}();
90
 
 
91
 
 
92
 
}, '3.0.0pr2' );