AdminLTE/build/js/Layout.js

152 lines
3.3 KiB
JavaScript
Raw Normal View History

2016-01-16 17:27:23 +01:00
/**
* --------------------------------------------
* AdminLTE Layout.js
* License MIT
* --------------------------------------------
*/
const Layout = (($) => {
/**
* Constants
* ====================================================
*/
2017-01-03 16:42:20 +01:00
const NAME = 'Layout'
const DATA_KEY = 'lte.layout'
const EVENT_KEY = `.${DATA_KEY}`
2016-01-16 17:27:23 +01:00
const JQUERY_NO_CONFLICT = $.fn[NAME]
const Event = {
SIDEBAR: 'sidebar'
}
const Selector = {
2017-01-03 16:42:20 +01:00
HEADER : '.main-header',
2019-03-24 17:58:28 +01:00
SIDEBAR : '.main-sidebar .sidebar',
2017-01-03 16:42:20 +01:00
CONTENT : '.content-wrapper',
CONTENT_HEADER : '.content-header',
WRAPPER : '.wrapper',
2016-01-16 17:27:23 +01:00
CONTROL_SIDEBAR: '.control-sidebar',
2017-01-03 16:42:20 +01:00
LAYOUT_FIXED : '.layout-fixed',
FOOTER : '.main-footer'
2016-01-16 17:27:23 +01:00
}
const ClassName = {
2017-01-03 16:42:20 +01:00
HOLD : 'hold-transition',
SIDEBAR : 'main-sidebar',
2016-01-16 17:27:23 +01:00
LAYOUT_FIXED: 'layout-fixed'
}
/**
* Class Definition
* ====================================================
*/
class Layout {
constructor(element) {
this._element = element
this._init()
}
// Public
fixLayoutHeight() {
2018-03-17 18:07:55 +01:00
const heights = {
2019-03-24 17:58:28 +01:00
window : $(window).height(),
header : $(Selector.HEADER).outerHeight(),
footer : $(Selector.FOOTER).outerHeight(),
sidebar : $(Selector.SIDEBAR).height(),
2018-03-17 18:07:55 +01:00
}
2019-03-24 17:58:28 +01:00
const max = this._max(heights)
2016-10-15 19:18:29 +02:00
$(Selector.CONTENT).css('min-height', max - heights.header - heights.footer)
2018-03-17 18:07:55 +01:00
$(Selector.SIDEBAR).css('min-height', max - heights.header)
2019-03-24 17:58:28 +01:00
if (!$('body').hasClass(ClassName.LAYOUT_FIXED)) {
if (typeof $.fn.slimScroll !== 'undefined') {
$(Selector.SIDEBAR)
.slimScroll({ destroy: true })
.slimScroll({ height: max - heights.header });
}
}
2016-01-16 17:27:23 +01:00
}
// Private
_init() {
// Enable transitions
2016-01-16 17:27:23 +01:00
$('body').removeClass(ClassName.HOLD)
// Activate layout height watcher
2016-01-16 17:27:23 +01:00
this.fixLayoutHeight()
2018-03-17 18:07:55 +01:00
$(Selector.SIDEBAR)
.on('collapsed.lte.treeview expanded.lte.treeview collapsed.lte.pushmenu expanded.lte.pushmenu', () => {
this.fixLayoutHeight()
})
2019-03-24 18:15:36 +01:00
$(window).resize(() => {
2016-01-16 17:27:23 +01:00
this.fixLayoutHeight()
})
2016-10-22 21:32:28 +02:00
2018-02-04 00:45:19 +01:00
$('body, html').css('height', 'auto')
2016-01-16 17:27:23 +01:00
}
_max(numbers) {
// Calculate the maximum number in a list
2016-01-16 17:27:23 +01:00
let max = 0
2018-03-17 18:07:55 +01:00
Object.keys(numbers).forEach((key) => {
if (numbers[key] > max) {
max = numbers[key]
2016-01-16 17:27:23 +01:00
}
})
return max
}
// Static
static _jQueryInterface(operation) {
return this.each(function () {
2018-03-17 18:07:55 +01:00
let data = $(this)
.data(DATA_KEY)
2016-01-16 17:27:23 +01:00
if (!data) {
data = new Layout(this)
$(this).data(DATA_KEY, data)
}
if (operation) {
data[operation]()
}
})
}
}
/**
* Data API
* ====================================================
*/
$(window).on('load', () => {
Layout._jQueryInterface.call($('body'))
2018-02-04 00:45:19 +01:00
})
2016-01-16 17:27:23 +01:00
/**
* jQuery API
* ====================================================
*/
$.fn[NAME] = Layout._jQueryInterface
$.fn[NAME].Constructor = Layout
2019-03-24 17:58:28 +01:00
$.fn[NAME].noConflict = function () {
2016-01-16 17:27:23 +01:00
$.fn[NAME] = JQUERY_NO_CONFLICT
return Layout._jQueryInterface
}
return Layout
})(jQuery)
2018-02-04 00:45:19 +01:00
2019-03-24 17:58:28 +01:00
export default Layout