Вопрос 1: Кто подскажет, по какой причине Ajax не рисует div class="overlay" для всплывающего окна (стили в css есть, да и скрипт вроде правильный)?
Вопрос 2: И почему кнопка "продолжить" в заказе в "1 клик" не закрывает всплывающее окно:
Код для первого вопроса:
site.basket.oneClick = function(id, form) {
var option = $(form).find('input[type="radio"]:checked');
var optional;
if (option.length > 0) {
optional = '?' + option.attr('name') + '=' + $(form).find('input[type="radio"]:checked').val()
} else {
optional = '';
}
var locale = location.pathname;
var lang = locale.substring(1,locale.substring(1).indexOf('/')+1);
jQuery.ajax({
url: '/udata/emarket/createForm/emarket-purchase-oneclick?transform=modules/catalog/one-click.xsl&lang=' + lang,
dataType: 'html',
success: function (data) {
site.message({
id: 'one_click_popup_' + id,
header: 'Заказ в "1 клик"',
width: 380,
content: data,
async: false
});
var form = jQuery('form.buyer_data');
form.attr('action', form.attr('action') + 'element/' + id + '.xml' + optional)
form.append('<table cellpadding="15" style="margin-top: -5px;"><tr><td></td><td align="right"><input type="submit" class="button2" value="' + 'Отправить' + '" /></td></tr></table>');
form.submit(function() {
var xml = site.basket.sendForm(form).responseXML;
form.closest('.content').find('.error').remove();
$(xml).find('error').each(
function() {
form.closest('div').prepend('<div class="error">' + $(this).text() + '</div>');
}
);
form.closest('.content').find('.success').remove();
if ($(xml).find('orderId').length > 0) {
site.basket.replace('all');
form.closest('div').prepend('<div class="success"><div><p>' + 'Заказ ' + '<strong>№' + $(xml).find('orderId').eq(0).text() + '</strong>' + ' успешно оформлен! <br/> Ожидайте звонка от менеджера нашего магазина.' + '</p></div><a class="button big close">' + 'Продолжить' + '</a></div>');
form.remove();
}
return false;
});
}
});
}
Код для второго вопроса:
site.basket.list = function(link) {
var oneClick = false;
var id = (link.id.indexOf('add_basket') != -1) ? link.id.replace(/^add_basket_/, '') : false;
if (!id) {
oneClick = true;
id = (link.id.indexOf('one_click') != -1) ? link.id.replace(/^one_click_/, '') : link;
}
if (!id) return false;
if (jQuery(link).hasClass('options_true')) {
var url = '/upage//' + id + '?transform=modules/catalog/popup-add-options.xsl';
if (oneClick) {
url = '/upage//' + id + '?transform=modules/catalog/popup-add-options-oneclick.xsl';
}
if (jQuery('#add_options_' + id).length == 0) {
jQuery.ajax({
url: url,
dataType: 'html',
success: function (data) {
site.message({
id: 'add_options_' + id,
header: 'Выбор опций',
width: 380,
content: data,
async: false
});
var form = jQuery('form.options');
form.append('<input type="submit" class="button2" value="' + 'Добавить' + '" />');
form.submit(function() {
if (!site.basket.is_cart && !oneClick) {
site.basket.add(id, this, true);
} else if (!site.basket.is_cart && oneClick) {
site.basket.oneClick(id, this);
site.message.close(jQuery('#add_options_' + id), jQuery('.overlay'));
}
return false;
});
}
});
}
}
else if(!oneClick) {
this.add(id);
} else {
site.basket.oneClick(id);
}
};
Решение в скрипте /js/site/message.js (спасибо за подсказку/помощь!):
site.message = function(params) {
var params = typeof(params) == 'object' ? params : {};
var id = params.id || new Date().getTime();
var header = params.header || 'Информация';
var content = params.content || '';
var width = params.width ? params.width + 'px' : 'auto';
var height = params.height ? params.height + 'px' : 'auto';
jQuery("<div/>", {
"id": id,
"class": "infoblock front_popup",
html: "<div class=\"title\" onmousedown=\"jQuery('#" + id + "').draggable({containment: 'document'})\">\
<img src=\"/images/cms/eip/close.png\" alt=\"Закрыть\" title=\"Закрыть\" />\
<h2>" + header + "</h2></div><div class=\"body\" onmousedown=\"jQuery('#" + id + "').draggable('destroy')\">\
<div class=\"in\">" + content + "</div></div>"
}).appendTo("body").parent().append("<div class='overlay'></div>");
var popup = jQuery('#' + id);
popup.css({'width':width, 'height':height});
var leftPosition = (window.document.documentElement.offsetWidth - popup.width()) / 2;
var windowHeight = window.innerHeight || window.document.documentElement.offsetHeight;
var topPosition = jQuery(window.document.documentElement).scrollTop() || jQuery(window.document).scrollTop();
topPosition = topPosition + (windowHeight - popup.height()) / 2;
popup.css({'left':leftPosition + 'px', 'top':topPosition + 'px'});
jQuery('div.title img', popup).add(('.overlay')).click(function() {
site.message.close(popup, jQuery('.overlay'))
});
jQuery(popup).on('click', 'a.close', function() {
site.message.close(popup, jQuery('.overlay'))
});
var close;
if (close = jQuery('.close', popup)) {
close.click(function() {popup.remove();});
}
};
site.message.close = function(popup, overlay) {
overlay.remove();
popup.remove();
}