|
|
|
|
@ -14,19 +14,39 @@ function getCookie(name) { |
|
|
|
|
return cookieValue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function countdownPrice(el, beginValue, decInSecond) { |
|
|
|
|
var counter = el.find(".counter"); |
|
|
|
|
|
|
|
|
|
counter.text(beginValue); |
|
|
|
|
|
|
|
|
|
if (el.attr("data-tid") ) { |
|
|
|
|
var tid = el.attr("data-tid") |
|
|
|
|
clearInterval(tid); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var delay = 1000; |
|
|
|
|
var div = 3.0; |
|
|
|
|
|
|
|
|
|
var timerId = setInterval(function(){ |
|
|
|
|
var val = parseFloat(counter.text()); |
|
|
|
|
var new_val = (val - (decInSecond / div)).toFixed(); |
|
|
|
|
counter.text(new_val); |
|
|
|
|
}, delay / div); |
|
|
|
|
|
|
|
|
|
el.attr("data-tid", timerId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function countdownPriceStop(el) { |
|
|
|
|
clearInterval(el.attr("data-tid")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function get_price() { |
|
|
|
|
$.ajax({ |
|
|
|
|
url: "/dtys/info/", |
|
|
|
|
method: "GET", |
|
|
|
|
// beforeSend: function(xhr) {
|
|
|
|
|
// // var csrftoken = getCookie("csrftoken");
|
|
|
|
|
|
|
|
|
|
// // if (csrftoken) {
|
|
|
|
|
// // xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
|
|
|
|
// // }
|
|
|
|
|
// },
|
|
|
|
|
success: function(data, textStatus, jqXHR) { |
|
|
|
|
// console.log("DTYS data", data);
|
|
|
|
|
console.log(data); |
|
|
|
|
|
|
|
|
|
if (data.dtys_list.length > 0) { |
|
|
|
|
var active = data.dtys_list; |
|
|
|
|
|
|
|
|
|
@ -39,11 +59,16 @@ function get_price() { |
|
|
|
|
product.addClass("stopped"); |
|
|
|
|
fake_add_to_cart_btn.show(); |
|
|
|
|
add_to_cart_btn.hide(); |
|
|
|
|
|
|
|
|
|
countdownPriceStop(product); |
|
|
|
|
console.log("price countdown stopped", i.id); |
|
|
|
|
} else { |
|
|
|
|
product.removeClass("stopped"); |
|
|
|
|
product.find(".price").text(i.current_price); |
|
|
|
|
fake_add_to_cart_btn.hide(); |
|
|
|
|
add_to_cart_btn.show(); |
|
|
|
|
|
|
|
|
|
countdownPrice(product, i.current_price, i.price_dec_in_sec); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
@ -56,7 +81,7 @@ function get_price() { |
|
|
|
|
|
|
|
|
|
var Updater = function(){ |
|
|
|
|
this.params = { |
|
|
|
|
period: 3000, |
|
|
|
|
period: 10000, |
|
|
|
|
url: '', |
|
|
|
|
onModified: function(data,x,modified){}, |
|
|
|
|
bgPause: false |
|
|
|
|
@ -112,11 +137,13 @@ var Updater = function(){ |
|
|
|
|
$(function(){ |
|
|
|
|
var upd = new Updater(); |
|
|
|
|
|
|
|
|
|
get_price(); |
|
|
|
|
|
|
|
|
|
upd.init({ |
|
|
|
|
url: "/dtys/etg/", |
|
|
|
|
onModified: function(data, x, modified) { |
|
|
|
|
get_price(); |
|
|
|
|
console.log(data, x, modified); |
|
|
|
|
// console.log(data, x, modified);
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|