toolbarseparatorrenderer.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. * @fileoverview Renderer for toolbar separators.
  16. *
  17. * @author attila@google.com (Attila Bodis)
  18. */
  19. goog.provide('goog.ui.ToolbarSeparatorRenderer');
  20. goog.require('goog.asserts');
  21. goog.require('goog.dom.TagName');
  22. goog.require('goog.dom.classlist');
  23. goog.require('goog.ui.INLINE_BLOCK_CLASSNAME');
  24. goog.require('goog.ui.MenuSeparatorRenderer');
  25. /**
  26. * Renderer for toolbar separators.
  27. * @constructor
  28. * @extends {goog.ui.MenuSeparatorRenderer}
  29. */
  30. goog.ui.ToolbarSeparatorRenderer = function() {
  31. goog.ui.MenuSeparatorRenderer.call(this);
  32. };
  33. goog.inherits(goog.ui.ToolbarSeparatorRenderer, goog.ui.MenuSeparatorRenderer);
  34. goog.addSingletonGetter(goog.ui.ToolbarSeparatorRenderer);
  35. /**
  36. * Default CSS class to be applied to the root element of components rendered
  37. * by this renderer.
  38. * @type {string}
  39. */
  40. goog.ui.ToolbarSeparatorRenderer.CSS_CLASS =
  41. goog.getCssName('goog-toolbar-separator');
  42. /**
  43. * Returns a styled toolbar separator implemented by the following DOM:
  44. *
  45. * <div class="goog-toolbar-separator goog-inline-block">&nbsp;</div>
  46. *
  47. * Overrides {@link goog.ui.MenuSeparatorRenderer#createDom}.
  48. * @param {goog.ui.Control} separator goog.ui.Separator to render.
  49. * @return {!Element} Root element for the separator.
  50. * @override
  51. */
  52. goog.ui.ToolbarSeparatorRenderer.prototype.createDom = function(separator) {
  53. // 00A0 is &nbsp;
  54. return separator.getDomHelper().createDom(
  55. goog.dom.TagName.DIV, this.getClassNames(separator).join(' ') + ' ' +
  56. goog.ui.INLINE_BLOCK_CLASSNAME,
  57. '\u00A0');
  58. };
  59. /**
  60. * Takes an existing element, and decorates it with the separator. Overrides
  61. * {@link goog.ui.MenuSeparatorRenderer#decorate}.
  62. * @param {goog.ui.Control} separator goog.ui.Separator to decorate the element.
  63. * @param {Element} element Element to decorate.
  64. * @return {!Element} Decorated element.
  65. * @override
  66. */
  67. goog.ui.ToolbarSeparatorRenderer.prototype.decorate = function(
  68. separator, element) {
  69. element = goog.ui.ToolbarSeparatorRenderer.superClass_.decorate.call(
  70. this, separator, element);
  71. goog.asserts.assert(element);
  72. goog.dom.classlist.add(element, goog.ui.INLINE_BLOCK_CLASSNAME);
  73. return element;
  74. };
  75. /**
  76. * Returns the CSS class to be applied to the root element of components
  77. * rendered using this renderer.
  78. * @return {string} Renderer-specific CSS class.
  79. * @override
  80. */
  81. goog.ui.ToolbarSeparatorRenderer.prototype.getCssClass = function() {
  82. return goog.ui.ToolbarSeparatorRenderer.CSS_CLASS;
  83. };