Layout.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 Layout.js
  7. * License MIT
  8. * --------------------------------------------
  9. */
  10. var Layout = function ($) {
  11. 'use strict';
  12. /**
  13. * Constants
  14. * ====================================================
  15. */
  16. var NAME = 'Layout';
  17. var DATA_KEY = 'lte.layout';
  18. var EVENT_KEY = '.' + DATA_KEY;
  19. var JQUERY_NO_CONFLICT = $.fn[NAME];
  20. var Event = {
  21. SIDEBAR: 'sidebar'
  22. };
  23. var Selector = {
  24. SIDEBAR: '.main-sidebar',
  25. HEADER: '.main-header',
  26. CONTENT: '.content-wrapper',
  27. CONTENT_HEADER: '.content-header',
  28. WRAPPER: '.wrapper',
  29. CONTROL_SIDEBAR: '.control-sidebar',
  30. LAYOUT_FIXED: '.layout-fixed',
  31. FOOTER: '.main-footer'
  32. };
  33. var ClassName = {
  34. HOLD: 'hold-transition',
  35. SIDEBAR: 'main-sidebar',
  36. LAYOUT_FIXED: 'layout-fixed'
  37. };
  38. /**
  39. * Class Definition
  40. * ====================================================
  41. */
  42. var Layout = function () {
  43. function Layout(element) {
  44. _classCallCheck(this, Layout);
  45. this._element = element;
  46. this._init();
  47. }
  48. // Public
  49. _createClass(Layout, [{
  50. key: 'fixLayoutHeight',
  51. value: function fixLayoutHeight() {
  52. var heights = [$(window).height(), $(Selector.HEADER).outerHeight(), $(Selector.FOOTER).outerHeight(), $(Selector.SIDEBAR).height()],
  53. max = this._max(heights);
  54. $(Selector.CONTENT).css('min-height', max - (heights[1] + heights[2]));
  55. }
  56. // Private
  57. }, {
  58. key: '_init',
  59. value: function _init() {
  60. var _this = this;
  61. // Enable transitions
  62. $('body').removeClass(ClassName.HOLD);
  63. // Activate layout height watcher
  64. this.fixLayoutHeight();
  65. $(Selector.SIDEBAR).on('collapsed.lte.treeview expanded.lte.treeview collapsed.lte.pushmenu expanded.lte.pushmenu', function () {
  66. _this.fixLayoutHeight();
  67. });
  68. $(window).resize(function () {
  69. _this.fixLayoutHeight();
  70. });
  71. }
  72. }, {
  73. key: '_max',
  74. value: function _max(numbers) {
  75. // Calculate the maximum number in a list
  76. var max = 0;
  77. numbers.forEach(function (v) {
  78. if (v > max) {
  79. max = v;
  80. }
  81. });
  82. return max;
  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 Layout(this);
  92. $(this).data(DATA_KEY, data);
  93. }
  94. if (operation) {
  95. data[operation]();
  96. }
  97. });
  98. }
  99. }]);
  100. return Layout;
  101. }();
  102. /**
  103. * jQuery API
  104. * ====================================================
  105. */
  106. $.fn[NAME] = Layout._jQueryInterface;
  107. $.fn[NAME].Constructor = Layout;
  108. $.fn[NAME].noConflict = function () {
  109. $.fn[NAME] = JQUERY_NO_CONFLICT;
  110. return Layout._jQueryInterface;
  111. };
  112. return Layout;
  113. }(jQuery);
  114. //# sourceMappingURL=Layout.js.map