Skip to content

Commit

Permalink
Fixed event not triggering on some flips
Browse files Browse the repository at this point in the history
  • Loading branch information
JemarJones committed Jul 18, 2015
1 parent 0872b16 commit 36d993c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 26 deletions.
40 changes: 28 additions & 12 deletions dist/jquery.flip.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*! flip - v1.0.14 - 2015-07-16
/*! flip - v1.0.14 - 2015-07-17
* https://github.com/nnattawat/flip
* Copyright (c) 2015 Nattawat Nonsung; Licensed MIT */
(function( $ ) {
var flip = function($dom) {
var flip = function($dom, callback) {
$dom.data("flipped", true);

var rotateAxis = "rotate" + $dom.data("axis");
Expand All @@ -15,9 +15,17 @@
transform: rotateAxis + "(0deg)",
"z-index": "1"
});

//Providing a nicely wrapped up callback because transform is essentially async
$dom.one(whichTransitionEvent(), function(){
$(this).trigger('flip:done');
if (callback !== undefined){
callback.call(this);
}
});
};

var unflip = function($dom) {
var unflip = function($dom, callback) {
$dom.data("flipped", false);

var rotateAxis = "rotate" + $dom.data("axis");
Expand All @@ -30,6 +38,14 @@
transform: rotateAxis + ($dom.data("reverse") ? "(180deg)" : "(-180deg)"),
"z-index": "0"
});

//Providing a nicely wrapped up callback because transform is essentially async
$dom.one(whichTransitionEvent(), function(){
$(this).trigger('flip:done');
if (callback !== undefined){
callback.call(this);
}
});
};
// Function from David Walsh: http://davidwalsh.name/css-animation-callback licensed with http://opensource.org/licenses/MIT
var whichTransitionEvent = function(){
Expand Down Expand Up @@ -61,17 +77,17 @@
options = !$dom.data("flipped");
}
if (options) {
flip($dom);
flip($dom,callback);
} else {
unflip($dom);
unflip($dom,callback);
}
//Providing a nicely wrapped up callback because transform is essentially async
$(this).one(whichTransitionEvent(), function(){
$(this).trigger('flip:done');
if (callback !== undefined){
callback.call(this);
}
});
// //Providing a nicely wrapped up callback because transform is essentially async
// $(this).one(whichTransitionEvent(), function(){
// $(this).trigger('flip:done');
// if (callback !== undefined){
// callback.call(this);
// }
// });
} else if (!$dom.data("initiated")){ //Init flipable DOM
$dom.data("initiated", true);

Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.flip.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jquery.flip.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 36d993c

Please sign in to comment.