Skip to content

Commit 38ccf12

Browse files
committed
All: Migrate from $.trim to bare String.prototype.trim
jQuery.trim will be deprecated in jQuery 3.5.
1 parent 998d7f5 commit 38ccf12

File tree

18 files changed

+134
-135
lines changed

18 files changed

+134
-135
lines changed

demos/autocomplete/xml.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
var data = $( "geoname", xmlResponse ).map(function() {
2626
return {
2727
value: $( "name", this ).text() + ", " +
28-
( $.trim( $( "countryName", this ).text() ) || "(unknown country)" ),
28+
( $( "countryName", this ).text().trim() || "(unknown country)" ),
2929
id: $( "geonameId", this ).text()
3030
};
3131
}).get();

demos/tooltip/video-player.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
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 " + ( input.data( "tooltip-title" ) || input.text() ).trim();
4141
$( "<div>" )
4242
.appendTo( document.body )
4343
.text( msg )

external/jquery-simulate/jquery.simulate.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,25 @@
1212
;(function( $, undefined ) {
1313

1414
var rkeyEvent = /^key/,
15+
rdashAlpha = /-([a-z])/g,
1516
rmouseEvent = /^(?:mouse|contextmenu)|click/;
1617

18+
function fcamelCase( _all, letter ) {
19+
return letter.toUpperCase();
20+
}
21+
22+
function camelCase( string ) {
23+
return string.replace( rdashAlpha, fcamelCase );
24+
}
25+
1726
$.fn.simulate = function( type, options ) {
1827
return this.each(function() {
1928
new $.simulate( this, type, options );
2029
});
2130
};
2231

2332
$.simulate = function( elem, type, options ) {
24-
var method = $.camelCase( "simulate-" + type );
33+
var method = camelCase( "simulate-" + type );
2534

2635
this.target = elem;
2736
this.options = options;
@@ -201,10 +210,10 @@ $.extend( $.simulate.prototype, {
201210
},
202211

203212
dispatchEvent: function( elem, type, event ) {
204-
if ( elem[ type ] ) {
205-
elem[ type ]();
206-
} else if ( elem.dispatchEvent ) {
213+
if ( elem.dispatchEvent ) {
207214
elem.dispatchEvent( event );
215+
} else if ( type === "click" && elem.click && elem.nodeName.toLowerCase() === "input" ) {
216+
elem.click();
208217
} else if ( elem.fireEvent ) {
209218
elem.fireEvent( "on" + type, event );
210219
}
@@ -295,6 +304,7 @@ $.extend( $.simulate.prototype, {
295304
simulateDrag: function() {
296305
var i = 0,
297306
target = this.target,
307+
eventDoc = target.ownerDocument,
298308
options = this.options,
299309
center = options.handle === "corner" ? findCorner( target ) : findCenter( target ),
300310
x = Math.floor( center.x ),
@@ -315,14 +325,14 @@ $.extend( $.simulate.prototype, {
315325
clientY: Math.round( y )
316326
};
317327

318-
this.simulateEvent( target.ownerDocument, "mousemove", coord );
328+
this.simulateEvent( eventDoc, "mousemove", coord );
319329
}
320330

321-
if ( $.contains( document, target ) ) {
331+
if ( $.contains( eventDoc, target ) ) {
322332
this.simulateEvent( target, "mouseup", coord );
323333
this.simulateEvent( target, "click", coord );
324334
} else {
325-
this.simulateEvent( document, "mouseup", coord );
335+
this.simulateEvent( eventDoc, "mouseup", coord );
326336
}
327337
}
328338
});

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( widget.text().trim(),
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( widget.text().trim(),
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( widget.text().trim(),
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( widget.text().trim(),
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( widget.text().trim(),
203203
"bar", "When null is passed text from dom is used in dom" );
204204
} );
205205

tests/unit/core/core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ 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 .trim() because core 1.9.x silently fails when white space is present
156+
return $( this ).text().trim();
157157
} ).get();
158158

159159
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( buttons.text().trim(), "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( buttons.text().trim(), "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( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text().trim(), "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( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text().trim(), "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( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text().trim(), "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( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text().trim(), "<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, style.cssText.trim(), "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+
button.text().trim(),
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+
button.text().trim(),
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( button.text().trim(), 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( button.text().trim(), 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( button.text().trim(), 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( widget.text().trim(), "Slower" );
356356
form[ 0 ].reset();
357357
setTimeout( function() {
358-
assert.equal( $.trim( widget.text() ), initialValue );
358+
assert.equal( widget.text().trim(), 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( button.text().trim(), "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( button.text().trim(), "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( button.text().trim(), "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( button.text().trim(), "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( $( "#template" ).html().trim() );
1111
$( html ).appendTo( "body" );
1212

1313
start = new Date();

0 commit comments

Comments
 (0)