You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AdminLTE/build/js/Layout.js

143 lines
3.0 KiB

9 years ago
/**
* --------------------------------------------
* AdminLTE Layout.js
* License MIT
* --------------------------------------------
*/
const Layout = (($) => {
/**
* Constants
* ====================================================
*/
const NAME = 'Layout'
const DATA_KEY = 'lte.layout'
const EVENT_KEY = `.${DATA_KEY}`
9 years ago
const JQUERY_NO_CONFLICT = $.fn[NAME]
const Event = {
SIDEBAR: 'sidebar'
}
const Selector = {
SIDEBAR : '.main-sidebar',
HEADER : '.main-header',
CONTENT : '.content-wrapper',
CONTENT_HEADER : '.content-header',
WRAPPER : '.wrapper',
9 years ago
CONTROL_SIDEBAR: '.control-sidebar',
LAYOUT_FIXED : '.layout-fixed',
FOOTER : '.main-footer'
9 years ago
}
const ClassName = {
HOLD : 'hold-transition',
SIDEBAR : 'main-sidebar',
9 years ago
LAYOUT_FIXED: 'layout-fixed'
}
/**
* Class Definition
* ====================================================
*/
class Layout {
constructor(element) {
this._element = element
this._init()
}
// Public
fixLayoutHeight() {
7 years ago
const heights = {
window : $(window).height(),
header : $(Selector.HEADER).outerHeight(),
footer : $(Selector.FOOTER).outerHeight(),
sidebar: $(Selector.SIDEBAR).height()
}
7 years ago
const max = this._max(heights)
$(Selector.CONTENT).css('min-height', max - heights.header - heights.footer)
7 years ago
$(Selector.SIDEBAR).css('min-height', max - heights.header)
9 years ago
}
// Private
_init() {
// Enable transitions
9 years ago
$('body').removeClass(ClassName.HOLD)
// Activate layout height watcher
9 years ago
this.fixLayoutHeight()
7 years ago
$(Selector.SIDEBAR)
.on('collapsed.lte.treeview expanded.lte.treeview collapsed.lte.pushmenu expanded.lte.pushmenu', () => {
this.fixLayoutHeight()
})
9 years ago
$(window).resize(() => {
this.fixLayoutHeight()
})
7 years ago
$('body, html').css('height', 'auto')
9 years ago
}
_max(numbers) {
// Calculate the maximum number in a list
9 years ago
let max = 0
7 years ago
Object.keys(numbers).forEach((key) => {
if (numbers[key] > max) {
max = numbers[key]
9 years ago
}
})
return max
}
// Static
static _jQueryInterface(operation) {
return this.each(function () {
7 years ago
let data = $(this)
.data(DATA_KEY)
9 years ago
if (!data) {
data = new Layout(this)
$(this).data(DATA_KEY, data)
}
if (operation) {
data[operation]()
}
})
}
}
/**
* Data API
* ====================================================
*/
$(window).on('load', () => {
Layout._jQueryInterface.call($('body'))
7 years ago
})
9 years ago
/**
* jQuery API
* ====================================================
*/
$.fn[NAME] = Layout._jQueryInterface
$.fn[NAME].Constructor = Layout
$.fn[NAME].noConflict = function () {
9 years ago
$.fn[NAME] = JQUERY_NO_CONFLICT
return Layout._jQueryInterface
}
return Layout
})(jQuery)
7 years ago
export default Layout