Skip to content

Commit 7e7a6c4

Browse files
author
naitsirch
committed
sortable: Use addClass in _setHandleClassName to improve performance
This addresses #2062 and is relevant for large lists with more than 1000 items. The solution to the issue was suggested at https://stackoverflow.com/a/46925710/1119601 (credits to @Ernst). At the end this commit restores the function's behaviour of previous 1.11.x version.
1 parent e21a254 commit 7e7a6c4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ui/widgets/sortable.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,19 @@ return $.widget( "ui.sortable", $.ui.mouse, {
118118
},
119119

120120
_setHandleClassName: function() {
121-
var that = this;
122121
this._removeClass( this.element.find( ".ui-sortable-handle" ), "ui-sortable-handle" );
123122
$.each( this.items, function() {
124-
that._addClass(
125-
this.instance.options.handle ?
126-
this.item.find( this.instance.options.handle ) :
127-
this.item,
128-
"ui-sortable-handle"
129-
);
123+
124+
// We use addClass() here, instead of _addClass(), because it is much faster.
125+
( this.instance.options.handle ?
126+
this.item.find( this.instance.options.handle ) :
127+
this.item
128+
).addClass( "ui-sortable-handle" );
130129
} );
131130
},
132131

133132
_destroy: function() {
133+
this.element.find( ".ui-sortable-handle" ).removeClass( "ui-sortable-handle" );
134134
this._mouseDestroy();
135135

136136
for ( var i = this.items.length - 1; i >= 0; i-- ) {

0 commit comments

Comments
 (0)