Debian Codegraph @

closure-library/closure/goog/ui/menuseparatorrenderer.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 Renderer for {@link goog.ui.MenuSeparator}s.
17 *
18 * @author [email protected] (Attila Bodis)
19 */
20
21 goog.provide('goog.ui.MenuSeparatorRenderer');
22
23 goog.require('goog.dom');
24 goog.require('goog.dom.TagName');
25 goog.require('goog.dom.classlist');
26 goog.require('goog.ui.ControlRenderer');
27
28
29
30 /**
31 * Renderer for menu separators.
32 * @constructor
33 * @extends {goog.ui.ControlRenderer}
34 */
35 goog.ui.MenuSeparatorRenderer = function() {
36 goog.ui.ControlRenderer.call(this);
37 };
38 goog.inherits(goog.ui.MenuSeparatorRenderer, goog.ui.ControlRenderer);
39 goog.addSingletonGetter(goog.ui.MenuSeparatorRenderer);
40
41
42 /**
43 * Default CSS class to be applied to the root element of components rendered
44 * by this renderer.
45 * @type {string}
46 */
47 goog.ui.MenuSeparatorRenderer.CSS_CLASS = goog.getCssName('goog-menuseparator');
48
49
50 /**
51 * Returns an empty, styled menu separator DIV. Overrides {@link
52 * goog.ui.ControlRenderer#createDom}.
53 * @param {goog.ui.Control} separator goog.ui.Separator to render.
54 * @return {!Element} Root element for the separator.
55 * @override
56 */
57 goog.ui.MenuSeparatorRenderer.prototype.createDom = function(separator) {
58 return separator.getDomHelper().createDom(
59 goog.dom.TagName.DIV, this.getCssClass());
60 };
61
62
63 /**
64 * Takes an existing element, and decorates it with the separator. Overrides
65 * {@link goog.ui.ControlRenderer#decorate}.
66 * @param {goog.ui.Control} separator goog.ui.MenuSeparator to decorate the
67 * element.
68 * @param {Element} element Element to decorate.
69 * @return {!Element} Decorated element.
70 * @override
71 */
72 goog.ui.MenuSeparatorRenderer.prototype.decorate = function(
73 separator, element) {
74 // Normally handled in the superclass. But we don't call the superclass.
75 if (element.id) {
76 separator.setId(element.id);
77 }
78
79 if (element.tagName == goog.dom.TagName.HR) {
80 // Replace HR with separator.
81 var hr = element;
82 element = this.createDom(separator);
83 goog.dom.insertSiblingBefore(element, hr);
84 goog.dom.removeNode(hr);
85 } else {
86 goog.dom.classlist.add(element, this.getCssClass());
87 }
88 return element;
89 };
90
91
92 /**
93 * Overrides {@link goog.ui.ControlRenderer#setContent} to do nothing, since
94 * separators are empty.
95 * @param {Element} separator The separator's root element.
96 * @param {goog.ui.ControlContent} content Text caption or DOM structure to be
97 * set as the separators's content (ignored).
98 * @override
99 */
100 goog.ui.MenuSeparatorRenderer.prototype.setContent = function(
101 separator, content) {
102 // Do nothing. Separators are empty.
103 };
104
105
106 /**
107 * Returns the CSS class to be applied to the root element of components
108 * rendered using this renderer.
109 * @return {string} Renderer-specific CSS class.
110 * @override
111 */
112 goog.ui.MenuSeparatorRenderer.prototype.getCssClass = function() {
113 return goog.ui.MenuSeparatorRenderer.CSS_CLASS;
114 };