MDL-65493 theme_bootstrapbase: Emulate transition ends for BS2 events
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
define(["jquery"],function(a){var b={alert:[{classMatch:".alert",start:"close",end:"closed"}],carousel:[{classMatch:".carousel",start:"slide",end:"slid"}],collapse:[{classMatch:".collapse",start:"hide",end:"hidden"},{classMatch:".collapse",start:"show",end:"shown"}],modal:[{classMatch:".modal",start:"hide",end:"hidden"},{classMatch:".modal",start:"show",end:"shown"}],tab:[{classMatch:".tab",start:"hide",end:"hidden"},{classMatch:".tab",start:"show",end:"shown"}],tooltip:[{classMatch:".tooltip",start:"hide",end:"hidden"},{classMatch:".tooltip",start:"show",end:"shown"}]};Object.keys(b).forEach(function(c){b[c].forEach(function(b){a(document.body).on(b.start,b.classMatch,function(){M.util.js_pending(b.end)}),a(document.body).on(b.end,b.classMatch,function(){M.util.js_complete(b.end)})})})});
|
||||
define(["jquery","core/pending"],function(a,b){var c={alert:[{classMatch:".alert",start:"close",end:"closed"}],carousel:[{classMatch:".carousel",start:"slide",end:"slid"}],collapse:[{classMatch:".collapse",start:"hide",end:"hidden"},{classMatch:".collapse",start:"show",end:"shown"}],modal:[{classMatch:".modal",start:"hide",end:"hidden"},{classMatch:".modal",start:"show",end:"shown"}],tab:[{classMatch:".tab",start:"hide",end:"hidden"},{classMatch:".tab",start:"show",end:"shown"}],tooltip:[{classMatch:".tooltip",start:"hide",end:"hidden"},{classMatch:".tooltip",start:"show",end:"shown"}]},d=function(b){var c=1e3;if(!b)return 0;var d=a(b).css("transition-duration"),e=a(b).css("transition-delay"),f=parseFloat(d),g=parseFloat(e);return f||g?(d=d.split(",")[0],e=e.split(",")[0],(parseFloat(d)+parseFloat(e))*c):0};Object.keys(c).forEach(function(e){c[e].forEach(function(c){a(document.body).on(c.start,c.classMatch,function(e){var f=a(e.target),g=new b(c.start),h=!1;a(document.body).one(c.end,c.classMatch,function(){h=!0,g.resolve()}),setTimeout(function(){h||f.trigger(c.end)},d(f))})})})});
|
||||
@@ -20,7 +20,7 @@
|
||||
* @copyright 2019 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define(['jquery'], function($) {
|
||||
define(['jquery', 'core/pending'], function($, Pending) {
|
||||
var moduleTransitions = {
|
||||
alert: [
|
||||
// Alert.
|
||||
@@ -92,14 +92,46 @@ define(['jquery'], function($) {
|
||||
],
|
||||
};
|
||||
|
||||
var getTransitionDurationFromElement = function(element) {
|
||||
var MILLISECONDS_MULTIPLIER = 1000;
|
||||
if (!element) {
|
||||
return 0;
|
||||
}
|
||||
// Get transition-duration of the element
|
||||
|
||||
var transitionDuration = $(element).css('transition-duration');
|
||||
var transitionDelay = $(element).css('transition-delay');
|
||||
var floatTransitionDuration = parseFloat(transitionDuration);
|
||||
var floatTransitionDelay = parseFloat(transitionDelay);
|
||||
|
||||
// Return 0 if element or transition duration is not found
|
||||
if (!floatTransitionDuration && !floatTransitionDelay) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// If multiple durations are defined, take the first
|
||||
transitionDuration = transitionDuration.split(',')[0];
|
||||
transitionDelay = transitionDelay.split(',')[0];
|
||||
return (parseFloat(transitionDuration) + parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
|
||||
};
|
||||
|
||||
Object.keys(moduleTransitions).forEach(function(key) {
|
||||
moduleTransitions[key].forEach(function(pair) {
|
||||
$(document.body).on(pair.start, pair.classMatch, function() {
|
||||
M.util.js_pending(pair.end);
|
||||
});
|
||||
$(document.body).on(pair.start, pair.classMatch, function(e) {
|
||||
var element = $(e.target);
|
||||
var pendingPromise = new Pending(pair.start);
|
||||
|
||||
$(document.body).on(pair.end, pair.classMatch, function() {
|
||||
M.util.js_complete(pair.end);
|
||||
var called = false;
|
||||
$(document.body).one(pair.end, pair.classMatch, function() {
|
||||
called = true;
|
||||
pendingPromise.resolve();
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
if (!called) {
|
||||
element.trigger(pair.end);
|
||||
}
|
||||
}, getTransitionDurationFromElement(element));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user