Проблема в том, что данный код устарел, блокирует браузер на время выполнения скрипта и выдает warning:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.
я понимаю, что нужно использовать колбэки, но у меня не получается корректно внести изменения, все по цепочки начинает отваливаться(
Что за tooltip? config.tooltip в любом случае (async: false или async: true) равен true, но при async: true сразу ошибка:
Uncaught TypeError: Cannot read property 'tooltip' of null
var JCART = (function() {
// This script sends Ajax requests to config-loader.php and relay.php using the path below
// We assume these files are in the 'jcart' directory, one level above this script
// Edit as needed if using a different directory structure
var path = 'jcart',
container = $('#jcart'),
token = $('[name=jcartToken]').val(),
tip = $('#jcart-tooltip');
var config = (function() {
var config = null;
$.ajax({
url: path + '/config-loader.php',
data: {
"ajax": "true"
},
dataType: 'json',
async: false,
success: function(response) {
config = response;
},
error: function() {
alert('Ajax error: Edit the path in jcart.js to fix.');
}
});
return config;
;
}());
var setup = (function() {
if(config.tooltip === true) {
tip.text(config.text.itemAdded);
// Tooltip is added to the DOM on mouseenter, but displayed only after a successful Ajax request
$('.jcart [type=submit]').mouseenter(
function(e) {
var x = e.pageY + 25,
y = e.pageX + -10;
$('body').append(tip);
tip.css({top: y + 'px', left: x + 'px'});
}
)
.mousemove(
function(e) {
var y = e.pageY + 25,
x = e.pageX + -10;
tip.css({top: y + 'px', left: x + 'px'});
}
)
.mouseleave(
function() {
tip.hide();
}
);
}