Skip to content

Commit

Permalink
Fix sub-menu behaviour on touch devices
Browse files Browse the repository at this point in the history
  • Loading branch information
francgrasso committed Oct 15, 2020
1 parent 36dd0d2 commit ec49153
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 80 deletions.
74 changes: 7 additions & 67 deletions js/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,86 +25,26 @@
return;
}

menu.setAttribute( 'aria-expanded', 'false' );
if ( -1 === menu.className.indexOf( 'nav-menu' ) ) {
menu.className += ' nav-menu';
}

button.onclick = function() {

if ( -1 !== container.className.indexOf( 'toggled' ) ) {
container.className = container.className.replace( ' toggled', '' );
jQuery('html').add('body').removeClass('mobile-menu-opened');
button.setAttribute( 'aria-expanded', 'false' );
menu.setAttribute( 'aria-expanded', 'false' );

} else {
container.className += ' toggled';
jQuery('html').add('body').addClass('mobile-menu-opened');
button.setAttribute( 'aria-expanded', 'true' );
menu.setAttribute( 'aria-expanded', 'true' );
}
};

// Get all the link elements within the menu.
links = menu.getElementsByTagName( 'a' );

// Each time a menu link is focused or blurred, toggle focus.
for ( i = 0, len = links.length; i < len; i++ ) {
links[i].addEventListener( 'focus', toggleFocus, true );
links[i].addEventListener( 'blur', toggleFocus, true );
}

/**
* Sets or removes .focus class on an element.
*/
function toggleFocus() {
var self = this;

// Move up through the ancestors of the current link until we hit .nav-menu.
while ( -1 === self.className.indexOf( 'nav-menu' ) ) {

// On li elements toggle the class .focus.
if ( 'li' === self.tagName.toLowerCase() ) {
if ( -1 !== self.className.indexOf( 'focus' ) ) {
self.className = self.className.replace( ' focus', '' );
} else {
self.className += ' focus';
}
}
jQuery('#primary-nav-menu > ul').attr('role',"navigation");
jQuery(".menu-item-has-children > a").attr({
'aria-label':'sub menu',
'aria-haspopup':'true',
'aria-expanded':'true'
});


self = self.parentElement;
}
}

/**
* Toggles `focus` class to allow submenu access on tablets.
*/
( function( container ) {
var touchStartFn, i,
parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );

if ( 'ontouchstart' in window ) {
touchStartFn = function( e ) {
var menuItem = this.parentNode, i;

if ( ! menuItem.classList.contains( 'focus' ) ) {
e.preventDefault();
for ( i = 0; i < menuItem.parentNode.children.length; ++i ) {
if ( menuItem === menuItem.parentNode.children[i] ) {
continue;
}
menuItem.parentNode.children[i].classList.remove( 'focus' );
}
menuItem.classList.add( 'focus' );
} else {
menuItem.classList.remove( 'focus' );
}
};

for ( i = 0; i < parentLink.length; ++i ) {
parentLink[i].addEventListener( 'touchstart', touchStartFn, false );
}
}
}( container ) );
} )();
28 changes: 17 additions & 11 deletions js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,23 @@
}).resize();
});

$('.menu-item-has-children > a').click(function (ev) {
var t = $(this);
if (t.hasClass('submenu-opened')) {
return true;
} else {
ev.preventDefault();
$('.menu-item-has-children > a').removeClass('submenu-opened');
$(this).addClass('submenu-opened');
}

});
if(window.matchMedia("(pointer: coarse)").matches) {
// touchscreen
$('.menu-item-has-children > a').click(function (ev) {
var t = $(this);
if (t.hasClass('submenu-opened')) {
return true;
} else {
ev.preventDefault();
$('.menu-item-has-children > a').removeClass('submenu-opened');
$(this).addClass('submenu-opened');
}

});
} else {
// is desktop
}


// Modals
$('a.open-modal').click(function (ev) {
Expand Down
2 changes: 1 addition & 1 deletion sass/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Author: YITH
Author URI: https://yithemes.com
Description: Proteo is a sleek, modern and “Gutenberg-friendly” e-commerce theme. Developed with a beautiful UI and a minimal design, is perfect for each kind of shop. Easy to manage and to customize, Proteo is the best solution if you want a complete e-commerce template and start quickly to sell your products with WooCommerce without a technical knowledge. Use it also for corporate site or a blog: there are no limits about what you can do with a beautiful and usable theme like this! Main features: Colors and Typography customization (Google font support), Logo customization, 3 different Header layouts, Advanced customizer theme options, Sidebar Management, Sidebar Chooser on each page and product, Page title icons, Top Bar Management, Easy main color shade chooser, Buttons style management (gradient buttons support), Footer management with multiple sidebars, WooCommerce support, Shop Theme Options, Custom WooCommerce messages and animated WooCommerce alert notices, Two cart page layouts, Bootstrap grid system, CSS animations, Gutenberg support, Responsive, Fullscreen search, Multilevel menus, Support to all YITH plugins, SVG icons for HiDPI screens, Translation Ready. <a href="https://proteo.yithemes.com/about-proteo/" rel="nofollow" target="_blank">Discover more ></a> | <a href="https://proteo.yithemes.com/" rel="nofollow" target="_blank">Check our live demo ></a>
Version: 1.3.8.1
Version: 1.3.8.6
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: yith-proteo
Expand Down
2 changes: 1 addition & 1 deletion style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ec49153

Please sign in to comment.