From a15d40eb5fae1e13f9f2cc1f6e05e880eb47e23b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 9 May 2012 20:19:51 -0400 Subject: [PATCH] Sortable: Remove uses of self var; use that var. --- ui/jquery.ui.sortable.js | 78 +++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/ui/jquery.ui.sortable.js b/ui/jquery.ui.sortable.js index 8ebd3b69c..55a64590b 100644 --- a/ui/jquery.ui.sortable.js +++ b/ui/jquery.ui.sortable.js @@ -100,13 +100,13 @@ $.widget("ui.sortable", $.ui.mouse, { this._refreshItems(event); //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() { - if($.data(this, that.widgetName + '-item') == self) { + var currentItem = null, nodes = $(event.target).parents().each(function() { + if($.data(this, that.widgetName + '-item') == that) { currentItem = $(this); 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(this.options.handle && !overrideHandle) { @@ -124,7 +124,7 @@ $.widget("ui.sortable", $.ui.mouse, { _mouseStart: function(event, overrideHandle, noActivation) { - var o = this.options, self = this; + var o = this.options; this.currentContainer = this; //We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture @@ -167,7 +167,7 @@ $.widget("ui.sortable", $.ui.mouse, { // TODO: Still need to figure out a way to make relative sorting possible this.helper.css("position", "absolute"); this.cssPosition = this.helper.css("position"); - + //Generate the original position this.originalPosition = this._generatePosition(event); this.originalPageX = event.pageX; @@ -220,7 +220,7 @@ $.widget("ui.sortable", $.ui.mouse, { //Post 'activate' events to possible containers 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 @@ -338,16 +338,16 @@ $.widget("ui.sortable", $.ui.mouse, { $.ui.ddmanager.drop(this, event); if(this.options.revert) { - var self = this; - var cur = self.placeholder.offset(); + var that = this; + var cur = this.placeholder.offset(); - self.reverting = true; + this.reverting = true; $(this.helper).animate({ - left: cur.left - this.offset.parent.left - self.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) + 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 - this.margins.top + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop) }, parseInt(this.options.revert, 10) || 500, function() { - self._clear(event); + that._clear(event); }); } else { this._clear(event, noPropagation); @@ -359,8 +359,6 @@ $.widget("ui.sortable", $.ui.mouse, { cancel: function() { - var self = this; - if(this.dragging) { this._mouseUp({ target: null }); @@ -372,9 +370,9 @@ $.widget("ui.sortable", $.ui.mouse, { //Post deactivating events to containers 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) { - this.containers[i]._trigger("out", null, self._uiHash(this)); + this.containers[i]._trigger("out", null, this._uiHash(this)); this.containers[i].containerCache.over = 0; } } @@ -522,7 +520,6 @@ $.widget("ui.sortable", $.ui.mouse, { _getItemsAsjQuery: function(connected) { - var self = this; var items = []; var queries = []; var connectWith = this._connectWith(); @@ -571,7 +568,6 @@ $.widget("ui.sortable", $.ui.mouse, { this.items = []; this.containers = [this]; 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 connectWith = this._connectWith(); @@ -650,16 +646,16 @@ $.widget("ui.sortable", $.ui.mouse, { }, _createPlaceholder: function(that) { - - var self = that || this, o = self.options; + that = that || this; + var o = that.options; if(!o.placeholder || o.placeholder.constructor == String) { var className = o.placeholder; o.placeholder = { element: function() { - var el = $(document.createElement(self.currentItem[0].nodeName)) - .addClass(className || self.currentItem[0].className+" ui-sortable-placeholder") + var el = $(document.createElement(that.currentItem[0].nodeName)) + .addClass(className || that.currentItem[0].className+" ui-sortable-placeholder") .removeClass("ui-sortable-helper")[0]; if(!className) @@ -674,20 +670,20 @@ $.widget("ui.sortable", $.ui.mouse, { 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(!p.height()) { p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.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.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(that.currentItem.innerWidth() - parseInt(that.currentItem.css('paddingLeft')||0, 10) - parseInt(that.currentItem.css('paddingRight')||0, 10)); }; } }; } //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 - self.currentItem.after(self.placeholder); + that.currentItem.after(that.placeholder); //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 // 4. this lets only the last addition to the timeout stack through this.counter = this.counter ? ++this.counter : 1; - var self = this, counter = this.counter; + var counter = this.counter; - window.setTimeout(function() { - if(counter == self.counter) self.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove - },0); + this._delay(function() { + if(counter == this.counter) this.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove + }); }, @@ -983,7 +979,7 @@ $.widget("ui.sortable", $.ui.mouse, { this.reverting = false; // We delay all events that have to be triggered to after the point where the placeholder has been removed and // everything else normalized again - var delayedTriggers = [], self = this; + var delayedTriggers = []; // 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) @@ -1058,16 +1054,16 @@ $.widget("ui.sortable", $.ui.mouse, { } }, - _uiHash: function(inst) { - var self = inst || this; + _uiHash: function(_inst) { + var inst = _inst || this; return { - helper: self.helper, - placeholder: self.placeholder || $([]), - position: self.position, - originalPosition: self.originalPosition, - offset: self.positionAbs, - item: self.currentItem, - sender: inst ? inst.element : null + helper: inst.helper, + placeholder: inst.placeholder || $([]), + position: inst.position, + originalPosition: inst.originalPosition, + offset: inst.positionAbs, + item: inst.currentItem, + sender: _inst ? _inst.element : null }; } -- 2.39.5