Skip to content

Commit

Permalink
Merge pull request #389 from Henri-K/hotfix/calculateSlides
Browse files Browse the repository at this point in the history
calculateSlides(): fix slide length calculation
  • Loading branch information
Visual Idiot committed May 13, 2016
2 parents e9e48ae + 8b6a386 commit 946c0ad
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/js/unslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
// An easing string to use. If you're using Velocity, use a
// Velocity string otherwise you can use jQuery/jQ UI options.
easing: 'swing', // [.42, 0, .58, 1],

// Does it support keyboard arrows?
// Can pass either true or false -
// or an object with the keycodes, like so:
Expand All @@ -57,7 +57,7 @@
prev: 37,
next: 39
},

// Do you want to generate clickable navigation
// to skip to each slide? Accepts boolean true/false or
// a callback function per item to generate.
Expand Down Expand Up @@ -100,7 +100,7 @@
swipe: true,
// Swipe threshold -
// lower float for enabling short swipe
swipeThreshold: 0.2
swipeThreshold: 0.2
};

// Set defaults
Expand All @@ -115,7 +115,7 @@
self.$slides = null;
self.$nav = null;
self.$arrows = [];

// Set our indexes and totals
self.total = 0;
self.current = 0;
Expand Down Expand Up @@ -186,6 +186,9 @@
// Set up the slide widths to animate with
// so the box doesn't float over
self.calculateSlides = function() {
// update slides before recalculating the total
self.$slides = self.$container.children(self.options.selectors.slides);

self.total = self.$slides.length;

// Set the total width
Expand Down Expand Up @@ -244,7 +247,7 @@
// And add it to our navigation item
$nav.children('ol').append('<li data-slide="' + key + '">' + label + '</li>');
});

// Keep a copy of the nav everywhere so we can use it
self.$nav = $nav.insertAfter(self.$context);

Expand Down Expand Up @@ -349,7 +352,7 @@
$.each(pos, function(index, item) {
self.$slides.push.apply(
self.$slides,

// Exclude all cloned slides and call .first() or .last()
// depending on what `item` is.
self.$slides.filter(':not(".' + self._ + '-clone")')[item]()
Expand Down Expand Up @@ -384,7 +387,7 @@
};

// Unset the keyboard navigation
// Remove the handler
// Remove the handler
self.destroyKeys = function() {
// Remove the event handler
$(document).off('keyup' + self.eventSuffix);
Expand All @@ -405,7 +408,7 @@

return self;
};

// Despite the name, this doesn't do any animation - since there's
// now three different types of animation, we let this method delegate
// to the right type, keeping the name for backwards compat.
Expand Down Expand Up @@ -433,7 +436,7 @@
self.$context.trigger(self._ + '.change', [to, self.$slides.eq(to)]);

// Delegate the right method - everything's named consistently
// so we can assume it'll be called "animate" +
// so we can assume it'll be called "animate" +
var fn = 'animate' + $._ucfirst(self.options.animation);

// Make sure it's a valid animation method, otherwise we'll get
Expand Down Expand Up @@ -465,7 +468,7 @@
self.prev = function() {
return self.animate(self.current - 1, 'prev');
};


// Our default animation method, the old-school left-to-right
// horizontal animation
Expand Down Expand Up @@ -644,5 +647,5 @@
return $this.data('unslider', new $.Unslider($this, opts));
});
};
}));

}));

0 comments on commit 946c0ad

Please sign in to comment.