From 2c41b0aea6b2b1d1f1d812ab4455bea4a0759428 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Tue, 13 Mar 2018 10:38:36 +0100 Subject: [PATCH] fix get the transition duration parent --- js/src/util.js | 9 ++++++--- js/tests/unit/util.js | 19 +++++-------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/js/src/util.js b/js/src/util.js index 05a69977c2..1b1f13beae 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -106,19 +106,22 @@ const Util = (($) => { }, getTransitionDurationFromElement(element) { + if (!element) { + return 0 + } + // Get transition-duration of the element let transitionDuration = $(element).css('transition-duration') + const floatTransitionDuration = parseFloat(transitionDuration) // Return 0 if element or transition duration is not found - if (!transitionDuration) { + if (!floatTransitionDuration) { return 0 } // If multiple durations are defined, take the first transitionDuration = transitionDuration.split(',')[0] - // jQuery always converts transition durations into seconds, - // so multiply by 1000 return parseFloat(transitionDuration) * MILLISECONDS_MULTIPLIER }, diff --git a/js/tests/unit/util.js b/js/tests/unit/util.js index 46b1e35fec..c4f9459f99 100644 --- a/js/tests/unit/util.js +++ b/js/tests/unit/util.js @@ -46,44 +46,35 @@ $(function () { assert.expect(1) var $div = $('
').appendTo($('#qunit-fixture')) - assert.strictEqual(Util.getTransitionDurationFromElement($div), 300) + assert.strictEqual(Util.getTransitionDurationFromElement($div[0]), 300) }) QUnit.test('Util.getTransitionDurationFromElement should accept transition durations in seconds', function (assert) { assert.expect(1) var $div = $('
').appendTo($('#qunit-fixture')) - assert.strictEqual(Util.getTransitionDurationFromElement($div), 400) + assert.strictEqual(Util.getTransitionDurationFromElement($div[0]), 400) }) QUnit.test('Util.getTransitionDurationFromElement should get the first transition duration if multiple transition durations are defined', function (assert) { assert.expect(1) var $div = $('
').appendTo($('#qunit-fixture')) - assert.strictEqual(Util.getTransitionDurationFromElement($div), 300) + assert.strictEqual(Util.getTransitionDurationFromElement($div[0]), 300) }) QUnit.test('Util.getTransitionDurationFromElement should return 0 if transition duration is not defined', function (assert) { assert.expect(1) var $div = $('
').appendTo($('#qunit-fixture')) - assert.strictEqual(Util.getTransitionDurationFromElement($div), 0) + assert.strictEqual(Util.getTransitionDurationFromElement($div[0]), 0) }) QUnit.test('Util.getTransitionDurationFromElement should return 0 if element is not found in DOM', function (assert) { assert.expect(1) var $div = $('#fake-id') - assert.strictEqual(Util.getTransitionDurationFromElement($div), 0) - }) - - QUnit.test('Util.getTransitionDurationFromElement should properly handle inherited transition durations', function (assert) { - assert.expect(1) - var $parent = $('
') - var $child = $('
') - $('#qunit-fixture').append($parent.append($child)) - - assert.strictEqual(Util.getTransitionDurationFromElement($child), 5000) + assert.strictEqual(Util.getTransitionDurationFromElement($div[0]), 0) }) QUnit.test('Util.getUID should generate a new id uniq', function (assert) {