Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#3171215] Close superfish menu when #anchor link is clicked #30

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion sfsmallscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@
accordionElement = $('#' + accordionID),
// Deciding what should be used as accordion buttons.
buttonElement = (options.accordionButton < 2) ? 'a.menuparent,span.nolink.menuparent' : 'a.sf-accordion-button',
button = accordionElement.find(buttonElement);
button = accordionElement.find(buttonElement),
link = accordionElement.find('a.is-active:not(.menuparent)');

// Attaching a click event to the toggle switch.
$('#' + toggleID).on('click', function(e){
Expand Down Expand Up @@ -233,6 +234,27 @@
}
}
});

// Attach a click event to the menu items (not buttons).
link.on('click', function(e){
// Adding the sf-expanded class.
$('#' + toggleID).toggleClass('sf-expanded');
if (accordionElement.hasClass('sf-expanded')) {
// If the accordion is already expanded:
// Hiding its expanded sub-menus and then the accordion itself as well.
accordionElement.add(accordionElement.find('li.sf-expanded')).removeClass('sf-expanded')
.end().children('ul').hide()
// This is a bit tricky, it's the same trick that has been in use in the main plugin for some time.
// Basically we'll add a class that keeps the sub-menu off-screen and still visible,
// and make it invisible and removing the class one moment before showing or hiding it.
// This helps screen reader software access all the menu items.
.end().hide().addClass('sf-hidden').show();
// Changing the caption of any existing accordion buttons to 'Expand'.
if (options.accordionButton == 2) {
accordionElement.find('a.sf-accordion-button').text(options.expandText);
}
}
});
}
}
else {
Expand Down