Skip to content

Commit

Permalink
Adds the following public methods:
Browse files Browse the repository at this point in the history
- showPhoto: Calls the _showPhoto method (useful for jumping directly to a photo)
- open: Calls the _open method (useful for manually opening the gallery via other methods)
- navigate: Calls the _navigate method (useful for manually navigating through photos via other methods)
  • Loading branch information
Eric C. Brown committed Apr 6, 2014
1 parent 401fe6c commit 684a12b
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion js/photostack.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,20 @@
this.current = options.start;
}
this._init();

var ps = this;

// Public methods.
return {
showPhoto: function(idx) {
ps._showPhoto.call(ps, idx);
},
open: function() {
ps._open.call(ps, true);
},
navigate: function(dir) {
ps._navigate.call(ps, dir);
},
}
}

Photostack.prototype.options = {
Expand Down Expand Up @@ -368,6 +381,22 @@
moveItems.call();
}

Photostack.prototype._navigate = function(dir) {
var current = this.current,
itemsCount = this.itemsCount,
lastItem = itemsCount - 1,
idx = 0;
if(dir == 'next') {
idx = current < lastItem ? current + 1 : 0
} else if(dir == 'prev') {
idx = current > 0 ? current - 1 : lastItem;
}
this._showPhoto(idx);
if(this.options.afterNavigate) {
this.options.afterNavigate(this);
}
}

Photostack.prototype._getSizes = function() {
this.sizes = {
inner : { width : this.inner.offsetWidth, height : this.inner.offsetHeight },
Expand Down

0 comments on commit 684a12b

Please sign in to comment.