This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AnimationComplete: Add transition, fallbacks and remove memory leaks
Also no its own module including support tests for animations and transitions Fixes gh-5156 Fixes gh-6816 Fixes gh-6697 Fixes gh-6895 Fixes gh-6148 Closes gh-7001
- Loading branch information
Showing
15 changed files
with
384 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude); | ||
//>>description: A handler for css transition & animation end events to ensure callback is executed | ||
//>>label: Animation Complete | ||
//>>group: Core | ||
define( [ | ||
"jquery" | ||
], function( jQuery ) { | ||
//>>excludeEnd("jqmBuildExclude"); | ||
(function( $, undefined ) { | ||
var props = { | ||
"animation": {}, | ||
"transition": {} | ||
}, | ||
testElement = document.createElement( "a" ), | ||
vendorPrefixes = [ "", "webkit-", "moz-", "o-" ]; | ||
|
||
$.each( [ "animation", "transition" ], function( i, test ) { | ||
|
||
// Get correct name for test | ||
var testName = ( i === 0 ) ? test + "-" + "name" : test; | ||
|
||
$.each( vendorPrefixes, function( j, prefix ) { | ||
if ( testElement.style[ $.camelCase( prefix + testName ) ] !== undefined ) { | ||
props[ test ][ "prefix" ] = prefix; | ||
return false; | ||
} | ||
}); | ||
|
||
// Set event and duration names for later use | ||
props[ test ][ "duration" ] = | ||
$.camelCase( props[ test ][ "prefix" ] + test + "-" + "duration" ); | ||
props[ test ][ "event" ] = | ||
$.camelCase( props[ test ][ "prefix" ] + test + "-" + "end" ); | ||
|
||
// All lower case if not a vendor prop | ||
if ( props[ test ][ "prefix" ] === "" ) { | ||
props[ test ][ "duration" ] = props[ test ][ "duration" ].toLowerCase(); | ||
props[ test ][ "event" ] = props[ test ][ "event" ].toLowerCase(); | ||
} | ||
}); | ||
|
||
// If a valid prefix was found then the it is supported by the browser | ||
$.support.cssTransitions = ( props[ "transition" ][ "prefix" ] !== undefined ); | ||
$.support.cssAnimations = ( props[ "animation" ][ "prefix" ] !== undefined ); | ||
|
||
// Remove the testElement | ||
$( testElement ).remove(); | ||
|
||
// Animation complete callback | ||
$.fn.animationComplete = function( callback, type, fallbackTime ) { | ||
var timer, duration, | ||
that = this, | ||
animationType = ( !type || type === "animation" ) ? "animation" : "transition"; | ||
|
||
// Make sure selected type is supported by browser | ||
if ( ( $.support.cssTransitions && animationType === "transition" ) || | ||
( $.support.cssAnimations && animationType === "animation" ) ) { | ||
|
||
// If a fallback time was not passed set one | ||
if ( fallbackTime === undefined ) { | ||
|
||
// Make sure the was not bound to document before checking .css | ||
if ( $( this ).context !== document ) { | ||
|
||
// Parse the durration since its in second multiple by 1000 for milliseconds | ||
// Multiply by 3 to make sure we give the animation plenty of time. | ||
duration = parseFloat( | ||
$( this ).css( props[ animationType ].duration ) | ||
) * 3000; | ||
} | ||
|
||
// If we could not read a duration use the default | ||
if ( duration === 0 || duration === undefined ) { | ||
duration = $.fn.animationComplete.default; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
} | ||
|
||
// Sets up the fallback if event never comes | ||
timer = setTimeout( function() { | ||
$( that ).off( props[ animationType ].event ); | ||
callback.apply( that ); | ||
}, duration ); | ||
|
||
// Bind the event | ||
return $( this ).one( props[ animationType ].event, function() { | ||
|
||
// Clear the timer so we dont call callback twice | ||
clearTimeout( timer ); | ||
callback.call( this, arguments ); | ||
}); | ||
} else { | ||
|
||
// CSS animation / transitions not supported | ||
// Defer execution for consistency between webkit/non webkit | ||
setTimeout( $.proxy( callback, this ), 0 ); | ||
return $( this ); | ||
} | ||
}; | ||
|
||
// Allow default callback to be configured on mobileInit | ||
$.fn.animationComplete.default = 1000; | ||
})( jQuery ); | ||
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude); | ||
}); | ||
//>>excludeEnd("jqmBuildExclude"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
default
is a reserved keyword and this results in syntax error on a lot of old browsers including Android 2.3 and IE8.