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

185 lines
4.4 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 = {
HEADER : '.main-header',
MAIN_SIDEBAR : '.main-sidebar',
SIDEBAR : '.main-sidebar .sidebar',
CONTENT : '.content-wrapper',
BRAND : '.brand-link',
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',
CONTENT_FIXED : 'content-fixed',
SIDEBAR_FOCUSED: 'sidebar-focused',
LAYOUT_FIXED : 'layout-fixed',
NAVBAR_FIXED : 'layout-navbar-fixed',
FOOTER_FIXED : 'layout-footer-fixed',
}
const Default = {
scrollbarTheme : 'os-theme-light',
scrollbarAutoHide: 'l'
9 years ago
}
/**
* Class Definition
* ====================================================
*/
class Layout {
constructor(element, config) {
this._config = config
9 years ago
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)
if ($('body').hasClass(ClassName.LAYOUT_FIXED)) {
$(Selector.CONTENT).css('min-height', max - heights.header - heights.footer)
// $(Selector.SIDEBAR).css('min-height', max - heights.header)
if (typeof $.fn.overlayScrollbars !== 'undefined') {
$(Selector.SIDEBAR).overlayScrollbars({
className : this._config.scrollbarTheme,
sizeAutoCapable : true,
scrollbars : {
autoHide: this._config.scrollbarAutoHide,
clickScrolling : true
}
})
}
} else {
if (heights.window > heights.sidebar) {
$(Selector.CONTENT).css('min-height', heights.window - heights.header - heights.footer)
} else {
$(Selector.CONTENT).css('min-height', heights.sidebar - 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()
})
6 years ago
$(window).resize(() => {
9 years ago
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(config) {
9 years ago
return this.each(function () {
let data = $(this).data(DATA_KEY)
const _config = $.extend({}, Default, $(this).data())
9 years ago
if (!data) {
data = new Layout($(this), _config)
9 years ago
$(this).data(DATA_KEY, data)
}
if (config === 'init') {
data[config]()
9 years ago
}
})
}
}
/**
* Data API
* ====================================================
*/
$(window).on('load', () => {
Layout._jQueryInterface.call($('body'))
7 years ago
})
$(Selector.SIDEBAR + ' a').on('focusin', () => {
$(Selector.MAIN_SIDEBAR).addClass(ClassName.SIDEBAR_FOCUSED);
})
$(Selector.SIDEBAR + ' a').on('focusout', () => {
$(Selector.MAIN_SIDEBAR).removeClass(ClassName.SIDEBAR_FOCUSED);
})
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