Skip to content

Commit

Permalink
Merge pull request OwlCarousel2#969 from smashingboxes/rtl-centered-fix
Browse files Browse the repository at this point in the history
Fixes off-by-one error when using rtl and center options
  • Loading branch information
greg5green committed Aug 3, 2015
2 parents 0402ea9 + a27221a commit 729ec92
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/js/owl.carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,9 @@
* @returns {Number|Array.<Number>} - The coordinate of the item in pixel or all coordinates.
*/
Owl.prototype.coordinates = function(position) {
var coordinate = null;
var multiplier = 1,
newPosition = position - 1,
coordinates;

if (position === undefined) {
return $.map(this._coordinates, $.proxy(function(coordinate, index) {
Expand All @@ -1124,10 +1126,15 @@
}

if (this.settings.center) {
if (this.settings.rtl) {
multiplier = -1;
newPosition = position + 1;
}

coordinate = this._coordinates[position];
coordinate += (this.width() - coordinate + (this._coordinates[position - 1] || 0)) / 2 * (this.settings.rtl ? -1 : 1);
coordinate += (this.width() - coordinate + (this._coordinates[newPosition] || 0)) / 2 * multiplier;
} else {
coordinate = this._coordinates[position - 1] || 0;
coordinate = this._coordinates[newPosition] || 0;
}

return coordinate;
Expand Down

0 comments on commit 729ec92

Please sign in to comment.