Advertisement
Guest User

Untitled

a guest
Apr 17th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var timers = []; // Creates an array to store your timers
  2. var socket = io.connect('http://localhost:8000');  
  3. socket.on('notification', function (data) {
  4.     $.each(data.auctions,function(index,auction){  
  5.     duration = auction.duration;
  6.    
  7.     if (duration > 0)
  8.     {
  9.     var price_retail = $("#" + auction.id).attr("data-retail");
  10.     var discount = ((100) - (Math.floor(auction.price/price_retail*100)));
  11.     var calc = auction.price.toFixed(2);
  12.     var price_calc = calc.toString().replace(/\./g, ',');  
  13.     $(".price" + auction.id).html(price_calc + "€");         
  14.     $(".discount" + auction.id).html(discount + "%");  
  15.    
  16.     if(timers.length > 0) {
  17.         for(i in timers)
  18.         {
  19.             if ($('.price' + auction.id).data('curr_text') !== $('.price' + auction.id).text())
  20.             {
  21.             $(".flashing" + auction.id).toggle("highlight").toggle("highlight");
  22.             timers[i][1] = 10; // If timer for auction.id already exists, set it to 10 seconds again.
  23.             }
  24.         }
  25.     } else {
  26.         timers.push([auction.id, auction.duration]);
  27.     }      
  28.  
  29.     $('.price' + auction.id).data('curr_text', $('.price' + auction.id).text());       
  30.    
  31.     } else {
  32.     // auction ended   
  33.     }
  34.     });
  35. });
  36.  
  37. function timerCount() {
  38.     for(i in timers) {     
  39.         if(timers[i][1] <= 0) {
  40.             delete timers[i]; // If timer seconds is less than 0, delete it.
  41.         } else {           
  42.             timers[i][1]--; // Else, decrease it by 1 second.
  43.             console.log(timers[i][0] + ": " + timers[i][1]);
  44.             duration_html = formatSeconds(timers[i][1]);       
  45.             $(".duration" + timers[i][0]).html(duration_html);             
  46.         }
  47.     }
  48. }
  49. setInterval(timerCount, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement