b3a3231f24
Attente d'un visuel pour la popup. Attente des règles à mettre en place.
270 lines
9.0 KiB
JavaScript
270 lines
9.0 KiB
JavaScript
$(document).ready(function(){
|
|
AntPopover._init();
|
|
});
|
|
|
|
|
|
var AntPopover = {
|
|
conf : {
|
|
'enable_delay' : 0,
|
|
'disable_delay' : 10000,
|
|
'cookie_lifetime' : 30*24*60*60,
|
|
'cart':{
|
|
'display' : 20000,
|
|
'cookie_lifetime' : 30*24*60*60
|
|
},
|
|
'customer':{
|
|
'display' : 0,
|
|
'cookie_lifetime' : 30*24*60*60
|
|
},
|
|
'product':{
|
|
'display' : 45000,
|
|
'cookie_lifetime' : 30*24*60*60,
|
|
'countdownLayout' : '<span class="ap_timer_item ap_timer_d">'+
|
|
'<span class="ap_timer_label">{dl}</span>'+
|
|
'<span class="ap_timer_value ap_timer_value_dozen">{d10}<i class="inner_sep"></i></span>'+
|
|
'<span class="ap_timer_value ap_timer_value_units">{d1}<i class="inner_sep"></i></span>'+
|
|
'</span>'+
|
|
'<span class="ap_timer_sep">:</span>'+
|
|
'<span class="ap_timer_item ap_timer_h">'+
|
|
'<span class="ap_timer_label">{hl}</span>'+
|
|
'<span class="ap_timer_value ap_timer_value_dozen">{h10}<i class="inner_sep"></i></span>'+
|
|
'<span class="ap_timer_value ap_timer_value_units">{h1}<i class="inner_sep"></i></span>'+
|
|
'</span>'+
|
|
'<span class="ap_timer_sep">:</span>'+
|
|
'<span class="ap_timer_item ap_timer_i">'+
|
|
'<span class="ap_timer_label">{ml}</span>'+
|
|
'<span class="ap_timer_value ap_timer_value_dozen">{m10}<i class="inner_sep"></i></span>'+
|
|
'<span class="ap_timer_value ap_timer_value_units">{m1}<i class="inner_sep"></i></span>'+
|
|
'</span>'
|
|
},
|
|
'concours':{
|
|
'display' : 0,
|
|
'cookie_lifetime' : 12*60*60
|
|
},
|
|
'promo':{
|
|
'display' : 3000,
|
|
'cookie_lifetime' : 24*60*60
|
|
}
|
|
},
|
|
// Global conf
|
|
overlay : $('.ap_overlay'),
|
|
popups : [$('#ANT_POPOVER_CART_YIELD'), $('#ANT_POPOVER_CUSTOMER_YIELD'), $('#ANT_POPOVER_PRODUCT_YIELD'), $('#ANT_POPOVER_CONCOURS_YIELD'), $('#ANT_POPOVER_PROMO_YIELD')],
|
|
triggered: false,
|
|
_init : function() {
|
|
|
|
/* Init popups */
|
|
var ap_intiTimer = new YTimer(function(){
|
|
AntPopover._cartYieldInit();
|
|
AntPopover._customerYieldInit();
|
|
AntPopover._productYieldInit();
|
|
AntPopover._concoursYieldInit();
|
|
AntPopover._promoYieldInit();
|
|
}, AntPopover.conf.enable_delay);
|
|
|
|
/* Init close button */
|
|
$('.ant_popover_container .close, .ant_popover_container .ap_btn').click(function(){
|
|
var container = $(this).closest('.ant_popover_container');
|
|
AntPopover.closePopup(container);
|
|
});
|
|
|
|
/* Init overlay click (temporaly close all popups) */
|
|
/*this.overlay.click(function(){AntPopover.closePopups();});*/
|
|
$('.ap_overlay').click(function(){AntPopover.closePopups();});
|
|
/* Init add to cart button click (temporaly close all popups) */
|
|
$('.ap_add_to_cart').click(function(e){
|
|
e.preventDefault();
|
|
AntPopover.addToCart();
|
|
});
|
|
|
|
// init cookie if we click on link
|
|
$('.ap_text_link').click(function(e){
|
|
e.preventDefault();
|
|
var container = $(this).closest('.ant_popover_container');
|
|
var ap_event = container.data('event');
|
|
var link = $(this).attr('href');
|
|
AntPopover._ajaxCall(ap_event, 1, 0, function(resp){
|
|
$('.ap_overlay').removeClass('shown');
|
|
container.removeClass('shown').addClass('closed');
|
|
window.location.href = link;
|
|
});
|
|
});
|
|
},
|
|
_cartYieldInit : function(){
|
|
console.log($('#ANT_POPOVER_CART_YIELD'));
|
|
console.log(AntPopover.conf.cart.cookie_lifetime);
|
|
if ($('#ANT_POPOVER_CART_YIELD').length){
|
|
// after a short delay
|
|
// AntPopover.displayOnStay('cart',$('#ANT_POPOVER_CART_YIELD'), AntPopover.conf.cart.cookie_lifetime, AntPopover.conf.disable_delay);
|
|
// mouse leave screen
|
|
AntPopover.displayOnLeave('cart', $('#ANT_POPOVER_CART_YIELD'), AntPopover.conf.cart.cookie_lifetime);
|
|
}
|
|
},
|
|
_customerYieldInit : function(){
|
|
if ($('#ANT_POPOVER_CUSTOMER_YIELD').length){
|
|
// after a short delay
|
|
AntPopover.displayOnStay('customer', $('#ANT_POPOVER_CUSTOMER_YIELD'), AntPopover.conf.customer.cookie_lifetime, AntPopover.conf.customer.display);
|
|
// mouse leave screen
|
|
// AntPopover.displayOnLeave('customer', $('#ANT_POPOVER_CUSTOMER_YIELD'), AntPopover.conf.customer.cookie_lifetime);
|
|
}
|
|
},
|
|
_productYieldInit : function(){
|
|
if ($('#ANT_POPOVER_PRODUCT_YIELD').length){
|
|
// mouse leave screen
|
|
AntPopover.displayOnLeave('product', $('#ANT_POPOVER_PRODUCT_YIELD'), AntPopover.conf.product.cookie_lifetime);
|
|
// private sale countdown
|
|
var now = new Date();
|
|
if (endofsale - now < 31536000000)
|
|
$('#ANT_POPOVER_PRODUCT_YIELD .ap_timer').countdown({serverSync:function(){return new Date();}, padZeroes: true, until: endofsale, layout: AntPopover.countdownLayout});
|
|
else
|
|
$('#ANT_POPOVER_PRODUCT_YIELD .ap_countdown_field').remove();
|
|
}
|
|
},
|
|
_concoursYieldInit : function(){
|
|
if ($('#ANT_POPOVER_CONCOURS_YIELD').length){
|
|
// after a short delay
|
|
AntPopover.displayOnStay('concours', $('#ANT_POPOVER_CONCOURS_YIELD'), AntPopover.conf.concours.cookie_lifetime, AntPopover.conf.concours.display);
|
|
// mouse leave screen
|
|
/*AntPopover.displayOnLeave('concours', $('#ANT_POPOVER_CONCOURS_YIELD'), AntPopover.conf.concours.cookie_lifetime);*/
|
|
}
|
|
},
|
|
_promoYieldInit : function(){
|
|
if ($('#ANT_POPOVER_PROMO_YIELD').length && $(window).width()>767){
|
|
// after a short delay
|
|
AntPopover.displayOnStay('promo', $('#ANT_POPOVER_PROMO_YIELD'), AntPopover.conf.promo.cookie_lifetime, AntPopover.conf.promo.display);
|
|
// mouse leave screen
|
|
/*AntPopover.displayOnLeave('promo', $('#ANT_POPOVER_PROMO_YIELD'), AntPopover.conf.promo.cookie_lifetime);*/
|
|
}
|
|
},
|
|
displayOnStay : function(event, element, cookie_lifetime, delay){
|
|
// after a short delay
|
|
var _ydost = new YTimer(function() {
|
|
AntPopover.displayPopup(event, element, cookie_lifetime, delay);
|
|
}, delay);
|
|
},
|
|
displayOnLeave : function(event, element, cookie_lifetime){
|
|
// mouse leave screen
|
|
$('body').mouseleave(function(){
|
|
AntPopover.displayPopup(event, element, cookie_lifetime, AntPopover.conf.disable_delay);
|
|
});
|
|
},
|
|
displayPopup : function(ap_event, element, cookie_lifetime, delay){
|
|
if (typeof(element)==='undefined')
|
|
return;
|
|
if (element.hasClass('closed') || element.hasClass('tmp_closed'))
|
|
return;
|
|
|
|
AntPopover._ajaxCall(ap_event, 0, cookie_lifetime, function(resp){
|
|
|
|
if (resp===true){
|
|
if (!$('input:focus').length && !$('.ant_popover_container.shown').length){
|
|
element.addClass('shown');
|
|
$('header').addClass('ap_overlay_header');
|
|
/*AntPopover.overlay.addClass('shown');*/
|
|
$('.ap_overlay').addClass('shown');
|
|
/*if(ap_event == "promo") {
|
|
AntPopover._ajaxCall(ap_event, 1, 0, function(resp){});
|
|
}*/
|
|
}
|
|
else if (typeof(delay!=='undefined') && delay){
|
|
_pdtid = new YTimer(function() {
|
|
AntPopover.displayPopup(ap_event, element, delay, cookie_lifetime);
|
|
}, delay);
|
|
}
|
|
}
|
|
});
|
|
},
|
|
closePopups : function(){
|
|
AntPopover.closePopup($('.ant_popover_container.shown'));
|
|
/*
|
|
this.overlay.removeClass('shown');
|
|
$('.ant_popover_container').removeClass('shown').addClass('tmp_closed');
|
|
var _pctid = new YTimer(function(){
|
|
$('.ant_popover_container').removeClass('tmp_closed')
|
|
}, AntPopover.conf.disable_delay);
|
|
if (typeof(_pdtid) !== 'undefined'){
|
|
_pdtid.add(AntPopover.conf.disable_delay);
|
|
}
|
|
*/
|
|
},
|
|
closePopup : function(element){
|
|
/*this.overlay.removeClass('shown');*/
|
|
$('.ap_overlay').removeClass('shown');
|
|
$('header').removeClass('ap_overlay_header');
|
|
var ap_event = element.data('event');
|
|
AntPopover._ajaxCall(ap_event, 1, 0, function(resp){});
|
|
element.removeClass('shown').addClass('closed');
|
|
},
|
|
addToCart : function(){
|
|
var add_button = $('#buy_block #add_to_cart .btn');
|
|
add_button.click();
|
|
AntPopover.closePopups();
|
|
},
|
|
_ajaxCall : function(ap_event, update, lifetime, callback){
|
|
if (typeof(update) === 'undefined')
|
|
update = 0;
|
|
if (typeof(lifetime) === 'undefined')
|
|
lifetime = AntPopover.conf.cookie_lifetime;
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: ap_ajax_path,
|
|
cache: false,
|
|
dataType: "json",
|
|
data : {
|
|
ajax: true,
|
|
ap_event: ap_event,
|
|
update: update,
|
|
lifetime: lifetime,
|
|
},
|
|
success : function(data)
|
|
{
|
|
callback(data);
|
|
}
|
|
});
|
|
},
|
|
__shutdown : function(){
|
|
/*this.overlay.removeClass('shown');*/
|
|
$('.ap_overlay').removeClass('shown');
|
|
if (typeof(_pctid)!=='undefined')
|
|
clearTimeout(_pctid)
|
|
if (typeof(_pytid)!=='undefined')
|
|
clearTimeout(_pytid)
|
|
if (typeof(_pdtid)!=='undefined')
|
|
clearTimeout(_pdtid)
|
|
$('.ant_popover_container').removeClass('shown').addClass('closed');
|
|
},
|
|
__restart : function(){
|
|
$('.ant_popover_container').removeClass('shown closed tmp_closed');
|
|
/*this.overlay.removeClass('shown');*/
|
|
$('.ap_overlay').removeClass('shown');
|
|
this._init();
|
|
}
|
|
}
|
|
|
|
/* TIMER */
|
|
function YTimer(callback, time) {
|
|
this.setTimeout(callback, time);
|
|
}
|
|
|
|
YTimer.prototype.setTimeout = function(callback, time) {
|
|
var self = this;
|
|
if(this.timer) {
|
|
clearTimeout(this.timer);
|
|
}
|
|
this.finished = false;
|
|
this.callback = callback;
|
|
this.time = time;
|
|
this.timer = setTimeout(function() {
|
|
self.finished = true;
|
|
callback();
|
|
}, time);
|
|
this.start = Date.now();
|
|
}
|
|
|
|
YTimer.prototype.add = function(time) {
|
|
if(!this.finished) {
|
|
// add time to time left
|
|
time = this.time - (Date.now() - this.start) + time;
|
|
this.setTimeout(this.callback, time);
|
|
}
|
|
} |