From 5f01942a72e3049716341c68cfb9bb607138cf00 Mon Sep 17 00:00:00 2001 From: Greg Poole Date: Thu, 9 May 2024 15:54:56 +1000 Subject: [PATCH 1/2] Add failing test for destroy event firing --- test/unit/destroy.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/unit/destroy.js b/test/unit/destroy.js index d2b2f23..d95e209 100644 --- a/test/unit/destroy.js +++ b/test/unit/destroy.js @@ -2,12 +2,18 @@ QUnit.test( 'destroy', function( assert ) { let elem = document.querySelector('#destroy'); let flkty = new Flickity( elem ); + let destroyFired = false; + + flkty.on( 'destroy', () => { + destroyFired = true; + } ); let done = assert.async(); // do it async setTimeout( function() { flkty.destroy(); assert.strictEqual( elem.flickityGUID, undefined, 'flickityGUID removed' ); + assert.ok( destroyFired, 'destroy event fired' ); assert.ok( !flkty.isActive, 'not active' ); assert.ok( !Flickity.data( elem ), '.data() returns falsey' ); assert.ok( elem.children[0], '.cell', 'cell is back as first child' ); From 3319648b272e4bcc49418ceea618eb2f35aa7f33 Mon Sep 17 00:00:00 2001 From: Greg Poole Date: Thu, 9 May 2024 15:57:18 +1000 Subject: [PATCH 2/2] Fix destroy event not firing --- js/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/core.js b/js/core.js index 5c13a14..0b48a4d 100644 --- a/js/core.js +++ b/js/core.js @@ -837,8 +837,8 @@ proto.deactivate = function() { proto.destroy = function() { this.deactivate(); window.removeEventListener( 'resize', this ); - this.allOff(); this.emitEvent('destroy'); + this.allOff(); if ( jQuery && this.$element ) { jQuery.removeData( this.element, 'flickity' ); }