2016-01-16 16:27:23 +00:00
|
|
|
/**
|
|
|
|
* --------------------------------------------
|
|
|
|
* AdminLTE Layout.js
|
|
|
|
* License MIT
|
|
|
|
* --------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
const Layout = (($) => {
|
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
* ====================================================
|
|
|
|
*/
|
|
|
|
|
2017-01-03 15:42:20 +00:00
|
|
|
const NAME = 'Layout'
|
|
|
|
const DATA_KEY = 'lte.layout'
|
|
|
|
const EVENT_KEY = `.${DATA_KEY}`
|
2016-01-16 16:27:23 +00:00
|
|
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
|
|
|
|
|
|
|
const Event = {
|
|
|
|
SIDEBAR: 'sidebar'
|
|
|
|
}
|
|
|
|
|
|
|
|
const Selector = {
|
2017-01-03 15:42:20 +00:00
|
|
|
HEADER : '.main-header',
|
2019-06-26 13:58:53 +00:00
|
|
|
MAIN_SIDEBAR : '.main-sidebar',
|
2019-03-24 16:58:28 +00:00
|
|
|
SIDEBAR : '.main-sidebar .sidebar',
|
2017-01-03 15:42:20 +00:00
|
|
|
CONTENT : '.content-wrapper',
|
2019-06-05 11:34:15 +00:00
|
|
|
BRAND : '.brand-link',
|
2017-01-03 15:42:20 +00:00
|
|
|
CONTENT_HEADER : '.content-header',
|
|
|
|
WRAPPER : '.wrapper',
|
2016-01-16 16:27:23 +00:00
|
|
|
CONTROL_SIDEBAR: '.control-sidebar',
|
2019-11-22 09:23:17 +00:00
|
|
|
CONTROL_SIDEBAR_CONTENT: '.control-sidebar-content',
|
|
|
|
CONTROL_SIDEBAR_BTN: '[data-widget="control-sidebar"]',
|
2017-01-03 15:42:20 +00:00
|
|
|
LAYOUT_FIXED : '.layout-fixed',
|
2019-09-23 09:39:30 +00:00
|
|
|
FOOTER : '.main-footer',
|
2019-10-23 07:11:47 +00:00
|
|
|
PUSHMENU_BTN : '[data-widget="pushmenu"]',
|
2019-09-23 09:39:30 +00:00
|
|
|
LOGIN_BOX : '.login-box',
|
|
|
|
REGISTER_BOX : '.register-box'
|
2016-01-16 16:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const ClassName = {
|
2019-06-26 13:58:53 +00:00
|
|
|
HOLD : 'hold-transition',
|
|
|
|
SIDEBAR : 'main-sidebar',
|
|
|
|
CONTENT_FIXED : 'content-fixed',
|
|
|
|
SIDEBAR_FOCUSED: 'sidebar-focused',
|
|
|
|
LAYOUT_FIXED : 'layout-fixed',
|
|
|
|
NAVBAR_FIXED : 'layout-navbar-fixed',
|
|
|
|
FOOTER_FIXED : 'layout-footer-fixed',
|
2019-09-23 09:39:30 +00:00
|
|
|
LOGIN_PAGE : 'login-page',
|
|
|
|
REGISTER_PAGE : 'register-page',
|
2019-11-22 09:23:17 +00:00
|
|
|
CONTROL_SIDEBAR_SLIDE_OPEN: 'control-sidebar-slide-open',
|
|
|
|
CONTROL_SIDEBAR_OPEN: 'control-sidebar-open',
|
2019-06-05 11:34:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const Default = {
|
|
|
|
scrollbarTheme : 'os-theme-light',
|
2020-02-25 13:25:05 +00:00
|
|
|
scrollbarAutoHide: 'l',
|
2020-03-10 08:28:26 +00:00
|
|
|
panelAutoHeight: true,
|
2020-02-25 13:25:05 +00:00
|
|
|
loginRegisterAutoHeight: true,
|
2016-01-16 16:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Definition
|
|
|
|
* ====================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Layout {
|
2019-06-05 11:34:15 +00:00
|
|
|
constructor(element, config) {
|
|
|
|
this._config = config
|
2016-01-16 16:27:23 +00:00
|
|
|
this._element = element
|
|
|
|
|
|
|
|
this._init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Public
|
|
|
|
|
2019-11-22 09:23:17 +00:00
|
|
|
fixLayoutHeight(extra = null) {
|
|
|
|
let control_sidebar = 0
|
|
|
|
|
2020-04-01 11:49:55 +00:00
|
|
|
if ($('body').hasClass(ClassName.CONTROL_SIDEBAR_SLIDE_OPEN) || $('body').hasClass(ClassName.CONTROL_SIDEBAR_OPEN) || extra == 'control_sidebar') {
|
2019-11-22 09:23:17 +00:00
|
|
|
control_sidebar = $(Selector.CONTROL_SIDEBAR_CONTENT).height()
|
|
|
|
}
|
|
|
|
|
2018-03-17 17:07:55 +00:00
|
|
|
const heights = {
|
2019-09-03 10:36:55 +00:00
|
|
|
window: $(window).height(),
|
|
|
|
header: $(Selector.HEADER).length !== 0 ? $(Selector.HEADER).outerHeight() : 0,
|
|
|
|
footer: $(Selector.FOOTER).length !== 0 ? $(Selector.FOOTER).outerHeight() : 0,
|
|
|
|
sidebar: $(Selector.SIDEBAR).length !== 0 ? $(Selector.SIDEBAR).height() : 0,
|
2019-11-22 09:23:17 +00:00
|
|
|
control_sidebar: control_sidebar,
|
2018-03-17 17:07:55 +00:00
|
|
|
}
|
2019-06-05 11:34:15 +00:00
|
|
|
|
2019-03-24 16:58:28 +00:00
|
|
|
const max = this._max(heights)
|
2020-03-10 08:28:26 +00:00
|
|
|
let offset = this._config.panelAutoHeight
|
2016-10-15 17:18:29 +00:00
|
|
|
|
2020-04-01 11:49:55 +00:00
|
|
|
if (offset === true) {
|
2020-03-10 08:28:26 +00:00
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset !== false) {
|
|
|
|
if (max == heights.control_sidebar) {
|
|
|
|
$(Selector.CONTENT).css('min-height', (max + offset))
|
|
|
|
} else if (max == heights.window) {
|
|
|
|
$(Selector.CONTENT).css('min-height', (max + offset) - heights.header - heights.footer)
|
|
|
|
} else {
|
|
|
|
$(Selector.CONTENT).css('min-height', (max + offset) - heights.header)
|
|
|
|
}
|
2020-04-27 17:28:05 +00:00
|
|
|
if (this._isFooterFixed()) {
|
|
|
|
$(Selector.CONTENT).css('min-height', parseFloat($(Selector.CONTENT).css('min-height')) + heights.footer);
|
|
|
|
}
|
2019-10-16 06:34:07 +00:00
|
|
|
}
|
2019-10-12 09:36:52 +00:00
|
|
|
|
2019-06-05 11:34:15 +00:00
|
|
|
if ($('body').hasClass(ClassName.LAYOUT_FIXED)) {
|
2020-03-10 08:28:26 +00:00
|
|
|
if (offset !== false) {
|
|
|
|
$(Selector.CONTENT).css('min-height', (max + offset) - heights.header - heights.footer)
|
|
|
|
}
|
2019-10-12 09:36:52 +00:00
|
|
|
|
2019-06-05 11:34:15 +00:00
|
|
|
if (typeof $.fn.overlayScrollbars !== 'undefined') {
|
|
|
|
$(Selector.SIDEBAR).overlayScrollbars({
|
|
|
|
className : this._config.scrollbarTheme,
|
|
|
|
sizeAutoCapable : true,
|
|
|
|
scrollbars : {
|
|
|
|
autoHide: this._config.scrollbarAutoHide,
|
|
|
|
clickScrolling : true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2019-03-24 16:58:28 +00:00
|
|
|
}
|
2016-01-16 16:27:23 +00:00
|
|
|
}
|
|
|
|
|
2020-02-25 13:25:05 +00:00
|
|
|
fixLoginRegisterHeight() {
|
|
|
|
if ($(Selector.LOGIN_BOX + ', ' + Selector.REGISTER_BOX).length === 0) {
|
|
|
|
$('body, html').css('height', 'auto')
|
|
|
|
} else if ($(Selector.LOGIN_BOX + ', ' + Selector.REGISTER_BOX).length !== 0) {
|
|
|
|
let box_height = $(Selector.LOGIN_BOX + ', ' + Selector.REGISTER_BOX).height()
|
|
|
|
|
|
|
|
if ($('body').css('min-height') !== box_height) {
|
|
|
|
$('body').css('min-height', box_height)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-16 16:27:23 +00:00
|
|
|
// Private
|
|
|
|
|
|
|
|
_init() {
|
2016-10-19 15:24:30 +00:00
|
|
|
// Activate layout height watcher
|
2016-01-16 16:27:23 +00:00
|
|
|
this.fixLayoutHeight()
|
2020-02-25 13:25:05 +00:00
|
|
|
|
2020-04-27 17:28:05 +00:00
|
|
|
if (this._config.loginRegisterAutoHeight === true) {
|
2020-02-25 13:25:05 +00:00
|
|
|
this.fixLoginRegisterHeight()
|
2020-04-27 17:28:05 +00:00
|
|
|
} else if (Number.isInteger(this._config.loginRegisterAutoHeight)) {
|
2020-02-25 13:25:05 +00:00
|
|
|
setInterval(this.fixLoginRegisterHeight, this._config.loginRegisterAutoHeight);
|
|
|
|
}
|
|
|
|
|
2018-03-17 17:07:55 +00:00
|
|
|
$(Selector.SIDEBAR)
|
2019-10-23 07:11:47 +00:00
|
|
|
.on('collapsed.lte.treeview expanded.lte.treeview', () => {
|
|
|
|
this.fixLayoutHeight()
|
|
|
|
})
|
|
|
|
|
|
|
|
$(Selector.PUSHMENU_BTN)
|
|
|
|
.on('collapsed.lte.pushmenu shown.lte.pushmenu', () => {
|
2018-03-17 17:07:55 +00:00
|
|
|
this.fixLayoutHeight()
|
|
|
|
})
|
|
|
|
|
2019-11-22 09:23:17 +00:00
|
|
|
$(Selector.CONTROL_SIDEBAR_BTN)
|
|
|
|
.on('collapsed.lte.controlsidebar', () => {
|
|
|
|
this.fixLayoutHeight()
|
|
|
|
})
|
|
|
|
.on('expanded.lte.controlsidebar', () => {
|
|
|
|
this.fixLayoutHeight('control_sidebar')
|
|
|
|
})
|
|
|
|
|
2019-03-24 17:15:36 +00:00
|
|
|
$(window).resize(() => {
|
2016-01-16 16:27:23 +00:00
|
|
|
this.fixLayoutHeight()
|
|
|
|
})
|
2016-10-22 19:32:28 +00:00
|
|
|
|
2020-05-03 11:22:59 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
$('body.hold-transition').removeClass('hold-transition')
|
|
|
|
|
|
|
|
}, 50);
|
2016-01-16 16:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_max(numbers) {
|
2016-10-19 15:24:30 +00:00
|
|
|
// Calculate the maximum number in a list
|
2016-01-16 16:27:23 +00:00
|
|
|
let max = 0
|
|
|
|
|
2018-03-17 17:07:55 +00:00
|
|
|
Object.keys(numbers).forEach((key) => {
|
|
|
|
if (numbers[key] > max) {
|
|
|
|
max = numbers[key]
|
2016-01-16 16:27:23 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return max
|
|
|
|
}
|
|
|
|
|
2020-04-27 17:28:05 +00:00
|
|
|
_isFooterFixed() {
|
|
|
|
return $('.main-footer').css('position') === 'fixed';
|
|
|
|
}
|
|
|
|
|
2016-01-16 16:27:23 +00:00
|
|
|
// Static
|
|
|
|
|
2019-12-12 08:49:02 +00:00
|
|
|
static _jQueryInterface(config = '') {
|
2016-01-16 16:27:23 +00:00
|
|
|
return this.each(function () {
|
2019-11-17 10:53:47 +00:00
|
|
|
let data = $(this).data(DATA_KEY)
|
|
|
|
const _options = $.extend({}, Default, $(this).data())
|
2016-01-16 16:27:23 +00:00
|
|
|
|
|
|
|
if (!data) {
|
2019-11-17 10:53:47 +00:00
|
|
|
data = new Layout($(this), _options)
|
2016-01-16 16:27:23 +00:00
|
|
|
$(this).data(DATA_KEY, data)
|
|
|
|
}
|
|
|
|
|
2020-04-01 11:49:55 +00:00
|
|
|
if (config === 'init' || config === '') {
|
2019-12-12 08:49:02 +00:00
|
|
|
data['_init']()
|
2020-02-25 13:25:05 +00:00
|
|
|
} else if (config === 'fixLayoutHeight' || config === 'fixLoginRegisterHeight') {
|
|
|
|
data[config]()
|
2016-01-16 16:27:23 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-06 19:44:01 +00:00
|
|
|
/**
|
|
|
|
* Data API
|
|
|
|
* ====================================================
|
|
|
|
*/
|
2019-06-05 11:34:15 +00:00
|
|
|
|
2016-11-06 19:44:01 +00:00
|
|
|
$(window).on('load', () => {
|
|
|
|
Layout._jQueryInterface.call($('body'))
|
2018-02-03 23:45:19 +00:00
|
|
|
})
|
2016-11-06 19:44:01 +00:00
|
|
|
|
2019-06-27 08:43:40 +00:00
|
|
|
$(Selector.SIDEBAR + ' a').on('focusin', () => {
|
2019-06-26 13:58:53 +00:00
|
|
|
$(Selector.MAIN_SIDEBAR).addClass(ClassName.SIDEBAR_FOCUSED);
|
|
|
|
})
|
|
|
|
|
2019-06-27 08:43:40 +00:00
|
|
|
$(Selector.SIDEBAR + ' a').on('focusout', () => {
|
2019-06-26 13:58:53 +00:00
|
|
|
$(Selector.MAIN_SIDEBAR).removeClass(ClassName.SIDEBAR_FOCUSED);
|
|
|
|
})
|
|
|
|
|
2016-01-16 16:27:23 +00:00
|
|
|
/**
|
|
|
|
* jQuery API
|
|
|
|
* ====================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
$.fn[NAME] = Layout._jQueryInterface
|
|
|
|
$.fn[NAME].Constructor = Layout
|
2019-03-24 16:58:28 +00:00
|
|
|
$.fn[NAME].noConflict = function () {
|
2016-01-16 16:27:23 +00:00
|
|
|
$.fn[NAME] = JQUERY_NO_CONFLICT
|
|
|
|
return Layout._jQueryInterface
|
|
|
|
}
|
|
|
|
|
|
|
|
return Layout
|
|
|
|
})(jQuery)
|
2018-02-03 23:45:19 +00:00
|
|
|
|
2019-06-05 12:02:11 +00:00
|
|
|
export default Layout
|