From 097b01f7f4c266aa8eb7e84b097dfeddf861936e Mon Sep 17 00:00:00 2001 From: Jeroen Dalsem Date: Tue, 8 Jan 2019 17:30:24 +0100 Subject: [PATCH] fix(menus): you can now have a link with toggleable features combined fixes #12261 --- views/default/elgg/menus/dropdown.js | 16 ++++++++++++++++ views/default/elgg/menus/toggle.js | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/views/default/elgg/menus/dropdown.js b/views/default/elgg/menus/dropdown.js index 8699b43b602..42688fa766b 100644 --- a/views/default/elgg/menus/dropdown.js +++ b/views/default/elgg/menus/dropdown.js @@ -11,6 +11,7 @@ define(function (require) { var dropdown = { init: function () { + // handles clicking on a menu item that has a dropdown menu $(document).on('click', '.elgg-menu-item-has-dropdown > a', function (e) { var $trigger = $(this); if ($trigger.data('dropdownMenu')) { @@ -48,6 +49,21 @@ define(function (require) { popup.open($trigger, $target, position); }); + + // if an anchor also has its own link the text acts as the link, the before pseudo element handles the toggle + $(document).on('click', '.elgg-menu-item-has-dropdown > a > .elgg-anchor-label', function (e) { + var $anchor = $(this).closest('a'); + var href = $anchor.attr('href'); + + if ($anchor.hasClass('elgg-non-link') || !href) { + return; + } + + document.location = href; + + e.preventDefault(); + e.stopImmediatePropagation(); + }); dropdown.init = elgg.nullFunction; } diff --git a/views/default/elgg/menus/toggle.js b/views/default/elgg/menus/toggle.js index 8b0f5ce8b58..4d1d06fad86 100644 --- a/views/default/elgg/menus/toggle.js +++ b/views/default/elgg/menus/toggle.js @@ -10,6 +10,7 @@ define(function (require) { var toggle = { init: function () { + // handles clicking on a menu item that has toggleable childmenu $(document).on('click', '.elgg-menu-item-has-toggle > a', function (e) { e.preventDefault(); @@ -32,6 +33,21 @@ define(function (require) { } }); }); + + // if an anchor also has its own link the text acts as the link, the before pseudo element handles the toggle + $(document).on('click', '.elgg-menu-item-has-toggle > a > .elgg-anchor-label', function (e) { + var $anchor = $(this).closest('a'); + var href = $anchor.attr('href'); + + if ($anchor.hasClass('elgg-non-link') || !href) { + return; + } + + document.location = href; + + e.preventDefault(); + e.stopImmediatePropagation(); + }); toggle.init = elgg.nullFunction; }