From 6bc278760217aa7b3f7a3d0c7db3351224908d51 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 11 Mar 2020 12:41:36 +1100 Subject: [PATCH] Improved sidebar open/close handling --- .../views/layouts/partials/scripts.blade.php | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/resources/themes/adminlte/views/layouts/partials/scripts.blade.php b/resources/themes/adminlte/views/layouts/partials/scripts.blade.php index 17ff101..f577915 100644 --- a/resources/themes/adminlte/views/layouts/partials/scripts.blade.php +++ b/resources/themes/adminlte/views/layouts/partials/scripts.blade.php @@ -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)); } } }