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

View File

@ -14,6 +14,7 @@
}); });
$.AdminLTESidebarTweak = {}; $.AdminLTESidebarTweak = {};
$.AdminLTESidebarTweak.Open = true;
$.AdminLTESidebarTweak.options = { $.AdminLTESidebarTweak.options = {
EnableRemember: true, EnableRemember: true,
@ -24,6 +25,29 @@
// Work out our timezone. // Work out our timezone.
const tz = Intl.DateTimeFormat().resolvedOptions().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 () { $(function () {
"use strict"; "use strict";
@ -31,22 +55,15 @@
if($.AdminLTESidebarTweak.options.EnableRemember) { if($.AdminLTESidebarTweak.options.EnableRemember) {
document.cookie = "toggleState=closed;path=/"; document.cookie = "toggleState=closed;path=/";
$("body").delay(500).queue(function () { $("body").queue(sidebaropenclose(false));
window.dispatchEvent(new Event('resize'));
$(this).dequeue();
});
} }
}); });
// @todo this is not firing.
$("body").on("shown.lte.pushmenu", function(){ $("body").on("shown.lte.pushmenu", function(){
if($.AdminLTESidebarTweak.options.EnableRemember){ if($.AdminLTESidebarTweak.options.EnableRemember){
document.cookie = "toggleState=opened;path=/"; document.cookie = "toggleState=opened;path=/";
$("body").delay(500).queue(function () { $("body").queue(sidebaropenclose(true));
window.dispatchEvent(new Event('resize'));
$(this).dequeue();
});
} }
}); });
@ -60,12 +77,7 @@
$(this).removeClass('hold-transition'); $(this).removeClass('hold-transition');
}); });
}else{ }else{
$("body") $("body").queue(sidebaropenclose(false,true));
.addClass('sidebar-collapse')
.delay(500).queue(function () {
window.dispatchEvent(new Event('resize'));
$(this).dequeue();
});
} }
} }
} }