From 4dd722d63fd840cbb5b9d8c9e216e07e620079b4 Mon Sep 17 00:00:00 2001 From: Vincenzo Mennella Date: Wed, 2 May 2018 19:14:21 +0200 Subject: [PATCH] Edited "remove" method. Childs can be preserved Childs can be preserved setting `true` as 2nd parameter of method "remove" --- jquery.nestable.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/jquery.nestable.js b/jquery.nestable.js index a6e0c42..593b709 100644 --- a/jquery.nestable.js +++ b/jquery.nestable.js @@ -259,17 +259,23 @@ }, //removes item and additional elements from list - removeItem: function (item){ + removeItem: function (item, keepChilds){ var opts = this.options, el = this.el; - // remove item + // get item item = item || this; - item.remove(); - // remove empty children lists var emptyListsSelector = '.' + opts.listClass + ' .' + opts.listClass + ':not(:has(*))'; + + if(keepChilds) { + var keepChilds_html = $(item).find('.' + opts.listClass).html(); + $(item).closest('ol').append(keepChilds_html); + } + + // remove item + item.remove(); $(el).find(emptyListsSelector).remove(); // remove buttons if parents do not have children @@ -283,7 +289,7 @@ }, //removes item by itemId and run callback at the end - remove: function (itemId, callback) + remove: function (itemId, keepChilds, callback) { var opts = this.options; var list = this; @@ -298,11 +304,11 @@ //add fadeOut effect when removing if (animation === 'fade'){ item.fadeOut(time, function(){ - list.removeItem(item); + list.removeItem(item, keepChilds); }); } else { - this.removeItem(item); + this.removeItem(item, keepChilds); } if (callback) callback(); @@ -325,7 +331,7 @@ function remove(){ //Removes each item and its children. items.each(function() { - list.removeItem($(this)); + list.removeItem($(this), false); }); //Now we can again show our node element node.show();