From d3d4f0655f23619e03911f8cb0967469026c41ce Mon Sep 17 00:00:00 2001 From: Jeremy Pyne Date: Wed, 12 Jun 2013 09:50:32 -0400 Subject: [PATCH] Added relocate event that is fired only once when an item is finished being relocated in the content tree. --- README.md | 13 +++++++++++++ jquery.mjs.nestedSortable.js | 13 ++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5138dde..20fd4ce 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,19 @@ Also, the default list type is `
    `. Similarly to toArray, it accepts attribute and expression options. +## Events + +
    +
    change
    +
    Fires when the item is dragged to a new location. This triggers for each location it is dragged into not just the ending location. +
    sort
    +
    Fires when the item is dragged.
    +
    revert
    +
    Fires once the object has moved if the new location is invalid.
    +
    relocate
    +
    Only fires once when the item is done bing moved at its final location.
    +
    + ## Known Bugs *nestedSortable* doesn't work properly with connected draggables, because of the way Draggable simulates Sortable `mouseStart` and `mouseStop` events. This bug might or might not be fixed some time in the future (it's not specific to this plugin). diff --git a/jquery.mjs.nestedSortable.js b/jquery.mjs.nestedSortable.js index e6c0d62..c669a63 100644 --- a/jquery.mjs.nestedSortable.js +++ b/jquery.mjs.nestedSortable.js @@ -1,7 +1,7 @@ /* * jQuery UI Nested Sortable - * v 1.3.5 / 21 jun 2012 - * http://mjsarfatti.com/code/nestedSortable + * v 1.3.6 / 21 jun 2012 + * https://github.com/mjsarfatti/nestedSortable * * Depends on: * jquery.ui.sortable.js 1.8+ @@ -237,7 +237,14 @@ } $.ui.sortable.prototype._mouseStop.apply(this, arguments); - + + var pid = $(this.domPosition.parent).parent().attr("id"); + var sort = this.domPosition.prev ? $(this.domPosition.prev).next().index() : 0; + + if(!(pid == this._uiHash().item.parent().parent().attr("id") && + sort == this._uiHash().item.index())) { + this._trigger("relocate", event, this._uiHash()); + } }, serialize: function(options) {