ControlSidebar.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. // Show the control sidebar
  50. if (this._config.slide) {
  51. $('body').removeClass(ClassName.CONTROL_SIDEBAR_SLIDE);
  52. } else {
  53. $('body').removeClass(ClassName.CONTROL_SIDEBAR_OPEN);
  54. }
  55. }
  56. }, {
  57. key: 'collapse',
  58. value: function collapse() {
  59. // Collapse the control sidebar
  60. if (this._config.slide) {
  61. $('body').addClass(ClassName.CONTROL_SIDEBAR_SLIDE);
  62. } else {
  63. $('body').addClass(ClassName.CONTROL_SIDEBAR_OPEN);
  64. }
  65. }
  66. }, {
  67. key: 'toggle',
  68. value: function toggle() {
  69. if ($('body').hasClass(ClassName.CONTROL_SIDEBAR_OPEN) || $('body').hasClass(ClassName.CONTROL_SIDEBAR_SLIDE)) {
  70. // Open the control sidebar
  71. this.show();
  72. } else {
  73. // Close the control sidebar
  74. this.collapse();
  75. }
  76. }
  77. // Private
  78. }, {
  79. key: '_getConfig',
  80. value: function _getConfig(config) {
  81. return $.extend({}, Default, config);
  82. }
  83. // Static
  84. }], [{
  85. key: '_jQueryInterface',
  86. value: function _jQueryInterface(operation) {
  87. return this.each(function () {
  88. var data = $(this).data(DATA_KEY);
  89. if (!data) {
  90. data = new ControlSidebar(this, $(this).data());
  91. $(this).data(DATA_KEY, data);
  92. }
  93. if (data[operation] === undefined) {
  94. throw new Error(operation + ' is not a function');
  95. }
  96. data[operation]();
  97. });
  98. }
  99. }]);
  100. return ControlSidebar;
  101. }();
  102. /**
  103. *
  104. * Data Api implementation
  105. * ====================================================
  106. */
  107. $(document).on('click', Selector.DATA_TOGGLE, function (event) {
  108. event.preventDefault();
  109. ControlSidebar._jQueryInterface.call($(this), 'toggle');
  110. });
  111. /**
  112. * jQuery API
  113. * ====================================================
  114. */
  115. $.fn[NAME] = ControlSidebar._jQueryInterface;
  116. $.fn[NAME].Constructor = ControlSidebar;
  117. $.fn[NAME].noConflict = function () {
  118. $.fn[NAME] = JQUERY_NO_CONFLICT;
  119. return ControlSidebar._jQueryInterface;
  120. };
  121. return ControlSidebar;
  122. }(jQuery);
  123. //# sourceMappingURL=ControlSidebar.js.map