mirror of https://github.com/ColorlibHQ/AdminLTE
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.
129 lines
2.6 KiB
129 lines
2.6 KiB
9 years ago
|
/**
|
||
|
* --------------------------------------------
|
||
|
* AdminLTE PushMenu.js
|
||
|
* License MIT
|
||
|
* --------------------------------------------
|
||
|
*/
|
||
|
|
||
|
const PushMenu = (($) => {
|
||
|
|
||
|
/**
|
||
|
* Constants
|
||
|
* ====================================================
|
||
|
*/
|
||
|
|
||
8 years ago
|
const NAME = 'PushMenu'
|
||
|
const DATA_KEY = 'lte.pushmenu'
|
||
|
const EVENT_KEY = `.${DATA_KEY}`
|
||
9 years ago
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||
|
|
||
|
const Event = {
|
||
|
COLLAPSED: `collapsed${EVENT_KEY}`,
|
||
9 years ago
|
SHOWN: `shown${EVENT_KEY}`
|
||
9 years ago
|
}
|
||
|
|
||
|
const Selector = {
|
||
|
COLLAPSED: 'sidebar-collapse',
|
||
|
TOGGLE_BUTTON: '[data-widget="pushmenu"]'
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Class Definition
|
||
|
* ====================================================
|
||
|
*/
|
||
|
|
||
|
class PushMenu {
|
||
|
|
||
9 years ago
|
constructor(element) {
|
||
9 years ago
|
this._element = element
|
||
9 years ago
|
this._isShown = !$('body').hasClass(Selector.COLLAPSED) || $('body').hasClass('sidebar-open')
|
||
9 years ago
|
}
|
||
|
|
||
|
// Public
|
||
|
|
||
|
show() {
|
||
9 years ago
|
$('body').addClass('sidebar-open')
|
||
8 years ago
|
.removeClass(Selector.COLLAPSED)
|
||
9 years ago
|
|
||
9 years ago
|
this._isShown = true
|
||
|
|
||
7 years ago
|
const shownEvent = $.Event(Event.SHOWN)
|
||
9 years ago
|
$(this._element).trigger(shownEvent)
|
||
|
}
|
||
|
|
||
|
collapse() {
|
||
9 years ago
|
$('body').removeClass('sidebar-open')
|
||
8 years ago
|
.addClass(Selector.COLLAPSED)
|
||
9 years ago
|
|
||
9 years ago
|
this._isShown = false
|
||
|
|
||
7 years ago
|
const collapsedEvent = $.Event(Event.COLLAPSED)
|
||
9 years ago
|
$(this._element).trigger(collapsedEvent)
|
||
|
}
|
||
|
|
||
|
toggle() {
|
||
|
|
||
|
if (typeof this._isShown === 'undefined') {
|
||
9 years ago
|
this._isShown = !$('body').hasClass(Selector.COLLAPSED) || $('body').hasClass('sidebar-open')
|
||
9 years ago
|
}
|
||
|
|
||
|
if (this._isShown) {
|
||
|
this.collapse()
|
||
|
} else {
|
||
|
this.show()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Static
|
||
|
|
||
|
static _jQueryInterface(operation) {
|
||
|
return this.each(function () {
|
||
|
let data = $(this).data(DATA_KEY)
|
||
|
|
||
|
if (!data) {
|
||
|
data = new PushMenu(this)
|
||
|
$(this).data(DATA_KEY, data)
|
||
|
}
|
||
|
|
||
|
if (operation) {
|
||
|
data[operation]()
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Data API
|
||
|
* ====================================================
|
||
|
*/
|
||
|
|
||
|
$(document).on('click', Selector.TOGGLE_BUTTON, (event) => {
|
||
|
event.preventDefault()
|
||
|
|
||
9 years ago
|
let button = event.currentTarget
|
||
9 years ago
|
|
||
|
if ($(button).data('widget') !== 'pushmenu') {
|
||
|
button = $(button).closest(Selector.TOGGLE_BUTTON)
|
||
|
}
|
||
|
|
||
|
PushMenu._jQueryInterface.call($(button), 'toggle')
|
||
|
})
|
||
|
|
||
|
/**
|
||
|
* jQuery API
|
||
|
* ====================================================
|
||
|
*/
|
||
|
|
||
|
$.fn[NAME] = PushMenu._jQueryInterface
|
||
|
$.fn[NAME].Constructor = PushMenu
|
||
8 years ago
|
$.fn[NAME].noConflict = function () {
|
||
9 years ago
|
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||
|
return PushMenu._jQueryInterface
|
||
|
}
|
||
|
|
||
|
return PushMenu
|
||
|
|
||
|
})(jQuery)
|
||
7 years ago
|
|
||
|
export default PushMenu
|