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) {