Skip to content

Commit b2574c1

Browse files
committed
All: Migrate from $.trim to bare String.prototype.trim
jQuery.trim will be deprecated in jQuery 3.5.
1 parent eb28157 commit b2574c1

File tree

16 files changed

+40
-35
lines changed

16 files changed

+40
-35
lines changed

demos/autocomplete/xml.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
var data = $( "geoname", xmlResponse ).map(function() {
2626
return {
2727
value: $( "name", this ).text() + ", " +
28-
( $.trim( $( "countryName", this ).text() ) || "(unknown country)" ),
28+
( String.prototype.trim.call( $( "countryName", this ).text() ) ||
29+
"(unknown country)" ),
2930
id: $( "geonameId", this ).text()
3031
};
3132
}).get();

demos/tooltip/video-player.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
<script src="../../external/requirejs/require.js"></script>
3838
<script src="../bootstrap.js" data-modules="button controlgroup menu effect effect-blind">
3939
function notify( input ) {
40-
var msg = "Selected " + $.trim( input.data( "tooltip-title" ) || input.text() );
40+
var msg = "Selected " +
41+
String.prototype.trim.call(
42+
input.data( "tooltip-title" ) || input.text() );
4143
$( "<div>" )
4244
.appendTo( document.body )
4345
.text( msg )

tests/unit/checkboxradio/options.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ QUnit.test( "label - default", function( assert ) {
137137
widget = checkbox.checkboxradio( "widget" );
138138
assert.strictEqual( checkbox.checkboxradio( "option", "label" ),
139139
"checkbox label", "When no value passed on create text from dom is used for option" );
140-
assert.strictEqual( $.trim( widget.text() ),
140+
assert.strictEqual( String.prototype.trim.call( widget.text() ),
141141
"checkbox label", "When no value passed on create text from dom is used in dom" );
142142
} );
143143

@@ -152,7 +152,7 @@ QUnit.test( "label - explicit value", function( assert ) {
152152

153153
assert.strictEqual( checkbox.checkboxradio( "option", "label" ),
154154
"foo", "When value is passed on create value is used for option" );
155-
assert.strictEqual( $.trim( widget.text() ),
155+
assert.strictEqual( String.prototype.trim.call( widget.text() ),
156156
"foo", "When value is passed on create value is used in dom" );
157157
assert.strictEqual( icon.length, 1,
158158
"Icon is preserved when label is set on init when wrapped in label" );
@@ -177,7 +177,7 @@ QUnit.test( "label - explicit null value", function( assert ) {
177177
widget = checkbox.checkboxradio( "widget" );
178178
assert.strictEqual( checkbox.checkboxradio( "option", "label" ),
179179
"checkbox label", "When null is passed on create text from dom is used for option" );
180-
assert.strictEqual( $.trim( widget.text() ),
180+
assert.strictEqual( String.prototype.trim.call( widget.text() ),
181181
"checkbox label", "When null is passed on create text from dom is used in dom" );
182182

183183
} );
@@ -193,13 +193,13 @@ QUnit.test( "label", function( assert ) {
193193
checkbox.checkboxradio( "option", "label", "bar" );
194194
assert.strictEqual( checkbox.checkboxradio( "option", "label" ),
195195
"bar", "When value is passed value is used for option" );
196-
assert.strictEqual( $.trim( widget.text() ),
196+
assert.strictEqual( String.prototype.trim.call( widget.text() ),
197197
"bar", "When value is passed value is used in dom" );
198198

199199
checkbox.checkboxradio( "option", "label", null );
200200
assert.strictEqual( checkbox.checkboxradio( "option", "label" ),
201201
"bar", "When null is passed text from dom is used for option" );
202-
assert.strictEqual( $.trim( widget.text() ),
202+
assert.strictEqual( String.prototype.trim.call( widget.text() ),
203203
"bar", "When null is passed text from dom is used in dom" );
204204
} );
205205

tests/unit/core/core.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ QUnit.test( "Labels", function( assert ) {
152152
var found = labels.map( function() {
153153

154154
// Support: Core 1.9 Only
155-
// We use $.trim() because core 1.9.x silently fails when white space is present
156-
return $.trim( $( this ).text() );
155+
// We use String.prototype.trim because core 1.9.x silently fails
156+
// when white space is present
157+
return String.prototype.trim.call( $( this ).text() );
157158
} ).get();
158159

159160
assert.deepEqual( found, expected,

tests/unit/dialog/deprecated.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ QUnit.test( "buttons - deprecated options", function( assert ) {
5050
buttons = element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" );
5151
assert.equal( buttons.length, 1, "correct number of buttons" );
5252
assert.equal( buttons.attr( "id" ), "my-button-id", "correct id" );
53-
assert.equal( $.trim( buttons.text() ), "a button", "correct label" );
53+
assert.equal( String.prototype.trim.call( buttons.text() ), "a button", "correct label" );
5454
assert.hasClasses( buttons, "additional-class" );
5555
assert.deepEqual( buttons.button( "option", "icon" ), "ui-icon-cancel" );
5656
assert.equal( buttons.button( "option", "showLabel" ), false );

tests/unit/dialog/options.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ QUnit.test( "buttons - advanced", function( assert ) {
166166
buttons = element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" );
167167
assert.equal( buttons.length, 1, "correct number of buttons" );
168168
assert.equal( buttons.attr( "id" ), "my-button-id", "correct id" );
169-
assert.equal( $.trim( buttons.text() ), "a button", "correct label" );
169+
assert.equal( String.prototype.trim.call( buttons.text() ), "a button", "correct label" );
170170
assert.hasClasses( buttons, "additional-class" );
171171
assert.deepEqual( buttons.button( "option", "icon" ), "ui-icon-cancel" );
172172
assert.equal( buttons.button( "option", "showLabel" ), false );
@@ -210,22 +210,22 @@ QUnit.test( "closeText", function( assert ) {
210210
assert.expect( 4 );
211211

212212
var element = $( "<div></div>" ).dialog();
213-
assert.equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "Close",
213+
assert.equal( String.prototype.trim.call( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "Close",
214214
"default close text" );
215215
element.remove();
216216

217217
element = $( "<div></div>" ).dialog( { closeText: "foo" } );
218-
assert.equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "foo",
218+
assert.equal( String.prototype.trim.call( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "foo",
219219
"closeText on init" );
220220
element.remove();
221221

222222
element = $( "<div></div>" ).dialog().dialog( "option", "closeText", "bar" );
223-
assert.equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "bar",
223+
assert.equal( String.prototype.trim.call( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "bar",
224224
"closeText via option method" );
225225
element.remove();
226226

227227
element = $( "<div></div>" ).dialog( { closeText: "<span>foo</span>" } );
228-
assert.equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "<span>foo</span>",
228+
assert.equal( String.prototype.trim.call( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "<span>foo</span>",
229229
"closeText is escaped" );
230230
element.remove();
231231
} );

tests/unit/effects/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ QUnit.test( "animateClass clears style properties when stopped", function( asser
210210
.stop( true, true )
211211
.promise()
212212
.then( function() {
213-
assert.equal( orig, $.trim( style.cssText ), "cssText is the same after stopping animation midway" );
213+
assert.equal( orig, String.prototype.trim.call( style.cssText ), "cssText is the same after stopping animation midway" );
214214
ready();
215215
} );
216216
} );

tests/unit/menu/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ return $.extend( helper, {
1414
if ( message === undefined ) {
1515
message = lastItem;
1616
}
17-
log.push( $.trim( message ) );
17+
log.push( String.prototype.trim.call( message ) );
1818
},
1919

2020
logOutput: function() {

tests/unit/selectmenu/core.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ QUnit.test( "_renderButtonItem()", function( assert ) {
9595
element.selectmenu( "refresh" );
9696
option = element.find( "option:selected" );
9797
assert.equal(
98-
$.trim( button.text() ),
98+
String.prototype.trim.call( button.text() ),
9999
option.text() + element[ 0 ].selectedIndex,
100100
"refresh: button item text"
101101
);
@@ -104,7 +104,7 @@ QUnit.test( "_renderButtonItem()", function( assert ) {
104104
menu.find( "li" ).last().simulate( "mouseover" ).trigger( "click" );
105105
option = element.find( "option" ).last();
106106
assert.equal(
107-
$.trim( button.text() ),
107+
String.prototype.trim.call( button.text() ),
108108
option.text() + element[ 0 ].selectedIndex,
109109
"click: button item text"
110110
);
@@ -153,7 +153,7 @@ $.each( [
153153
selected.val(),
154154
"original select state"
155155
);
156-
assert.equal( $.trim( button.text() ), selected.text(), "button text" );
156+
assert.equal( String.prototype.trim.call( button.text() ), selected.text(), "button text" );
157157
ready();
158158
} );
159159
} );
@@ -189,7 +189,7 @@ $.each( [
189189
selected.val(),
190190
"original select state"
191191
);
192-
assert.equal( $.trim( button.text() ), selected.text(), "button text" );
192+
assert.equal( String.prototype.trim.call( button.text() ), selected.text(), "button text" );
193193
ready();
194194
}, 1 );
195195
} );
@@ -231,7 +231,7 @@ $.each( [
231231
"button aria-activedescendant" );
232232
assert.equal( element.find( "option:selected" ).val(), options.eq( 1 ).val(),
233233
"original select state" );
234-
assert.equal( $.trim( button.text() ), options.eq( 1 ).text(), "button text" );
234+
assert.equal( String.prototype.trim.call( button.text() ), options.eq( 1 ).text(), "button text" );
235235
ready();
236236
} );
237237
} );
@@ -352,10 +352,10 @@ QUnit.test( "Selectmenu should reset when its parent form resets", function( ass
352352

353353
element.val( "Slower" );
354354
element.selectmenu( "refresh" );
355-
assert.equal( $.trim( widget.text() ), "Slower" );
355+
assert.equal( String.prototype.trim.call( widget.text() ), "Slower" );
356356
form[ 0 ].reset();
357357
setTimeout( function() {
358-
assert.equal( $.trim( widget.text() ), initialValue );
358+
assert.equal( String.prototype.trim.call( widget.text() ), initialValue );
359359
ready();
360360
} );
361361
} );

tests/unit/selectmenu/methods.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,21 @@ QUnit.test( "refresh - change selected option", function( assert ) {
8383
var element = $( "#speed" ).selectmenu(),
8484
button = element.selectmenu( "widget" );
8585

86-
assert.equal( $.trim( button.text() ), "Medium", "button text after init" );
86+
assert.equal( String.prototype.trim.call( button.text() ), "Medium", "button text after init" );
8787

8888
button.simulate( "focus" );
8989

9090
setTimeout( function() {
91-
assert.equal( $.trim( button.text() ), "Medium", "button text after focus" );
91+
assert.equal( String.prototype.trim.call( button.text() ), "Medium", "button text after focus" );
9292

9393
element[ 0 ].selectedIndex = 0;
9494
element.selectmenu( "refresh" );
95-
assert.equal( $.trim( button.text() ), "Slower", "button text after changing selected option" );
95+
assert.equal( String.prototype.trim.call( button.text() ), "Slower", "button text after changing selected option" );
9696

9797
element.find( "option" ).prop( "selected", false );
9898
element.append( "<option selected value=\"selected_option\">Selected option</option>" );
9999
element.selectmenu( "refresh" );
100-
assert.equal( $.trim( button.text() ), "Selected option", "button text after adding selected option" );
100+
assert.equal( String.prototype.trim.call( button.text() ), "Selected option", "button text after adding selected option" );
101101

102102
ready();
103103
} );

tests/visual/dialog/performance.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<script src="../../../external/requirejs/require.js"></script>
88
<script src="../../../demos/bootstrap.js">
99
var start,
10-
html = new Array( 500 ).join( $.trim( $( "#template" ).html() ) );
10+
html = new Array( 500 ).join( String.prototype.trim.call( $( "#template" ).html() ) );
1111
$( html ).appendTo( "body" );
1212

1313
start = new Date();

ui/widgets/autocomplete.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ $.widget( "ui.autocomplete", {
263263

264264
// Announce the value in the liveRegion
265265
label = ui.item.attr( "aria-label" ) || item.value;
266-
if ( label && $.trim( label ).length ) {
266+
if ( label && String.prototype.trim.call( label ).length ) {
267267
this.liveRegion.children().hide();
268268
$( "<div>" ).text( label ).appendTo( this.liveRegion );
269269
}

ui/widgets/controlgroup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ return $.widget( "ui.controlgroup", {
234234
var result = {};
235235
$.each( classes, function( key ) {
236236
var current = instance.options.classes[ key ] || "";
237-
current = $.trim( current.replace( controlgroupCornerRegex, "" ) );
237+
current = String.prototype.trim.call( current.replace( controlgroupCornerRegex, "" ) );
238238
result[ key ] = ( current + " " + classes[ key ] ).replace( /\s+/g, " " );
239239
} );
240240
return result;

ui/widgets/menu.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@ return $.widget( "ui.menu", {
689689
.filter( ".ui-menu-item" )
690690
.filter( function() {
691691
return regex.test(
692-
$.trim( $( this ).children( ".ui-menu-item-wrapper" ).text() ) );
692+
String.prototype.trim.call(
693+
$( this ).children( ".ui-menu-item-wrapper" ).text() ) );
693694
} );
694695
}
695696
} );

ui/widgets/resizable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ $.widget( "ui.resizable", $.ui.mouse, {
261261

262262
for ( i = 0; i < n.length; i++ ) {
263263

264-
handle = $.trim( n[ i ] );
264+
handle = String.prototype.trim.call( n[ i ] );
265265
hname = "ui-resizable-" + handle;
266266
axis = $( "<div>" );
267267
this._addClass( axis, "ui-resizable-handle " + hname );

ui/widgets/tooltip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ $.widget( "ui.tooltip", {
7272
describedby.push( id );
7373
elem
7474
.data( "ui-tooltip-id", id )
75-
.attr( "aria-describedby", $.trim( describedby.join( " " ) ) );
75+
.attr( "aria-describedby", String.prototype.trim.call( describedby.join( " " ) ) );
7676
},
7777

7878
_removeDescribedBy: function( elem ) {
@@ -85,7 +85,7 @@ $.widget( "ui.tooltip", {
8585
}
8686

8787
elem.removeData( "ui-tooltip-id" );
88-
describedby = $.trim( describedby.join( " " ) );
88+
describedby = String.prototype.trim.call( describedby.join( " " ) );
8989
if ( describedby ) {
9090
elem.attr( "aria-describedby", describedby );
9191
} else {

0 commit comments

Comments
 (0)