1 // Copyright 2008 The Closure Library Authors. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
16 * @fileoverview Renderer for {@link goog.ui.MenuSeparator}s.
18 * @author attila@google.com (Attila Bodis)
21 goog.provide('goog.ui.MenuSeparatorRenderer');
23 goog.require('goog.dom');
24 goog.require('goog.dom.classes');
25 goog.require('goog.ui.ControlContent');
26 goog.require('goog.ui.ControlRenderer');
31 * Renderer for menu separators.
33 * @extends {goog.ui.ControlRenderer}
35 goog.ui.MenuSeparatorRenderer = function() {
36 goog.ui.ControlRenderer.call(this);
38 goog.inherits(goog.ui.MenuSeparatorRenderer, goog.ui.ControlRenderer);
39 goog.addSingletonGetter(goog.ui.MenuSeparatorRenderer);
43 * Default CSS class to be applied to the root element of components rendered
47 goog.ui.MenuSeparatorRenderer.CSS_CLASS = goog.getCssName('goog-menuseparator');
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.
57 goog.ui.MenuSeparatorRenderer.prototype.createDom = function(separator) {
58 return separator.getDomHelper().createDom('div', this.getCssClass());
63 * Takes an existing element, and decorates it with the separator. Overrides
64 * {@link goog.ui.ControlRenderer#decorate}.
65 * @param {goog.ui.Control} separator goog.ui.MenuSeparator to decorate the
67 * @param {Element} element Element to decorate.
68 * @return {Element} Decorated element.
71 goog.ui.MenuSeparatorRenderer.prototype.decorate = function(separator,
73 // Normally handled in the superclass. But we don't call the superclass.
75 separator.setId(element.id);
78 if (element.tagName == 'HR') {
79 // Replace HR with separator.
81 element = this.createDom(separator);
82 goog.dom.insertSiblingBefore(element, hr);
83 goog.dom.removeNode(hr);
85 goog.dom.classes.add(element, this.getCssClass());
92 * Overrides {@link goog.ui.ControlRenderer#setContent} to do nothing, since
93 * separators are empty.
94 * @param {Element} separator The separator's root element.
95 * @param {goog.ui.ControlContent} content Text caption or DOM structure to be
96 * set as the separators's content (ignored).
99 goog.ui.MenuSeparatorRenderer.prototype.setContent = function(separator,
101 // Do nothing. Separators are empty.
106 * Returns the CSS class to be applied to the root element of components
107 * rendered using this renderer.
108 * @return {string} Renderer-specific CSS class.
111 goog.ui.MenuSeparatorRenderer.prototype.getCssClass = function() {
112 return goog.ui.MenuSeparatorRenderer.CSS_CLASS;