Skip to content

Commit

Permalink
Fix for multiple sliders & events handlers refined
Browse files Browse the repository at this point in the history
  • Loading branch information
jedrzejchalubek committed Feb 21, 2014
1 parent 1884dbc commit d337d83
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 74 deletions.
67 changes: 30 additions & 37 deletions dist/jquery.glide.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@
*/
if (this.options.touchDistance) {
this.parent.on({
'touchstart': $.proxy(this.events.touchstart, this),
'touchmove': $.proxy(this.events.touchmove, this),
'touchend': $.proxy(this.events.touchend, this),
'touchstart MSPointerDown': $.proxy(this.events.touchstart, this),
'touchmove MSPointerMove': $.proxy(this.events.touchmove, this),
'touchend MSPointerUp': $.proxy(this.events.touchend, this),
});
}

Expand Down Expand Up @@ -499,10 +499,12 @@
*/
Glide.prototype.events.navigation = function(event) {

// Prevent default behaviour
event.preventDefault();
// Slide distance specified in data attribute
this.slide( $(event.currentTarget).data('distance'), true );
if ( !this.wrapper.attr('disabled') ) {
// Prevent default behaviour
event.preventDefault();
// Slide distance specified in data attribute
this.slide( $(event.currentTarget).data('distance'), true );
}

};

Expand All @@ -514,10 +516,12 @@
*/
Glide.prototype.events.arrows = function(event) {

// Prevent default behaviour
event.preventDefault();
// Slide distance specified in data attribute
this.slide( $(event.currentTarget).data('distance'), false );
if ( !this.wrapper.attr('disabled') ) {
// Prevent default behaviour
event.preventDefault();
// Slide distance specified in data attribute
this.slide( $(event.currentTarget).data('distance'), false );
}

};

Expand All @@ -527,10 +531,12 @@
*/
Glide.prototype.events.keyboard = function(event) {

// Next
if (event.keyCode === 39) this.slide(1);
// Prev
if (event.keyCode === 37) this.slide(-1);
if ( !this.wrapper.attr('disabled') ) {
// Next
if (event.keyCode === 39) this.slide(1);
// Prev
if (event.keyCode === 37) this.slide(-1);
}

};

Expand All @@ -549,7 +555,6 @@
};

/**
* !!! TO DO !!!
* When resize browser window
* Reinit plugin for new slider dimensions
* Correct crop to current slide
Expand All @@ -564,29 +569,17 @@
};

/**
* Unbind events thats controls slide changes
* Disable events thats controls slide changes
*/
Glide.prototype.eventsUnbind = function() {

$(this.parent).unbind('touchstart touchmove touchend');
$(this.arrows.wrapper).children().unbind('click touchstart');
$(document).unbind('keyup.glideKeyup');

Glide.prototype.disableEvents = function() {
this.wrapper.attr( "disabled", true );
};

/**
* Bind events thats controls slide changes
* Enable events thats controls slide changes
*/
Glide.prototype.eventsBind = function() {

$(this.arrows.wrapper).children().bind('click touchstart', $.proxy(this.events.arrows, this));
$(document).bind('keyup.glideKeyup', $.proxy(this.events.keyboard, this));
$(this.parent).bind({
'touchstart': $.proxy(this.events.touchstart, this),
'touchmove': $.proxy(this.events.touchmove, this),
'touchend': $.proxy(this.events.touchend, this),
});

Glide.prototype.enableEvents = function() {
this.wrapper.attr( "disabled", false );
};

/**
Expand Down Expand Up @@ -712,7 +705,7 @@
*/
if (this.options.circular) {
offset = offset - this.slides.spread;
if (fromLast || fromFirst) this.eventsUnbind();
if (fromLast || fromFirst) this.disableEvents();
if (fromLast) offset = this.slides.spread * (slidesLength - 2);
if (fromFirst) offset = 0;
}
Expand All @@ -737,7 +730,7 @@
if (fromFirst || fromLast) {
this.afterAnimation(function(){
self.wrapper.trigger('clearTransition');
self.eventsBind();
self.enableEvents();
});
}

Expand Down Expand Up @@ -767,7 +760,7 @@

// Set to navigation item current class
if (this.options.navigation && this.navigation.wrapper) {
$(this.navigation.wrapper).children()
$(this.parent).children('.' + this.options.navigationClass).children()
.eq(-currentSlide)
.addClass(this.options.navigationCurrentItemClass)
.siblings()
Expand Down

0 comments on commit d337d83

Please sign in to comment.