From 16291ec5bd559cc08ebe52ffb7fbc0486b18c37a Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 2 Sep 2019 13:25:54 +0800 Subject: [PATCH] MDL-65493 theme_bootstrapbase: Emulate transition ends for BS2 events --- theme/bootstrapbase/amd/build/pending.min.js | 2 +- theme/bootstrapbase/amd/src/pending.js | 44 +++++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/theme/bootstrapbase/amd/build/pending.min.js b/theme/bootstrapbase/amd/build/pending.min.js index 7503008eb60..73eaa3a7616 100644 --- a/theme/bootstrapbase/amd/build/pending.min.js +++ b/theme/bootstrapbase/amd/build/pending.min.js @@ -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)})})})}); \ No newline at end of file +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))})})})}); \ No newline at end of file diff --git a/theme/bootstrapbase/amd/src/pending.js b/theme/bootstrapbase/amd/src/pending.js index fa5716de817..12393d431ec 100644 --- a/theme/bootstrapbase/amd/src/pending.js +++ b/theme/bootstrapbase/amd/src/pending.js @@ -20,7 +20,7 @@ * @copyright 2019 Andrew Nicols * @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)); }); }); });