Skip to content

Commit

Permalink
sortable: Use addClass in _setHandleClassName to improve performance
Browse files Browse the repository at this point in the history
This addresses jquery#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.
  • Loading branch information
stollr committed Mar 31, 2022
1 parent e21a254 commit 7e7a6c4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ui/widgets/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,19 @@ return $.widget( "ui.sortable", $.ui.mouse, {
},

_setHandleClassName: function() {
var that = this;
this._removeClass( this.element.find( ".ui-sortable-handle" ), "ui-sortable-handle" );
$.each( this.items, function() {
that._addClass(
this.instance.options.handle ?
this.item.find( this.instance.options.handle ) :
this.item,
"ui-sortable-handle"
);

// We use addClass() here, instead of _addClass(), because it is much faster.
( this.instance.options.handle ?
this.item.find( this.instance.options.handle ) :
this.item
).addClass( "ui-sortable-handle" );
} );
},

_destroy: function() {
this.element.find( ".ui-sortable-handle" ).removeClass( "ui-sortable-handle" );
this._mouseDestroy();

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

0 comments on commit 7e7a6c4

Please sign in to comment.