Debian Codegraph @

closure-library/closure/goog/ui/toolbarcolormenubuttonrenderer.js

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