У меня есть приложение, которое использует colorbox и различные запросы AJAX.Иногда я получаю запрос ajax внутри colorbox, который будет вызывать другой запрос ajax, который загружается за пределы colorbox ... Я чувствую себя очень грязно, вот мой код, есть ли лучший способ сделать это?Без повторной инициализации colorbox столько раз?
jQuery.fn.initFunctions = function() {
$(".overlay_box").colorbox({
opacity: 0.40,
transition: 'none',
speed: 200,
height: 480,
width: 700,
scrolling: true,
title: ' ',
overlayClose: true,
onComplete: function () {
$(this).initFunctions();
}
});
$(".overlay_box_inline").colorbox({
opacity: 0.40,
transition: 'none',
speed: 200,
height: 480,
width: 700,
scrolling: true,
inline: true,
title: ' ',
overlayClose: true,
onComplete: function () {
$(this).initFunctions();
}
});
$(".overlay_box_inline_resize").colorbox({
opacity: 0.40,
transition: 'none',
speed: 200,
scrolling: true,
inline: true,
title: ' ',
overlayClose: true,
onComplete: function () {
$(this).initFunctions();
$.colorbox.resize();
}
});
$('.remove').click(function(){
var id = $(this).attr('id');
$.ajax({
url: $(this).attr('href'),
success: function(data){
$.ajax({
url: "/checkout/ten/"+id,
success: function(data){
$('#ten').html(data);
$(this).initFunctions();
}
});
}
});
return false;
});
$('.friends .add').bind('click', function(){
var id = $(this).attr('id');
$.ajax({
url: $(this).attr('href'),
success: function(data){
$.colorbox({
href: "/checkout/"+id,
opacity: 0.40,
transition: 'none',
speed: 200,
height: 480,
width: 700,
scrolling: true,
title: ' ',
overlayClose: true,
onComplete: function () {
$.ajax({
url: "/checkout/invite/"+id,
success: function(data){
$('#ten_friends').html(data);
$(this).initFunctions();
}
});
}
});
}
});
});
};
$(this).initFunctions();