From 758743220d9a864b2b9fabcf5dc75ab9b0d7bf13 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 8 Feb 2022 10:29:18 -0500 Subject: [PATCH] feat: added client-size hook to enable configuration of navbar hiding, closes #541 --- public/persona.js | 69 ++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/public/persona.js b/public/persona.js index 4c2e4aa..7875617 100644 --- a/public/persona.js +++ b/public/persona.js @@ -45,42 +45,49 @@ $(document).ready(function () { if (!$.fn.autoHidingNavbar) { return; } - var env = utils.findBootstrapEnvironment(); - // if env didn't change don't destroy and recreate - if (env === lastBSEnv) { - return; - } - lastBSEnv = env; - var navbarEl = $('.navbar-fixed-top'); - navbarEl.autoHidingNavbar('destroy').removeData('plugin_autoHidingNavbar'); - navbarEl.css('top', ''); - - if (env === 'xs' || env === 'sm') { - navbarEl.autoHidingNavbar({ - showOnBottom: false, - }); - } - function fixTopCss(topValue) { - if (ajaxify.data.template.topic) { - $('.topic .topic-header').css({ top: topValue }); - } else { - var topicListHeader = $('.topic-list-header'); - if (topicListHeader.length) { - topicListHeader.css({ top: topValue }); - } + require(['hooks'], (hooks) => { + var env = utils.findBootstrapEnvironment(); + // if env didn't change don't destroy and recreate + if (env === lastBSEnv) { + return; } - } + lastBSEnv = env; + var navbarEl = $('.navbar-fixed-top'); + navbarEl.autoHidingNavbar('destroy').removeData('plugin_autoHidingNavbar'); + navbarEl.css('top', ''); + + hooks.fire('filter:persona.configureNavbarHiding', { + resizeEnvs: ['xs', 'sm'], + }).then(({ resizeEnvs }) => { + if (resizeEnvs.includes(env)) { + navbarEl.autoHidingNavbar({ + showOnBottom: false, + }); + } - navbarEl.off('show.autoHidingNavbar') - .on('show.autoHidingNavbar', function () { - fixTopCss(''); - }); + function fixTopCss(topValue) { + if (ajaxify.data.template.topic) { + $('.topic .topic-header').css({ top: topValue }); + } else { + var topicListHeader = $('.topic-list-header'); + if (topicListHeader.length) { + topicListHeader.css({ top: topValue }); + } + } + } + + navbarEl.off('show.autoHidingNavbar') + .on('show.autoHidingNavbar', function () { + fixTopCss(''); + }); - navbarEl.off('hide.autoHidingNavbar') - .on('hide.autoHidingNavbar', function () { - fixTopCss('0px'); + navbarEl.off('hide.autoHidingNavbar') + .on('hide.autoHidingNavbar', function () { + fixTopCss('0px'); + }); }); + }); } function setupNProgress() {