| 1975 | $container.find('*').off(); | 1972 | $container.find('*').off(); |
| 1976 | $.cleanData($container.find('*').get()); | 1973 | $.cleanData($container.find('*').get()); |
| 1977 | $container.remove(); | 1974 | $container.remove(); |
| 1978 | } else { | | |
| 1979 | console.warn('container not found'); | | |
| 1980 | console.warn($select.parent().html()); | | |
| 1981 | } | 1975 | } |
| 1982 | // Destroy Select2 if applicable | | |
| 1983 | | 1976 | |
| 1984 | $select.off(); | 1977 | $select.off(); |
| 1985 | $.cleanData([$select[0]]); | 1978 | $.cleanData([$select[0]]); |
| 1986 | | 1979 | |
| 1987 | }); | 1980 | }); |
| 1988 | console.warn(`Post-clean: ${$list.find('select').length} selects in list`); | | |
| 1989 | | 1981 | |
| 1990 | // Step 3: Clean <div>, <span>, <input> | 1982 | // Step 3: Clean <div>, <span>, <input> |
| 1991 | console.warn(`Before cleaning: ${$list.find('div, span, input').length} divs, spans, inputs in list`); | | |
| 1992 | $list.find('div, span, input').each(function () { | 1983 | $list.find('div, span, input').each(function () { |
| 1993 | const $elem = $(this); | 1984 | const $elem = $(this); |
| 1994 | $elem.off(); | 1985 | $elem.off(); |
| 1995 | $.cleanData([$elem[0]]); | 1986 | $.cleanData([$elem[0]]); |
| 1996 | $elem.remove(); | 1987 | $elem.remove(); |
| 1997 | }); | 1988 | }); |
| 1998 | console.warn(`Post-clean: ${$list.find('div, span, input').length} divs, spans, inputs in list`); | | |
| 1999 | | 1989 | |
| 2000 | // Destroy Sortable | 1990 | // Destroy Sortable |
| 2001 | console.warn(`Before cleaning: ${$list.sortable('instance') ? 1 : 0} sortable instance in list`); | | |
| 2002 | if ($list.sortable('instance')) { | 1991 | if ($list.sortable('instance')) { |
| 2003 | $list.sortable('destroy'); | 1992 | $list.sortable('destroy'); |
| 2004 | } | 1993 | } |
| 2005 | console.warn(`Post-cleaning: ${$list.sortable('instance') ? 1 : 0} sortable instance in list`); | | |
| 2006 | | 1994 | |
| 2007 | let totalElementsOfanyKindLeftInList = $list.children().length; | 1995 | let totalElementsOfanyKindLeftInList = $list.children().length; |
| 2008 | | 1996 | |
| 2009 | // Final cleanup | 1997 | // Final cleanup |
| 2010 | if (totalElementsOfanyKindLeftInList !== 0) { | 1998 | if (totalElementsOfanyKindLeftInList !== 0) { |
| 2011 | console.time('empty'); | 1999 | console.time('empty'); |
| 2012 | console.warn(`Before .empty(): ${totalElementsOfanyKindLeftInList} elements left in list`); | | |
| 2013 | $list.empty(); | 2000 | $list.empty(); |
| 2014 | totalElementsOfanyKindLeftInList = $list.children().length; | 2001 | totalElementsOfanyKindLeftInList = $list.children().length; |
| 2015 | console.warn(`After .empty(): ${totalElementsOfanyKindLeftInList} elements left in list`); | | |
| 2016 | console.timeEnd('empty'); | 2002 | console.timeEnd('empty'); |
| 2017 | } else { | | |
| 2018 | console.warn('Entry List is already totally empty, no need to call .empty()'); | | |
| 2019 | } | 2003 | } |
| 2020 | | 2004 | |
| 2021 | console.timeEnd('clearEntryList'); | 2005 | console.timeEnd('clearEntryList'); |