Skip to content

Commit

Permalink
Merge pull request nolimits4web#329 from strack/master
Browse files Browse the repository at this point in the history
Granular / Bubbling check for noSwiping slides
  • Loading branch information
nolimits4web committed Aug 24, 2013
2 parents 2a430bb + 0784ab6 commit bae1a6f
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion dev/idangerous.swiper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,8 @@ var Swiper = function (selector, params) {
return false;
}

if (params.noSwiping && event.target && event.target.className && event.target.className.indexOf(params.noSwipingClass) > -1) return false;
//if (params.noSwiping && event.target && event.target.className && event.target.className.indexOf(params.noSwipingClass) > -1) return false;
if (params.noSwiping && event.target && event.target.className && noSwipingSlide(event.target)) return false;
allowMomentumBounce = false;

//Check For Nested Swipers
Expand Down Expand Up @@ -1488,6 +1489,41 @@ var Swiper = function (selector, params) {
_this.callPlugins('onTouchEnd');
}


/*==================================================
noSwiping Bubble Check
====================================================*/
function noSwipingSlide(el){
/*This function is specifically designed to check the parent elements for the noSwiping class, up to the wrapper.
We need to check parents because while onTouchStart bubbles, _this.isTouched is checked in onTouchStart, which stops the bubbling.
So, if a text box, for example, is the initial target, and the parent slide container has the noSwiping class, the _this.isTouched
check will never find it, and what was supposed to be noSwiping is able to be swiped.
This function will iterate up and check for the noSwiping class in parents, up through the wrapperClass.*/

// First we create a truthy variable, which is that swiping is allowd (noSwiping = false)
var noSwiping = false;

// Now we iterate up (parentElements) until we reach the node with the wrapperClass.

do{

// Each time, we check to see if there's a 'swiper-no-swiping' class (noSwipingClass).
if (el.className.indexOf(params.noSwipingClass)>-1)
{
noSwiping = true; // If there is, we set noSwiping = true;
}

el = el.parentElement; // now we iterate up (parent node)

} while(!noSwiping && el.parentElement && el.className.indexOf(params.wrapperClass)==-1); // also include el.parentElement truthy, just in case.

// because we didn't check the wrapper itself, we do so now, if noSwiping is false:
if (!noSwiping && el.className.indexOf(params.wrapperClass)>-1 && el.className.indexOf(params.noSwipingClass)>-1)
noSwiping = true; // if the wrapper has the noSwipingClass, we set noSwiping = true;

return noSwiping;
}

/*==================================================
Swipe Functions
====================================================*/
Expand Down

0 comments on commit bae1a6f

Please sign in to comment.