Skip to content

Commit

Permalink
fix(chore): replace jquery deprecated methods
Browse files Browse the repository at this point in the history
Fixed deprecated jquery logics as been told by jquery/jquery-migrate@main/warnings.md
  • Loading branch information
lubber-de authored Nov 24, 2022
1 parent 02b01ff commit 7071e59
Show file tree
Hide file tree
Showing 25 changed files with 281 additions and 268 deletions.
25 changes: 14 additions & 11 deletions src/definitions/behaviors/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@

'use strict';

$.isWindow = $.isWindow || function(obj) {
return obj != null && obj === obj.window;
};
function isWindow(obj) {
return obj != null && obj === obj.window;
}
function isFunction(obj) {
return typeof obj === "function" && typeof obj.nodeType !== "number";
}

window = (typeof window != 'undefined' && window.Math == Math)
? window
Expand All @@ -27,7 +30,7 @@ $.api = $.fn.api = function(parameters) {

var
// use window context if none specified
$allModules = $.isFunction(this)
$allModules = isFunction(this)
? $(window)
: $(this),
moduleSelector = $allModules.selector || '',
Expand Down Expand Up @@ -316,7 +319,7 @@ $.api = $.fn.api = function(parameters) {
}
},
validResponse: function(response) {
if( (!module.is.expectingJSON()) || !$.isFunction(settings.successTest) ) {
if( (!module.is.expectingJSON()) || !isFunction(settings.successTest) ) {
module.verbose('Response is not JSON, skipping validation', settings.successTest, response);
return true;
}
Expand Down Expand Up @@ -539,7 +542,7 @@ $.api = $.fn.api = function(parameters) {
context = this,
elapsedTime = (new Date().getTime() - requestStartTime),
timeLeft = (settings.loadingDuration - elapsedTime),
translatedResponse = ( $.isFunction(settings.onResponse) )
translatedResponse = ( isFunction(settings.onResponse) )
? module.is.expectingJSON() && !settings.rawResponse
? settings.onResponse.call(context, $.extend(true, {}, response))
: settings.onResponse.call(context, response)
Expand Down Expand Up @@ -683,7 +686,7 @@ $.api = $.fn.api = function(parameters) {
;

if(responder) {
if( $.isFunction(responder) ) {
if( isFunction(responder) ) {
module.debug('Using specified synchronous callback', responder);
response = responder.call(context, requestSettings);
}
Expand All @@ -694,7 +697,7 @@ $.api = $.fn.api = function(parameters) {
// simulating response
mockedXHR.resolveWith(context, [ response, textStatus, { responseText: response }]);
}
else if( $.isFunction(asyncResponder) ) {
else if( isFunction(asyncResponder) ) {
asyncCallback = function(response) {
module.debug('Async callback returned response', response);

Expand Down Expand Up @@ -825,7 +828,7 @@ $.api = $.fn.api = function(parameters) {
var
data = {}
;
if( !$.isWindow(element) ) {
if( !isWindow(element) ) {
if( module.is.input() ) {
data.value = $module.val();
}
Expand All @@ -839,7 +842,7 @@ $.api = $.fn.api = function(parameters) {
return data;
},
event: function() {
if( $.isWindow(element) || settings.on == 'now' ) {
if( isWindow(element) || settings.on == 'now' ) {
module.debug('API called without element, no events attached');
return false;
}
Expand Down Expand Up @@ -1046,7 +1049,7 @@ $.api = $.fn.api = function(parameters) {
}
});
}
if ( $.isFunction( found ) ) {
if ( isFunction( found ) ) {
response = found.apply(context, passedArguments);
}
else if(found !== undefined) {
Expand Down
28 changes: 14 additions & 14 deletions src/definitions/behaviors/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

'use strict';

$.isFunction = $.isFunction || function(obj) {
function isFunction(obj) {
return typeof obj === "function" && typeof obj.nodeType !== "number";
};
}

window = (typeof window != 'undefined' && window.Math == Math)
? window
Expand Down Expand Up @@ -139,7 +139,7 @@ $.fn.form = function(parameters) {
submit: function() {
module.verbose('Submitting form', $module);
submitting = true;
$module.submit();
$module.trigger('submit');
},

attachEvents: function(selector, action) {
Expand Down Expand Up @@ -538,7 +538,7 @@ $.fn.form = function(parameters) {
ancillary = module.get.ancillaryValue(rule),
$field = module.get.field(field.identifier),
value = $field.val(),
prompt = $.isFunction(rule.prompt)
prompt = isFunction(rule.prompt)
? rule.prompt(value)
: rule.prompt || settings.prompt[ruleName] || settings.text.unspecifiedRule,
requiresValue = (prompt.search('{value}') !== -1),
Expand Down Expand Up @@ -1146,7 +1146,7 @@ $.fn.form = function(parameters) {
$field.each(function (_index, el) {
var
$el = $(el),
$elGroup = $(el).closest($group),
$elGroup = $el.closest($group),
isCheckbox = ($el.filter(selector.checkbox).length > 0),
isRequired = $el.prop('required') || $elGroup.hasClass(className.required) || $elGroup.parent().hasClass(className.required),
isDisabled = $el.is(':disabled') || $elGroup.hasClass(className.disabled) || $elGroup.parent().hasClass(className.disabled),
Expand Down Expand Up @@ -1211,21 +1211,21 @@ $.fn.form = function(parameters) {
event.stopImmediatePropagation();
}
if(settings.errorFocus && ignoreCallbacks !== true) {
var focusElement, hasTabIndex = true;
var $focusElement, hasTabIndex = true;
if (typeof settings.errorFocus === 'string') {
focusElement = $(document).find(settings.errorFocus);
hasTabIndex = focusElement.is('[tabindex]');
$focusElement = $(document).find(settings.errorFocus);
hasTabIndex = $focusElement.is('[tabindex]');
// to be able to focus/scroll into non input elements we need a tabindex
if (!hasTabIndex) {
focusElement.attr('tabindex',-1);
$focusElement.attr('tabindex',-1);
}
} else {
focusElement = $group.filter('.' + className.error).first().find(selector.field);
$focusElement = $group.filter('.' + className.error).first().find(selector.field);
}
focusElement.focus();
$focusElement.trigger('focus');
// only remove tabindex if it was dynamically created above
if (!hasTabIndex){
focusElement.removeAttr('tabindex');
$focusElement.removeAttr('tabindex');
}
}
if(ignoreCallbacks !== true) {
Expand Down Expand Up @@ -1322,7 +1322,7 @@ $.fn.form = function(parameters) {
return ruleFunction.call(field, value, ancillary, $module);
}
;
if( !$.isFunction(ruleFunction) ) {
if( !isFunction(ruleFunction) ) {
module.error(error.noRule, ruleName);
return;
}
Expand Down Expand Up @@ -1481,7 +1481,7 @@ $.fn.form = function(parameters) {
}
});
}
if( $.isFunction( found ) ) {
if( isFunction( found ) ) {
response = found.apply(context, passedArguments);
}
else if(found !== undefined) {
Expand Down
6 changes: 3 additions & 3 deletions src/definitions/behaviors/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

"use strict";

$.isFunction = $.isFunction || function(obj) {
function isFunction(obj) {
return typeof obj === "function" && typeof obj.nodeType !== "number";
};
}

window = (typeof window != 'undefined' && window.Math == Math)
? window
Expand Down Expand Up @@ -556,7 +556,7 @@ $.fn.state = function(parameters) {
}
});
}
if ( $.isFunction( found ) ) {
if ( isFunction( found ) ) {
response = found.apply(context, passedArguments);
}
else if(found !== undefined) {
Expand Down
8 changes: 4 additions & 4 deletions src/definitions/behaviors/visibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

'use strict';

$.isFunction = $.isFunction || function(obj) {
function isFunction(obj) {
return typeof obj === "function" && typeof obj.nodeType !== "number";
};
}

window = (typeof window != 'undefined' && window.Math == Math)
? window
Expand Down Expand Up @@ -243,7 +243,7 @@ $.fn.visibility = function(parameters) {
handleLoad = function() {
loadedCounter++;
if (loadedCounter >= images.length) {
if ($.isFunction(callback)) {
if (isFunction(callback)) {
callback();
}
}
Expand Down Expand Up @@ -1168,7 +1168,7 @@ $.fn.visibility = function(parameters) {
}
});
}
if ( $.isFunction( found ) ) {
if ( isFunction( found ) ) {
response = found.apply(context, passedArguments);
}
else if(found !== undefined) {
Expand Down
23 changes: 9 additions & 14 deletions src/definitions/globals/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

;(function ($, window, document, undefined) {

$.isFunction = $.isFunction || function(obj) {
function isFunction(obj) {
return typeof obj === "function" && typeof obj.nodeType !== "number";
};
}

$.site = $.fn.site = function(parameters) {
var
Expand Down Expand Up @@ -388,7 +388,7 @@ $.site = $.fn.site = function(parameters) {
}
});
}
if ( $.isFunction( found ) ) {
if ( isFunction( found ) ) {
response = found.apply(context, passedArguments);
}
else if(found !== undefined) {
Expand Down Expand Up @@ -476,17 +476,12 @@ $.site.settings = {
};

// allows for selection of elements with data attributes
$.extend($.expr[ ":" ], {
data: ($.expr.createPseudo)
? $.expr.createPseudo(function(dataName) {
return function(elem) {
return !!$.data(elem, dataName);
};
})
: function(elem, i, match) {
// support: jQuery < 1.8
return !!$.data(elem, match[ 3 ]);
}
$.extend($.expr.pseudos, {
data: $.expr.createPseudo(function(dataName) {
return function(elem) {
return !!$.data(elem, dataName);
};
})
});


Expand Down
24 changes: 13 additions & 11 deletions src/definitions/modules/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

'use strict';

$.isFunction = $.isFunction || function(obj) {
function isFunction(obj) {
return typeof obj === "function" && typeof obj.nodeType !== "number";
};
}

window = (typeof window != 'undefined' && window.Math == Math)
? window
Expand Down Expand Up @@ -356,9 +356,10 @@ $.fn.accordion = function(parameters) {

display: function() {
module.verbose('Removing inline display from element', this);
$(this).css('display', '');
if( $(this).attr('style') === '') {
$(this)
var $element = $(this);
$element.css('display', '');
if($element.attr('style') === '') {
$element
.attr('style', '')
.removeAttr('style')
;
Expand All @@ -367,9 +368,10 @@ $.fn.accordion = function(parameters) {

opacity: function() {
module.verbose('Removing inline opacity from element', this);
$(this).css('opacity', '');
if( $(this).attr('style') === '') {
$(this)
var $element = $(this);
$element.css('opacity', '');
if($element.attr('style') === '') {
$element
.attr('style', '')
.removeAttr('style')
;
Expand Down Expand Up @@ -525,7 +527,7 @@ $.fn.accordion = function(parameters) {
}
});
}
if ( $.isFunction( found ) ) {
if ( isFunction( found ) ) {
response = found.apply(context, passedArguments);
}
else if(found !== undefined) {
Expand Down Expand Up @@ -615,8 +617,8 @@ $.fn.accordion.settings = {

// Adds easing
$.extend( $.easing, {
easeOutQuad: function (x, t, b, c, d) {
return -c *(t/=d)*(t-2) + b;
easeOutQuad: function (x) {
return 1 - (1 - x) * (1 - x);;
}
});

Expand Down
Loading

0 comments on commit 7071e59

Please sign in to comment.