| 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 |
/** |
| 16 |
* @fileoverview A class for representing a separator, with renderers for both |
| 17 |
* horizontal (menu) and vertical (toolbar) separators. |
| 18 |
* |
| 19 |
* @author [email protected] (Attila Bodis) |
| 20 |
*/ |
| 21 |
|
| 22 |
goog.provide('goog.ui.Separator'); |
| 23 |
|
| 24 |
goog.require('goog.a11y.aria'); |
| 25 |
goog.require('goog.asserts'); |
| 26 |
goog.require('goog.ui.Component'); |
| 27 |
goog.require('goog.ui.Control'); |
| 28 |
goog.require('goog.ui.MenuSeparatorRenderer'); |
| 29 |
goog.require('goog.ui.registry'); |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
/** |
| 34 |
* Class representing a separator. Although it extends {@link goog.ui.Control}, |
| 35 |
* the Separator class doesn't allocate any event handlers, nor does it change |
| 36 |
* its appearance on mouseover, etc. |
| 37 |
* @param {goog.ui.MenuSeparatorRenderer=} opt_renderer Renderer to render or |
| 38 |
* decorate the separator; defaults to {@link goog.ui.MenuSeparatorRenderer}. |
| 39 |
* @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper, used for |
| 40 |
* document interaction. |
| 41 |
* @constructor |
| 42 |
* @extends {goog.ui.Control} |
| 43 |
*/ |
| 44 |
goog.ui.Separator = function(opt_renderer, opt_domHelper) { |
| 45 |
goog.ui.Control.call( |
| 46 |
this, null, opt_renderer || goog.ui.MenuSeparatorRenderer.getInstance(), |
| 47 |
opt_domHelper); |
| 48 |
|
| 49 |
this.setSupportedState(goog.ui.Component.State.DISABLED, false); |
| 50 |
this.setSupportedState(goog.ui.Component.State.HOVER, false); |
| 51 |
this.setSupportedState(goog.ui.Component.State.ACTIVE, false); |
| 52 |
this.setSupportedState(goog.ui.Component.State.FOCUSED, false); |
| 53 |
|
| 54 |
// Separators are always considered disabled. |
| 55 |
this.setStateInternal(goog.ui.Component.State.DISABLED); |
| 56 |
}; |
| 57 |
goog.inherits(goog.ui.Separator, goog.ui.Control); |
| 58 |
|
| 59 |
|
| 60 |
/** |
| 61 |
* Configures the component after its DOM has been rendered. Overrides |
| 62 |
* {@link goog.ui.Control#enterDocument} by making sure no event handler |
| 63 |
* is allocated. |
| 64 |
* @override |
| 65 |
*/ |
| 66 |
goog.ui.Separator.prototype.enterDocument = function() { |
| 67 |
goog.ui.Separator.superClass_.enterDocument.call(this); |
| 68 |
var element = this.getElement(); |
| 69 |
goog.asserts.assert( |
| 70 |
element, 'The DOM element for the separator cannot be null.'); |
| 71 |
goog.a11y.aria.setRole(element, 'separator'); |
| 72 |
}; |
| 73 |
|
| 74 |
|
| 75 |
// Register a decorator factory function for goog.ui.MenuSeparators. |
| 76 |
goog.ui.registry.setDecoratorByClassName( |
| 77 |
goog.ui.MenuSeparatorRenderer.CSS_CLASS, function() { |
| 78 |
// Separator defaults to using MenuSeparatorRenderer. |
| 79 |
return new goog.ui.Separator(); |
| 80 |
}); |