toolbarcolormenubuttonrenderer.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2008 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 toolbar-style renderer for {@link goog.ui.ColorMenuButton}.
  16. *
  17. * @author attila@google.com (Attila Bodis)
  18. */
  19. goog.provide('goog.ui.ToolbarColorMenuButtonRenderer');
  20. goog.require('goog.asserts');
  21. goog.require('goog.dom.classlist');
  22. goog.require('goog.ui.ColorMenuButtonRenderer');
  23. goog.require('goog.ui.MenuButtonRenderer');
  24. goog.require('goog.ui.ToolbarMenuButtonRenderer');
  25. /**
  26. * Toolbar-style renderer for {@link goog.ui.ColorMenuButton}s.
  27. * @constructor
  28. * @extends {goog.ui.ToolbarMenuButtonRenderer}
  29. * @final
  30. */
  31. goog.ui.ToolbarColorMenuButtonRenderer = function() {
  32. goog.ui.ToolbarMenuButtonRenderer.call(this);
  33. };
  34. goog.inherits(
  35. goog.ui.ToolbarColorMenuButtonRenderer, goog.ui.ToolbarMenuButtonRenderer);
  36. goog.addSingletonGetter(goog.ui.ToolbarColorMenuButtonRenderer);
  37. /**
  38. * Overrides the superclass implementation by wrapping the caption text or DOM
  39. * structure in a color indicator element. Creates the following DOM structure:
  40. *
  41. * <div class="goog-inline-block goog-toolbar-menu-button-caption">
  42. * <div class="goog-color-menu-button-indicator">
  43. * Contents...
  44. * </div>
  45. * </div>
  46. *
  47. * @param {goog.ui.ControlContent} content Text caption or DOM structure.
  48. * @param {goog.dom.DomHelper} dom DOM helper, used for document interaction.
  49. * @return {!Element} Caption element.
  50. * @see goog.ui.ToolbarColorMenuButtonRenderer#createColorIndicator
  51. * @override
  52. */
  53. goog.ui.ToolbarColorMenuButtonRenderer.prototype.createCaption = function(
  54. content, dom) {
  55. return goog.ui.MenuButtonRenderer.wrapCaption(
  56. goog.ui.ColorMenuButtonRenderer.wrapCaption(content, dom),
  57. this.getCssClass(), dom);
  58. };
  59. /**
  60. * Takes a color menu button control's root element and a value object
  61. * (which is assumed to be a color), and updates the button's DOM to reflect
  62. * the new color. Overrides {@link goog.ui.ButtonRenderer#setValue}.
  63. * @param {Element} element The button control's root element (if rendered).
  64. * @param {*} value New value; assumed to be a color spec string.
  65. * @override
  66. */
  67. goog.ui.ToolbarColorMenuButtonRenderer.prototype.setValue = function(
  68. element, value) {
  69. if (element) {
  70. goog.ui.ColorMenuButtonRenderer.setCaptionValue(
  71. this.getContentElement(element), value);
  72. }
  73. };
  74. /**
  75. * Initializes the button's DOM when it enters the document. Overrides the
  76. * superclass implementation by making sure the button's color indicator is
  77. * initialized.
  78. * @param {goog.ui.Control} button goog.ui.ColorMenuButton whose DOM is to be
  79. * initialized as it enters the document.
  80. * @override
  81. */
  82. goog.ui.ToolbarColorMenuButtonRenderer.prototype.initializeDom = function(
  83. button) {
  84. this.setValue(button.getElement(), button.getValue());
  85. goog.dom.classlist.add(
  86. goog.asserts.assert(button.getElement()),
  87. goog.getCssName('goog-toolbar-color-menu-button'));
  88. goog.ui.ToolbarColorMenuButtonRenderer.superClass_.initializeDom.call(
  89. this, button);
  90. };