Skip to content

Instantly share code, notes, and snippets.

@edrdesigner
Created July 24, 2017 12:24
Show Gist options
  • Save edrdesigner/79d6018bb9815d8f0342197d69438cb9 to your computer and use it in GitHub Desktop.
Save edrdesigner/79d6018bb9815d8f0342197d69438cb9 to your computer and use it in GitHub Desktop.
/**
* Add funcionality to change the focus using tab and shiftkey
*/
function matrixTabIndex() {
var tabKey = 9;
$('#product-matrix-std .owl-item').each(function(){
$(this).find('INPUT[type=hidden]').attr('tabindex', '-1');
$(this).find('a.swatch-link').attr('tabindex', '-1');
$(this).find('INPUT.qty:last').addClass('qlast');
$(this).find('INPUT.qty:first').addClass('qfirst');
$(this).find('INPUT.qty:last').keydown( function(e) {
if( e.which == tabKey || e.keyCode == tabKey ) {
owlFcpm.trigger('owl.next');
e.preventDefault();
$.tabNext();
}
if( e.shiftKey ) {
if (!$(this).hasClass('qfirst')) {
e.preventDefault();
jQuery.tabPrev();
}
}
});
$(this).find('INPUT.qty:first').keydown( function(e) {
if( e.shiftKey ) {
owlFcpm.trigger('owl.prev');
e.preventDefault();
$.tabPrev();
}
});
$(this).find('INPUT.qty').keydown( function(e) {
if ( !$(this).hasClass('qlast') && !$(this).hasClass('qfirst')) {
if( e.shiftKey ) {
e.preventDefault();
$.tabPrev();
}
if( e.which == tabKey || e.keyCode == tabKey ) {
e.preventDefault();
$.tabNext();
}
}
});
});
}
matrixTabIndex();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment