Skip to content

Commit 1edf1f9

Browse files
committed
All: Stop relying on jquery-patch.js internally
Avoid relying on jQuery patches. Instead: * use `CSS.escape` instead of `jQuery.escapeSelector` * use `.filter()` with a proper handler instead of `.even()` Keep `jquery-patch.js` for backwards compatibility, though.
1 parent 7c296cc commit 1edf1f9

File tree

9 files changed

+30
-42
lines changed

9 files changed

+30
-42
lines changed

tests/lib/bootstrap.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,6 @@ function migrateUrl() {
171171
}
172172
}
173173

174-
var jQueryVersion = parseUrl().jquery;
175-
176-
// Load the jQuery fixes, if necessary
177-
if ( !jQueryVersion ||
178-
( jQueryVersion.indexOf( "git" ) === -1 && parseFloat( jQueryVersion ) < 4 ) ) {
179-
modules.unshift( "ui/jquery-patch" );
180-
}
181-
182174
requireTests( modules, { backCompat: backCompat } );
183175
} )();
184176

tests/unit/accordion/common.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@ common.testWidget( "accordion", {
1616
disabled: false,
1717
event: "click",
1818
header: function( elem ) {
19-
return elem.find( "> li > :first-child" ).add( elem.find( "> :not(li)" ).even() );
19+
return elem
20+
.find( "> li > :first-child" )
21+
.add(
22+
elem.find( "> :not(li)" )
23+
24+
// Support: jQuery <3.5 only
25+
// We could use `.even()` but that's unavailable in older jQuery.
26+
.filter( function( i ) {
27+
return i % 2 === 0;
28+
} )
29+
);
2030
},
2131
heightStyle: "auto",
2232
icons: {

ui/core.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ define( [
99
"./focusable",
1010
"./keycode",
1111
"./labels",
12-
"./jquery-patch",
1312
"./plugin",
1413
"./scroll-parent",
1514
"./tabbable",

ui/jquery-patch.js

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery UI Support for jQuery core 1.8.x and newer @VERSION
2+
* jQuery UI Legacy jQuery Core patches @VERSION
33
* https://jqueryui.com
44
*
55
* Copyright OpenJS Foundation and other contributors
@@ -8,9 +8,9 @@
88
*
99
*/
1010

11-
//>>label: jQuery 1.8+ Support
11+
//>>label: Legacy jQuery Core patches
1212
//>>group: Core
13-
//>>description: Support version 1.8.x and newer of jQuery core
13+
//>>description: Backport a few newer jQuery Core APIs to older jQuery Core versions
1414

1515
( function( factory ) {
1616
"use strict";
@@ -31,30 +31,7 @@
3131
// This method has been defined in jQuery 3.0.0.
3232
// Code from https://github.com/jquery/jquery/blob/e539bac79e666bba95bba86d690b4e609dca2286/src/selector/escapeSelector.js
3333
if ( !$.escapeSelector ) {
34-
35-
// CSS string/identifier serialization
36-
// https://drafts.csswg.org/cssom/#common-serializing-idioms
37-
var rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g;
38-
39-
var fcssescape = function( ch, asCodePoint ) {
40-
if ( asCodePoint ) {
41-
42-
// U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER
43-
if ( ch === "\0" ) {
44-
return "\uFFFD";
45-
}
46-
47-
// Control characters and (dependent upon position) numbers get escaped as code points
48-
return ch.slice( 0, -1 ) + "\\" + ch.charCodeAt( ch.length - 1 ).toString( 16 ) + " ";
49-
}
50-
51-
// Other potentially-special ASCII characters get backslash-escaped
52-
return "\\" + ch;
53-
};
54-
55-
$.escapeSelector = function( sel ) {
56-
return ( sel + "" ).replace( rcssescape, fcssescape );
57-
};
34+
$.escapeSelector = CSS.escape;
5835
}
5936

6037
// Support: jQuery 3.4.x or older

ui/labels.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ return $.fn.labels = function() {
5555
ancestors = ancestor.add( ancestor.length ? ancestor.siblings() : this.siblings() );
5656

5757
// Create a selector for the label based on the id
58-
selector = "label[for='" + $.escapeSelector( id ) + "']";
58+
selector = "label[for='" + CSS.escape( id ) + "']";
5959

6060
labels = labels.add( ancestors.find( selector ).addBack( selector ) );
6161

ui/widgets/accordion.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,17 @@ return $.widget( "ui.accordion", {
5252
collapsible: false,
5353
event: "click",
5454
header: function( elem ) {
55-
return elem.find( "> li > :first-child" ).add( elem.find( "> :not(li)" ).even() );
55+
return elem
56+
.find( "> li > :first-child" )
57+
.add(
58+
elem.find( "> :not(li)" )
59+
60+
// Support: jQuery <3.5 only
61+
// We could use `.even()` but that's unavailable in older jQuery.
62+
.filter( function( i ) {
63+
return i % 2 === 0;
64+
} )
65+
);
5666
},
5767
heightStyle: "auto",
5868
icons: {

ui/widgets/checkboxradio.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ $.widget( "ui.checkboxradio", [ $.ui.formResetMixin, {
156156
_getRadioGroup: function() {
157157
var group;
158158
var name = this.element[ 0 ].name;
159-
var nameSelector = "input[name='" + $.escapeSelector( name ) + "']";
159+
var nameSelector = "input[name='" + CSS.escape( name ) + "']";
160160

161161
if ( !name ) {
162162
return $( [] );

ui/widgets/selectmenu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ return $.widget( "ui.selectmenu", [ $.ui.formResetMixin, {
415415
}
416416

417417
if ( !$( event.target ).closest( ".ui-selectmenu-menu, #" +
418-
$.escapeSelector( this.ids.button ) ).length ) {
418+
CSS.escape( this.ids.button ) ).length ) {
419419
this.close( event );
420420
}
421421
}

ui/widgets/tabs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ $.widget( "ui.tabs", {
722722
// meta-function to give users option to provide a href string instead of a numerical index.
723723
if ( typeof index === "string" ) {
724724
index = this.anchors.index( this.anchors.filter( "[href$='" +
725-
$.escapeSelector( index ) + "']" ) );
725+
CSS.escape( index ) + "']" ) );
726726
}
727727

728728
return index;

0 commit comments

Comments
 (0)