jquery-ui/ui/jquery-patch.js
Michał Gołębiowski-Owczarek 9887579b61
All: Stop relying on jquery-patch.js internally, add tests
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.

Also, add tests for jquery-patch.

Ref gh-2249
2024-05-15 00:38:40 +02:00

57 lines
1.3 KiB
JavaScript

/*!
* jQuery UI Legacy jQuery Core patches @VERSION
* https://jqueryui.com
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license.
* https://jquery.org/license
*
*/
//>>label: Legacy jQuery Core patches
//>>group: Core
//>>description: Backport `.even()`, `.odd()` and `$.escapeSelector` to older jQuery Core versions (deprecated)
( function( factory ) {
"use strict";
if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
define( [ "jquery", "./version" ], factory );
} else {
// Browser globals
factory( jQuery );
}
} )( function( $ ) {
"use strict";
// Support: jQuery 2.2.x or older.
// This method has been defined in jQuery 3.0.0.
// Code from https://github.com/jquery/jquery/blob/e539bac79e666bba95bba86d690b4e609dca2286/src/selector/escapeSelector.js
if ( !$.escapeSelector ) {
$.escapeSelector = function( id ) {
return CSS.escape( id + "" );
};
}
// Support: jQuery 3.4.x or older
// These methods have been defined in jQuery 3.5.0.
if ( !$.fn.even || !$.fn.odd ) {
$.fn.extend( {
even: function() {
return this.filter( function( i ) {
return i % 2 === 0;
} );
},
odd: function() {
return this.filter( function( i ) {
return i % 2 === 1;
} );
}
} );
}
} );