mirror of https://github.com/ColorlibHQ/AdminLTE
Remove unneeded IIFEs (#2774)
parent
bbfcc0639e
commit
e848621b32
|
@ -21,6 +21,7 @@ module.exports = {
|
|||
},
|
||||
name: 'adminlte'
|
||||
},
|
||||
external: ['jquery'],
|
||||
plugins: [
|
||||
babel({
|
||||
exclude: 'node_modules/**',
|
||||
|
|
|
@ -5,158 +5,156 @@
|
|||
* --------------------------------------------
|
||||
*/
|
||||
|
||||
const CardRefresh = ($ => {
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
import $ from 'jquery'
|
||||
|
||||
const NAME = 'CardRefresh'
|
||||
const DATA_KEY = 'lte.cardrefresh'
|
||||
const EVENT_KEY = `.${DATA_KEY}`
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
const Event = {
|
||||
LOADED: `loaded${EVENT_KEY}`,
|
||||
OVERLAY_ADDED: `overlay.added${EVENT_KEY}`,
|
||||
OVERLAY_REMOVED: `overlay.removed${EVENT_KEY}`
|
||||
const NAME = 'CardRefresh'
|
||||
const DATA_KEY = 'lte.cardrefresh'
|
||||
const EVENT_KEY = `.${DATA_KEY}`
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
|
||||
const Event = {
|
||||
LOADED: `loaded${EVENT_KEY}`,
|
||||
OVERLAY_ADDED: `overlay.added${EVENT_KEY}`,
|
||||
OVERLAY_REMOVED: `overlay.removed${EVENT_KEY}`
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
CARD: 'card'
|
||||
}
|
||||
|
||||
const Selector = {
|
||||
CARD: `.${ClassName.CARD}`,
|
||||
DATA_REFRESH: '[data-card-widget="card-refresh"]'
|
||||
}
|
||||
|
||||
const Default = {
|
||||
source: '',
|
||||
sourceSelector: '',
|
||||
params: {},
|
||||
trigger: Selector.DATA_REFRESH,
|
||||
content: '.card-body',
|
||||
loadInContent: true,
|
||||
loadOnInit: true,
|
||||
responseType: '',
|
||||
overlayTemplate: '<div class="overlay"><i class="fas fa-2x fa-sync-alt fa-spin"></i></div>',
|
||||
onLoadStart() {
|
||||
},
|
||||
onLoadDone(response) {
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
CARD: 'card'
|
||||
}
|
||||
class CardRefresh {
|
||||
constructor(element, settings) {
|
||||
this._element = element
|
||||
this._parent = element.parents(Selector.CARD).first()
|
||||
this._settings = $.extend({}, Default, settings)
|
||||
this._overlay = $(this._settings.overlayTemplate)
|
||||
|
||||
const Selector = {
|
||||
CARD: `.${ClassName.CARD}`,
|
||||
DATA_REFRESH: '[data-card-widget="card-refresh"]'
|
||||
}
|
||||
if (element.hasClass(ClassName.CARD)) {
|
||||
this._parent = element
|
||||
}
|
||||
|
||||
const Default = {
|
||||
source: '',
|
||||
sourceSelector: '',
|
||||
params: {},
|
||||
trigger: Selector.DATA_REFRESH,
|
||||
content: '.card-body',
|
||||
loadInContent: true,
|
||||
loadOnInit: true,
|
||||
responseType: '',
|
||||
overlayTemplate: '<div class="overlay"><i class="fas fa-2x fa-sync-alt fa-spin"></i></div>',
|
||||
onLoadStart() {
|
||||
},
|
||||
onLoadDone(response) {
|
||||
return response
|
||||
if (this._settings.source === '') {
|
||||
throw new Error('Source url was not defined. Please specify a url in your CardRefresh source option.')
|
||||
}
|
||||
}
|
||||
|
||||
class CardRefresh {
|
||||
constructor(element, settings) {
|
||||
this._element = element
|
||||
this._parent = element.parents(Selector.CARD).first()
|
||||
this._settings = $.extend({}, Default, settings)
|
||||
this._overlay = $(this._settings.overlayTemplate)
|
||||
load() {
|
||||
this._addOverlay()
|
||||
this._settings.onLoadStart.call($(this))
|
||||
|
||||
if (element.hasClass(ClassName.CARD)) {
|
||||
this._parent = element
|
||||
}
|
||||
|
||||
if (this._settings.source === '') {
|
||||
throw new Error('Source url was not defined. Please specify a url in your CardRefresh source option.')
|
||||
}
|
||||
}
|
||||
|
||||
load() {
|
||||
this._addOverlay()
|
||||
this._settings.onLoadStart.call($(this))
|
||||
|
||||
$.get(this._settings.source, this._settings.params, response => {
|
||||
if (this._settings.loadInContent) {
|
||||
if (this._settings.sourceSelector !== '') {
|
||||
response = $(response).find(this._settings.sourceSelector).html()
|
||||
}
|
||||
|
||||
this._parent.find(this._settings.content).html(response)
|
||||
$.get(this._settings.source, this._settings.params, response => {
|
||||
if (this._settings.loadInContent) {
|
||||
if (this._settings.sourceSelector !== '') {
|
||||
response = $(response).find(this._settings.sourceSelector).html()
|
||||
}
|
||||
|
||||
this._settings.onLoadDone.call($(this), response)
|
||||
this._removeOverlay()
|
||||
}, this._settings.responseType !== '' && this._settings.responseType)
|
||||
|
||||
$(this._element).trigger($.Event(Event.LOADED))
|
||||
}
|
||||
|
||||
_addOverlay() {
|
||||
this._parent.append(this._overlay)
|
||||
$(this._element).trigger($.Event(Event.OVERLAY_ADDED))
|
||||
}
|
||||
|
||||
_removeOverlay() {
|
||||
this._parent.find(this._overlay).remove()
|
||||
$(this._element).trigger($.Event(Event.OVERLAY_REMOVED))
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
_init() {
|
||||
$(this).find(this._settings.trigger).on('click', () => {
|
||||
this.load()
|
||||
})
|
||||
|
||||
if (this._settings.loadOnInit) {
|
||||
this.load()
|
||||
}
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(config) {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _options = $.extend({}, Default, $(this).data())
|
||||
|
||||
if (!data) {
|
||||
data = new CardRefresh($(this), _options)
|
||||
$(this).data(DATA_KEY, typeof config === 'string' ? data : config)
|
||||
this._parent.find(this._settings.content).html(response)
|
||||
}
|
||||
|
||||
if (typeof config === 'string' && config.match(/load/)) {
|
||||
data[config]()
|
||||
} else {
|
||||
data._init($(this))
|
||||
}
|
||||
}
|
||||
this._settings.onLoadDone.call($(this), response)
|
||||
this._removeOverlay()
|
||||
}, this._settings.responseType !== '' && this._settings.responseType)
|
||||
|
||||
$(this._element).trigger($.Event(Event.LOADED))
|
||||
}
|
||||
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
_addOverlay() {
|
||||
this._parent.append(this._overlay)
|
||||
$(this._element).trigger($.Event(Event.OVERLAY_ADDED))
|
||||
}
|
||||
|
||||
$(document).on('click', Selector.DATA_REFRESH, function (event) {
|
||||
if (event) {
|
||||
event.preventDefault()
|
||||
}
|
||||
_removeOverlay() {
|
||||
this._parent.find(this._overlay).remove()
|
||||
$(this._element).trigger($.Event(Event.OVERLAY_REMOVED))
|
||||
}
|
||||
|
||||
CardRefresh._jQueryInterface.call($(this), 'load')
|
||||
})
|
||||
// Private
|
||||
|
||||
$(() => {
|
||||
$(Selector.DATA_REFRESH).each(function () {
|
||||
CardRefresh._jQueryInterface.call($(this))
|
||||
_init() {
|
||||
$(this).find(this._settings.trigger).on('click', () => {
|
||||
this.load()
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = CardRefresh._jQueryInterface
|
||||
$.fn[NAME].Constructor = CardRefresh
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return CardRefresh._jQueryInterface
|
||||
if (this._settings.loadOnInit) {
|
||||
this.load()
|
||||
}
|
||||
}
|
||||
|
||||
return CardRefresh
|
||||
})(jQuery)
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(config) {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _options = $.extend({}, Default, $(this).data())
|
||||
|
||||
if (!data) {
|
||||
data = new CardRefresh($(this), _options)
|
||||
$(this).data(DATA_KEY, typeof config === 'string' ? data : config)
|
||||
}
|
||||
|
||||
if (typeof config === 'string' && config.match(/load/)) {
|
||||
data[config]()
|
||||
} else {
|
||||
data._init($(this))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$(document).on('click', Selector.DATA_REFRESH, function (event) {
|
||||
if (event) {
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
CardRefresh._jQueryInterface.call($(this), 'load')
|
||||
})
|
||||
|
||||
$(() => {
|
||||
$(Selector.DATA_REFRESH).each(function () {
|
||||
CardRefresh._jQueryInterface.call($(this))
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = CardRefresh._jQueryInterface
|
||||
$.fn[NAME].Constructor = CardRefresh
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return CardRefresh._jQueryInterface
|
||||
}
|
||||
|
||||
export default CardRefresh
|
||||
|
|
|
@ -5,239 +5,237 @@
|
|||
* --------------------------------------------
|
||||
*/
|
||||
|
||||
const CardWidget = ($ => {
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
import $ from 'jquery'
|
||||
|
||||
const NAME = 'CardWidget'
|
||||
const DATA_KEY = 'lte.cardwidget'
|
||||
const EVENT_KEY = `.${DATA_KEY}`
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
const Event = {
|
||||
EXPANDED: `expanded${EVENT_KEY}`,
|
||||
COLLAPSED: `collapsed${EVENT_KEY}`,
|
||||
MAXIMIZED: `maximized${EVENT_KEY}`,
|
||||
MINIMIZED: `minimized${EVENT_KEY}`,
|
||||
REMOVED: `removed${EVENT_KEY}`
|
||||
const NAME = 'CardWidget'
|
||||
const DATA_KEY = 'lte.cardwidget'
|
||||
const EVENT_KEY = `.${DATA_KEY}`
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
|
||||
const Event = {
|
||||
EXPANDED: `expanded${EVENT_KEY}`,
|
||||
COLLAPSED: `collapsed${EVENT_KEY}`,
|
||||
MAXIMIZED: `maximized${EVENT_KEY}`,
|
||||
MINIMIZED: `minimized${EVENT_KEY}`,
|
||||
REMOVED: `removed${EVENT_KEY}`
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
CARD: 'card',
|
||||
COLLAPSED: 'collapsed-card',
|
||||
COLLAPSING: 'collapsing-card',
|
||||
EXPANDING: 'expanding-card',
|
||||
WAS_COLLAPSED: 'was-collapsed',
|
||||
MAXIMIZED: 'maximized-card'
|
||||
}
|
||||
|
||||
const Selector = {
|
||||
DATA_REMOVE: '[data-card-widget="remove"]',
|
||||
DATA_COLLAPSE: '[data-card-widget="collapse"]',
|
||||
DATA_MAXIMIZE: '[data-card-widget="maximize"]',
|
||||
CARD: `.${ClassName.CARD}`,
|
||||
CARD_HEADER: '.card-header',
|
||||
CARD_BODY: '.card-body',
|
||||
CARD_FOOTER: '.card-footer'
|
||||
}
|
||||
|
||||
const Default = {
|
||||
animationSpeed: 'normal',
|
||||
collapseTrigger: Selector.DATA_COLLAPSE,
|
||||
removeTrigger: Selector.DATA_REMOVE,
|
||||
maximizeTrigger: Selector.DATA_MAXIMIZE,
|
||||
collapseIcon: 'fa-minus',
|
||||
expandIcon: 'fa-plus',
|
||||
maximizeIcon: 'fa-expand',
|
||||
minimizeIcon: 'fa-compress'
|
||||
}
|
||||
|
||||
class CardWidget {
|
||||
constructor(element, settings) {
|
||||
this._element = element
|
||||
this._parent = element.parents(Selector.CARD).first()
|
||||
|
||||
if (element.hasClass(ClassName.CARD)) {
|
||||
this._parent = element
|
||||
}
|
||||
|
||||
this._settings = $.extend({}, Default, settings)
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
CARD: 'card',
|
||||
COLLAPSED: 'collapsed-card',
|
||||
COLLAPSING: 'collapsing-card',
|
||||
EXPANDING: 'expanding-card',
|
||||
WAS_COLLAPSED: 'was-collapsed',
|
||||
MAXIMIZED: 'maximized-card'
|
||||
}
|
||||
|
||||
const Selector = {
|
||||
DATA_REMOVE: '[data-card-widget="remove"]',
|
||||
DATA_COLLAPSE: '[data-card-widget="collapse"]',
|
||||
DATA_MAXIMIZE: '[data-card-widget="maximize"]',
|
||||
CARD: `.${ClassName.CARD}`,
|
||||
CARD_HEADER: '.card-header',
|
||||
CARD_BODY: '.card-body',
|
||||
CARD_FOOTER: '.card-footer'
|
||||
}
|
||||
|
||||
const Default = {
|
||||
animationSpeed: 'normal',
|
||||
collapseTrigger: Selector.DATA_COLLAPSE,
|
||||
removeTrigger: Selector.DATA_REMOVE,
|
||||
maximizeTrigger: Selector.DATA_MAXIMIZE,
|
||||
collapseIcon: 'fa-minus',
|
||||
expandIcon: 'fa-plus',
|
||||
maximizeIcon: 'fa-expand',
|
||||
minimizeIcon: 'fa-compress'
|
||||
}
|
||||
|
||||
class CardWidget {
|
||||
constructor(element, settings) {
|
||||
this._element = element
|
||||
this._parent = element.parents(Selector.CARD).first()
|
||||
|
||||
if (element.hasClass(ClassName.CARD)) {
|
||||
this._parent = element
|
||||
}
|
||||
|
||||
this._settings = $.extend({}, Default, settings)
|
||||
}
|
||||
|
||||
collapse() {
|
||||
this._parent.addClass(ClassName.COLLAPSING).children(`${Selector.CARD_BODY}, ${Selector.CARD_FOOTER}`)
|
||||
.slideUp(this._settings.animationSpeed, () => {
|
||||
this._parent.addClass(ClassName.COLLAPSED).removeClass(ClassName.COLLAPSING)
|
||||
})
|
||||
|
||||
this._parent.find('> ' + Selector.CARD_HEADER + ' ' + this._settings.collapseTrigger + ' .' + this._settings.collapseIcon)
|
||||
.addClass(this._settings.expandIcon)
|
||||
.removeClass(this._settings.collapseIcon)
|
||||
|
||||
this._element.trigger($.Event(Event.COLLAPSED), this._parent)
|
||||
}
|
||||
|
||||
expand() {
|
||||
this._parent.addClass(ClassName.EXPANDING).children(`${Selector.CARD_BODY}, ${Selector.CARD_FOOTER}`)
|
||||
.slideDown(this._settings.animationSpeed, () => {
|
||||
this._parent.removeClass(ClassName.COLLAPSED).removeClass(ClassName.EXPANDING)
|
||||
})
|
||||
|
||||
this._parent.find('> ' + Selector.CARD_HEADER + ' ' + this._settings.collapseTrigger + ' .' + this._settings.expandIcon)
|
||||
.addClass(this._settings.collapseIcon)
|
||||
.removeClass(this._settings.expandIcon)
|
||||
|
||||
this._element.trigger($.Event(Event.EXPANDED), this._parent)
|
||||
}
|
||||
|
||||
remove() {
|
||||
this._parent.slideUp()
|
||||
this._element.trigger($.Event(Event.REMOVED), this._parent)
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if (this._parent.hasClass(ClassName.COLLAPSED)) {
|
||||
this.expand()
|
||||
return
|
||||
}
|
||||
|
||||
this.collapse()
|
||||
}
|
||||
|
||||
maximize() {
|
||||
this._parent.find(this._settings.maximizeTrigger + ' .' + this._settings.maximizeIcon)
|
||||
.addClass(this._settings.minimizeIcon)
|
||||
.removeClass(this._settings.maximizeIcon)
|
||||
this._parent.css({
|
||||
height: this._parent.height(),
|
||||
width: this._parent.width(),
|
||||
transition: 'all .15s'
|
||||
}).delay(150).queue(function () {
|
||||
$(this).addClass(ClassName.MAXIMIZED)
|
||||
$('html').addClass(ClassName.MAXIMIZED)
|
||||
if ($(this).hasClass(ClassName.COLLAPSED)) {
|
||||
$(this).addClass(ClassName.WAS_COLLAPSED)
|
||||
}
|
||||
|
||||
$(this).dequeue()
|
||||
collapse() {
|
||||
this._parent.addClass(ClassName.COLLAPSING).children(`${Selector.CARD_BODY}, ${Selector.CARD_FOOTER}`)
|
||||
.slideUp(this._settings.animationSpeed, () => {
|
||||
this._parent.addClass(ClassName.COLLAPSED).removeClass(ClassName.COLLAPSING)
|
||||
})
|
||||
|
||||
this._element.trigger($.Event(Event.MAXIMIZED), this._parent)
|
||||
}
|
||||
this._parent.find('> ' + Selector.CARD_HEADER + ' ' + this._settings.collapseTrigger + ' .' + this._settings.collapseIcon)
|
||||
.addClass(this._settings.expandIcon)
|
||||
.removeClass(this._settings.collapseIcon)
|
||||
|
||||
minimize() {
|
||||
this._parent.find(this._settings.maximizeTrigger + ' .' + this._settings.minimizeIcon)
|
||||
.addClass(this._settings.maximizeIcon)
|
||||
.removeClass(this._settings.minimizeIcon)
|
||||
this._parent.css('cssText', 'height:' + this._parent[0].style.height + ' !important;' +
|
||||
'width:' + this._parent[0].style.width + ' !important; transition: all .15s;'
|
||||
).delay(10).queue(function () {
|
||||
$(this).removeClass(ClassName.MAXIMIZED)
|
||||
$('html').removeClass(ClassName.MAXIMIZED)
|
||||
$(this).css({
|
||||
height: 'inherit',
|
||||
width: 'inherit'
|
||||
})
|
||||
if ($(this).hasClass(ClassName.WAS_COLLAPSED)) {
|
||||
$(this).removeClass(ClassName.WAS_COLLAPSED)
|
||||
}
|
||||
|
||||
$(this).dequeue()
|
||||
})
|
||||
|
||||
this._element.trigger($.Event(Event.MINIMIZED), this._parent)
|
||||
}
|
||||
|
||||
toggleMaximize() {
|
||||
if (this._parent.hasClass(ClassName.MAXIMIZED)) {
|
||||
this.minimize()
|
||||
return
|
||||
}
|
||||
|
||||
this.maximize()
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
_init(card) {
|
||||
this._parent = card
|
||||
|
||||
$(this).find(this._settings.collapseTrigger).click(() => {
|
||||
this.toggle()
|
||||
})
|
||||
|
||||
$(this).find(this._settings.maximizeTrigger).click(() => {
|
||||
this.toggleMaximize()
|
||||
})
|
||||
|
||||
$(this).find(this._settings.removeTrigger).click(() => {
|
||||
this.remove()
|
||||
})
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(config) {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _options = $.extend({}, Default, $(this).data())
|
||||
|
||||
if (!data) {
|
||||
data = new CardWidget($(this), _options)
|
||||
$(this).data(DATA_KEY, typeof config === 'string' ? data : config)
|
||||
}
|
||||
|
||||
if (typeof config === 'string' && config.match(/collapse|expand|remove|toggle|maximize|minimize|toggleMaximize/)) {
|
||||
data[config]()
|
||||
} else if (typeof config === 'object') {
|
||||
data._init($(this))
|
||||
}
|
||||
}
|
||||
this._element.trigger($.Event(Event.COLLAPSED), this._parent)
|
||||
}
|
||||
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
expand() {
|
||||
this._parent.addClass(ClassName.EXPANDING).children(`${Selector.CARD_BODY}, ${Selector.CARD_FOOTER}`)
|
||||
.slideDown(this._settings.animationSpeed, () => {
|
||||
this._parent.removeClass(ClassName.COLLAPSED).removeClass(ClassName.EXPANDING)
|
||||
})
|
||||
|
||||
$(document).on('click', Selector.DATA_COLLAPSE, function (event) {
|
||||
if (event) {
|
||||
event.preventDefault()
|
||||
}
|
||||
this._parent.find('> ' + Selector.CARD_HEADER + ' ' + this._settings.collapseTrigger + ' .' + this._settings.expandIcon)
|
||||
.addClass(this._settings.collapseIcon)
|
||||
.removeClass(this._settings.expandIcon)
|
||||
|
||||
CardWidget._jQueryInterface.call($(this), 'toggle')
|
||||
})
|
||||
|
||||
$(document).on('click', Selector.DATA_REMOVE, function (event) {
|
||||
if (event) {
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
CardWidget._jQueryInterface.call($(this), 'remove')
|
||||
})
|
||||
|
||||
$(document).on('click', Selector.DATA_MAXIMIZE, function (event) {
|
||||
if (event) {
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
CardWidget._jQueryInterface.call($(this), 'toggleMaximize')
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = CardWidget._jQueryInterface
|
||||
$.fn[NAME].Constructor = CardWidget
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return CardWidget._jQueryInterface
|
||||
this._element.trigger($.Event(Event.EXPANDED), this._parent)
|
||||
}
|
||||
|
||||
return CardWidget
|
||||
})(jQuery)
|
||||
remove() {
|
||||
this._parent.slideUp()
|
||||
this._element.trigger($.Event(Event.REMOVED), this._parent)
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if (this._parent.hasClass(ClassName.COLLAPSED)) {
|
||||
this.expand()
|
||||
return
|
||||
}
|
||||
|
||||
this.collapse()
|
||||
}
|
||||
|
||||
maximize() {
|
||||
this._parent.find(this._settings.maximizeTrigger + ' .' + this._settings.maximizeIcon)
|
||||
.addClass(this._settings.minimizeIcon)
|
||||
.removeClass(this._settings.maximizeIcon)
|
||||
this._parent.css({
|
||||
height: this._parent.height(),
|
||||
width: this._parent.width(),
|
||||
transition: 'all .15s'
|
||||
}).delay(150).queue(function () {
|
||||
$(this).addClass(ClassName.MAXIMIZED)
|
||||
$('html').addClass(ClassName.MAXIMIZED)
|
||||
if ($(this).hasClass(ClassName.COLLAPSED)) {
|
||||
$(this).addClass(ClassName.WAS_COLLAPSED)
|
||||
}
|
||||
|
||||
$(this).dequeue()
|
||||
})
|
||||
|
||||
this._element.trigger($.Event(Event.MAXIMIZED), this._parent)
|
||||
}
|
||||
|
||||
minimize() {
|
||||
this._parent.find(this._settings.maximizeTrigger + ' .' + this._settings.minimizeIcon)
|
||||
.addClass(this._settings.maximizeIcon)
|
||||
.removeClass(this._settings.minimizeIcon)
|
||||
this._parent.css('cssText', 'height:' + this._parent[0].style.height + ' !important;' +
|
||||
'width:' + this._parent[0].style.width + ' !important; transition: all .15s;'
|
||||
).delay(10).queue(function () {
|
||||
$(this).removeClass(ClassName.MAXIMIZED)
|
||||
$('html').removeClass(ClassName.MAXIMIZED)
|
||||
$(this).css({
|
||||
height: 'inherit',
|
||||
width: 'inherit'
|
||||
})
|
||||
if ($(this).hasClass(ClassName.WAS_COLLAPSED)) {
|
||||
$(this).removeClass(ClassName.WAS_COLLAPSED)
|
||||
}
|
||||
|
||||
$(this).dequeue()
|
||||
})
|
||||
|
||||
this._element.trigger($.Event(Event.MINIMIZED), this._parent)
|
||||
}
|
||||
|
||||
toggleMaximize() {
|
||||
if (this._parent.hasClass(ClassName.MAXIMIZED)) {
|
||||
this.minimize()
|
||||
return
|
||||
}
|
||||
|
||||
this.maximize()
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
_init(card) {
|
||||
this._parent = card
|
||||
|
||||
$(this).find(this._settings.collapseTrigger).click(() => {
|
||||
this.toggle()
|
||||
})
|
||||
|
||||
$(this).find(this._settings.maximizeTrigger).click(() => {
|
||||
this.toggleMaximize()
|
||||
})
|
||||
|
||||
$(this).find(this._settings.removeTrigger).click(() => {
|
||||
this.remove()
|
||||
})
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(config) {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _options = $.extend({}, Default, $(this).data())
|
||||
|
||||
if (!data) {
|
||||
data = new CardWidget($(this), _options)
|
||||
$(this).data(DATA_KEY, typeof config === 'string' ? data : config)
|
||||
}
|
||||
|
||||
if (typeof config === 'string' && config.match(/collapse|expand|remove|toggle|maximize|minimize|toggleMaximize/)) {
|
||||
data[config]()
|
||||
} else if (typeof config === 'object') {
|
||||
data._init($(this))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$(document).on('click', Selector.DATA_COLLAPSE, function (event) {
|
||||
if (event) {
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
CardWidget._jQueryInterface.call($(this), 'toggle')
|
||||
})
|
||||
|
||||
$(document).on('click', Selector.DATA_REMOVE, function (event) {
|
||||
if (event) {
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
CardWidget._jQueryInterface.call($(this), 'remove')
|
||||
})
|
||||
|
||||
$(document).on('click', Selector.DATA_MAXIMIZE, function (event) {
|
||||
if (event) {
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
CardWidget._jQueryInterface.call($(this), 'toggleMaximize')
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = CardWidget._jQueryInterface
|
||||
$.fn[NAME].Constructor = CardWidget
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return CardWidget._jQueryInterface
|
||||
}
|
||||
|
||||
export default CardWidget
|
||||
|
|
|
@ -5,286 +5,283 @@
|
|||
* --------------------------------------------
|
||||
*/
|
||||
|
||||
const ControlSidebar = ($ => {
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
import $ from 'jquery'
|
||||
|
||||
const NAME = 'ControlSidebar'
|
||||
const DATA_KEY = 'lte.controlsidebar'
|
||||
const EVENT_KEY = `.${DATA_KEY}`
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
const Event = {
|
||||
COLLAPSED: `collapsed${EVENT_KEY}`,
|
||||
EXPANDED: `expanded${EVENT_KEY}`
|
||||
const NAME = 'ControlSidebar'
|
||||
const DATA_KEY = 'lte.controlsidebar'
|
||||
const EVENT_KEY = `.${DATA_KEY}`
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
|
||||
const Event = {
|
||||
COLLAPSED: `collapsed${EVENT_KEY}`,
|
||||
EXPANDED: `expanded${EVENT_KEY}`
|
||||
}
|
||||
|
||||
const Selector = {
|
||||
CONTROL_SIDEBAR: '.control-sidebar',
|
||||
CONTROL_SIDEBAR_CONTENT: '.control-sidebar-content',
|
||||
DATA_TOGGLE: '[data-widget="control-sidebar"]',
|
||||
HEADER: '.main-header',
|
||||
FOOTER: '.main-footer'
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
CONTROL_SIDEBAR_ANIMATE: 'control-sidebar-animate',
|
||||
CONTROL_SIDEBAR_OPEN: 'control-sidebar-open',
|
||||
CONTROL_SIDEBAR_SLIDE: 'control-sidebar-slide-open',
|
||||
LAYOUT_FIXED: 'layout-fixed',
|
||||
NAVBAR_FIXED: 'layout-navbar-fixed',
|
||||
NAVBAR_SM_FIXED: 'layout-sm-navbar-fixed',
|
||||
NAVBAR_MD_FIXED: 'layout-md-navbar-fixed',
|
||||
NAVBAR_LG_FIXED: 'layout-lg-navbar-fixed',
|
||||
NAVBAR_XL_FIXED: 'layout-xl-navbar-fixed',
|
||||
FOOTER_FIXED: 'layout-footer-fixed',
|
||||
FOOTER_SM_FIXED: 'layout-sm-footer-fixed',
|
||||
FOOTER_MD_FIXED: 'layout-md-footer-fixed',
|
||||
FOOTER_LG_FIXED: 'layout-lg-footer-fixed',
|
||||
FOOTER_XL_FIXED: 'layout-xl-footer-fixed'
|
||||
}
|
||||
|
||||
const Default = {
|
||||
controlsidebarSlide: true,
|
||||
scrollbarTheme: 'os-theme-light',
|
||||
scrollbarAutoHide: 'l'
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
class ControlSidebar {
|
||||
constructor(element, config) {
|
||||
this._element = element
|
||||
this._config = config
|
||||
|
||||
this._init()
|
||||
}
|
||||
|
||||
const Selector = {
|
||||
CONTROL_SIDEBAR: '.control-sidebar',
|
||||
CONTROL_SIDEBAR_CONTENT: '.control-sidebar-content',
|
||||
DATA_TOGGLE: '[data-widget="control-sidebar"]',
|
||||
HEADER: '.main-header',
|
||||
FOOTER: '.main-footer'
|
||||
}
|
||||
// Public
|
||||
|
||||
const ClassName = {
|
||||
CONTROL_SIDEBAR_ANIMATE: 'control-sidebar-animate',
|
||||
CONTROL_SIDEBAR_OPEN: 'control-sidebar-open',
|
||||
CONTROL_SIDEBAR_SLIDE: 'control-sidebar-slide-open',
|
||||
LAYOUT_FIXED: 'layout-fixed',
|
||||
NAVBAR_FIXED: 'layout-navbar-fixed',
|
||||
NAVBAR_SM_FIXED: 'layout-sm-navbar-fixed',
|
||||
NAVBAR_MD_FIXED: 'layout-md-navbar-fixed',
|
||||
NAVBAR_LG_FIXED: 'layout-lg-navbar-fixed',
|
||||
NAVBAR_XL_FIXED: 'layout-xl-navbar-fixed',
|
||||
FOOTER_FIXED: 'layout-footer-fixed',
|
||||
FOOTER_SM_FIXED: 'layout-sm-footer-fixed',
|
||||
FOOTER_MD_FIXED: 'layout-md-footer-fixed',
|
||||
FOOTER_LG_FIXED: 'layout-lg-footer-fixed',
|
||||
FOOTER_XL_FIXED: 'layout-xl-footer-fixed'
|
||||
}
|
||||
|
||||
const Default = {
|
||||
controlsidebarSlide: true,
|
||||
scrollbarTheme: 'os-theme-light',
|
||||
scrollbarAutoHide: 'l'
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
class ControlSidebar {
|
||||
constructor(element, config) {
|
||||
this._element = element
|
||||
this._config = config
|
||||
|
||||
this._init()
|
||||
collapse() {
|
||||
// Show the control sidebar
|
||||
if (this._config.controlsidebarSlide) {
|
||||
$('html').addClass(ClassName.CONTROL_SIDEBAR_ANIMATE)
|
||||
$('body').removeClass(ClassName.CONTROL_SIDEBAR_SLIDE).delay(300).queue(function () {
|
||||
$(Selector.CONTROL_SIDEBAR).hide()
|
||||
$('html').removeClass(ClassName.CONTROL_SIDEBAR_ANIMATE)
|
||||
$(this).dequeue()
|
||||
})
|
||||
} else {
|
||||
$('body').removeClass(ClassName.CONTROL_SIDEBAR_OPEN)
|
||||
}
|
||||
|
||||
// Public
|
||||
$(this._element).trigger($.Event(Event.COLLAPSED))
|
||||
}
|
||||
|
||||
collapse() {
|
||||
// Show the control sidebar
|
||||
if (this._config.controlsidebarSlide) {
|
||||
$('html').addClass(ClassName.CONTROL_SIDEBAR_ANIMATE)
|
||||
$('body').removeClass(ClassName.CONTROL_SIDEBAR_SLIDE).delay(300).queue(function () {
|
||||
$(Selector.CONTROL_SIDEBAR).hide()
|
||||
show() {
|
||||
// Collapse the control sidebar
|
||||
if (this._config.controlsidebarSlide) {
|
||||
$('html').addClass(ClassName.CONTROL_SIDEBAR_ANIMATE)
|
||||
$(Selector.CONTROL_SIDEBAR).show().delay(10).queue(function () {
|
||||
$('body').addClass(ClassName.CONTROL_SIDEBAR_SLIDE).delay(300).queue(function () {
|
||||
$('html').removeClass(ClassName.CONTROL_SIDEBAR_ANIMATE)
|
||||
$(this).dequeue()
|
||||
})
|
||||
} else {
|
||||
$('body').removeClass(ClassName.CONTROL_SIDEBAR_OPEN)
|
||||
}
|
||||
|
||||
$(this._element).trigger($.Event(Event.COLLAPSED))
|
||||
$(this).dequeue()
|
||||
})
|
||||
} else {
|
||||
$('body').addClass(ClassName.CONTROL_SIDEBAR_OPEN)
|
||||
}
|
||||
|
||||
show() {
|
||||
// Collapse the control sidebar
|
||||
if (this._config.controlsidebarSlide) {
|
||||
$('html').addClass(ClassName.CONTROL_SIDEBAR_ANIMATE)
|
||||
$(Selector.CONTROL_SIDEBAR).show().delay(10).queue(function () {
|
||||
$('body').addClass(ClassName.CONTROL_SIDEBAR_SLIDE).delay(300).queue(function () {
|
||||
$('html').removeClass(ClassName.CONTROL_SIDEBAR_ANIMATE)
|
||||
$(this).dequeue()
|
||||
})
|
||||
$(this).dequeue()
|
||||
})
|
||||
} else {
|
||||
$('body').addClass(ClassName.CONTROL_SIDEBAR_OPEN)
|
||||
}
|
||||
$(this._element).trigger($.Event(Event.EXPANDED))
|
||||
}
|
||||
|
||||
$(this._element).trigger($.Event(Event.EXPANDED))
|
||||
}
|
||||
|
||||
toggle() {
|
||||
const shouldClose = $('body').hasClass(ClassName.CONTROL_SIDEBAR_OPEN) || $('body')
|
||||
toggle() {
|
||||
const shouldClose = $('body').hasClass(ClassName.CONTROL_SIDEBAR_OPEN) || $('body')
|
||||
.hasClass(ClassName.CONTROL_SIDEBAR_SLIDE)
|
||||
if (shouldClose) {
|
||||
// Close the control sidebar
|
||||
this.collapse()
|
||||
} else {
|
||||
// Open the control sidebar
|
||||
this.show()
|
||||
}
|
||||
if (shouldClose) {
|
||||
// Close the control sidebar
|
||||
this.collapse()
|
||||
} else {
|
||||
// Open the control sidebar
|
||||
this.show()
|
||||
}
|
||||
}
|
||||
|
||||
// Private
|
||||
// Private
|
||||
|
||||
_init() {
|
||||
_init() {
|
||||
this._fixHeight()
|
||||
this._fixScrollHeight()
|
||||
|
||||
$(window).resize(() => {
|
||||
this._fixHeight()
|
||||
this._fixScrollHeight()
|
||||
})
|
||||
|
||||
$(window).resize(() => {
|
||||
this._fixHeight()
|
||||
$(window).scroll(() => {
|
||||
if ($('body').hasClass(ClassName.CONTROL_SIDEBAR_OPEN) || $('body').hasClass(ClassName.CONTROL_SIDEBAR_SLIDE)) {
|
||||
this._fixScrollHeight()
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
$(window).scroll(() => {
|
||||
if ($('body').hasClass(ClassName.CONTROL_SIDEBAR_OPEN) || $('body').hasClass(ClassName.CONTROL_SIDEBAR_SLIDE)) {
|
||||
this._fixScrollHeight()
|
||||
}
|
||||
})
|
||||
_fixScrollHeight() {
|
||||
if (!$('body').hasClass(ClassName.LAYOUT_FIXED)) {
|
||||
return
|
||||
}
|
||||
|
||||
_fixScrollHeight() {
|
||||
if (!$('body').hasClass(ClassName.LAYOUT_FIXED)) {
|
||||
return
|
||||
}
|
||||
const heights = {
|
||||
scroll: $(document).height(),
|
||||
window: $(window).height(),
|
||||
header: $(Selector.HEADER).outerHeight(),
|
||||
footer: $(Selector.FOOTER).outerHeight()
|
||||
}
|
||||
const positions = {
|
||||
bottom: Math.abs((heights.window + $(window).scrollTop()) - heights.scroll),
|
||||
top: $(window).scrollTop()
|
||||
}
|
||||
|
||||
const heights = {
|
||||
scroll: $(document).height(),
|
||||
window: $(window).height(),
|
||||
header: $(Selector.HEADER).outerHeight(),
|
||||
footer: $(Selector.FOOTER).outerHeight()
|
||||
}
|
||||
const positions = {
|
||||
bottom: Math.abs((heights.window + $(window).scrollTop()) - heights.scroll),
|
||||
top: $(window).scrollTop()
|
||||
}
|
||||
let navbarFixed = false
|
||||
let footerFixed = false
|
||||
|
||||
let navbarFixed = false
|
||||
let footerFixed = false
|
||||
|
||||
if (
|
||||
$('body').hasClass(ClassName.NAVBAR_FIXED) ||
|
||||
if (
|
||||
$('body').hasClass(ClassName.NAVBAR_FIXED) ||
|
||||
$('body').hasClass(ClassName.NAVBAR_SM_FIXED) ||
|
||||
$('body').hasClass(ClassName.NAVBAR_MD_FIXED) ||
|
||||
$('body').hasClass(ClassName.NAVBAR_LG_FIXED) ||
|
||||
$('body').hasClass(ClassName.NAVBAR_XL_FIXED)
|
||||
) {
|
||||
if ($(Selector.HEADER).css('position') === 'fixed') {
|
||||
navbarFixed = true
|
||||
}
|
||||
) {
|
||||
if ($(Selector.HEADER).css('position') === 'fixed') {
|
||||
navbarFixed = true
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
$('body').hasClass(ClassName.FOOTER_FIXED) ||
|
||||
if (
|
||||
$('body').hasClass(ClassName.FOOTER_FIXED) ||
|
||||
$('body').hasClass(ClassName.FOOTER_SM_FIXED) ||
|
||||
$('body').hasClass(ClassName.FOOTER_MD_FIXED) ||
|
||||
$('body').hasClass(ClassName.FOOTER_LG_FIXED) ||
|
||||
$('body').hasClass(ClassName.FOOTER_XL_FIXED)
|
||||
) {
|
||||
if ($(Selector.FOOTER).css('position') === 'fixed') {
|
||||
footerFixed = true
|
||||
}
|
||||
}
|
||||
|
||||
if (positions.top === 0 && positions.bottom === 0) {
|
||||
$(Selector.CONTROL_SIDEBAR).css('bottom', heights.footer)
|
||||
$(Selector.CONTROL_SIDEBAR).css('top', heights.header)
|
||||
$(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window - (heights.header + heights.footer))
|
||||
} else if (positions.bottom <= heights.footer) {
|
||||
if (footerFixed === false) {
|
||||
$(Selector.CONTROL_SIDEBAR).css('bottom', heights.footer - positions.bottom)
|
||||
$(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window - (heights.footer - positions.bottom))
|
||||
} else {
|
||||
$(Selector.CONTROL_SIDEBAR).css('bottom', heights.footer)
|
||||
}
|
||||
} else if (positions.top <= heights.header) {
|
||||
if (navbarFixed === false) {
|
||||
$(Selector.CONTROL_SIDEBAR).css('top', heights.header - positions.top)
|
||||
$(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window - (heights.header - positions.top))
|
||||
} else {
|
||||
$(Selector.CONTROL_SIDEBAR).css('top', heights.header)
|
||||
}
|
||||
} else if (navbarFixed === false) {
|
||||
$(Selector.CONTROL_SIDEBAR).css('top', 0)
|
||||
$(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window)
|
||||
} else {
|
||||
$(Selector.CONTROL_SIDEBAR).css('top', heights.header)
|
||||
) {
|
||||
if ($(Selector.FOOTER).css('position') === 'fixed') {
|
||||
footerFixed = true
|
||||
}
|
||||
}
|
||||
|
||||
_fixHeight() {
|
||||
if (!$('body').hasClass(ClassName.LAYOUT_FIXED)) {
|
||||
return
|
||||
if (positions.top === 0 && positions.bottom === 0) {
|
||||
$(Selector.CONTROL_SIDEBAR).css('bottom', heights.footer)
|
||||
$(Selector.CONTROL_SIDEBAR).css('top', heights.header)
|
||||
$(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window - (heights.header + heights.footer))
|
||||
} else if (positions.bottom <= heights.footer) {
|
||||
if (footerFixed === false) {
|
||||
$(Selector.CONTROL_SIDEBAR).css('bottom', heights.footer - positions.bottom)
|
||||
$(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window - (heights.footer - positions.bottom))
|
||||
} else {
|
||||
$(Selector.CONTROL_SIDEBAR).css('bottom', heights.footer)
|
||||
}
|
||||
|
||||
const heights = {
|
||||
window: $(window).height(),
|
||||
header: $(Selector.HEADER).outerHeight(),
|
||||
footer: $(Selector.FOOTER).outerHeight()
|
||||
} else if (positions.top <= heights.header) {
|
||||
if (navbarFixed === false) {
|
||||
$(Selector.CONTROL_SIDEBAR).css('top', heights.header - positions.top)
|
||||
$(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window - (heights.header - positions.top))
|
||||
} else {
|
||||
$(Selector.CONTROL_SIDEBAR).css('top', heights.header)
|
||||
}
|
||||
} else if (navbarFixed === false) {
|
||||
$(Selector.CONTROL_SIDEBAR).css('top', 0)
|
||||
$(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window)
|
||||
} else {
|
||||
$(Selector.CONTROL_SIDEBAR).css('top', heights.header)
|
||||
}
|
||||
}
|
||||
|
||||
let sidebarHeight = heights.window - heights.header
|
||||
_fixHeight() {
|
||||
if (!$('body').hasClass(ClassName.LAYOUT_FIXED)) {
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
$('body').hasClass(ClassName.FOOTER_FIXED) ||
|
||||
const heights = {
|
||||
window: $(window).height(),
|
||||
header: $(Selector.HEADER).outerHeight(),
|
||||
footer: $(Selector.FOOTER).outerHeight()
|
||||
}
|
||||
|
||||
let sidebarHeight = heights.window - heights.header
|
||||
|
||||
if (
|
||||
$('body').hasClass(ClassName.FOOTER_FIXED) ||
|
||||
$('body').hasClass(ClassName.FOOTER_SM_FIXED) ||
|
||||
$('body').hasClass(ClassName.FOOTER_MD_FIXED) ||
|
||||
$('body').hasClass(ClassName.FOOTER_LG_FIXED) ||
|
||||
$('body').hasClass(ClassName.FOOTER_XL_FIXED)
|
||||
) {
|
||||
if ($(Selector.FOOTER).css('position') === 'fixed') {
|
||||
sidebarHeight = heights.window - heights.header - heights.footer
|
||||
}
|
||||
}
|
||||
|
||||
$(Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', sidebarHeight)
|
||||
|
||||
if (typeof $.fn.overlayScrollbars !== 'undefined') {
|
||||
$(Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).overlayScrollbars({
|
||||
className: this._config.scrollbarTheme,
|
||||
sizeAutoCapable: true,
|
||||
scrollbars: {
|
||||
autoHide: this._config.scrollbarAutoHide,
|
||||
clickScrolling: true
|
||||
}
|
||||
})
|
||||
) {
|
||||
if ($(Selector.FOOTER).css('position') === 'fixed') {
|
||||
sidebarHeight = heights.window - heights.header - heights.footer
|
||||
}
|
||||
}
|
||||
|
||||
// Static
|
||||
$(Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', sidebarHeight)
|
||||
|
||||
static _jQueryInterface(operation) {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _options = $.extend({}, Default, $(this).data())
|
||||
|
||||
if (!data) {
|
||||
data = new ControlSidebar(this, _options)
|
||||
$(this).data(DATA_KEY, data)
|
||||
if (typeof $.fn.overlayScrollbars !== 'undefined') {
|
||||
$(Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).overlayScrollbars({
|
||||
className: this._config.scrollbarTheme,
|
||||
sizeAutoCapable: true,
|
||||
scrollbars: {
|
||||
autoHide: this._config.scrollbarAutoHide,
|
||||
clickScrolling: true
|
||||
}
|
||||
|
||||
if (data[operation] === 'undefined') {
|
||||
throw new Error(`${operation} is not a function`)
|
||||
}
|
||||
|
||||
data[operation]()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Data Api implementation
|
||||
* ====================================================
|
||||
*/
|
||||
$(document).on('click', Selector.DATA_TOGGLE, function (event) {
|
||||
event.preventDefault()
|
||||
// Static
|
||||
|
||||
ControlSidebar._jQueryInterface.call($(this), 'toggle')
|
||||
})
|
||||
static _jQueryInterface(operation) {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _options = $.extend({}, Default, $(this).data())
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
if (!data) {
|
||||
data = new ControlSidebar(this, _options)
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
|
||||
$.fn[NAME] = ControlSidebar._jQueryInterface
|
||||
$.fn[NAME].Constructor = ControlSidebar
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return ControlSidebar._jQueryInterface
|
||||
if (data[operation] === 'undefined') {
|
||||
throw new Error(`${operation} is not a function`)
|
||||
}
|
||||
|
||||
data[operation]()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return ControlSidebar
|
||||
})(jQuery)
|
||||
/**
|
||||
*
|
||||
* Data Api implementation
|
||||
* ====================================================
|
||||
*/
|
||||
$(document).on('click', Selector.DATA_TOGGLE, function (event) {
|
||||
event.preventDefault()
|
||||
|
||||
ControlSidebar._jQueryInterface.call($(this), 'toggle')
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = ControlSidebar._jQueryInterface
|
||||
$.fn[NAME].Constructor = ControlSidebar
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return ControlSidebar._jQueryInterface
|
||||
}
|
||||
|
||||
export default ControlSidebar
|
||||
|
||||
|
|
|
@ -5,87 +5,85 @@
|
|||
* --------------------------------------------
|
||||
*/
|
||||
|
||||
const DirectChat = ($ => {
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
import $ from 'jquery'
|
||||
|
||||
const NAME = 'DirectChat'
|
||||
const DATA_KEY = 'lte.directchat'
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
const Event = {
|
||||
TOGGLED: 'toggled{EVENT_KEY}'
|
||||
const NAME = 'DirectChat'
|
||||
const DATA_KEY = 'lte.directchat'
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
|
||||
const Event = {
|
||||
TOGGLED: 'toggled{EVENT_KEY}'
|
||||
}
|
||||
|
||||
const Selector = {
|
||||
DATA_TOGGLE: '[data-widget="chat-pane-toggle"]',
|
||||
DIRECT_CHAT: '.direct-chat'
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
DIRECT_CHAT_OPEN: 'direct-chat-contacts-open'
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
class DirectChat {
|
||||
constructor(element) {
|
||||
this._element = element
|
||||
}
|
||||
|
||||
const Selector = {
|
||||
DATA_TOGGLE: '[data-widget="chat-pane-toggle"]',
|
||||
DIRECT_CHAT: '.direct-chat'
|
||||
toggle() {
|
||||
$(this._element).parents(Selector.DIRECT_CHAT).first().toggleClass(ClassName.DIRECT_CHAT_OPEN)
|
||||
$(this._element).trigger($.Event(Event.TOGGLED))
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
DIRECT_CHAT_OPEN: 'direct-chat-contacts-open'
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
|
||||
if (!data) {
|
||||
data = new DirectChat($(this))
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
|
||||
data[config]()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Data Api implementation
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$(document).on('click', Selector.DATA_TOGGLE, function (event) {
|
||||
if (event) {
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
DirectChat._jQueryInterface.call($(this), 'toggle')
|
||||
})
|
||||
|
||||
class DirectChat {
|
||||
constructor(element) {
|
||||
this._element = element
|
||||
}
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
toggle() {
|
||||
$(this._element).parents(Selector.DIRECT_CHAT).first().toggleClass(ClassName.DIRECT_CHAT_OPEN)
|
||||
$(this._element).trigger($.Event(Event.TOGGLED))
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
|
||||
if (!data) {
|
||||
data = new DirectChat($(this))
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
|
||||
data[config]()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Data Api implementation
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$(document).on('click', Selector.DATA_TOGGLE, function (event) {
|
||||
if (event) {
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
DirectChat._jQueryInterface.call($(this), 'toggle')
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = DirectChat._jQueryInterface
|
||||
$.fn[NAME].Constructor = DirectChat
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return DirectChat._jQueryInterface
|
||||
}
|
||||
|
||||
return DirectChat
|
||||
})(jQuery)
|
||||
$.fn[NAME] = DirectChat._jQueryInterface
|
||||
$.fn[NAME].Constructor = DirectChat
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return DirectChat._jQueryInterface
|
||||
}
|
||||
|
||||
export default DirectChat
|
||||
|
|
|
@ -5,134 +5,132 @@
|
|||
* --------------------------------------------
|
||||
*/
|
||||
|
||||
const Dropdown = ($ => {
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
import $ from 'jquery'
|
||||
|
||||
const NAME = 'Dropdown'
|
||||
const DATA_KEY = 'lte.dropdown'
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
const Selector = {
|
||||
NAVBAR: '.navbar',
|
||||
DROPDOWN_MENU: '.dropdown-menu',
|
||||
DROPDOWN_MENU_ACTIVE: '.dropdown-menu.show',
|
||||
DROPDOWN_TOGGLE: '[data-toggle="dropdown"]'
|
||||
const NAME = 'Dropdown'
|
||||
const DATA_KEY = 'lte.dropdown'
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
|
||||
const Selector = {
|
||||
NAVBAR: '.navbar',
|
||||
DROPDOWN_MENU: '.dropdown-menu',
|
||||
DROPDOWN_MENU_ACTIVE: '.dropdown-menu.show',
|
||||
DROPDOWN_TOGGLE: '[data-toggle="dropdown"]'
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
DROPDOWN_RIGHT: 'dropdown-menu-right'
|
||||
}
|
||||
|
||||
const Default = {
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
class Dropdown {
|
||||
constructor(element, config) {
|
||||
this._config = config
|
||||
this._element = element
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
DROPDOWN_RIGHT: 'dropdown-menu-right'
|
||||
}
|
||||
// Public
|
||||
|
||||
const Default = {
|
||||
}
|
||||
toggleSubmenu() {
|
||||
this._element.siblings().show().toggleClass('show')
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
class Dropdown {
|
||||
constructor(element, config) {
|
||||
this._config = config
|
||||
this._element = element
|
||||
if (!this._element.next().hasClass('show')) {
|
||||
this._element.parents(Selector.DROPDOWN_MENU).first().find('.show').removeClass('show').hide()
|
||||
}
|
||||
|
||||
// Public
|
||||
this._element.parents('li.nav-item.dropdown.show').on('hidden.bs.dropdown', () => {
|
||||
$('.dropdown-submenu .show').removeClass('show').hide()
|
||||
})
|
||||
}
|
||||
|
||||
toggleSubmenu() {
|
||||
this._element.siblings().show().toggleClass('show')
|
||||
fixPosition() {
|
||||
const elm = $(Selector.DROPDOWN_MENU_ACTIVE)
|
||||
|
||||
if (!this._element.next().hasClass('show')) {
|
||||
this._element.parents(Selector.DROPDOWN_MENU).first().find('.show').removeClass('show').hide()
|
||||
if (elm.length !== 0) {
|
||||
if (elm.hasClass(ClassName.DROPDOWN_RIGHT)) {
|
||||
elm.css('left', 'inherit')
|
||||
elm.css('right', 0)
|
||||
} else {
|
||||
elm.css('left', 0)
|
||||
elm.css('right', 'inherit')
|
||||
}
|
||||
|
||||
this._element.parents('li.nav-item.dropdown.show').on('hidden.bs.dropdown', () => {
|
||||
$('.dropdown-submenu .show').removeClass('show').hide()
|
||||
})
|
||||
}
|
||||
const offset = elm.offset()
|
||||
const width = elm.width()
|
||||
const windowWidth = $(window).width()
|
||||
const visiblePart = windowWidth - offset.left
|
||||
|
||||
fixPosition() {
|
||||
const elm = $(Selector.DROPDOWN_MENU_ACTIVE)
|
||||
|
||||
if (elm.length !== 0) {
|
||||
if (elm.hasClass(ClassName.DROPDOWN_RIGHT)) {
|
||||
elm.css('left', 'inherit')
|
||||
elm.css('right', 0)
|
||||
} else {
|
||||
elm.css('left', 0)
|
||||
elm.css('right', 'inherit')
|
||||
}
|
||||
|
||||
const offset = elm.offset()
|
||||
const width = elm.width()
|
||||
const windowWidth = $(window).width()
|
||||
const visiblePart = windowWidth - offset.left
|
||||
|
||||
if (offset.left < 0) {
|
||||
elm.css('left', 'inherit')
|
||||
elm.css('right', (offset.left - 5))
|
||||
} else if (visiblePart < width) {
|
||||
elm.css('left', 'inherit')
|
||||
elm.css('right', 0)
|
||||
}
|
||||
if (offset.left < 0) {
|
||||
elm.css('left', 'inherit')
|
||||
elm.css('right', (offset.left - 5))
|
||||
} else if (visiblePart < width) {
|
||||
elm.css('left', 'inherit')
|
||||
elm.css('right', 0)
|
||||
}
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _config = $.extend({}, Default, $(this).data())
|
||||
|
||||
if (!data) {
|
||||
data = new Dropdown($(this), _config)
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
|
||||
if (config === 'toggleSubmenu' || config === 'fixPosition') {
|
||||
data[config]()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
// Static
|
||||
|
||||
$(Selector.DROPDOWN_MENU + ' ' + Selector.DROPDOWN_TOGGLE).on('click', function (event) {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
static _jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _config = $.extend({}, Default, $(this).data())
|
||||
|
||||
Dropdown._jQueryInterface.call($(this), 'toggleSubmenu')
|
||||
})
|
||||
if (!data) {
|
||||
data = new Dropdown($(this), _config)
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
|
||||
$(Selector.NAVBAR + ' ' + Selector.DROPDOWN_TOGGLE).on('click', event => {
|
||||
event.preventDefault()
|
||||
|
||||
setTimeout(function () {
|
||||
Dropdown._jQueryInterface.call($(this), 'fixPosition')
|
||||
}, 1)
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = Dropdown._jQueryInterface
|
||||
$.fn[NAME].Constructor = Dropdown
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return Dropdown._jQueryInterface
|
||||
if (config === 'toggleSubmenu' || config === 'fixPosition') {
|
||||
data[config]()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return Dropdown
|
||||
})(jQuery)
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$(Selector.DROPDOWN_MENU + ' ' + Selector.DROPDOWN_TOGGLE).on('click', function (event) {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
|
||||
Dropdown._jQueryInterface.call($(this), 'toggleSubmenu')
|
||||
})
|
||||
|
||||
$(Selector.NAVBAR + ' ' + Selector.DROPDOWN_TOGGLE).on('click', event => {
|
||||
event.preventDefault()
|
||||
|
||||
setTimeout(function () {
|
||||
Dropdown._jQueryInterface.call($(this), 'fixPosition')
|
||||
}, 1)
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = Dropdown._jQueryInterface
|
||||
$.fn[NAME].Constructor = Dropdown
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return Dropdown._jQueryInterface
|
||||
}
|
||||
|
||||
export default Dropdown
|
||||
|
|
|
@ -5,233 +5,231 @@
|
|||
* --------------------------------------------
|
||||
*/
|
||||
|
||||
const Layout = ($ => {
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
import $ from 'jquery'
|
||||
|
||||
const NAME = 'Layout'
|
||||
const DATA_KEY = 'lte.layout'
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
const Selector = {
|
||||
HEADER: '.main-header',
|
||||
MAIN_SIDEBAR: '.main-sidebar',
|
||||
SIDEBAR: '.main-sidebar .sidebar',
|
||||
CONTENT: '.content-wrapper',
|
||||
CONTROL_SIDEBAR_CONTENT: '.control-sidebar-content',
|
||||
CONTROL_SIDEBAR_BTN: '[data-widget="control-sidebar"]',
|
||||
FOOTER: '.main-footer',
|
||||
PUSHMENU_BTN: '[data-widget="pushmenu"]',
|
||||
LOGIN_BOX: '.login-box',
|
||||
REGISTER_BOX: '.register-box'
|
||||
const NAME = 'Layout'
|
||||
const DATA_KEY = 'lte.layout'
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
|
||||
const Selector = {
|
||||
HEADER: '.main-header',
|
||||
MAIN_SIDEBAR: '.main-sidebar',
|
||||
SIDEBAR: '.main-sidebar .sidebar',
|
||||
CONTENT: '.content-wrapper',
|
||||
CONTROL_SIDEBAR_CONTENT: '.control-sidebar-content',
|
||||
CONTROL_SIDEBAR_BTN: '[data-widget="control-sidebar"]',
|
||||
FOOTER: '.main-footer',
|
||||
PUSHMENU_BTN: '[data-widget="pushmenu"]',
|
||||
LOGIN_BOX: '.login-box',
|
||||
REGISTER_BOX: '.register-box'
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
SIDEBAR_FOCUSED: 'sidebar-focused',
|
||||
LAYOUT_FIXED: 'layout-fixed',
|
||||
CONTROL_SIDEBAR_SLIDE_OPEN: 'control-sidebar-slide-open',
|
||||
CONTROL_SIDEBAR_OPEN: 'control-sidebar-open'
|
||||
}
|
||||
|
||||
const Default = {
|
||||
scrollbarTheme: 'os-theme-light',
|
||||
scrollbarAutoHide: 'l',
|
||||
panelAutoHeight: true,
|
||||
loginRegisterAutoHeight: true
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
class Layout {
|
||||
constructor(element, config) {
|
||||
this._config = config
|
||||
this._element = element
|
||||
|
||||
this._init()
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
SIDEBAR_FOCUSED: 'sidebar-focused',
|
||||
LAYOUT_FIXED: 'layout-fixed',
|
||||
CONTROL_SIDEBAR_SLIDE_OPEN: 'control-sidebar-slide-open',
|
||||
CONTROL_SIDEBAR_OPEN: 'control-sidebar-open'
|
||||
}
|
||||
// Public
|
||||
|
||||
const Default = {
|
||||
scrollbarTheme: 'os-theme-light',
|
||||
scrollbarAutoHide: 'l',
|
||||
panelAutoHeight: true,
|
||||
loginRegisterAutoHeight: true
|
||||
}
|
||||
fixLayoutHeight(extra = null) {
|
||||
let controlSidebar = 0
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
class Layout {
|
||||
constructor(element, config) {
|
||||
this._config = config
|
||||
this._element = element
|
||||
|
||||
this._init()
|
||||
if ($('body').hasClass(ClassName.CONTROL_SIDEBAR_SLIDE_OPEN) || $('body').hasClass(ClassName.CONTROL_SIDEBAR_OPEN) || extra === 'control_sidebar') {
|
||||
controlSidebar = $(Selector.CONTROL_SIDEBAR_CONTENT).height()
|
||||
}
|
||||
|
||||
// Public
|
||||
const heights = {
|
||||
window: $(window).height(),
|
||||
header: $(Selector.HEADER).length !== 0 ? $(Selector.HEADER).outerHeight() : 0,
|
||||
footer: $(Selector.FOOTER).length !== 0 ? $(Selector.FOOTER).outerHeight() : 0,
|
||||
sidebar: $(Selector.SIDEBAR).length !== 0 ? $(Selector.SIDEBAR).height() : 0,
|
||||
controlSidebar
|
||||
}
|
||||
|
||||
fixLayoutHeight(extra = null) {
|
||||
let controlSidebar = 0
|
||||
const max = this._max(heights)
|
||||
let offset = this._config.panelAutoHeight
|
||||
|
||||
if ($('body').hasClass(ClassName.CONTROL_SIDEBAR_SLIDE_OPEN) || $('body').hasClass(ClassName.CONTROL_SIDEBAR_OPEN) || extra === 'control_sidebar') {
|
||||
controlSidebar = $(Selector.CONTROL_SIDEBAR_CONTENT).height()
|
||||
}
|
||||
if (offset === true) {
|
||||
offset = 0
|
||||
}
|
||||
|
||||
const heights = {
|
||||
window: $(window).height(),
|
||||
header: $(Selector.HEADER).length !== 0 ? $(Selector.HEADER).outerHeight() : 0,
|
||||
footer: $(Selector.FOOTER).length !== 0 ? $(Selector.FOOTER).outerHeight() : 0,
|
||||
sidebar: $(Selector.SIDEBAR).length !== 0 ? $(Selector.SIDEBAR).height() : 0,
|
||||
controlSidebar
|
||||
}
|
||||
|
||||
const max = this._max(heights)
|
||||
let offset = this._config.panelAutoHeight
|
||||
|
||||
if (offset === true) {
|
||||
offset = 0
|
||||
}
|
||||
|
||||
if (offset !== false) {
|
||||
if (max === heights.controlSidebar) {
|
||||
$(Selector.CONTENT).css('min-height', (max + offset))
|
||||
} else if (max === heights.window) {
|
||||
$(Selector.CONTENT).css('min-height', (max + offset) - heights.header - heights.footer)
|
||||
} else {
|
||||
$(Selector.CONTENT).css('min-height', (max + offset) - heights.header)
|
||||
}
|
||||
|
||||
if (this._isFooterFixed()) {
|
||||
$(Selector.CONTENT).css('min-height', parseFloat($(Selector.CONTENT).css('min-height')) + heights.footer)
|
||||
}
|
||||
}
|
||||
|
||||
if (!$('body').hasClass(ClassName.LAYOUT_FIXED)) {
|
||||
return
|
||||
}
|
||||
|
||||
if (offset !== false) {
|
||||
if (offset !== false) {
|
||||
if (max === heights.controlSidebar) {
|
||||
$(Selector.CONTENT).css('min-height', (max + offset))
|
||||
} else if (max === heights.window) {
|
||||
$(Selector.CONTENT).css('min-height', (max + offset) - heights.header - heights.footer)
|
||||
}
|
||||
|
||||
if (typeof $.fn.overlayScrollbars !== 'undefined') {
|
||||
$(Selector.SIDEBAR).overlayScrollbars({
|
||||
className: this._config.scrollbarTheme,
|
||||
sizeAutoCapable: true,
|
||||
scrollbars: {
|
||||
autoHide: this._config.scrollbarAutoHide,
|
||||
clickScrolling: true
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fixLoginRegisterHeight() {
|
||||
if ($(Selector.LOGIN_BOX + ', ' + Selector.REGISTER_BOX).length === 0) {
|
||||
$('body, html').css('height', 'auto')
|
||||
} else {
|
||||
const boxHeight = $(Selector.LOGIN_BOX + ', ' + Selector.REGISTER_BOX).height()
|
||||
$(Selector.CONTENT).css('min-height', (max + offset) - heights.header)
|
||||
}
|
||||
|
||||
if ($('body').css('min-height') !== boxHeight) {
|
||||
$('body').css('min-height', boxHeight)
|
||||
}
|
||||
if (this._isFooterFixed()) {
|
||||
$(Selector.CONTENT).css('min-height', parseFloat($(Selector.CONTENT).css('min-height')) + heights.footer)
|
||||
}
|
||||
}
|
||||
|
||||
// Private
|
||||
if (!$('body').hasClass(ClassName.LAYOUT_FIXED)) {
|
||||
return
|
||||
}
|
||||
|
||||
_init() {
|
||||
// Activate layout height watcher
|
||||
this.fixLayoutHeight()
|
||||
if (offset !== false) {
|
||||
$(Selector.CONTENT).css('min-height', (max + offset) - heights.header - heights.footer)
|
||||
}
|
||||
|
||||
if (this._config.loginRegisterAutoHeight === true) {
|
||||
this.fixLoginRegisterHeight()
|
||||
} else if (this._config.loginRegisterAutoHeight === parseInt(this._config.loginRegisterAutoHeight, 10)) {
|
||||
setInterval(this.fixLoginRegisterHeight, this._config.loginRegisterAutoHeight)
|
||||
if (typeof $.fn.overlayScrollbars !== 'undefined') {
|
||||
$(Selector.SIDEBAR).overlayScrollbars({
|
||||
className: this._config.scrollbarTheme,
|
||||
sizeAutoCapable: true,
|
||||
scrollbars: {
|
||||
autoHide: this._config.scrollbarAutoHide,
|
||||
clickScrolling: true
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fixLoginRegisterHeight() {
|
||||
if ($(Selector.LOGIN_BOX + ', ' + Selector.REGISTER_BOX).length === 0) {
|
||||
$('body, html').css('height', 'auto')
|
||||
} else {
|
||||
const boxHeight = $(Selector.LOGIN_BOX + ', ' + Selector.REGISTER_BOX).height()
|
||||
|
||||
if ($('body').css('min-height') !== boxHeight) {
|
||||
$('body').css('min-height', boxHeight)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$(Selector.SIDEBAR)
|
||||
.on('collapsed.lte.treeview expanded.lte.treeview', () => {
|
||||
this.fixLayoutHeight()
|
||||
})
|
||||
// Private
|
||||
|
||||
$(Selector.PUSHMENU_BTN)
|
||||
.on('collapsed.lte.pushmenu shown.lte.pushmenu', () => {
|
||||
this.fixLayoutHeight()
|
||||
})
|
||||
_init() {
|
||||
// Activate layout height watcher
|
||||
this.fixLayoutHeight()
|
||||
|
||||
$(Selector.CONTROL_SIDEBAR_BTN)
|
||||
.on('collapsed.lte.controlsidebar', () => {
|
||||
this.fixLayoutHeight()
|
||||
})
|
||||
.on('expanded.lte.controlsidebar', () => {
|
||||
this.fixLayoutHeight('control_sidebar')
|
||||
})
|
||||
if (this._config.loginRegisterAutoHeight === true) {
|
||||
this.fixLoginRegisterHeight()
|
||||
} else if (this._config.loginRegisterAutoHeight === parseInt(this._config.loginRegisterAutoHeight, 10)) {
|
||||
setInterval(this.fixLoginRegisterHeight, this._config.loginRegisterAutoHeight)
|
||||
}
|
||||
|
||||
$(window).resize(() => {
|
||||
$(Selector.SIDEBAR)
|
||||
.on('collapsed.lte.treeview expanded.lte.treeview', () => {
|
||||
this.fixLayoutHeight()
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
$('body.hold-transition').removeClass('hold-transition')
|
||||
}, 50)
|
||||
}
|
||||
|
||||
_max(numbers) {
|
||||
// Calculate the maximum number in a list
|
||||
let max = 0
|
||||
|
||||
Object.keys(numbers).forEach(key => {
|
||||
if (numbers[key] > max) {
|
||||
max = numbers[key]
|
||||
}
|
||||
$(Selector.PUSHMENU_BTN)
|
||||
.on('collapsed.lte.pushmenu shown.lte.pushmenu', () => {
|
||||
this.fixLayoutHeight()
|
||||
})
|
||||
|
||||
return max
|
||||
}
|
||||
|
||||
_isFooterFixed() {
|
||||
return $('.main-footer').css('position') === 'fixed'
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(config = '') {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _options = $.extend({}, Default, $(this).data())
|
||||
|
||||
if (!data) {
|
||||
data = new Layout($(this), _options)
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
|
||||
if (config === 'init' || config === '') {
|
||||
data._init()
|
||||
} else if (config === 'fixLayoutHeight' || config === 'fixLoginRegisterHeight') {
|
||||
data[config]()
|
||||
}
|
||||
$(Selector.CONTROL_SIDEBAR_BTN)
|
||||
.on('collapsed.lte.controlsidebar', () => {
|
||||
this.fixLayoutHeight()
|
||||
})
|
||||
}
|
||||
.on('expanded.lte.controlsidebar', () => {
|
||||
this.fixLayoutHeight('control_sidebar')
|
||||
})
|
||||
|
||||
$(window).resize(() => {
|
||||
this.fixLayoutHeight()
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
$('body.hold-transition').removeClass('hold-transition')
|
||||
}, 50)
|
||||
}
|
||||
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
_max(numbers) {
|
||||
// Calculate the maximum number in a list
|
||||
let max = 0
|
||||
|
||||
$(window).on('load', () => {
|
||||
Layout._jQueryInterface.call($('body'))
|
||||
})
|
||||
Object.keys(numbers).forEach(key => {
|
||||
if (numbers[key] > max) {
|
||||
max = numbers[key]
|
||||
}
|
||||
})
|
||||
|
||||
$(Selector.SIDEBAR + ' a').on('focusin', () => {
|
||||
$(Selector.MAIN_SIDEBAR).addClass(ClassName.SIDEBAR_FOCUSED)
|
||||
})
|
||||
|
||||
$(Selector.SIDEBAR + ' a').on('focusout', () => {
|
||||
$(Selector.MAIN_SIDEBAR).removeClass(ClassName.SIDEBAR_FOCUSED)
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = Layout._jQueryInterface
|
||||
$.fn[NAME].Constructor = Layout
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return Layout._jQueryInterface
|
||||
return max
|
||||
}
|
||||
|
||||
return Layout
|
||||
})(jQuery)
|
||||
_isFooterFixed() {
|
||||
return $('.main-footer').css('position') === 'fixed'
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(config = '') {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _options = $.extend({}, Default, $(this).data())
|
||||
|
||||
if (!data) {
|
||||
data = new Layout($(this), _options)
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
|
||||
if (config === 'init' || config === '') {
|
||||
data._init()
|
||||
} else if (config === 'fixLayoutHeight' || config === 'fixLoginRegisterHeight') {
|
||||
data[config]()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$(window).on('load', () => {
|
||||
Layout._jQueryInterface.call($('body'))
|
||||
})
|
||||
|
||||
$(Selector.SIDEBAR + ' a').on('focusin', () => {
|
||||
$(Selector.MAIN_SIDEBAR).addClass(ClassName.SIDEBAR_FOCUSED)
|
||||
})
|
||||
|
||||
$(Selector.SIDEBAR + ' a').on('focusout', () => {
|
||||
$(Selector.MAIN_SIDEBAR).removeClass(ClassName.SIDEBAR_FOCUSED)
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = Layout._jQueryInterface
|
||||
$.fn[NAME].Constructor = Layout
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return Layout._jQueryInterface
|
||||
}
|
||||
|
||||
export default Layout
|
||||
|
|
|
@ -5,219 +5,217 @@
|
|||
* --------------------------------------------
|
||||
*/
|
||||
|
||||
const PushMenu = ($ => {
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
import $ from 'jquery'
|
||||
|
||||
const NAME = 'PushMenu'
|
||||
const DATA_KEY = 'lte.pushmenu'
|
||||
const EVENT_KEY = `.${DATA_KEY}`
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
const Event = {
|
||||
COLLAPSED: `collapsed${EVENT_KEY}`,
|
||||
SHOWN: `shown${EVENT_KEY}`
|
||||
}
|
||||
const NAME = 'PushMenu'
|
||||
const DATA_KEY = 'lte.pushmenu'
|
||||
const EVENT_KEY = `.${DATA_KEY}`
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
|
||||
const Default = {
|
||||
autoCollapseSize: 992,
|
||||
enableRemember: false,
|
||||
noTransitionAfterReload: true
|
||||
}
|
||||
const Event = {
|
||||
COLLAPSED: `collapsed${EVENT_KEY}`,
|
||||
SHOWN: `shown${EVENT_KEY}`
|
||||
}
|
||||
|
||||
const Selector = {
|
||||
TOGGLE_BUTTON: '[data-widget="pushmenu"]',
|
||||
BODY: 'body',
|
||||
OVERLAY: '#sidebar-overlay',
|
||||
WRAPPER: '.wrapper'
|
||||
}
|
||||
const Default = {
|
||||
autoCollapseSize: 992,
|
||||
enableRemember: false,
|
||||
noTransitionAfterReload: true
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
COLLAPSED: 'sidebar-collapse',
|
||||
OPEN: 'sidebar-open',
|
||||
CLOSED: 'sidebar-closed'
|
||||
}
|
||||
const Selector = {
|
||||
TOGGLE_BUTTON: '[data-widget="pushmenu"]',
|
||||
BODY: 'body',
|
||||
OVERLAY: '#sidebar-overlay',
|
||||
WRAPPER: '.wrapper'
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
const ClassName = {
|
||||
COLLAPSED: 'sidebar-collapse',
|
||||
OPEN: 'sidebar-open',
|
||||
CLOSED: 'sidebar-closed'
|
||||
}
|
||||
|
||||
class PushMenu {
|
||||
constructor(element, options) {
|
||||
this._element = element
|
||||
this._options = $.extend({}, Default, options)
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
if ($(Selector.OVERLAY).length === 0) {
|
||||
this._addOverlay()
|
||||
}
|
||||
class PushMenu {
|
||||
constructor(element, options) {
|
||||
this._element = element
|
||||
this._options = $.extend({}, Default, options)
|
||||
|
||||
this._init()
|
||||
if ($(Selector.OVERLAY).length === 0) {
|
||||
this._addOverlay()
|
||||
}
|
||||
|
||||
// Public
|
||||
this._init()
|
||||
}
|
||||
|
||||
expand() {
|
||||
if (this._options.autoCollapseSize) {
|
||||
if ($(window).width() <= this._options.autoCollapseSize) {
|
||||
$(Selector.BODY).addClass(ClassName.OPEN)
|
||||
}
|
||||
// Public
|
||||
|
||||
expand() {
|
||||
if (this._options.autoCollapseSize) {
|
||||
if ($(window).width() <= this._options.autoCollapseSize) {
|
||||
$(Selector.BODY).addClass(ClassName.OPEN)
|
||||
}
|
||||
|
||||
$(Selector.BODY).removeClass(ClassName.COLLAPSED).removeClass(ClassName.CLOSED)
|
||||
|
||||
if (this._options.enableRemember) {
|
||||
localStorage.setItem(`remember${EVENT_KEY}`, ClassName.OPEN)
|
||||
}
|
||||
|
||||
$(this._element).trigger($.Event(Event.SHOWN))
|
||||
}
|
||||
|
||||
collapse() {
|
||||
if (this._options.autoCollapseSize) {
|
||||
if ($(window).width() <= this._options.autoCollapseSize) {
|
||||
$(Selector.BODY).removeClass(ClassName.OPEN).addClass(ClassName.CLOSED)
|
||||
}
|
||||
}
|
||||
$(Selector.BODY).removeClass(ClassName.COLLAPSED).removeClass(ClassName.CLOSED)
|
||||
|
||||
$(Selector.BODY).addClass(ClassName.COLLAPSED)
|
||||
|
||||
if (this._options.enableRemember) {
|
||||
localStorage.setItem(`remember${EVENT_KEY}`, ClassName.COLLAPSED)
|
||||
}
|
||||
|
||||
$(this._element).trigger($.Event(Event.COLLAPSED))
|
||||
if (this._options.enableRemember) {
|
||||
localStorage.setItem(`remember${EVENT_KEY}`, ClassName.OPEN)
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if ($(Selector.BODY).hasClass(ClassName.COLLAPSED)) {
|
||||
this.expand()
|
||||
} else {
|
||||
$(this._element).trigger($.Event(Event.SHOWN))
|
||||
}
|
||||
|
||||
collapse() {
|
||||
if (this._options.autoCollapseSize) {
|
||||
if ($(window).width() <= this._options.autoCollapseSize) {
|
||||
$(Selector.BODY).removeClass(ClassName.OPEN).addClass(ClassName.CLOSED)
|
||||
}
|
||||
}
|
||||
|
||||
$(Selector.BODY).addClass(ClassName.COLLAPSED)
|
||||
|
||||
if (this._options.enableRemember) {
|
||||
localStorage.setItem(`remember${EVENT_KEY}`, ClassName.COLLAPSED)
|
||||
}
|
||||
|
||||
$(this._element).trigger($.Event(Event.COLLAPSED))
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if ($(Selector.BODY).hasClass(ClassName.COLLAPSED)) {
|
||||
this.expand()
|
||||
} else {
|
||||
this.collapse()
|
||||
}
|
||||
}
|
||||
|
||||
autoCollapse(resize = false) {
|
||||
if (!this._options.autoCollapseSize) {
|
||||
return
|
||||
}
|
||||
|
||||
if ($(window).width() <= this._options.autoCollapseSize) {
|
||||
if (!$(Selector.BODY).hasClass(ClassName.OPEN)) {
|
||||
this.collapse()
|
||||
}
|
||||
}
|
||||
|
||||
autoCollapse(resize = false) {
|
||||
if (!this._options.autoCollapseSize) {
|
||||
return
|
||||
}
|
||||
|
||||
if ($(window).width() <= this._options.autoCollapseSize) {
|
||||
if (!$(Selector.BODY).hasClass(ClassName.OPEN)) {
|
||||
this.collapse()
|
||||
}
|
||||
} else if (resize === true) {
|
||||
if ($(Selector.BODY).hasClass(ClassName.OPEN)) {
|
||||
$(Selector.BODY).removeClass(ClassName.OPEN)
|
||||
} else if ($(Selector.BODY).hasClass(ClassName.CLOSED)) {
|
||||
this.expand()
|
||||
}
|
||||
} else if (resize === true) {
|
||||
if ($(Selector.BODY).hasClass(ClassName.OPEN)) {
|
||||
$(Selector.BODY).removeClass(ClassName.OPEN)
|
||||
} else if ($(Selector.BODY).hasClass(ClassName.CLOSED)) {
|
||||
this.expand()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
remember() {
|
||||
if (!this._options.enableRemember) {
|
||||
return
|
||||
}
|
||||
remember() {
|
||||
if (!this._options.enableRemember) {
|
||||
return
|
||||
}
|
||||
|
||||
const toggleState = localStorage.getItem(`remember${EVENT_KEY}`)
|
||||
if (toggleState === ClassName.COLLAPSED) {
|
||||
if (this._options.noTransitionAfterReload) {
|
||||
$('body').addClass('hold-transition').addClass(ClassName.COLLAPSED).delay(50).queue(function () {
|
||||
$(this).removeClass('hold-transition')
|
||||
$(this).dequeue()
|
||||
})
|
||||
} else {
|
||||
$('body').addClass(ClassName.COLLAPSED)
|
||||
}
|
||||
} else if (this._options.noTransitionAfterReload) {
|
||||
$('body').addClass('hold-transition').removeClass(ClassName.COLLAPSED).delay(50).queue(function () {
|
||||
const toggleState = localStorage.getItem(`remember${EVENT_KEY}`)
|
||||
if (toggleState === ClassName.COLLAPSED) {
|
||||
if (this._options.noTransitionAfterReload) {
|
||||
$('body').addClass('hold-transition').addClass(ClassName.COLLAPSED).delay(50).queue(function () {
|
||||
$(this).removeClass('hold-transition')
|
||||
$(this).dequeue()
|
||||
})
|
||||
} else {
|
||||
$('body').removeClass(ClassName.COLLAPSED)
|
||||
$('body').addClass(ClassName.COLLAPSED)
|
||||
}
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
_init() {
|
||||
this.remember()
|
||||
this.autoCollapse()
|
||||
|
||||
$(window).resize(() => {
|
||||
this.autoCollapse(true)
|
||||
})
|
||||
}
|
||||
|
||||
_addOverlay() {
|
||||
const overlay = $('<div />', {
|
||||
id: 'sidebar-overlay'
|
||||
})
|
||||
|
||||
overlay.on('click', () => {
|
||||
this.collapse()
|
||||
})
|
||||
|
||||
$(Selector.WRAPPER).append(overlay)
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(operation) {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _options = $.extend({}, Default, $(this).data())
|
||||
|
||||
if (!data) {
|
||||
data = new PushMenu(this, _options)
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
|
||||
if (typeof operation === 'string' && operation.match(/collapse|expand|toggle/)) {
|
||||
data[operation]()
|
||||
}
|
||||
} else if (this._options.noTransitionAfterReload) {
|
||||
$('body').addClass('hold-transition').removeClass(ClassName.COLLAPSED).delay(50).queue(function () {
|
||||
$(this).removeClass('hold-transition')
|
||||
$(this).dequeue()
|
||||
})
|
||||
} else {
|
||||
$('body').removeClass(ClassName.COLLAPSED)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
// Private
|
||||
|
||||
$(document).on('click', Selector.TOGGLE_BUTTON, event => {
|
||||
event.preventDefault()
|
||||
_init() {
|
||||
this.remember()
|
||||
this.autoCollapse()
|
||||
|
||||
let button = event.currentTarget
|
||||
|
||||
if ($(button).data('widget') !== 'pushmenu') {
|
||||
button = $(button).closest(Selector.TOGGLE_BUTTON)
|
||||
}
|
||||
|
||||
PushMenu._jQueryInterface.call($(button), 'toggle')
|
||||
})
|
||||
|
||||
$(window).on('load', () => {
|
||||
PushMenu._jQueryInterface.call($(Selector.TOGGLE_BUTTON))
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = PushMenu._jQueryInterface
|
||||
$.fn[NAME].Constructor = PushMenu
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return PushMenu._jQueryInterface
|
||||
$(window).resize(() => {
|
||||
this.autoCollapse(true)
|
||||
})
|
||||
}
|
||||
|
||||
return PushMenu
|
||||
})(jQuery)
|
||||
_addOverlay() {
|
||||
const overlay = $('<div />', {
|
||||
id: 'sidebar-overlay'
|
||||
})
|
||||
|
||||
overlay.on('click', () => {
|
||||
this.collapse()
|
||||
})
|
||||
|
||||
$(Selector.WRAPPER).append(overlay)
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(operation) {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _options = $.extend({}, Default, $(this).data())
|
||||
|
||||
if (!data) {
|
||||
data = new PushMenu(this, _options)
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
|
||||
if (typeof operation === 'string' && operation.match(/collapse|expand|toggle/)) {
|
||||
data[operation]()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$(document).on('click', Selector.TOGGLE_BUTTON, event => {
|
||||
event.preventDefault()
|
||||
|
||||
let button = event.currentTarget
|
||||
|
||||
if ($(button).data('widget') !== 'pushmenu') {
|
||||
button = $(button).closest(Selector.TOGGLE_BUTTON)
|
||||
}
|
||||
|
||||
PushMenu._jQueryInterface.call($(button), 'toggle')
|
||||
})
|
||||
|
||||
$(window).on('load', () => {
|
||||
PushMenu._jQueryInterface.call($(Selector.TOGGLE_BUTTON))
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = PushMenu._jQueryInterface
|
||||
$.fn[NAME].Constructor = PushMenu
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return PushMenu._jQueryInterface
|
||||
}
|
||||
|
||||
export default PushMenu
|
||||
|
|
|
@ -5,119 +5,117 @@
|
|||
* --------------------------------------------
|
||||
*/
|
||||
|
||||
const SiteSearch = ($ => {
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
import $ from 'jquery'
|
||||
|
||||
const NAME = 'SiteSearch'
|
||||
const DATA_KEY = 'lte.site-search'
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
const Selector = {
|
||||
TOGGLE_BUTTON: '[data-widget="site-search"]',
|
||||
SEARCH_BLOCK: '.site-search-block',
|
||||
SEARCH_BACKDROP: '.site-search-backdrop',
|
||||
SEARCH_INPUT: '.site-search-block .form-control'
|
||||
const NAME = 'SiteSearch'
|
||||
const DATA_KEY = 'lte.site-search'
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
|
||||
const Selector = {
|
||||
TOGGLE_BUTTON: '[data-widget="site-search"]',
|
||||
SEARCH_BLOCK: '.site-search-block',
|
||||
SEARCH_BACKDROP: '.site-search-backdrop',
|
||||
SEARCH_INPUT: '.site-search-block .form-control'
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
OPEN: 'site-search-open'
|
||||
}
|
||||
|
||||
const Default = {
|
||||
transitionSpeed: 300
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
class SiteSearch {
|
||||
constructor(_element, _options) {
|
||||
this.element = _element
|
||||
this.options = $.extend({}, Default, _options)
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
OPEN: 'site-search-open'
|
||||
// Public
|
||||
|
||||
open() {
|
||||
$(Selector.SEARCH_BLOCK).slideDown(this.options.transitionSpeed)
|
||||
$(Selector.SEARCH_BACKDROP).show(0)
|
||||
$(Selector.SEARCH_INPUT).focus()
|
||||
$(Selector.SEARCH_BLOCK).addClass(ClassName.OPEN)
|
||||
}
|
||||
|
||||
const Default = {
|
||||
transitionSpeed: 300
|
||||
close() {
|
||||
$(Selector.SEARCH_BLOCK).slideUp(this.options.transitionSpeed)
|
||||
$(Selector.SEARCH_BACKDROP).hide(0)
|
||||
$(Selector.SEARCH_BLOCK).removeClass(ClassName.OPEN)
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
class SiteSearch {
|
||||
constructor(_element, _options) {
|
||||
this.element = _element
|
||||
this.options = $.extend({}, Default, _options)
|
||||
toggle() {
|
||||
if ($(Selector.SEARCH_BLOCK).hasClass(ClassName.OPEN)) {
|
||||
this.close()
|
||||
} else {
|
||||
this.open()
|
||||
}
|
||||
}
|
||||
|
||||
// Public
|
||||
// Static
|
||||
|
||||
open() {
|
||||
$(Selector.SEARCH_BLOCK).slideDown(this.options.transitionSpeed)
|
||||
$(Selector.SEARCH_BACKDROP).show(0)
|
||||
$(Selector.SEARCH_INPUT).focus()
|
||||
$(Selector.SEARCH_BLOCK).addClass(ClassName.OPEN)
|
||||
}
|
||||
static _jQueryInterface(options) {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
|
||||
close() {
|
||||
$(Selector.SEARCH_BLOCK).slideUp(this.options.transitionSpeed)
|
||||
$(Selector.SEARCH_BACKDROP).hide(0)
|
||||
$(Selector.SEARCH_BLOCK).removeClass(ClassName.OPEN)
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if ($(Selector.SEARCH_BLOCK).hasClass(ClassName.OPEN)) {
|
||||
this.close()
|
||||
} else {
|
||||
this.open()
|
||||
if (!data) {
|
||||
data = new SiteSearch(this, options)
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
}
|
||||
|
||||
// Static
|
||||
if (!/toggle|close/.test(options)) {
|
||||
throw new Error(`Undefined method ${options}`)
|
||||
}
|
||||
|
||||
static _jQueryInterface(options) {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
data[options]()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
data = new SiteSearch(this, options)
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
$(document).on('click', Selector.TOGGLE_BUTTON, event => {
|
||||
event.preventDefault()
|
||||
|
||||
if (!/toggle|close/.test(options)) {
|
||||
throw new Error(`Undefined method ${options}`)
|
||||
}
|
||||
let button = $(event.currentTarget)
|
||||
|
||||
data[options]()
|
||||
})
|
||||
}
|
||||
if (button.data('widget') !== 'site-search') {
|
||||
button = button.closest(Selector.TOGGLE_BUTTON)
|
||||
}
|
||||
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
$(document).on('click', Selector.TOGGLE_BUTTON, event => {
|
||||
event.preventDefault()
|
||||
SiteSearch._jQueryInterface.call(button, 'toggle')
|
||||
})
|
||||
|
||||
let button = $(event.currentTarget)
|
||||
$(document).on('click', Selector.SEARCH_BACKDROP, event => {
|
||||
const backdrop = $(event.currentTarget)
|
||||
SiteSearch._jQueryInterface.call(backdrop, 'close')
|
||||
})
|
||||
|
||||
if (button.data('widget') !== 'site-search') {
|
||||
button = button.closest(Selector.TOGGLE_BUTTON)
|
||||
}
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
SiteSearch._jQueryInterface.call(button, 'toggle')
|
||||
})
|
||||
|
||||
$(document).on('click', Selector.SEARCH_BACKDROP, event => {
|
||||
const backdrop = $(event.currentTarget)
|
||||
SiteSearch._jQueryInterface.call(backdrop, 'close')
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = SiteSearch._jQueryInterface
|
||||
$.fn[NAME].Constructor = SiteSearch
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return SiteSearch._jQueryInterface
|
||||
}
|
||||
|
||||
return SiteSearch
|
||||
})(jQuery)
|
||||
$.fn[NAME] = SiteSearch._jQueryInterface
|
||||
$.fn[NAME].Constructor = SiteSearch
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return SiteSearch._jQueryInterface
|
||||
}
|
||||
|
||||
export default SiteSearch
|
||||
|
|
|
@ -5,214 +5,212 @@
|
|||
* --------------------------------------------
|
||||
*/
|
||||
|
||||
const Toasts = ($ => {
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
import $ from 'jquery'
|
||||
|
||||
const NAME = 'Toasts'
|
||||
const DATA_KEY = 'lte.toasts'
|
||||
const EVENT_KEY = `.${DATA_KEY}`
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
const Event = {
|
||||
INIT: `init${EVENT_KEY}`,
|
||||
CREATED: `created${EVENT_KEY}`,
|
||||
REMOVED: `removed${EVENT_KEY}`
|
||||
const NAME = 'Toasts'
|
||||
const DATA_KEY = 'lte.toasts'
|
||||
const EVENT_KEY = `.${DATA_KEY}`
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
|
||||
const Event = {
|
||||
INIT: `init${EVENT_KEY}`,
|
||||
CREATED: `created${EVENT_KEY}`,
|
||||
REMOVED: `removed${EVENT_KEY}`
|
||||
}
|
||||
|
||||
const Selector = {
|
||||
CONTAINER_TOP_RIGHT: '#toastsContainerTopRight',
|
||||
CONTAINER_TOP_LEFT: '#toastsContainerTopLeft',
|
||||
CONTAINER_BOTTOM_RIGHT: '#toastsContainerBottomRight',
|
||||
CONTAINER_BOTTOM_LEFT: '#toastsContainerBottomLeft'
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
TOP_RIGHT: 'toasts-top-right',
|
||||
TOP_LEFT: 'toasts-top-left',
|
||||
BOTTOM_RIGHT: 'toasts-bottom-right',
|
||||
BOTTOM_LEFT: 'toasts-bottom-left'
|
||||
}
|
||||
|
||||
const Position = {
|
||||
TOP_RIGHT: 'topRight',
|
||||
TOP_LEFT: 'topLeft',
|
||||
BOTTOM_RIGHT: 'bottomRight',
|
||||
BOTTOM_LEFT: 'bottomLeft'
|
||||
}
|
||||
|
||||
const Default = {
|
||||
position: Position.TOP_RIGHT,
|
||||
fixed: true,
|
||||
autohide: false,
|
||||
autoremove: true,
|
||||
delay: 1000,
|
||||
fade: true,
|
||||
icon: null,
|
||||
image: null,
|
||||
imageAlt: null,
|
||||
imageHeight: '25px',
|
||||
title: null,
|
||||
subtitle: null,
|
||||
close: true,
|
||||
body: null,
|
||||
class: null
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
class Toasts {
|
||||
constructor(element, config) {
|
||||
this._config = config
|
||||
this._prepareContainer()
|
||||
|
||||
$('body').trigger($.Event(Event.INIT))
|
||||
}
|
||||
|
||||
const Selector = {
|
||||
CONTAINER_TOP_RIGHT: '#toastsContainerTopRight',
|
||||
CONTAINER_TOP_LEFT: '#toastsContainerTopLeft',
|
||||
CONTAINER_BOTTOM_RIGHT: '#toastsContainerBottomRight',
|
||||
CONTAINER_BOTTOM_LEFT: '#toastsContainerBottomLeft'
|
||||
}
|
||||
// Public
|
||||
|
||||
const ClassName = {
|
||||
TOP_RIGHT: 'toasts-top-right',
|
||||
TOP_LEFT: 'toasts-top-left',
|
||||
BOTTOM_RIGHT: 'toasts-bottom-right',
|
||||
BOTTOM_LEFT: 'toasts-bottom-left'
|
||||
}
|
||||
create() {
|
||||
const toast = $('<div class="toast" role="alert" aria-live="assertive" aria-atomic="true"/>')
|
||||
|
||||
const Position = {
|
||||
TOP_RIGHT: 'topRight',
|
||||
TOP_LEFT: 'topLeft',
|
||||
BOTTOM_RIGHT: 'bottomRight',
|
||||
BOTTOM_LEFT: 'bottomLeft'
|
||||
}
|
||||
toast.data('autohide', this._config.autohide)
|
||||
toast.data('animation', this._config.fade)
|
||||
|
||||
const Default = {
|
||||
position: Position.TOP_RIGHT,
|
||||
fixed: true,
|
||||
autohide: false,
|
||||
autoremove: true,
|
||||
delay: 1000,
|
||||
fade: true,
|
||||
icon: null,
|
||||
image: null,
|
||||
imageAlt: null,
|
||||
imageHeight: '25px',
|
||||
title: null,
|
||||
subtitle: null,
|
||||
close: true,
|
||||
body: null,
|
||||
class: null
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
class Toasts {
|
||||
constructor(element, config) {
|
||||
this._config = config
|
||||
this._prepareContainer()
|
||||
|
||||
$('body').trigger($.Event(Event.INIT))
|
||||
if (this._config.class) {
|
||||
toast.addClass(this._config.class)
|
||||
}
|
||||
|
||||
// Public
|
||||
|
||||
create() {
|
||||
const toast = $('<div class="toast" role="alert" aria-live="assertive" aria-atomic="true"/>')
|
||||
|
||||
toast.data('autohide', this._config.autohide)
|
||||
toast.data('animation', this._config.fade)
|
||||
|
||||
if (this._config.class) {
|
||||
toast.addClass(this._config.class)
|
||||
}
|
||||
|
||||
if (this._config.delay && this._config.delay != 500) {
|
||||
toast.data('delay', this._config.delay)
|
||||
}
|
||||
|
||||
const toastHeader = $('<div class="toast-header">')
|
||||
|
||||
if (this._config.image != null) {
|
||||
const toastImage = $('<img />').addClass('rounded mr-2').attr('src', this._config.image).attr('alt', this._config.imageAlt)
|
||||
|
||||
if (this._config.imageHeight != null) {
|
||||
toastImage.height(this._config.imageHeight).width('auto')
|
||||
}
|
||||
|
||||
toastHeader.append(toastImage)
|
||||
}
|
||||
|
||||
if (this._config.icon != null) {
|
||||
toastHeader.append($('<i />').addClass('mr-2').addClass(this._config.icon))
|
||||
}
|
||||
|
||||
if (this._config.title != null) {
|
||||
toastHeader.append($('<strong />').addClass('mr-auto').html(this._config.title))
|
||||
}
|
||||
|
||||
if (this._config.subtitle != null) {
|
||||
toastHeader.append($('<small />').html(this._config.subtitle))
|
||||
}
|
||||
|
||||
if (this._config.close == true) {
|
||||
const toastClose = $('<button data-dismiss="toast" />').attr('type', 'button').addClass('ml-2 mb-1 close').attr('aria-label', 'Close').append('<span aria-hidden="true">×</span>')
|
||||
|
||||
if (this._config.title == null) {
|
||||
toastClose.toggleClass('ml-2 ml-auto')
|
||||
}
|
||||
|
||||
toastHeader.append(toastClose)
|
||||
}
|
||||
|
||||
toast.append(toastHeader)
|
||||
|
||||
if (this._config.body != null) {
|
||||
toast.append($('<div class="toast-body" />').html(this._config.body))
|
||||
}
|
||||
|
||||
$(this._getContainerId()).prepend(toast)
|
||||
|
||||
$('body').trigger($.Event(Event.CREATED))
|
||||
|
||||
toast.toast('show')
|
||||
|
||||
if (this._config.autoremove) {
|
||||
toast.on('hidden.bs.toast', function () {
|
||||
$(this).delay(200).remove()
|
||||
$('body').trigger($.Event(Event.REMOVED))
|
||||
})
|
||||
}
|
||||
if (this._config.delay && this._config.delay != 500) {
|
||||
toast.data('delay', this._config.delay)
|
||||
}
|
||||
|
||||
// Static
|
||||
const toastHeader = $('<div class="toast-header">')
|
||||
|
||||
_getContainerId() {
|
||||
if (this._config.position == Position.TOP_RIGHT) {
|
||||
return Selector.CONTAINER_TOP_RIGHT
|
||||
if (this._config.image != null) {
|
||||
const toastImage = $('<img />').addClass('rounded mr-2').attr('src', this._config.image).attr('alt', this._config.imageAlt)
|
||||
|
||||
if (this._config.imageHeight != null) {
|
||||
toastImage.height(this._config.imageHeight).width('auto')
|
||||
}
|
||||
|
||||
if (this._config.position == Position.TOP_LEFT) {
|
||||
return Selector.CONTAINER_TOP_LEFT
|
||||
}
|
||||
|
||||
if (this._config.position == Position.BOTTOM_RIGHT) {
|
||||
return Selector.CONTAINER_BOTTOM_RIGHT
|
||||
}
|
||||
|
||||
if (this._config.position == Position.BOTTOM_LEFT) {
|
||||
return Selector.CONTAINER_BOTTOM_LEFT
|
||||
}
|
||||
toastHeader.append(toastImage)
|
||||
}
|
||||
|
||||
_prepareContainer() {
|
||||
if ($(this._getContainerId()).length === 0) {
|
||||
const container = $('<div />').attr('id', this._getContainerId().replace('#', ''))
|
||||
if (this._config.position == Position.TOP_RIGHT) {
|
||||
container.addClass(ClassName.TOP_RIGHT)
|
||||
} else if (this._config.position == Position.TOP_LEFT) {
|
||||
container.addClass(ClassName.TOP_LEFT)
|
||||
} else if (this._config.position == Position.BOTTOM_RIGHT) {
|
||||
container.addClass(ClassName.BOTTOM_RIGHT)
|
||||
} else if (this._config.position == Position.BOTTOM_LEFT) {
|
||||
container.addClass(ClassName.BOTTOM_LEFT)
|
||||
}
|
||||
|
||||
$('body').append(container)
|
||||
}
|
||||
|
||||
if (this._config.fixed) {
|
||||
$(this._getContainerId()).addClass('fixed')
|
||||
} else {
|
||||
$(this._getContainerId()).removeClass('fixed')
|
||||
}
|
||||
if (this._config.icon != null) {
|
||||
toastHeader.append($('<i />').addClass('mr-2').addClass(this._config.icon))
|
||||
}
|
||||
|
||||
// Static
|
||||
if (this._config.title != null) {
|
||||
toastHeader.append($('<strong />').addClass('mr-auto').html(this._config.title))
|
||||
}
|
||||
|
||||
static _jQueryInterface(option, config) {
|
||||
return this.each(function () {
|
||||
const _options = $.extend({}, Default, config)
|
||||
const toast = new Toasts($(this), _options)
|
||||
if (this._config.subtitle != null) {
|
||||
toastHeader.append($('<small />').html(this._config.subtitle))
|
||||
}
|
||||
|
||||
if (option === 'create') {
|
||||
toast[option]()
|
||||
}
|
||||
if (this._config.close == true) {
|
||||
const toastClose = $('<button data-dismiss="toast" />').attr('type', 'button').addClass('ml-2 mb-1 close').attr('aria-label', 'Close').append('<span aria-hidden="true">×</span>')
|
||||
|
||||
if (this._config.title == null) {
|
||||
toastClose.toggleClass('ml-2 ml-auto')
|
||||
}
|
||||
|
||||
toastHeader.append(toastClose)
|
||||
}
|
||||
|
||||
toast.append(toastHeader)
|
||||
|
||||
if (this._config.body != null) {
|
||||
toast.append($('<div class="toast-body" />').html(this._config.body))
|
||||
}
|
||||
|
||||
$(this._getContainerId()).prepend(toast)
|
||||
|
||||
$('body').trigger($.Event(Event.CREATED))
|
||||
|
||||
toast.toast('show')
|
||||
|
||||
if (this._config.autoremove) {
|
||||
toast.on('hidden.bs.toast', function () {
|
||||
$(this).delay(200).remove()
|
||||
$('body').trigger($.Event(Event.REMOVED))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
// Static
|
||||
|
||||
$.fn[NAME] = Toasts._jQueryInterface
|
||||
$.fn[NAME].Constructor = Toasts
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return Toasts._jQueryInterface
|
||||
_getContainerId() {
|
||||
if (this._config.position == Position.TOP_RIGHT) {
|
||||
return Selector.CONTAINER_TOP_RIGHT
|
||||
}
|
||||
|
||||
if (this._config.position == Position.TOP_LEFT) {
|
||||
return Selector.CONTAINER_TOP_LEFT
|
||||
}
|
||||
|
||||
if (this._config.position == Position.BOTTOM_RIGHT) {
|
||||
return Selector.CONTAINER_BOTTOM_RIGHT
|
||||
}
|
||||
|
||||
if (this._config.position == Position.BOTTOM_LEFT) {
|
||||
return Selector.CONTAINER_BOTTOM_LEFT
|
||||
}
|
||||
}
|
||||
|
||||
return Toasts
|
||||
})(jQuery)
|
||||
_prepareContainer() {
|
||||
if ($(this._getContainerId()).length === 0) {
|
||||
const container = $('<div />').attr('id', this._getContainerId().replace('#', ''))
|
||||
if (this._config.position == Position.TOP_RIGHT) {
|
||||
container.addClass(ClassName.TOP_RIGHT)
|
||||
} else if (this._config.position == Position.TOP_LEFT) {
|
||||
container.addClass(ClassName.TOP_LEFT)
|
||||
} else if (this._config.position == Position.BOTTOM_RIGHT) {
|
||||
container.addClass(ClassName.BOTTOM_RIGHT)
|
||||
} else if (this._config.position == Position.BOTTOM_LEFT) {
|
||||
container.addClass(ClassName.BOTTOM_LEFT)
|
||||
}
|
||||
|
||||
$('body').append(container)
|
||||
}
|
||||
|
||||
if (this._config.fixed) {
|
||||
$(this._getContainerId()).addClass('fixed')
|
||||
} else {
|
||||
$(this._getContainerId()).removeClass('fixed')
|
||||
}
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(option, config) {
|
||||
return this.each(function () {
|
||||
const _options = $.extend({}, Default, config)
|
||||
const toast = new Toasts($(this), _options)
|
||||
|
||||
if (option === 'create') {
|
||||
toast[option]()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = Toasts._jQueryInterface
|
||||
$.fn[NAME].Constructor = Toasts
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return Toasts._jQueryInterface
|
||||
}
|
||||
|
||||
export default Toasts
|
||||
|
|
|
@ -5,116 +5,114 @@
|
|||
* --------------------------------------------
|
||||
*/
|
||||
|
||||
const TodoList = ($ => {
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
import $ from 'jquery'
|
||||
|
||||
const NAME = 'TodoList'
|
||||
const DATA_KEY = 'lte.todolist'
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
const Selector = {
|
||||
DATA_TOGGLE: '[data-widget="todo-list"]'
|
||||
const NAME = 'TodoList'
|
||||
const DATA_KEY = 'lte.todolist'
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
|
||||
const Selector = {
|
||||
DATA_TOGGLE: '[data-widget="todo-list"]'
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
TODO_LIST_DONE: 'done'
|
||||
}
|
||||
|
||||
const Default = {
|
||||
onCheck(item) {
|
||||
return item
|
||||
},
|
||||
onUnCheck(item) {
|
||||
return item
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
class TodoList {
|
||||
constructor(element, config) {
|
||||
this._config = config
|
||||
this._element = element
|
||||
|
||||
this._init()
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
TODO_LIST_DONE: 'done'
|
||||
}
|
||||
// Public
|
||||
|
||||
const Default = {
|
||||
onCheck(item) {
|
||||
return item
|
||||
},
|
||||
onUnCheck(item) {
|
||||
return item
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
class TodoList {
|
||||
constructor(element, config) {
|
||||
this._config = config
|
||||
this._element = element
|
||||
|
||||
this._init()
|
||||
toggle(item) {
|
||||
item.parents('li').toggleClass(ClassName.TODO_LIST_DONE)
|
||||
if (!$(item).prop('checked')) {
|
||||
this.unCheck($(item))
|
||||
return
|
||||
}
|
||||
|
||||
// Public
|
||||
this.check(item)
|
||||
}
|
||||
|
||||
toggle(item) {
|
||||
item.parents('li').toggleClass(ClassName.TODO_LIST_DONE)
|
||||
if (!$(item).prop('checked')) {
|
||||
this.unCheck($(item))
|
||||
return
|
||||
check(item) {
|
||||
this._config.onCheck.call(item)
|
||||
}
|
||||
|
||||
unCheck(item) {
|
||||
this._config.onUnCheck.call(item)
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
_init() {
|
||||
$(Selector.DATA_TOGGLE).find('input:checkbox:checked').parents('li').toggleClass(ClassName.TODO_LIST_DONE)
|
||||
$(Selector.DATA_TOGGLE).on('change', 'input:checkbox', event => {
|
||||
this.toggle($(event.target))
|
||||
})
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _options = $.extend({}, Default, $(this).data())
|
||||
|
||||
if (!data) {
|
||||
data = new TodoList($(this), _options)
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
|
||||
this.check(item)
|
||||
}
|
||||
|
||||
check(item) {
|
||||
this._config.onCheck.call(item)
|
||||
}
|
||||
|
||||
unCheck(item) {
|
||||
this._config.onUnCheck.call(item)
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
_init() {
|
||||
$(Selector.DATA_TOGGLE).find('input:checkbox:checked').parents('li').toggleClass(ClassName.TODO_LIST_DONE)
|
||||
$(Selector.DATA_TOGGLE).on('change', 'input:checkbox', event => {
|
||||
this.toggle($(event.target))
|
||||
})
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _options = $.extend({}, Default, $(this).data())
|
||||
|
||||
if (!data) {
|
||||
data = new TodoList($(this), _options)
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
|
||||
if (config === 'init') {
|
||||
data[config]()
|
||||
}
|
||||
})
|
||||
}
|
||||
if (config === 'init') {
|
||||
data[config]()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$(window).on('load', () => {
|
||||
TodoList._jQueryInterface.call($(Selector.DATA_TOGGLE))
|
||||
})
|
||||
$(window).on('load', () => {
|
||||
TodoList._jQueryInterface.call($(Selector.DATA_TOGGLE))
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = TodoList._jQueryInterface
|
||||
$.fn[NAME].Constructor = TodoList
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return TodoList._jQueryInterface
|
||||
}
|
||||
|
||||
return TodoList
|
||||
})(jQuery)
|
||||
$.fn[NAME] = TodoList._jQueryInterface
|
||||
$.fn[NAME].Constructor = TodoList
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return TodoList._jQueryInterface
|
||||
}
|
||||
|
||||
export default TodoList
|
||||
|
|
|
@ -5,178 +5,176 @@
|
|||
* --------------------------------------------
|
||||
*/
|
||||
|
||||
const Treeview = ($ => {
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
import $ from 'jquery'
|
||||
|
||||
const NAME = 'Treeview'
|
||||
const DATA_KEY = 'lte.treeview'
|
||||
const EVENT_KEY = `.${DATA_KEY}`
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
/**
|
||||
* Constants
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
const Event = {
|
||||
EXPANDED: `expanded${EVENT_KEY}`,
|
||||
COLLAPSED: `collapsed${EVENT_KEY}`,
|
||||
LOAD_DATA_API: `load${EVENT_KEY}`
|
||||
const NAME = 'Treeview'
|
||||
const DATA_KEY = 'lte.treeview'
|
||||
const EVENT_KEY = `.${DATA_KEY}`
|
||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||
|
||||
const Event = {
|
||||
EXPANDED: `expanded${EVENT_KEY}`,
|
||||
COLLAPSED: `collapsed${EVENT_KEY}`,
|
||||
LOAD_DATA_API: `load${EVENT_KEY}`
|
||||
}
|
||||
|
||||
const Selector = {
|
||||
LI: '.nav-item',
|
||||
LINK: '.nav-link',
|
||||
TREEVIEW_MENU: '.nav-treeview',
|
||||
OPEN: '.menu-open',
|
||||
DATA_WIDGET: '[data-widget="treeview"]'
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
OPEN: 'menu-open',
|
||||
IS_OPENING: 'menu-is-opening',
|
||||
SIDEBAR_COLLAPSED: 'sidebar-collapse'
|
||||
}
|
||||
|
||||
const Default = {
|
||||
trigger: `${Selector.DATA_WIDGET} ${Selector.LINK}`,
|
||||
animationSpeed: 300,
|
||||
accordion: true,
|
||||
expandSidebar: false,
|
||||
sidebarButtonSelector: '[data-widget="pushmenu"]'
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
class Treeview {
|
||||
constructor(element, config) {
|
||||
this._config = config
|
||||
this._element = element
|
||||
}
|
||||
|
||||
const Selector = {
|
||||
LI: '.nav-item',
|
||||
LINK: '.nav-link',
|
||||
TREEVIEW_MENU: '.nav-treeview',
|
||||
OPEN: '.menu-open',
|
||||
DATA_WIDGET: '[data-widget="treeview"]'
|
||||
// Public
|
||||
|
||||
init() {
|
||||
$(`${Selector.LI}${Selector.OPEN} ${Selector.TREEVIEW_MENU}`).css('display', 'block')
|
||||
this._setupListeners()
|
||||
}
|
||||
|
||||
const ClassName = {
|
||||
OPEN: 'menu-open',
|
||||
IS_OPENING: 'menu-is-opening',
|
||||
SIDEBAR_COLLAPSED: 'sidebar-collapse'
|
||||
}
|
||||
expand(treeviewMenu, parentLi) {
|
||||
const expandedEvent = $.Event(Event.EXPANDED)
|
||||
|
||||
const Default = {
|
||||
trigger: `${Selector.DATA_WIDGET} ${Selector.LINK}`,
|
||||
animationSpeed: 300,
|
||||
accordion: true,
|
||||
expandSidebar: false,
|
||||
sidebarButtonSelector: '[data-widget="pushmenu"]'
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Definition
|
||||
* ====================================================
|
||||
*/
|
||||
class Treeview {
|
||||
constructor(element, config) {
|
||||
this._config = config
|
||||
this._element = element
|
||||
if (this._config.accordion) {
|
||||
const openMenuLi = parentLi.siblings(Selector.OPEN).first()
|
||||
const openTreeview = openMenuLi.find(Selector.TREEVIEW_MENU).first()
|
||||
this.collapse(openTreeview, openMenuLi)
|
||||
}
|
||||
|
||||
// Public
|
||||
parentLi.addClass(ClassName.IS_OPENING)
|
||||
treeviewMenu.stop().slideDown(this._config.animationSpeed, () => {
|
||||
parentLi.addClass(ClassName.OPEN)
|
||||
$(this._element).trigger(expandedEvent)
|
||||
})
|
||||
|
||||
init() {
|
||||
$(`${Selector.LI}${Selector.OPEN} ${Selector.TREEVIEW_MENU}`).css('display', 'block')
|
||||
this._setupListeners()
|
||||
if (this._config.expandSidebar) {
|
||||
this._expandSidebar()
|
||||
}
|
||||
}
|
||||
|
||||
expand(treeviewMenu, parentLi) {
|
||||
const expandedEvent = $.Event(Event.EXPANDED)
|
||||
collapse(treeviewMenu, parentLi) {
|
||||
const collapsedEvent = $.Event(Event.COLLAPSED)
|
||||
|
||||
if (this._config.accordion) {
|
||||
const openMenuLi = parentLi.siblings(Selector.OPEN).first()
|
||||
const openTreeview = openMenuLi.find(Selector.TREEVIEW_MENU).first()
|
||||
this.collapse(openTreeview, openMenuLi)
|
||||
parentLi.removeClass(`${ClassName.IS_OPENING} ${ClassName.OPEN}`)
|
||||
treeviewMenu.stop().slideUp(this._config.animationSpeed, () => {
|
||||
$(this._element).trigger(collapsedEvent)
|
||||
treeviewMenu.find(`${Selector.OPEN} > ${Selector.TREEVIEW_MENU}`).slideUp()
|
||||
treeviewMenu.find(Selector.OPEN).removeClass(ClassName.OPEN)
|
||||
})
|
||||
}
|
||||
|
||||
toggle(event) {
|
||||
const $relativeTarget = $(event.currentTarget)
|
||||
const $parent = $relativeTarget.parent()
|
||||
|
||||
let treeviewMenu = $parent.find('> ' + Selector.TREEVIEW_MENU)
|
||||
|
||||
if (!treeviewMenu.is(Selector.TREEVIEW_MENU)) {
|
||||
if (!$parent.is(Selector.LI)) {
|
||||
treeviewMenu = $parent.parent().find('> ' + Selector.TREEVIEW_MENU)
|
||||
}
|
||||
|
||||
parentLi.addClass(ClassName.IS_OPENING)
|
||||
treeviewMenu.stop().slideDown(this._config.animationSpeed, () => {
|
||||
parentLi.addClass(ClassName.OPEN)
|
||||
$(this._element).trigger(expandedEvent)
|
||||
})
|
||||
|
||||
if (this._config.expandSidebar) {
|
||||
this._expandSidebar()
|
||||
}
|
||||
}
|
||||
|
||||
collapse(treeviewMenu, parentLi) {
|
||||
const collapsedEvent = $.Event(Event.COLLAPSED)
|
||||
|
||||
parentLi.removeClass(`${ClassName.IS_OPENING} ${ClassName.OPEN}`)
|
||||
treeviewMenu.stop().slideUp(this._config.animationSpeed, () => {
|
||||
$(this._element).trigger(collapsedEvent)
|
||||
treeviewMenu.find(`${Selector.OPEN} > ${Selector.TREEVIEW_MENU}`).slideUp()
|
||||
treeviewMenu.find(Selector.OPEN).removeClass(ClassName.OPEN)
|
||||
})
|
||||
}
|
||||
|
||||
toggle(event) {
|
||||
const $relativeTarget = $(event.currentTarget)
|
||||
const $parent = $relativeTarget.parent()
|
||||
|
||||
let treeviewMenu = $parent.find('> ' + Selector.TREEVIEW_MENU)
|
||||
|
||||
if (!treeviewMenu.is(Selector.TREEVIEW_MENU)) {
|
||||
if (!$parent.is(Selector.LI)) {
|
||||
treeviewMenu = $parent.parent().find('> ' + Selector.TREEVIEW_MENU)
|
||||
}
|
||||
|
||||
if (!treeviewMenu.is(Selector.TREEVIEW_MENU)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
const parentLi = $relativeTarget.parents(Selector.LI).first()
|
||||
const isOpen = parentLi.hasClass(ClassName.OPEN)
|
||||
|
||||
if (isOpen) {
|
||||
this.collapse($(treeviewMenu), parentLi)
|
||||
} else {
|
||||
this.expand($(treeviewMenu), parentLi)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Private
|
||||
event.preventDefault()
|
||||
|
||||
_setupListeners() {
|
||||
$(document).on('click', this._config.trigger, event => {
|
||||
this.toggle(event)
|
||||
})
|
||||
}
|
||||
const parentLi = $relativeTarget.parents(Selector.LI).first()
|
||||
const isOpen = parentLi.hasClass(ClassName.OPEN)
|
||||
|
||||
_expandSidebar() {
|
||||
if ($('body').hasClass(ClassName.SIDEBAR_COLLAPSED)) {
|
||||
$(this._config.sidebarButtonSelector).PushMenu('expand')
|
||||
}
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _options = $.extend({}, Default, $(this).data())
|
||||
|
||||
if (!data) {
|
||||
data = new Treeview($(this), _options)
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
|
||||
if (config === 'init') {
|
||||
data[config]()
|
||||
}
|
||||
})
|
||||
if (isOpen) {
|
||||
this.collapse($(treeviewMenu), parentLi)
|
||||
} else {
|
||||
this.expand($(treeviewMenu), parentLi)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
// Private
|
||||
|
||||
$(window).on(Event.LOAD_DATA_API, () => {
|
||||
$(Selector.DATA_WIDGET).each(function () {
|
||||
Treeview._jQueryInterface.call($(this), 'init')
|
||||
_setupListeners() {
|
||||
$(document).on('click', this._config.trigger, event => {
|
||||
this.toggle(event)
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = Treeview._jQueryInterface
|
||||
$.fn[NAME].Constructor = Treeview
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return Treeview._jQueryInterface
|
||||
}
|
||||
|
||||
return Treeview
|
||||
})(jQuery)
|
||||
_expandSidebar() {
|
||||
if ($('body').hasClass(ClassName.SIDEBAR_COLLAPSED)) {
|
||||
$(this._config.sidebarButtonSelector).PushMenu('expand')
|
||||
}
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static _jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
let data = $(this).data(DATA_KEY)
|
||||
const _options = $.extend({}, Default, $(this).data())
|
||||
|
||||
if (!data) {
|
||||
data = new Treeview($(this), _options)
|
||||
$(this).data(DATA_KEY, data)
|
||||
}
|
||||
|
||||
if (config === 'init') {
|
||||
data[config]()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$(window).on(Event.LOAD_DATA_API, () => {
|
||||
$(Selector.DATA_WIDGET).each(function () {
|
||||
Treeview._jQueryInterface.call($(this), 'init')
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* jQuery API
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
$.fn[NAME] = Treeview._jQueryInterface
|
||||
$.fn[NAME].Constructor = Treeview
|
||||
$.fn[NAME].noConflict = function () {
|
||||
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||
return Treeview._jQueryInterface
|
||||
}
|
||||
|
||||
export default Treeview
|
||||
|
|
Loading…
Reference in New Issue