separator.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2007 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview A class for representing a separator, with renderers for both
  16. * horizontal (menu) and vertical (toolbar) separators.
  17. *
  18. * @author attila@google.com (Attila Bodis)
  19. */
  20. goog.provide('goog.ui.Separator');
  21. goog.require('goog.a11y.aria');
  22. goog.require('goog.asserts');
  23. goog.require('goog.ui.Component');
  24. goog.require('goog.ui.Control');
  25. goog.require('goog.ui.MenuSeparatorRenderer');
  26. goog.require('goog.ui.registry');
  27. /**
  28. * Class representing a separator. Although it extends {@link goog.ui.Control},
  29. * the Separator class doesn't allocate any event handlers, nor does it change
  30. * its appearance on mouseover, etc.
  31. * @param {goog.ui.MenuSeparatorRenderer=} opt_renderer Renderer to render or
  32. * decorate the separator; defaults to {@link goog.ui.MenuSeparatorRenderer}.
  33. * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper, used for
  34. * document interaction.
  35. * @constructor
  36. * @extends {goog.ui.Control}
  37. */
  38. goog.ui.Separator = function(opt_renderer, opt_domHelper) {
  39. goog.ui.Control.call(
  40. this, null, opt_renderer || goog.ui.MenuSeparatorRenderer.getInstance(),
  41. opt_domHelper);
  42. this.setSupportedState(goog.ui.Component.State.DISABLED, false);
  43. this.setSupportedState(goog.ui.Component.State.HOVER, false);
  44. this.setSupportedState(goog.ui.Component.State.ACTIVE, false);
  45. this.setSupportedState(goog.ui.Component.State.FOCUSED, false);
  46. // Separators are always considered disabled.
  47. this.setStateInternal(goog.ui.Component.State.DISABLED);
  48. };
  49. goog.inherits(goog.ui.Separator, goog.ui.Control);
  50. /**
  51. * Configures the component after its DOM has been rendered. Overrides
  52. * {@link goog.ui.Control#enterDocument} by making sure no event handler
  53. * is allocated.
  54. * @override
  55. */
  56. goog.ui.Separator.prototype.enterDocument = function() {
  57. goog.ui.Separator.superClass_.enterDocument.call(this);
  58. var element = this.getElement();
  59. goog.asserts.assert(
  60. element, 'The DOM element for the separator cannot be null.');
  61. goog.a11y.aria.setRole(element, 'separator');
  62. };
  63. // Register a decorator factory function for goog.ui.MenuSeparators.
  64. goog.ui.registry.setDecoratorByClassName(
  65. goog.ui.MenuSeparatorRenderer.CSS_CLASS, function() {
  66. // Separator defaults to using MenuSeparatorRenderer.
  67. return new goog.ui.Separator();
  68. });