Skip to content
This repository has been archived by the owner on Aug 26, 2019. It is now read-only.

Commit

Permalink
Disable prev/next buttons for contain metafizzy#289
Browse files Browse the repository at this point in the history
Usage:
[object].flickity({
        cellAlign: 'left',
        contain: true,
        wrapAround: false
        });
  • Loading branch information
Jack committed Sep 14, 2016
1 parent 6c4e5e2 commit 978b0ee
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
18 changes: 18 additions & 0 deletions dist/flickity.pkgd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,7 @@ Flickity.prototype._create = function() {
this.viewport = document.createElement('div');
this.viewport.className = 'flickity-viewport';
Flickity.setUnselectable( this.viewport );
this.boundLastSlide = null;
this._createSlider();

if ( this.options.resize || this.options.watchCSS ) {
Expand Down Expand Up @@ -2297,6 +2298,7 @@ Flickity.prototype._containCells = function() {
// content is less than gallery size
var isContentSmaller = contentWidth < this.size.innerWidth;
// contain each cell target
this.boundLastSlide = null;
for ( var i=0, len = this.cells.length; i < len; i++ ) {
var cell = this.cells[i];
// reset default target
Expand All @@ -2308,6 +2310,16 @@ Flickity.prototype._containCells = function() {
// contain to bounds
cell.target = Math.max( cell.target, this.cursorPosition + firstCellStartMargin );
cell.target = Math.min( cell.target, endLimit );

if ( cell.target == endLimit) {
var slideIndex = this.cells.indexOf(cell);
if (this.boundLastSlide === null ) {
this.boundLastSlide = slideIndex;
}
else if ( this.boundLastSlide > slideIndex ) {
this.boundLastSlide = slideIndex;
}
}
}
}
};
Expand Down Expand Up @@ -3971,6 +3983,12 @@ PrevNextButton.prototype.onTap = function() {
}
this.parent.uiChange();
var method = this.isPrevious ? 'previous' : 'next';
if ( this.parent.options.contain || !this.parent.options.wrapAround || this.parent.cells.length || this.parent.boundLastSlide !== null ) {
if ( this.parent.selectedIndex > this.parent.boundLastSlide ) {
this.parent.selectedIndex = this.parent.boundLastSlide;
}
}

this.parent[ method ]();
};

Expand Down
4 changes: 2 additions & 2 deletions dist/flickity.pkgd.min.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions js/flickity.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Flickity.prototype._create = function() {
this.viewport = document.createElement('div');
this.viewport.className = 'flickity-viewport';
Flickity.setUnselectable( this.viewport );
this.boundLastSlide = null;
this._createSlider();

if ( this.options.resize || this.options.watchCSS ) {
Expand Down Expand Up @@ -386,6 +387,7 @@ Flickity.prototype._containCells = function() {
// content is less than gallery size
var isContentSmaller = contentWidth < this.size.innerWidth;
// contain each cell target
this.boundLastSlide = null;
for ( var i=0, len = this.cells.length; i < len; i++ ) {
var cell = this.cells[i];
// reset default target
Expand All @@ -397,6 +399,16 @@ Flickity.prototype._containCells = function() {
// contain to bounds
cell.target = Math.max( cell.target, this.cursorPosition + firstCellStartMargin );
cell.target = Math.min( cell.target, endLimit );

if ( cell.target == endLimit) {
var slideIndex = this.cells.indexOf(cell);
if (this.boundLastSlide === null ) {
this.boundLastSlide = slideIndex;
}
else if ( this.boundLastSlide > slideIndex ) {
this.boundLastSlide = slideIndex;
}
}
}
}
};
Expand Down
6 changes: 6 additions & 0 deletions js/prev-next-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ PrevNextButton.prototype.onTap = function() {
}
this.parent.uiChange();
var method = this.isPrevious ? 'previous' : 'next';
if ( this.parent.options.contain || !this.parent.options.wrapAround || this.parent.cells.length || this.parent.boundLastSlide !== null ) {
if ( this.parent.selectedIndex > this.parent.boundLastSlide ) {
this.parent.selectedIndex = this.parent.boundLastSlide;
}
}

this.parent[ method ]();
};

Expand Down

0 comments on commit 978b0ee

Please sign in to comment.