Skip to content

Commit

Permalink
Fixes off-by-one error when using rtl and center options
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Green committed Aug 3, 2015
1 parent 0402ea9 commit a27221a
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 a27221a

Please sign in to comment.