Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var timers = []; // Creates an array to store your timers
- var socket = io.connect('http://localhost:8000');
- socket.on('notification', function (data) {
- $.each(data.auctions,function(index,auction){
- duration = auction.duration;
- if (duration > 0)
- {
- var price_retail = $("#" + auction.id).attr("data-retail");
- var discount = ((100) - (Math.floor(auction.price/price_retail*100)));
- var calc = auction.price.toFixed(2);
- var price_calc = calc.toString().replace(/\./g, ',');
- $(".price" + auction.id).html(price_calc + "€");
- $(".discount" + auction.id).html(discount + "%");
- if(timers.length > 0) {
- for(i in timers)
- {
- if ($('.price' + auction.id).data('curr_text') !== $('.price' + auction.id).text())
- {
- $(".flashing" + auction.id).toggle("highlight").toggle("highlight");
- timers[i][1] = 10; // If timer for auction.id already exists, set it to 10 seconds again.
- }
- }
- } else {
- timers.push([auction.id, auction.duration]);
- }
- $('.price' + auction.id).data('curr_text', $('.price' + auction.id).text());
- } else {
- // auction ended
- }
- });
- });
- function timerCount() {
- for(i in timers) {
- if(timers[i][1] <= 0) {
- delete timers[i]; // If timer seconds is less than 0, delete it.
- } else {
- timers[i][1]--; // Else, decrease it by 1 second.
- console.log(timers[i][0] + ": " + timers[i][1]);
- duration_html = formatSeconds(timers[i][1]);
- $(".duration" + timers[i][0]).html(duration_html);
- }
- }
- }
- setInterval(timerCount, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement