webpack-bootstrap-ui-kit/src/js_old/_components/_ui.menu.js

66 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-05-03 20:50:57 +02:00
'use strict'
2020-12-24 23:42:33 +01:00
2022-05-03 20:50:57 +02:00
import $ from 'jquery'
2019-06-08 17:20:51 +02:00
const SlidingMenu = (($) => {
// Constants
2022-05-03 20:50:57 +02:00
const NAME = 'jsSlidingMenu'
const DATA_KEY = NAME
2019-06-08 17:20:51 +02:00
class SlidingMenu {
// Constructor
2022-05-03 20:50:57 +02:00
constructor (element) {
console.log(`${NAME}: init`)
this._element = element
const $element = $(this._element)
$element.addClass(`${NAME}-active`)
2019-06-08 17:20:51 +02:00
// esc button
2022-05-03 20:50:57 +02:00
$(window).on('keyup', (e) => {
2019-06-08 17:20:51 +02:00
if (e.which === 27) {
2022-05-03 20:50:57 +02:00
$element.find('.is-open[data-toggle="offcanvas"]').click()
2019-06-08 17:20:51 +02:00
}
2022-05-03 20:50:57 +02:00
})
2019-06-08 17:20:51 +02:00
}
// Public methods
2022-05-03 20:50:57 +02:00
dispose () {
console.log(`${NAME}: dispose`)
2019-06-08 17:20:51 +02:00
2022-05-03 20:50:57 +02:00
$(this._element).removeClass(`${NAME}-active`)
$.removeData(this._element, DATA_KEY)
this._element = null
2019-06-08 17:20:51 +02:00
}
2022-05-03 20:50:57 +02:00
static _jQueryInterface () {
2019-10-20 01:40:40 +02:00
return this.each(function () {
// attach functionality to element
2022-05-03 20:50:57 +02:00
const $element = $(this)
let data = $element.data(DATA_KEY)
2019-06-08 17:20:51 +02:00
if (!data) {
2022-05-03 20:50:57 +02:00
data = new SlidingMenu(this)
$element.data(DATA_KEY, data)
2019-06-08 17:20:51 +02:00
}
2022-05-03 20:50:57 +02:00
})
2019-06-08 17:20:51 +02:00
}
}
// jQuery interface
2022-05-03 20:50:57 +02:00
$.fn[NAME] = SlidingMenu._jQueryInterface
$.fn[NAME].Constructor = SlidingMenu
2019-10-20 01:40:40 +02:00
$.fn[NAME].noConflict = function () {
2022-05-03 20:50:57 +02:00
$.fn[NAME] = JQUERY_NO_CONFLICT
return SlidingMenu._jQueryInterface
}
2019-06-08 17:20:51 +02:00
// auto-apply
$(`.ui.${NAME}`).ready(() => {
2022-05-03 20:50:57 +02:00
$(`.ui.${NAME}`).jsSlidingMenu()
})
2019-06-08 17:20:51 +02:00
2022-05-03 20:50:57 +02:00
return SlidingMenu
})($)
2019-06-08 17:20:51 +02:00
2022-05-03 20:50:57 +02:00
export default SlidingMenu