collapsible.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. /**
  6. * @api
  7. */
  8. define([
  9. 'uiComponent'
  10. ], function (Component) {
  11. 'use strict';
  12. return Component.extend({
  13. defaults: {
  14. opened: false,
  15. collapsible: true
  16. },
  17. /**
  18. * Initializes observable properties.
  19. *
  20. * @returns {Collapsible} Chainable.
  21. */
  22. initObservable: function () {
  23. this._super()
  24. .observe('opened');
  25. return this;
  26. },
  27. /**
  28. * Toggles value of the 'opened' property.
  29. *
  30. * @returns {Collapsible} Chainable.
  31. */
  32. toggleOpened: function () {
  33. this.opened() ?
  34. this.close() :
  35. this.open();
  36. return this;
  37. },
  38. /**
  39. * Sets 'opened' flag to false.
  40. *
  41. * @returns {Collapsible} Chainable.
  42. */
  43. close: function () {
  44. if (this.collapsible) {
  45. this.opened(false);
  46. }
  47. return this;
  48. },
  49. /**
  50. * Sets 'opened' flag to true.
  51. *
  52. * @returns {Collapsible} Chainable.
  53. */
  54. open: function () {
  55. if (this.collapsible) {
  56. this.opened(true);
  57. }
  58. return this;
  59. }
  60. });
  61. });