Source: widgets/filters/button.js

  1. define('application/widgets/filters/button', [
  2. 'application/widgets/pointerfocusablebutton',
  3. 'rofl/widgets/label'
  4. ], function (
  5. Button,
  6. Label
  7. ) {
  8. 'use strict';
  9. return Button.extend({
  10. /**
  11. * Initialises the button.
  12. *
  13. * @param {Object} data - The filter data.
  14. */
  15. init: function init (data) {
  16. init.base.call(this, data.id);
  17. this.addClass(['filter']);
  18. if (data.classList) {
  19. this.addClass(data.classList);
  20. }
  21. if (data.isDropDown) {
  22. this.addClass('dropdown');
  23. }
  24. this._build(data);
  25. },
  26. /**
  27. * Builds the widget.
  28. *
  29. * @param {Object} data - The widget data.
  30. * @private
  31. */
  32. _build: function (data) {
  33. var label = this._label = new Label({ text: data.text || '' }),
  34. icon = new Label({ text: '', classNames: ['icon-chevron-down', 'icon'] }),
  35. helper = new Label({ text: '', classNames: ['v-align-helper'] });
  36. this.appendChildWidget(helper);
  37. this.appendChildWidget(label);
  38. if (data.isDropDown) {
  39. label.addClass('v-align-target');
  40. icon.addClass('v-align-target');
  41. this.appendChildWidget(icon);
  42. }
  43. },
  44. /**
  45. * Sets the text of the button.
  46. *
  47. * @param {string} text - The text to set.
  48. */
  49. setText: function (text) {
  50. this._label.setText(text);
  51. },
  52. /**
  53. * Sets icon on button.
  54. *
  55. * @param {string} icon - Icon.
  56. */
  57. setIcon: function (icon) {
  58. this._label.addClass(icon);
  59. this._label.addClass('icon-dropdown');
  60. if (this._iconClass && icon !== this._iconClass) {
  61. this._label.removeClass(this._iconClass);
  62. this._label.removeClass('icon-dropdown');
  63. }
  64. this._iconClass = icon;
  65. },
  66. /**
  67. * Returns the text.
  68. *
  69. * @returns {string} - The text.
  70. */
  71. getText: function () {
  72. return this._label.getText();
  73. }
  74. });
  75. });