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

Disable swipe/next/prev when not in carousel mode #56

Open
wants to merge 1 commit into
base: master
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
117 changes: 60 additions & 57 deletions responsiveCarousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,69 +306,72 @@
});
};

var mouseHover = false, current;
$(window).on('mouseleave', function(event){
// Detect current
if (event.target) current = event.target;
else if (event.srcElement) current = event.srcElement;
// Detect mouseover
if( ( $(obj).attr('id') && $(current).parents('.crsl-items').attr('id') === $(obj).attr('id') ) || ( $(current).parents('.crsl-items').data('navigation') === $(obj).data('navigation') ) ){
mouseHover = true;
} else {
mouseHover = false;
}
// False
return false;
});
if ( defaults.carousel ) {

var mouseHover = false, current;
$(window).on('mouseleave', function(event){
// Detect current
if (event.target) current = event.target;
else if (event.srcElement) current = event.srcElement;
// Detect mouseover
if( ( $(obj).attr('id') && $(current).parents('.crsl-items').attr('id') === $(obj).attr('id') ) || ( $(current).parents('.crsl-items').data('navigation') === $(obj).data('navigation') ) ){
mouseHover = true;
} else {
mouseHover = false;
}
// False
return false;
});

$(window).on('keydown', function(event){
if( mouseHover === true ){
// Previous & next action
if( event.keyCode === 37 ){
// Prepare execute
obj.prepareExecute();
// Previous
obj.previous();
} else if( event.keyCode === 39 ){
// Prepare execute
obj.prepareExecute();
// Next
obj.next();
$(window).on('keydown', function(event){
if( mouseHover === true ){
// Previous & next action
if( event.keyCode === 37 ){
// Prepare execute
obj.prepareExecute();
// Previous
obj.previous();
} else if( event.keyCode === 39 ){
// Prepare execute
obj.prepareExecute();
// Next
obj.next();
}
}
}
return;
});
return;
});

if( defaults.isTouch ){
$(obj).on('touchstart', function(e){
$(obj).addClass('touching');
defaults.startCoords.pageX = defaults.endCoords.pageX = e.originalEvent.targetTouches[0].pageX;
defaults.startCoords.pageY = defaults.endCoords.pageY = e.originalEvent.targetTouches[0].pageY;
$('.touching').on('touchmove',function(e){
defaults.endCoords.pageX = e.originalEvent.targetTouches[0].pageX;
defaults.endCoords.pageY = e.originalEvent.targetTouches[0].pageY;
if( Math.abs( parseInt( defaults.endCoords.pageX-defaults.startCoords.pageX, 10 ) ) > Math.abs( parseInt( defaults.endCoords.pageY-defaults.startCoords.pageY, 10 ) ) ){
if( defaults.isTouch ){
$(obj).on('touchstart', function(e){
$(obj).addClass('touching');
defaults.startCoords.pageX = defaults.endCoords.pageX = e.originalEvent.targetTouches[0].pageX;
defaults.startCoords.pageY = defaults.endCoords.pageY = e.originalEvent.targetTouches[0].pageY;
$('.touching').on('touchmove',function(e){
defaults.endCoords.pageX = e.originalEvent.targetTouches[0].pageX;
defaults.endCoords.pageY = e.originalEvent.targetTouches[0].pageY;
if( Math.abs( parseInt( defaults.endCoords.pageX-defaults.startCoords.pageX, 10 ) ) > Math.abs( parseInt( defaults.endCoords.pageY-defaults.startCoords.pageY, 10 ) ) ){
e.preventDefault();
e.stopPropagation();
}
});
}).on('touchend', function(e){
defaults.swipeDistance = defaults.endCoords.pageX - defaults.startCoords.pageX;
if( defaults.swipeDistance >= defaults.swipeMinDistance ){
obj.prepareExecute();
// swipeLeft
obj.previous();
e.preventDefault();
e.stopPropagation();
} else if( defaults.swipeDistance <= - defaults.swipeMinDistance ){
obj.prepareExecute();
// swipeRight
obj.next();
e.preventDefault();
e.stopPropagation();
}
$('.touching').off('touchmove').removeClass('touching');
});
}).on('touchend', function(e){
defaults.swipeDistance = defaults.endCoords.pageX - defaults.startCoords.pageX;
if( defaults.swipeDistance >= defaults.swipeMinDistance ){
obj.prepareExecute();
// swipeLeft
obj.previous();
e.preventDefault();
e.stopPropagation();
} else if( defaults.swipeDistance <= - defaults.swipeMinDistance ){
obj.prepareExecute();
// swipeRight
obj.next();
e.preventDefault();
e.stopPropagation();
}
$('.touching').off('touchmove').removeClass('touching');
});
}
}

$(obj).on('loadedCarousel loadedImagesCarousel', function(){
Expand Down Expand Up @@ -409,4 +412,4 @@
});
});
};
})(jQuery);
})(jQuery);