Skip to content

Commit

Permalink
Fix #19 and #10: less select/change events
Browse files Browse the repository at this point in the history
  • Loading branch information
vanderlee committed May 23, 2015
1 parent 341fad2 commit 7c3fce6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jQuery Coverflow
================
Version 1.1.9
Version 1.1.10

Copyright © 2013-2015 Martijn van der Lee (http://martijn.vanderlee.com).
MIT Open Source license applies.
Expand Down Expand Up @@ -147,31 +147,37 @@ or removing covers or changing the covers yourself.
Events
------
### **change**
Triggered whenever the current cover index changes.
Triggered whenever the current cover index changes. This includes initially and
for each cover passed by when skipping past multiple covers. Change triggers as
soon as the cover is on front; this may be before or after it's animation is
completed (but only once!).

`function(event, cover, index)`
Callback: `function(event, cover, index)`

### **confirm**
Triggered when the user clicks on the current cover.

Callback signature: `function(event, cover, index)`
Callback: `function(event, cover, index)`

`event.originalEvent.target` contains the DOM element that was clicked to
trigger the confirm event.

### **select**
Triggered whenever a cover is selected. This includes initially.
`function(event, cover, index)`
Triggered whenever a cover is selected. This includes initially. In contrast to
the `change` event, `select` only triggers once after the requested cover
position has been reached.

Callback: `function(event, cover, index)`

### **animateStep**
Triggered for every animation frame. Use this event to customize how the
animation looks if the default options provide insufficient control.

Callback signature: `function(event, cover, offset, isVisible, isMiddle, sin, cos)`
Callback: `function(event, cover, offset, isVisible, isMiddle, sin, cos)`

### **animateComplete**
Triggered after the animation has stopped. A final `animateStep` will
be triggered after animation as well, so you don't need to use the
`animateComplete` event for normal animation frames.

Callback signature: `function(event, cover, offset, isVisible, isMiddle, sin, cos)`
Callback: `function(event, cover, offset, isVisible, isMiddle, sin, cos)`
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Vanderlee Coverflow",
"version": "1.1.9",
"version": "1.1.10",
"homepage": "https://github.com/vanderlee/coverflow",
"authors": [
"Martijn van der Lee <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
console.log('Confirm');
},

select: function(event, cover) {
change: function(event, cover) {
var img = $(cover).children().andSelf().filter('img').last();
$('#photos-name').text(img.data('name') || 'unknown');
}
Expand Down
2 changes: 1 addition & 1 deletion jqcoverflow.jquery.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jqcoverflow",
"version": "1.1.9",
"version": "1.1.10",
"title": "Vanderlee Coverflow",
"description": "A jQuery-based Coverflow components with optional mousewheel, CSS3 interpolation, transformations, touch swipe, reflections and more.",
"author": {
Expand Down
32 changes: 19 additions & 13 deletions jquery.coverflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
that.refresh();
};

that._window_handler_keydown = function(event) {
that._window_handler_keydown = function(event) {
if (that.hovering) {
switch (event.which) {
case 36: // home
Expand Down Expand Up @@ -211,7 +211,9 @@
index = Math.max(0, Math.min(index, covers.length - 1));

if (index !== that.options.index) {
this.refresh(); // pre-correct for reflection/mods
// Fix reflections
covers.css('position', 'absolute');
this._frame(that.options.index);

if (animate === true || that.options.duration === 0) {
that.options.index = Math.round(index);
Expand Down Expand Up @@ -315,16 +317,16 @@
});
},

refresh: function(duration, index) {
refresh: function(duration, index) {
var that = this,
previous = null,
previous = that.currentIndex,
covers = that._getCovers(),
covercount = covers.length;
covercount = covers.length,
triggered = false;

covers.css('position', 'absolute');

that.element.stop().animate({
'__coverflow_frame': index || that.options.index
'__coverflow_frame': index || that.options.index
}, {
'easing': that.options.easing,
'duration': duration || 0,
Expand All @@ -334,13 +336,17 @@
that.currentIndex = Math.max(0, Math.min(Math.round(now), covercount - 1));
if (previous !== that.currentIndex) {
previous = that.currentIndex;
that._callback('change');
that._callback('select');
}
that._callback('change');
if (that.currentIndex === that.options.index) {
triggered = true;
}
}
},
'complete': function() {
that.currentIndex = that.options.index;
that._callback('change');
'complete': function() {
that.currentIndex = that.options.index;
if (!triggered) {
that._callback('change');
}
that._callback('select');
}
});
Expand Down

0 comments on commit 7c3fce6

Please sign in to comment.