aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorPaul Bakaus <paul.bakaus@googlemail.com>2008-11-03 21:41:59 +0000
committerPaul Bakaus <paul.bakaus@googlemail.com>2008-11-03 21:41:59 +0000
commit5e5116b3d4ce615baaa62c8cf2a45a5dd3523ffa (patch)
tree79ae28851d36bff70d056ca53c8c6761151a3a9d /ui
parent1045a83f49a5f7938e4c81ee2924f3fbc697245b (diff)
downloadjquery-ui-5e5116b3d4ce615baaa62c8cf2a45a5dd3523ffa.tar.gz
jquery-ui-5e5116b3d4ce615baaa62c8cf2a45a5dd3523ffa.zip
sortable: implemented ui.cancel(), a function that can be called to completely cancel the sortable attempt, and revert to the original state (implements #3283, #3402)
Diffstat (limited to 'ui')
-rw-r--r--ui/ui.sortable.js53
1 files changed, 47 insertions, 6 deletions
diff --git a/ui/ui.sortable.js b/ui/ui.sortable.js
index 4c165d342..ed9f4198c 100644
--- a/ui/ui.sortable.js
+++ b/ui/ui.sortable.js
@@ -46,17 +46,58 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
},
plugins: {},
ui: function(inst) {
+ var self = inst || this;
return {
- helper: (inst || this)["helper"],
- placeholder: (inst || this)["placeholder"] || $([]),
- position: (inst || this)["position"],
- absolutePosition: (inst || this)["positionAbs"],
+ helper: self.helper,
+ placeholder: self.placeholder || $([]),
+ position: self.position,
+ absolutePosition: self.positionAbs,
options: this.options,
element: this.element,
- item: (inst || this)["currentItem"],
- sender: inst ? inst.element : null
+ item: self.currentItem,
+ sender: inst ? inst.element : null,
+ cancel: function() { self.cancel(); }
};
},
+
+ cancel: function() {
+
+ if(this.dragging) {
+ if(this.options.helper == "original")
+ this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
+ else
+ this.currentItem.show();
+
+ //Post deactivating events to containers
+ for (var i = this.containers.length - 1; i >= 0; i--){
+ this.containers[i]._propagate("deactivate", null, this);
+ if(this.containers[i].containerCache.over) {
+ this.containers[i]._propagate("out", null, this);
+ this.containers[i].containerCache.over = 0;
+ }
+ }
+ }
+
+ //$(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);
+ }
+
+ return true;
+
+ },
_propagate: function(n,e,inst, noPropagation) {
$.ui.plugin.call(this, n, [e, this.ui(inst)]);