superfish icon indicating copy to clipboard operation
superfish copied to clipboard

Bit of a tweak: click outside to close

Open StealthWombat opened this issue 11 years ago • 2 comments

This is not an issue as such. It's just something I thought of as a convenience, for anyone who wants to provide a long mouseout delay for less physically capable users, while still allowing open menus to be cleared quickly when necessary.

I adapted the close routine from Superclick and inserted it in the same location in Superfish. It functions perfectly on the browsers I have available, and I assume it will generally work as well in SF as it does in SC. If anyone is interested, code is below.

Find:

    var methods = (function () {
        // private properties and methods go here
        var c = {
                bcClass: 'sf-breadcrumb',
                menuClass: 'sf-js-enabled',
                anchorClass: 'sf-with-ul',
                menuArrowClass: 'sf-arrows'
            },

Add after:

            outerClick = (function() {
                $(window).load(function() {
                    $('body').children().on('click.superfish', function() {
                        var $allMenus = $('.sf-js-enabled');
                        $allMenus.superfish('hide');
                    });
                });
            })(),

StealthWombat avatar Jun 20 '14 22:06 StealthWombat

:+1:

This is also a great improvement for a mobile solution I used. With this code it's possible to close a menu by touching the root element of an open submenu again on mobile devices.

larsbo avatar Sep 15 '14 13:09 larsbo

Hmm, as far as I remember the submenus should behave in this way in Superfish (although not quite as @larsbo described) without the above code due to focus being removed (the blur event) which should trigger the close handler. Have you found this not to be the case?

joeldbirch avatar May 03 '16 03:05 joeldbirch