From 091e241c17c0527bf499aa51fdbf1c327acf7359 Mon Sep 17 00:00:00 2001 From: Jens Balvig Date: Mon, 24 Jun 2019 10:33:20 +0900 Subject: [PATCH] add option for leaving DOM untouched when calling destroy --- README.md | 9 +++++++++ colcade.js | 12 +++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f33f4c5..cc131b9 100644 --- a/README.md +++ b/README.md @@ -214,6 +214,15 @@ $grid.colcade('destroy') colc.destroy() ``` +Remove event listeners and instances, but preserve DOM as is. + +``` js +// jQuery +$grid.colcade('destroy', false) +// vanilla JS +colc.destroy(false) +``` + --- By David DeSandro diff --git a/colcade.js b/colcade.js index 67261ad..e2670bb 100644 --- a/colcade.js +++ b/colcade.js @@ -214,11 +214,13 @@ proto.onLoad = function( event ) { // ----- destroy ----- // -proto.destroy = function() { - // move items back to container - this.items.forEach( function( item ) { - this.element.appendChild( item ); - }, this ); +proto.destroy = function(moveItemsBack = true) { + if(moveItemsBack) { + // move items back to container + this.items.forEach( function( item ) { + this.element.appendChild( item ); + }, this ); + } // remove events window.removeEventListener( 'resize', this._windowResizeHandler ); this.element.removeEventListener( 'load', this._loadHandler, true );