Skip to content

Commit

Permalink
Core: Replaced deprecated jQuery functions
Browse files Browse the repository at this point in the history
Replaced $.isArray and $.isFunction
  • Loading branch information
bytestream committed Jun 23, 2020
1 parent af445b3 commit 272bb4f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/core.js
Expand Up @@ -205,6 +205,13 @@ var trim = function( str ) {
return str.replace( /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "" );
};

// $.isArray is deprecated.
var isArray = function( arg ) {

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray#Polyfill
return Object.prototype.toString.call( arg ) === "[object Array]";
};

// Custom selectors
$.extend( $.expr.pseudos || $.expr[ ":" ], { // '|| $.expr[ ":" ]' here enables backwards compatibility to jQuery 1.7. Can be removed when dropping jQ 1.7.x support

Expand Down Expand Up @@ -1313,7 +1320,7 @@ $.extend( $.validator, {

// Evaluate parameters
$.each( rules, function( rule, parameter ) {
rules[ rule ] = $.isFunction( parameter ) && rule !== "normalizer" ? parameter( element ) : parameter;
rules[ rule ] = typeof parameter === "function" && rule !== "normalizer" ? parameter( element ) : parameter;
} );

// Clean number parameters
Expand All @@ -1325,7 +1332,7 @@ $.extend( $.validator, {
$.each( [ "rangelength", "range" ], function() {
var parts;
if ( rules[ this ] ) {
if ( $.isArray( rules[ this ] ) ) {
if ( isArray( rules[ this ] ) ) {
rules[ this ] = [ Number( rules[ this ][ 0 ] ), Number( rules[ this ][ 1 ] ) ];
} else if ( typeof rules[ this ] === "string" ) {
parts = rules[ this ].replace( /[\[\]]/g, "" ).split( /[\s,]+/ );
Expand Down Expand Up @@ -1454,19 +1461,19 @@ $.extend( $.validator, {

// https://jqueryvalidation.org/minlength-method/
minlength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength( value, element );
var length = isArray( value ) ? value.length : this.getLength( value, element );
return this.optional( element ) || length >= param;
},

// https://jqueryvalidation.org/maxlength-method/
maxlength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength( value, element );
var length = isArray( value ) ? value.length : this.getLength( value, element );
return this.optional( element ) || length <= param;
},

// https://jqueryvalidation.org/rangelength-method/
rangelength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength( value, element );
var length = isArray( value ) ? value.length : this.getLength( value, element );
return this.optional( element ) || ( length >= param[ 0 ] && length <= param[ 1 ] );
},

Expand Down

0 comments on commit 272bb4f

Please sign in to comment.