2016-10-19 15:23:34 +00:00
|
|
|
/**
|
|
|
|
* --------------------------------------------
|
|
|
|
* AdminLTE ControlSidebar.js
|
|
|
|
* License MIT
|
|
|
|
* --------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
import $ from 'jquery'
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
* ====================================================
|
|
|
|
*/
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
const NAME = 'ControlSidebar'
|
|
|
|
const DATA_KEY = 'lte.controlsidebar'
|
|
|
|
const EVENT_KEY = `.${DATA_KEY}`
|
|
|
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
|
|
|
|
2020-06-11 12:34:44 +00:00
|
|
|
const EVENT_COLLAPSED = `collapsed${EVENT_KEY}`
|
|
|
|
const EVENT_EXPANDED = `expanded${EVENT_KEY}`
|
|
|
|
|
|
|
|
const SELECTOR_CONTROL_SIDEBAR = '.control-sidebar'
|
|
|
|
const SELECTOR_CONTROL_SIDEBAR_CONTENT = '.control-sidebar-content'
|
|
|
|
const SELECTOR_DATA_TOGGLE = '[data-widget="control-sidebar"]'
|
|
|
|
const SELECTOR_HEADER = '.main-header'
|
|
|
|
const SELECTOR_FOOTER = '.main-footer'
|
|
|
|
|
|
|
|
const CLASS_NAME_CONTROL_SIDEBAR_ANIMATE = 'control-sidebar-animate'
|
|
|
|
const CLASS_NAME_CONTROL_SIDEBAR_OPEN = 'control-sidebar-open'
|
|
|
|
const CLASS_NAME_CONTROL_SIDEBAR_SLIDE = 'control-sidebar-slide-open'
|
|
|
|
const CLASS_NAME_LAYOUT_FIXED = 'layout-fixed'
|
|
|
|
const CLASS_NAME_NAVBAR_FIXED = 'layout-navbar-fixed'
|
|
|
|
const CLASS_NAME_NAVBAR_SM_FIXED = 'layout-sm-navbar-fixed'
|
|
|
|
const CLASS_NAME_NAVBAR_MD_FIXED = 'layout-md-navbar-fixed'
|
|
|
|
const CLASS_NAME_NAVBAR_LG_FIXED = 'layout-lg-navbar-fixed'
|
|
|
|
const CLASS_NAME_NAVBAR_XL_FIXED = 'layout-xl-navbar-fixed'
|
|
|
|
const CLASS_NAME_FOOTER_FIXED = 'layout-footer-fixed'
|
|
|
|
const CLASS_NAME_FOOTER_SM_FIXED = 'layout-sm-footer-fixed'
|
|
|
|
const CLASS_NAME_FOOTER_MD_FIXED = 'layout-md-footer-fixed'
|
|
|
|
const CLASS_NAME_FOOTER_LG_FIXED = 'layout-lg-footer-fixed'
|
|
|
|
const CLASS_NAME_FOOTER_XL_FIXED = 'layout-xl-footer-fixed'
|
2020-06-02 13:23:22 +00:00
|
|
|
|
|
|
|
const Default = {
|
|
|
|
controlsidebarSlide: true,
|
|
|
|
scrollbarTheme: 'os-theme-light',
|
2020-11-27 09:21:42 +00:00
|
|
|
scrollbarAutoHide: 'l',
|
|
|
|
target: SELECTOR_CONTROL_SIDEBAR
|
2020-06-02 13:23:22 +00:00
|
|
|
}
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
/**
|
|
|
|
* Class Definition
|
|
|
|
* ====================================================
|
|
|
|
*/
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
class ControlSidebar {
|
|
|
|
constructor(element, config) {
|
|
|
|
this._element = element
|
|
|
|
this._config = config
|
|
|
|
}
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
// Public
|
2019-08-30 09:45:07 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
collapse() {
|
2020-06-04 18:06:38 +00:00
|
|
|
const $body = $('body')
|
|
|
|
const $html = $('html')
|
2020-11-27 09:21:42 +00:00
|
|
|
const that = this
|
2020-06-04 18:06:38 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
// Show the control sidebar
|
|
|
|
if (this._config.controlsidebarSlide) {
|
2020-06-11 12:34:44 +00:00
|
|
|
$html.addClass(CLASS_NAME_CONTROL_SIDEBAR_ANIMATE)
|
|
|
|
$body.removeClass(CLASS_NAME_CONTROL_SIDEBAR_SLIDE).delay(300).queue(function () {
|
2020-11-27 09:21:42 +00:00
|
|
|
$(that._config.target).hide()
|
2020-06-11 12:34:44 +00:00
|
|
|
$html.removeClass(CLASS_NAME_CONTROL_SIDEBAR_ANIMATE)
|
2020-06-02 13:23:22 +00:00
|
|
|
$(this).dequeue()
|
|
|
|
})
|
|
|
|
} else {
|
2020-06-11 12:34:44 +00:00
|
|
|
$body.removeClass(CLASS_NAME_CONTROL_SIDEBAR_OPEN)
|
2016-10-19 15:23:34 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 12:34:44 +00:00
|
|
|
$(this._element).trigger($.Event(EVENT_COLLAPSED))
|
2020-06-02 13:23:22 +00:00
|
|
|
}
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
show() {
|
2020-06-04 18:06:38 +00:00
|
|
|
const $body = $('body')
|
|
|
|
const $html = $('html')
|
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
// Collapse the control sidebar
|
|
|
|
if (this._config.controlsidebarSlide) {
|
2020-06-11 12:34:44 +00:00
|
|
|
$html.addClass(CLASS_NAME_CONTROL_SIDEBAR_ANIMATE)
|
2020-11-27 09:21:42 +00:00
|
|
|
$(this._config.target).show().delay(10).queue(function () {
|
2020-06-11 12:34:44 +00:00
|
|
|
$body.addClass(CLASS_NAME_CONTROL_SIDEBAR_SLIDE).delay(300).queue(function () {
|
|
|
|
$html.removeClass(CLASS_NAME_CONTROL_SIDEBAR_ANIMATE)
|
2019-07-10 14:02:33 +00:00
|
|
|
$(this).dequeue()
|
|
|
|
})
|
2020-06-02 13:23:22 +00:00
|
|
|
$(this).dequeue()
|
|
|
|
})
|
|
|
|
} else {
|
2020-06-11 12:34:44 +00:00
|
|
|
$body.addClass(CLASS_NAME_CONTROL_SIDEBAR_OPEN)
|
2016-10-19 15:23:34 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 22:39:07 +00:00
|
|
|
this._fixHeight()
|
|
|
|
this._fixScrollHeight()
|
|
|
|
|
2020-06-11 12:34:44 +00:00
|
|
|
$(this._element).trigger($.Event(EVENT_EXPANDED))
|
2020-06-02 13:23:22 +00:00
|
|
|
}
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
toggle() {
|
2020-06-04 18:06:38 +00:00
|
|
|
const $body = $('body')
|
2020-06-11 12:34:44 +00:00
|
|
|
const shouldClose = $body.hasClass(CLASS_NAME_CONTROL_SIDEBAR_OPEN) ||
|
|
|
|
$body.hasClass(CLASS_NAME_CONTROL_SIDEBAR_SLIDE)
|
2020-06-04 18:06:38 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
if (shouldClose) {
|
|
|
|
// Close the control sidebar
|
|
|
|
this.collapse()
|
|
|
|
} else {
|
|
|
|
// Open the control sidebar
|
|
|
|
this.show()
|
2016-10-19 15:23:34 +00:00
|
|
|
}
|
2020-06-02 13:23:22 +00:00
|
|
|
}
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
// Private
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
_init() {
|
2020-11-27 09:21:42 +00:00
|
|
|
const $body = $('body')
|
|
|
|
const shouldNotHideAll = $body.hasClass(CLASS_NAME_CONTROL_SIDEBAR_OPEN) ||
|
|
|
|
$body.hasClass(CLASS_NAME_CONTROL_SIDEBAR_SLIDE)
|
|
|
|
|
|
|
|
if (shouldNotHideAll) {
|
|
|
|
$(SELECTOR_CONTROL_SIDEBAR).not(this._config.target).hide()
|
|
|
|
$(this._config.target).css('display', 'block')
|
|
|
|
} else {
|
|
|
|
$(SELECTOR_CONTROL_SIDEBAR).hide()
|
|
|
|
}
|
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
this._fixHeight()
|
|
|
|
this._fixScrollHeight()
|
|
|
|
|
|
|
|
$(window).resize(() => {
|
2019-08-30 09:45:07 +00:00
|
|
|
this._fixHeight()
|
|
|
|
this._fixScrollHeight()
|
2020-06-02 13:23:22 +00:00
|
|
|
})
|
2019-08-30 09:45:07 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
$(window).scroll(() => {
|
2020-06-04 18:06:38 +00:00
|
|
|
const $body = $('body')
|
2020-06-11 12:34:44 +00:00
|
|
|
const shouldFixHeight = $body.hasClass(CLASS_NAME_CONTROL_SIDEBAR_OPEN) ||
|
|
|
|
$body.hasClass(CLASS_NAME_CONTROL_SIDEBAR_SLIDE)
|
2020-06-04 18:06:38 +00:00
|
|
|
|
2020-06-05 13:49:56 +00:00
|
|
|
if (shouldFixHeight) {
|
2019-08-30 09:45:07 +00:00
|
|
|
this._fixScrollHeight()
|
2020-06-02 13:23:22 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2019-08-30 09:45:07 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
_fixScrollHeight() {
|
2020-06-04 18:06:38 +00:00
|
|
|
const $body = $('body')
|
|
|
|
|
2020-06-11 12:34:44 +00:00
|
|
|
if (!$body.hasClass(CLASS_NAME_LAYOUT_FIXED)) {
|
2020-06-02 13:23:22 +00:00
|
|
|
return
|
2019-08-30 09:45:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
const heights = {
|
|
|
|
scroll: $(document).height(),
|
|
|
|
window: $(window).height(),
|
2020-06-11 12:34:44 +00:00
|
|
|
header: $(SELECTOR_HEADER).outerHeight(),
|
|
|
|
footer: $(SELECTOR_FOOTER).outerHeight()
|
2020-06-02 13:23:22 +00:00
|
|
|
}
|
|
|
|
const positions = {
|
|
|
|
bottom: Math.abs((heights.window + $(window).scrollTop()) - heights.scroll),
|
|
|
|
top: $(window).scrollTop()
|
|
|
|
}
|
2019-08-30 09:45:07 +00:00
|
|
|
|
2020-06-13 12:42:56 +00:00
|
|
|
const navbarFixed = (
|
2020-06-11 12:34:44 +00:00
|
|
|
$body.hasClass(CLASS_NAME_NAVBAR_FIXED) ||
|
|
|
|
$body.hasClass(CLASS_NAME_NAVBAR_SM_FIXED) ||
|
|
|
|
$body.hasClass(CLASS_NAME_NAVBAR_MD_FIXED) ||
|
|
|
|
$body.hasClass(CLASS_NAME_NAVBAR_LG_FIXED) ||
|
|
|
|
$body.hasClass(CLASS_NAME_NAVBAR_XL_FIXED)
|
2020-06-13 12:42:56 +00:00
|
|
|
) && $(SELECTOR_HEADER).css('position') === 'fixed'
|
2020-05-30 13:44:20 +00:00
|
|
|
|
2020-06-13 12:42:56 +00:00
|
|
|
const footerFixed = (
|
2020-06-11 12:34:44 +00:00
|
|
|
$body.hasClass(CLASS_NAME_FOOTER_FIXED) ||
|
|
|
|
$body.hasClass(CLASS_NAME_FOOTER_SM_FIXED) ||
|
|
|
|
$body.hasClass(CLASS_NAME_FOOTER_MD_FIXED) ||
|
|
|
|
$body.hasClass(CLASS_NAME_FOOTER_LG_FIXED) ||
|
|
|
|
$body.hasClass(CLASS_NAME_FOOTER_XL_FIXED)
|
2020-06-13 12:42:56 +00:00
|
|
|
) && $(SELECTOR_FOOTER).css('position') === 'fixed'
|
2019-08-30 09:45:07 +00:00
|
|
|
|
2020-11-27 09:21:42 +00:00
|
|
|
const $controlSidebar = $(this._config.target)
|
|
|
|
const $controlsidebarContent = $(`${this._config.target}, ${this._config.target} ${SELECTOR_CONTROL_SIDEBAR_CONTENT}`)
|
2020-06-04 18:06:38 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
if (positions.top === 0 && positions.bottom === 0) {
|
2020-06-04 18:06:38 +00:00
|
|
|
$controlSidebar.css({
|
2020-06-02 15:50:19 +00:00
|
|
|
bottom: heights.footer,
|
|
|
|
top: heights.header
|
|
|
|
})
|
2020-06-04 18:06:38 +00:00
|
|
|
$controlsidebarContent.css('height', heights.window - (heights.header + heights.footer))
|
2020-06-02 13:23:22 +00:00
|
|
|
} else if (positions.bottom <= heights.footer) {
|
|
|
|
if (footerFixed === false) {
|
2020-07-24 22:39:07 +00:00
|
|
|
const top = heights.header - positions.top
|
|
|
|
$controlSidebar.css('bottom', heights.footer - positions.bottom).css('top', top >= 0 ? top : 0)
|
2020-06-04 18:06:38 +00:00
|
|
|
$controlsidebarContent.css('height', heights.window - (heights.footer - positions.bottom))
|
2020-06-02 13:23:22 +00:00
|
|
|
} else {
|
2020-06-04 18:06:38 +00:00
|
|
|
$controlSidebar.css('bottom', heights.footer)
|
2020-06-02 13:23:22 +00:00
|
|
|
}
|
|
|
|
} else if (positions.top <= heights.header) {
|
|
|
|
if (navbarFixed === false) {
|
2020-06-04 18:06:38 +00:00
|
|
|
$controlSidebar.css('top', heights.header - positions.top)
|
|
|
|
$controlsidebarContent.css('height', heights.window - (heights.header - positions.top))
|
2020-05-31 13:45:54 +00:00
|
|
|
} else {
|
2020-06-04 18:06:38 +00:00
|
|
|
$controlSidebar.css('top', heights.header)
|
2019-08-30 09:45:07 +00:00
|
|
|
}
|
2020-06-02 13:23:22 +00:00
|
|
|
} else if (navbarFixed === false) {
|
2020-06-04 18:06:38 +00:00
|
|
|
$controlSidebar.css('top', 0)
|
|
|
|
$controlsidebarContent.css('height', heights.window)
|
2020-06-02 13:23:22 +00:00
|
|
|
} else {
|
2020-06-04 18:06:38 +00:00
|
|
|
$controlSidebar.css('top', heights.header)
|
2019-08-30 09:45:07 +00:00
|
|
|
}
|
2020-06-02 13:23:22 +00:00
|
|
|
}
|
2019-08-30 09:45:07 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
_fixHeight() {
|
2020-06-04 18:06:38 +00:00
|
|
|
const $body = $('body')
|
|
|
|
|
2020-06-11 12:34:44 +00:00
|
|
|
if (!$body.hasClass(CLASS_NAME_LAYOUT_FIXED)) {
|
2020-06-02 13:23:22 +00:00
|
|
|
return
|
|
|
|
}
|
2020-05-31 13:45:54 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
const heights = {
|
|
|
|
window: $(window).height(),
|
2020-06-11 12:34:44 +00:00
|
|
|
header: $(SELECTOR_HEADER).outerHeight(),
|
|
|
|
footer: $(SELECTOR_FOOTER).outerHeight()
|
2020-06-02 13:23:22 +00:00
|
|
|
}
|
2019-08-30 09:45:07 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
let sidebarHeight = heights.window - heights.header
|
2019-08-30 09:45:07 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
if (
|
2020-06-11 12:34:44 +00:00
|
|
|
$body.hasClass(CLASS_NAME_FOOTER_FIXED) ||
|
|
|
|
$body.hasClass(CLASS_NAME_FOOTER_SM_FIXED) ||
|
|
|
|
$body.hasClass(CLASS_NAME_FOOTER_MD_FIXED) ||
|
|
|
|
$body.hasClass(CLASS_NAME_FOOTER_LG_FIXED) ||
|
|
|
|
$body.hasClass(CLASS_NAME_FOOTER_XL_FIXED)
|
2020-06-02 13:23:22 +00:00
|
|
|
) {
|
2020-06-11 12:34:44 +00:00
|
|
|
if ($(SELECTOR_FOOTER).css('position') === 'fixed') {
|
2020-06-02 13:23:22 +00:00
|
|
|
sidebarHeight = heights.window - heights.header - heights.footer
|
2020-05-31 13:45:54 +00:00
|
|
|
}
|
2020-06-02 13:23:22 +00:00
|
|
|
}
|
2019-08-30 09:45:07 +00:00
|
|
|
|
2020-11-27 09:21:42 +00:00
|
|
|
const $controlSidebar = $(`${this._config.target} ${SELECTOR_CONTROL_SIDEBAR_CONTENT}`)
|
2020-06-04 18:06:38 +00:00
|
|
|
$controlSidebar.css('height', sidebarHeight)
|
2020-05-30 13:44:20 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
if (typeof $.fn.overlayScrollbars !== 'undefined') {
|
2020-06-04 18:06:38 +00:00
|
|
|
$controlSidebar.overlayScrollbars({
|
2020-06-02 13:23:22 +00:00
|
|
|
className: this._config.scrollbarTheme,
|
|
|
|
sizeAutoCapable: true,
|
|
|
|
scrollbars: {
|
|
|
|
autoHide: this._config.scrollbarAutoHide,
|
|
|
|
clickScrolling: true
|
|
|
|
}
|
|
|
|
})
|
2016-10-19 15:23:34 +00:00
|
|
|
}
|
2020-06-02 13:23:22 +00:00
|
|
|
}
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
// Static
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
static _jQueryInterface(operation) {
|
|
|
|
return this.each(function () {
|
|
|
|
let data = $(this).data(DATA_KEY)
|
|
|
|
const _options = $.extend({}, Default, $(this).data())
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
if (!data) {
|
|
|
|
data = new ControlSidebar(this, _options)
|
|
|
|
$(this).data(DATA_KEY, data)
|
|
|
|
}
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
if (data[operation] === 'undefined') {
|
|
|
|
throw new Error(`${operation} is not a function`)
|
|
|
|
}
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
data[operation]()
|
|
|
|
})
|
2016-10-19 15:23:34 +00:00
|
|
|
}
|
2020-06-02 13:23:22 +00:00
|
|
|
}
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Data Api implementation
|
|
|
|
* ====================================================
|
|
|
|
*/
|
2020-06-11 12:34:44 +00:00
|
|
|
$(document).on('click', SELECTOR_DATA_TOGGLE, function (event) {
|
2020-06-02 13:23:22 +00:00
|
|
|
event.preventDefault()
|
2016-10-19 15:23:34 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
ControlSidebar._jQueryInterface.call($(this), 'toggle')
|
|
|
|
})
|
2018-02-03 23:45:19 +00:00
|
|
|
|
2020-11-27 09:21:42 +00:00
|
|
|
$(document).ready(() => {
|
|
|
|
ControlSidebar._jQueryInterface.call($(SELECTOR_DATA_TOGGLE), '_init')
|
|
|
|
})
|
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
/**
|
|
|
|
* jQuery API
|
|
|
|
* ====================================================
|
|
|
|
*/
|
2020-05-30 13:44:20 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
$.fn[NAME] = ControlSidebar._jQueryInterface
|
|
|
|
$.fn[NAME].Constructor = ControlSidebar
|
|
|
|
$.fn[NAME].noConflict = function () {
|
|
|
|
$.fn[NAME] = JQUERY_NO_CONFLICT
|
|
|
|
return ControlSidebar._jQueryInterface
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ControlSidebar
|