Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. <div class="sf-caution-time-box" data-time='1346364000000'>
  2. <div class="sf-caution-inner">
  3. <div class="sf-countdown-days">
  4. <div class="count">--</div>
  5. <div class="units">DAYS</div>
  6. </div>
  7. <div class="sf-countdown-hours">
  8. <div class="count">--</div>
  9. <div class="units">HOURS</div>
  10. </div>
  11. <div class="sf-countdown-minutes">
  12. <div class="count">--</div>
  13. <div class="units">MINS</div>
  14. </div>
  15. <div class="sf-countdown-seconds">
  16. <div class="count">--</div>
  17. <div class="units">SECS</div>
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. var sf = sf || {};
  29.  
  30. sf.home = (function ($) {
  31.  
  32. var myStartTime,
  33. times,
  34. timerElms;
  35.  
  36. function init(){
  37.  
  38.  
  39. if($('.sf-caution-time-box').length > 0){
  40.  
  41. var d = new Date();
  42. myStartTime = d.getTime();
  43. times = [];
  44. timerElms = $('.sf-caution-time-box');
  45.  
  46. $('.sf-caution-time-box').each(function(i,elm){
  47. times.push($(elm).attr('data-time'));
  48. })
  49.  
  50. setInterval(calculateTime,1000);
  51. calculateTime();
  52. }
  53.  
  54. $('.sf-fb-icon').bind('click',function(e){ sf.tracker.trackFacebookFollow()});
  55. $('.sf-tweet-icon').bind('click',function(e){ sf.tracker.trackTwitterFollow()});
  56. }
  57.  
  58.  
  59.  
  60. function calculateTime(){
  61. var d = new Date();
  62. var nowTime = d.getTime();
  63. var secsPassed = nowTime - myStartTime;
  64.  
  65. timerElms.each(function(i,elm){
  66. var d = Math.floor((times[i] - LOAD_TIME - secsPassed)/86400000);
  67. var h = Math.floor((times[i] -LOAD_TIME - secsPassed) / (1000*60*60));
  68. var m = Math.floor((times[i] - LOAD_TIME - secsPassed) % (1000*60*60)) / (1000*60);
  69. var s = Math.floor((((times[i] - LOAD_TIME - secsPassed) % (1000*60*60)) % (1000*60)) / 1000);
  70.  
  71. h = Math.floor(h%24);
  72. m = Math.floor(m%60);
  73. s = Math.floor(s%60);
  74.  
  75. var ds = "" + d;
  76. var hs = "" + h;
  77. var ms = "" + m;
  78. var ss = "" + s;
  79.  
  80. if(ds.length < 2){
  81. ds = "0"+ds;
  82. }
  83. if(hs.length < 2){
  84. hs = "0"+hs;
  85. }
  86. if(ms.length < 2){
  87. ms = "0"+ms;
  88. }
  89. if(ss.length < 2){
  90. ss = "0"+ss;
  91. }
  92.  
  93. elm =$(elm);
  94.  
  95. elm.find('.sf-countdown-days').find('.count').text(ds);
  96. elm.find('.sf-countdown-hours').find('.count').text(hs);
  97. elm.find('.sf-countdown-minutes').find('.count').text(ms);
  98. elm.find('.sf-countdown-seconds').find('.count').text(ss);
  99.  
  100. })
  101. }
  102.  
  103.  
  104.  
  105. return {
  106. init:init
  107. };
  108.  
  109. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement