]> source.dussan.org Git - jquery-ui.git/commitdiff
Sortable: Don't create functions inside loops.
authorScott González <scott.gonzalez@gmail.com>
Mon, 22 Apr 2013 16:33:35 +0000 (12:33 -0400)
committerScott González <scott.gonzalez@gmail.com>
Mon, 25 Nov 2013 22:24:13 +0000 (17:24 -0500)
(cherry picked from commit 7033544cdd9792f4b1be473eeea7bc37eed52469)

ui/jquery.ui.sortable.js

index 136f4c6717cffe650e0edf87a4fba5f9c7ada829..dbc47fbc8fa1eb75cbe8d536d6d7fe98c300ce7a 100644 (file)
@@ -15,8 +15,6 @@
  */
 (function( $, undefined ) {
 
-/*jshint loopfunc: true */
-
 function isOverAxis( x, reference, size ) {
        return ( x > reference ) && ( x < ( reference + size ) );
 }
@@ -640,10 +638,11 @@ $.widget("ui.sortable", $.ui.mouse, {
 
                queries.push([$.isFunction(this.options.items) ? this.options.items.call(this.element, null, { options: this.options, item: this.currentItem }) : $(this.options.items, this.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"), this]);
 
+               function addItems() {
+                       items.push( this );
+               }
                for (i = queries.length - 1; i >= 0; i--){
-                       queries[i][0].each(function() {
-                               items.push(this);
-                       });
+                       queries[i][0].each( addItems );
                }
 
                return $(items);
@@ -1201,12 +1200,17 @@ $.widget("ui.sortable", $.ui.mouse, {
 
 
                //Post events to containers
+               function delayEvent( type, instance, container ) {
+                       return function( event ) {
+                               container._trigger( type, event, instance._uiHash( instance ) );
+                       };
+               }
                for (i = this.containers.length - 1; i >= 0; i--){
-                       if(!noPropagation) {
-                               delayedTriggers.push((function(c) { return function(event) { c._trigger("deactivate", event, this._uiHash(this)); };  }).call(this, this.containers[i]));
+                       if (!noPropagation) {
+                               delayedTriggers.push( delayEvent( "deactivate", this, this.containers[ i ] ) );
                        }
                        if(this.containers[i].containerCache.over) {
-                               delayedTriggers.push((function(c) { return function(event) { c._trigger("out", event, this._uiHash(this)); };  }).call(this, this.containers[i]));
+                               delayedTriggers.push( delayEvent( "out", this, this.containers[ i ] ) );
                                this.containers[i].containerCache.over = 0;
                        }
                }