ControlSidebar.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. 'use strict';
  2. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. /**
  5. * --------------------------------------------
  6. * AdminLTE ControlSidebar.js
  7. * License MIT
  8. * --------------------------------------------
  9. */
  10. var ControlSidebar = function ($) {
  11. 'use strict';
  12. /**
  13. * Constants
  14. * ====================================================
  15. */
  16. var NAME = 'ControlSidebar';
  17. var DATA_KEY = 'lte.control.sidebar';
  18. var EVENT_KEY = '.' + DATA_KEY;
  19. var JQUERY_NO_CONFLICT = $.fn[NAME];
  20. var DATA_API_KEY = '.data-api';
  21. var Event = {
  22. CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY
  23. };
  24. var Selector = {
  25. CONTROL_SIDEBAR: '.control-sidebar',
  26. DATA_TOGGLE: '[data-widget="control-sidebar"]'
  27. };
  28. var ClassName = {
  29. CONTROL_SIDEBAR_OPEN: 'control-sidebar-open',
  30. CONTROL_SIDEBAR_SLIDE: 'control-sidebar-slide-open'
  31. };
  32. var Default = {
  33. slide: true
  34. };
  35. /**
  36. * Class Definition
  37. * ====================================================
  38. */
  39. var ControlSidebar = function () {
  40. function ControlSidebar(element, config) {
  41. _classCallCheck(this, ControlSidebar);
  42. this._element = element;
  43. this._config = this._getConfig(config);
  44. }
  45. // Public
  46. _createClass(ControlSidebar, [{
  47. key: 'show',
  48. value: function show() {
  49. console.log('showing', this._config.slide);
  50. // Show the control sidebar
  51. if (this._config.slide) {
  52. $('body').removeClass(ClassName.CONTROL_SIDEBAR_SLIDE);
  53. } else {
  54. $('body').removeClass(ClassName.CONTROL_SIDEBAR_OPEN);
  55. }
  56. }
  57. }, {
  58. key: 'collapse',
  59. value: function collapse() {
  60. // Collapse the control sidebar
  61. if (this._config.slide) {
  62. $('body').addClass(ClassName.CONTROL_SIDEBAR_SLIDE);
  63. } else {
  64. $('body').addClass(ClassName.CONTROL_SIDEBAR_OPEN);
  65. }
  66. }
  67. }, {
  68. key: 'toggle',
  69. value: function toggle() {
  70. if ($('body').hasClass(ClassName.CONTROL_SIDEBAR_OPEN) || $('body').hasClass(ClassName.CONTROL_SIDEBAR_SLIDE)) {
  71. // Open the control sidebar
  72. this.show();
  73. } else {
  74. // Close the control sidebar
  75. this.collapse();
  76. }
  77. }
  78. // Private
  79. }, {
  80. key: '_getConfig',
  81. value: function _getConfig(config) {
  82. return $.extend({}, Default, config);
  83. }
  84. // Static
  85. }], [{
  86. key: '_jQueryInterface',
  87. value: function _jQueryInterface(operation) {
  88. return this.each(function () {
  89. var data = $(this).data(DATA_KEY);
  90. if (!data) {
  91. data = new ControlSidebar(this, $(this).data());
  92. $(this).data(DATA_KEY, data);
  93. }
  94. if (data[operation] === undefined) {
  95. throw new Error(operation + ' is not a function');
  96. }
  97. data[operation]();
  98. });
  99. }
  100. }]);
  101. return ControlSidebar;
  102. }();
  103. /**
  104. *
  105. * Data Api implementation
  106. * ====================================================
  107. */
  108. $(document).on('click', Selector.DATA_TOGGLE, function (event) {
  109. event.preventDefault();
  110. ControlSidebar._jQueryInterface.call($(this), 'toggle');
  111. });
  112. /**
  113. * jQuery API
  114. * ====================================================
  115. */
  116. $.fn[NAME] = ControlSidebar._jQueryInterface;
  117. $.fn[NAME].Constructor = ControlSidebar;
  118. $.fn[NAME].noConflict = function () {
  119. $.fn[NAME] = JQUERY_NO_CONFLICT;
  120. return ControlSidebar._jQueryInterface;
  121. };
  122. return ControlSidebar;
  123. }(jQuery);
  124. //# sourceMappingURL=ControlSidebar.js.map