From: marcos.sousa Date: Tue, 18 Jan 2011 18:33:30 +0000 (-0200) Subject: Sortable: Make sure we have a placeholder before trying to remove it during a cancel... X-Git-Tag: 1.9m4~38^2~25 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f165c93127495d5041c3d49fa592fddbe8000bd1;p=jquery-ui.git Sortable: Make sure we have a placeholder before trying to remove it during a cancel. Fixes #6879 - Sortable: Calling cancel when there is no sort occurring throws an error. --- diff --git a/ui/jquery.ui.sortable.js b/ui/jquery.ui.sortable.js index dd01e1d63..05cbf2132 100644 --- a/ui/jquery.ui.sortable.js +++ b/ui/jquery.ui.sortable.js @@ -377,21 +377,23 @@ $.widget("ui.sortable", $.ui.mouse, { } - //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node! - if(this.placeholder[0].parentNode) this.placeholder[0].parentNode.removeChild(this.placeholder[0]); - if(this.options.helper != "original" && this.helper && this.helper[0].parentNode) this.helper.remove(); - - $.extend(this, { - helper: null, - dragging: false, - reverting: false, - _noFinalSort: null - }); + if (this.placeholder) { + //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node! + if(this.placeholder[0].parentNode) this.placeholder[0].parentNode.removeChild(this.placeholder[0]); + if(this.options.helper != "original" && this.helper && this.helper[0].parentNode) this.helper.remove(); + + $.extend(this, { + helper: null, + dragging: false, + reverting: false, + _noFinalSort: null + }); - if(this.domPosition.prev) { - $(this.domPosition.prev).after(this.currentItem); - } else { - $(this.domPosition.parent).prepend(this.currentItem); + if(this.domPosition.prev) { + $(this.domPosition.prev).after(this.currentItem); + } else { + $(this.domPosition.parent).prepend(this.currentItem); + } } return this;