Files
drupal-quartiersdedemain/web/themes/custom/quartiers_de_demain/librairies/jquery4-compat.js
T

48 lines
1.4 KiB
JavaScript

/**
* @file
* Shim de compatibilité jQuery 4 pour les librairies legacy du thème.
*
* Drupal 11 embarque jQuery 4.0, qui a supprimé des API utilisées par
* slick 1.8.1 ($.type, $.proxy) -> "TypeError: i.type is not a function"
* dans la console et carrousels cassés. Ce shim les restaure si absentes.
*/
(function ($) {
if (typeof $ === 'undefined') {
return;
}
if (!$.type) {
var class2type = {};
'Boolean Number String Function Array Date RegExp Object Error Symbol'.split(' ').forEach(function (name) {
class2type['[object ' + name + ']'] = name.toLowerCase();
});
$.type = function (obj) {
if (obj == null) {
return obj + '';
}
return typeof obj === 'object' || typeof obj === 'function'
? (class2type[Object.prototype.toString.call(obj)] || 'object')
: typeof obj;
};
}
if (!$.proxy) {
$.proxy = function (fn, context) {
var args = Array.prototype.slice.call(arguments, 2);
return function () {
return fn.apply(context || this, args.concat(Array.prototype.slice.call(arguments)));
};
};
}
if (!$.isArray) {
$.isArray = Array.isArray;
}
if (!$.isFunction) {
$.isFunction = function (obj) { return typeof obj === 'function'; };
}
if (!$.trim) {
$.trim = function (text) { return text == null ? '' : String(text).trim(); };
}
})(jQuery);