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/PushMenu.js

129 lines
2.6 KiB

/**
* --------------------------------------------
* AdminLTE PushMenu.js
* License MIT
* --------------------------------------------
*/
const PushMenu = (($) => {
/**
* Constants
* ====================================================
*/
8 years ago
const NAME = 'PushMenu'
const DATA_KEY = 'lte.pushmenu'
const EVENT_KEY = `.${DATA_KEY}`
const JQUERY_NO_CONFLICT = $.fn[NAME]
const Event = {
COLLAPSED: `collapsed${EVENT_KEY}`,
9 years ago
SHOWN: `shown${EVENT_KEY}`
}
const Selector = {
COLLAPSED: 'sidebar-collapse',
TOGGLE_BUTTON: '[data-widget="pushmenu"]'
}
/**
* Class Definition
* ====================================================
*/
class PushMenu {
9 years ago
constructor(element) {
this._element = element
9 years ago
this._isShown = !$('body').hasClass(Selector.COLLAPSED) || $('body').hasClass('sidebar-open')
}
// Public
show() {
9 years ago
$('body').addClass('sidebar-open')
8 years ago
.removeClass(Selector.COLLAPSED)
9 years ago
this._isShown = true
7 years ago
const shownEvent = $.Event(Event.SHOWN)
$(this._element).trigger(shownEvent)
}
collapse() {
9 years ago
$('body').removeClass('sidebar-open')
8 years ago
.addClass(Selector.COLLAPSED)
9 years ago
this._isShown = false
7 years ago
const collapsedEvent = $.Event(Event.COLLAPSED)
$(this._element).trigger(collapsedEvent)
}
toggle() {
if (typeof this._isShown === 'undefined') {
9 years ago
this._isShown = !$('body').hasClass(Selector.COLLAPSED) || $('body').hasClass('sidebar-open')
}
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
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 () {
$.fn[NAME] = JQUERY_NO_CONFLICT
return PushMenu._jQueryInterface
}
return PushMenu
})(jQuery)
7 years ago
export default PushMenu