Improved sidebar open/close handling

This commit is contained in:
Deon George 2020-03-11 12:41:36 +11:00
parent 96a6830e61
commit 6bc2787602
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
1 changed files with 27 additions and 15 deletions

View File

@ -14,6 +14,7 @@
});
$.AdminLTESidebarTweak = {};
$.AdminLTESidebarTweak.Open = true;
$.AdminLTESidebarTweak.options = {
EnableRemember: true,
@ -24,6 +25,29 @@
// Work out our timezone.
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
/**
* Open and close the sidebar
* @param state
* @param addclass
*/
function sidebaropenclose(state,addclass) {
// Dont do anything if the state hasnt changed.
if (state == $.AdminLTESidebarTweak.Open) {
return;
}
$.AdminLTESidebarTweak.Open = state;
if (addclass !== 'undefined')
$("body")
.addClass(state ? 'sidebar-open' : 'sidebar-collapse');
$(this).delay(500).queue(function() {
window.dispatchEvent(new Event('resize'));
$(this).dequeue();
});
}
$(function () {
"use strict";
@ -31,22 +55,15 @@
if($.AdminLTESidebarTweak.options.EnableRemember) {
document.cookie = "toggleState=closed;path=/";
$("body").delay(500).queue(function () {
window.dispatchEvent(new Event('resize'));
$(this).dequeue();
});
$("body").queue(sidebaropenclose(false));
}
});
// @todo this is not firing.
$("body").on("shown.lte.pushmenu", function(){
if($.AdminLTESidebarTweak.options.EnableRemember){
document.cookie = "toggleState=opened;path=/";
$("body").delay(500).queue(function () {
window.dispatchEvent(new Event('resize'));
$(this).dequeue();
});
$("body").queue(sidebaropenclose(true));
}
});
@ -60,12 +77,7 @@
$(this).removeClass('hold-transition');
});
}else{
$("body")
.addClass('sidebar-collapse')
.delay(500).queue(function () {
window.dispatchEvent(new Event('resize'));
$(this).dequeue();
});
$("body").queue(sidebaropenclose(false,true));
}
}
}