mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Sortable: Remove uses of self var; use that var.
This commit is contained in:
parent
71c0562f51
commit
a15d40eb5f
76
ui/jquery.ui.sortable.js
vendored
76
ui/jquery.ui.sortable.js
vendored
@ -100,13 +100,13 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
this._refreshItems(event);
|
this._refreshItems(event);
|
||||||
|
|
||||||
//Find out if the clicked node (or one of its parents) is a actual item in this.items
|
//Find out if the clicked node (or one of its parents) is a actual item in this.items
|
||||||
var currentItem = null, self = this, nodes = $(event.target).parents().each(function() {
|
var currentItem = null, nodes = $(event.target).parents().each(function() {
|
||||||
if($.data(this, that.widgetName + '-item') == self) {
|
if($.data(this, that.widgetName + '-item') == that) {
|
||||||
currentItem = $(this);
|
currentItem = $(this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if($.data(event.target, that.widgetName + '-item') == self) currentItem = $(event.target);
|
if($.data(event.target, that.widgetName + '-item') == that) currentItem = $(event.target);
|
||||||
|
|
||||||
if(!currentItem) return false;
|
if(!currentItem) return false;
|
||||||
if(this.options.handle && !overrideHandle) {
|
if(this.options.handle && !overrideHandle) {
|
||||||
@ -124,7 +124,7 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
|
|
||||||
_mouseStart: function(event, overrideHandle, noActivation) {
|
_mouseStart: function(event, overrideHandle, noActivation) {
|
||||||
|
|
||||||
var o = this.options, self = this;
|
var o = this.options;
|
||||||
this.currentContainer = this;
|
this.currentContainer = this;
|
||||||
|
|
||||||
//We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture
|
//We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture
|
||||||
@ -220,7 +220,7 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
|
|
||||||
//Post 'activate' events to possible containers
|
//Post 'activate' events to possible containers
|
||||||
if(!noActivation) {
|
if(!noActivation) {
|
||||||
for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, self._uiHash(this)); }
|
for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, this._uiHash(this)); }
|
||||||
}
|
}
|
||||||
|
|
||||||
//Prepare possible droppables
|
//Prepare possible droppables
|
||||||
@ -338,16 +338,16 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
$.ui.ddmanager.drop(this, event);
|
$.ui.ddmanager.drop(this, event);
|
||||||
|
|
||||||
if(this.options.revert) {
|
if(this.options.revert) {
|
||||||
var self = this;
|
var that = this;
|
||||||
var cur = self.placeholder.offset();
|
var cur = this.placeholder.offset();
|
||||||
|
|
||||||
self.reverting = true;
|
this.reverting = true;
|
||||||
|
|
||||||
$(this.helper).animate({
|
$(this.helper).animate({
|
||||||
left: cur.left - this.offset.parent.left - self.margins.left + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft),
|
left: cur.left - this.offset.parent.left - this.margins.left + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft),
|
||||||
top: cur.top - this.offset.parent.top - self.margins.top + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop)
|
top: cur.top - this.offset.parent.top - this.margins.top + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop)
|
||||||
}, parseInt(this.options.revert, 10) || 500, function() {
|
}, parseInt(this.options.revert, 10) || 500, function() {
|
||||||
self._clear(event);
|
that._clear(event);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this._clear(event, noPropagation);
|
this._clear(event, noPropagation);
|
||||||
@ -359,8 +359,6 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
|
|
||||||
cancel: function() {
|
cancel: function() {
|
||||||
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if(this.dragging) {
|
if(this.dragging) {
|
||||||
|
|
||||||
this._mouseUp({ target: null });
|
this._mouseUp({ target: null });
|
||||||
@ -372,9 +370,9 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
|
|
||||||
//Post deactivating events to containers
|
//Post deactivating events to containers
|
||||||
for (var i = this.containers.length - 1; i >= 0; i--){
|
for (var i = this.containers.length - 1; i >= 0; i--){
|
||||||
this.containers[i]._trigger("deactivate", null, self._uiHash(this));
|
this.containers[i]._trigger("deactivate", null, this._uiHash(this));
|
||||||
if(this.containers[i].containerCache.over) {
|
if(this.containers[i].containerCache.over) {
|
||||||
this.containers[i]._trigger("out", null, self._uiHash(this));
|
this.containers[i]._trigger("out", null, this._uiHash(this));
|
||||||
this.containers[i].containerCache.over = 0;
|
this.containers[i].containerCache.over = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -522,7 +520,6 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
|
|
||||||
_getItemsAsjQuery: function(connected) {
|
_getItemsAsjQuery: function(connected) {
|
||||||
|
|
||||||
var self = this;
|
|
||||||
var items = [];
|
var items = [];
|
||||||
var queries = [];
|
var queries = [];
|
||||||
var connectWith = this._connectWith();
|
var connectWith = this._connectWith();
|
||||||
@ -571,7 +568,6 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
this.items = [];
|
this.items = [];
|
||||||
this.containers = [this];
|
this.containers = [this];
|
||||||
var items = this.items;
|
var items = this.items;
|
||||||
var self = this;
|
|
||||||
var queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]];
|
var queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]];
|
||||||
var connectWith = this._connectWith();
|
var connectWith = this._connectWith();
|
||||||
|
|
||||||
@ -650,16 +646,16 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_createPlaceholder: function(that) {
|
_createPlaceholder: function(that) {
|
||||||
|
that = that || this;
|
||||||
var self = that || this, o = self.options;
|
var o = that.options;
|
||||||
|
|
||||||
if(!o.placeholder || o.placeholder.constructor == String) {
|
if(!o.placeholder || o.placeholder.constructor == String) {
|
||||||
var className = o.placeholder;
|
var className = o.placeholder;
|
||||||
o.placeholder = {
|
o.placeholder = {
|
||||||
element: function() {
|
element: function() {
|
||||||
|
|
||||||
var el = $(document.createElement(self.currentItem[0].nodeName))
|
var el = $(document.createElement(that.currentItem[0].nodeName))
|
||||||
.addClass(className || self.currentItem[0].className+" ui-sortable-placeholder")
|
.addClass(className || that.currentItem[0].className+" ui-sortable-placeholder")
|
||||||
.removeClass("ui-sortable-helper")[0];
|
.removeClass("ui-sortable-helper")[0];
|
||||||
|
|
||||||
if(!className)
|
if(!className)
|
||||||
@ -674,20 +670,20 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
if(className && !o.forcePlaceholderSize) return;
|
if(className && !o.forcePlaceholderSize) return;
|
||||||
|
|
||||||
//If the element doesn't have a actual height by itself (without styles coming from a stylesheet), it receives the inline height from the dragged item
|
//If the element doesn't have a actual height by itself (without styles coming from a stylesheet), it receives the inline height from the dragged item
|
||||||
if(!p.height()) { p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.currentItem.css('paddingBottom')||0, 10)); };
|
if(!p.height()) { p.height(that.currentItem.innerHeight() - parseInt(that.currentItem.css('paddingTop')||0, 10) - parseInt(that.currentItem.css('paddingBottom')||0, 10)); };
|
||||||
if(!p.width()) { p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft')||0, 10) - parseInt(self.currentItem.css('paddingRight')||0, 10)); };
|
if(!p.width()) { p.width(that.currentItem.innerWidth() - parseInt(that.currentItem.css('paddingLeft')||0, 10) - parseInt(that.currentItem.css('paddingRight')||0, 10)); };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create the placeholder
|
//Create the placeholder
|
||||||
self.placeholder = $(o.placeholder.element.call(self.element, self.currentItem));
|
that.placeholder = $(o.placeholder.element.call(that.element, that.currentItem));
|
||||||
|
|
||||||
//Append it after the actual current item
|
//Append it after the actual current item
|
||||||
self.currentItem.after(self.placeholder);
|
that.currentItem.after(that.placeholder);
|
||||||
|
|
||||||
//Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317)
|
//Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317)
|
||||||
o.placeholder.update(self, self.placeholder);
|
o.placeholder.update(that, that.placeholder);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -970,11 +966,11 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
// 3. on the local scope, we copy the counter variable, and check in the timeout, if it's still the same
|
// 3. on the local scope, we copy the counter variable, and check in the timeout, if it's still the same
|
||||||
// 4. this lets only the last addition to the timeout stack through
|
// 4. this lets only the last addition to the timeout stack through
|
||||||
this.counter = this.counter ? ++this.counter : 1;
|
this.counter = this.counter ? ++this.counter : 1;
|
||||||
var self = this, counter = this.counter;
|
var counter = this.counter;
|
||||||
|
|
||||||
window.setTimeout(function() {
|
this._delay(function() {
|
||||||
if(counter == self.counter) self.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove
|
if(counter == this.counter) this.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove
|
||||||
},0);
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -983,7 +979,7 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
this.reverting = false;
|
this.reverting = false;
|
||||||
// We delay all events that have to be triggered to after the point where the placeholder has been removed and
|
// We delay all events that have to be triggered to after the point where the placeholder has been removed and
|
||||||
// everything else normalized again
|
// everything else normalized again
|
||||||
var delayedTriggers = [], self = this;
|
var delayedTriggers = [];
|
||||||
|
|
||||||
// We first have to update the dom position of the actual currentItem
|
// We first have to update the dom position of the actual currentItem
|
||||||
// Note: don't do it if the current item is already removed (by a user), or it gets reappended (see #4088)
|
// Note: don't do it if the current item is already removed (by a user), or it gets reappended (see #4088)
|
||||||
@ -1058,16 +1054,16 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_uiHash: function(inst) {
|
_uiHash: function(_inst) {
|
||||||
var self = inst || this;
|
var inst = _inst || this;
|
||||||
return {
|
return {
|
||||||
helper: self.helper,
|
helper: inst.helper,
|
||||||
placeholder: self.placeholder || $([]),
|
placeholder: inst.placeholder || $([]),
|
||||||
position: self.position,
|
position: inst.position,
|
||||||
originalPosition: self.originalPosition,
|
originalPosition: inst.originalPosition,
|
||||||
offset: self.positionAbs,
|
offset: inst.positionAbs,
|
||||||
item: self.currentItem,
|
item: inst.currentItem,
|
||||||
sender: inst ? inst.element : null
|
sender: _inst ? _inst.element : null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user