API Docs for: 3.10.3
Show:

File: classnamemanager/js/classnamemanager.js

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