togglebutton.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 toggle button control. Extends {@link goog.ui.Button} by
  16. * providing checkbox-like semantics.
  17. *
  18. * @author attila@google.com (Attila Bodis)
  19. */
  20. goog.provide('goog.ui.ToggleButton');
  21. goog.require('goog.ui.Button');
  22. goog.require('goog.ui.Component');
  23. goog.require('goog.ui.CustomButtonRenderer');
  24. goog.require('goog.ui.registry');
  25. /**
  26. * A toggle button, with checkbox-like semantics. Rendered using
  27. * {@link goog.ui.CustomButtonRenderer} by default, though any
  28. * {@link goog.ui.ButtonRenderer} would work.
  29. *
  30. * @param {goog.ui.ControlContent} content Text caption or existing DOM
  31. * structure to display as the button's caption.
  32. * @param {goog.ui.ButtonRenderer=} opt_renderer Renderer used to render or
  33. * decorate the button; defaults to {@link goog.ui.CustomButtonRenderer}.
  34. * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper, used for
  35. * document interaction.
  36. * @constructor
  37. * @extends {goog.ui.Button}
  38. */
  39. goog.ui.ToggleButton = function(content, opt_renderer, opt_domHelper) {
  40. goog.ui.Button.call(
  41. this, content, opt_renderer || goog.ui.CustomButtonRenderer.getInstance(),
  42. opt_domHelper);
  43. this.setSupportedState(goog.ui.Component.State.CHECKED, true);
  44. };
  45. goog.inherits(goog.ui.ToggleButton, goog.ui.Button);
  46. // Register a decorator factory function for goog.ui.ToggleButtons.
  47. goog.ui.registry.setDecoratorByClassName(
  48. goog.getCssName('goog-toggle-button'), function() {
  49. // ToggleButton defaults to using CustomButtonRenderer.
  50. return new goog.ui.ToggleButton(null);
  51. });