SHARE
TWEET

Untitled

a guest Jun 24th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function update(obj) {
  2.   let percentOfTarget = Math.round((obj.detail.amount.current / obj.detail.amount.target) * 435);
  3.   let barWidth = percentOfTarget;
  4.   const goalBar = document.getElementById('goal-bar');
  5.  
  6.   if (percentOfTarget >= 435) {
  7.     barWidth = 500;
  8.   }
  9.  
  10.   goalBar.style.width = barWidth + 'px';
  11.   const barString = `${obj.detail.amount.current} (${percentOfTarget}%)`;
  12.  
  13.   $('#title').html(obj.detail.title);
  14.   $('#goal-current').text(barString);
  15.   $('#bottom-info').text( obj.detail.amount.current + "/" + obj.detail.amount.target + " | ends " + moment(obj.detail.to_go.ends_at).fromNow());
  16.   $('#time').text(moment(obj.detail.to_go.ends_at).fromNow());
  17.   var date = $('#goal-end-date').html();
  18.   date = date.split(' ')[0];
  19.   var dt = new Date(date + "z");
  20.   var today = new Date();
  21.   var dt_ms = dt.getTime();
  22.   var today_ms = today.getTime();
  23.   var timeDiff = dt_ms - today_ms;
  24.   var remaining = Math.round(timeDiff / (60 * 60 * 24 * 1000));
  25.  
  26.   if (remaining === 1 ) {
  27.     $('#goal-end-date').html(remaining + " day to go");
  28.   } else if (remaining === 0 || remaining > 1) {
  29.     $('#goal-end-date').html(remaining + " days to go");
  30.   }
  31. }
  32.   // Events will be sent when someone followers
  33.   // Please use event listeners to run functions.
  34.   document.addEventListener('goalLoad', function(obj) {
  35.   // obj.detail will contain information about the current goal
  36.   // this will fire only once when the widget loads
  37.   update(obj);
  38. });
  39.  
  40.   document.addEventListener('goalEvent', function(obj) {
  41.   // obj.detail will contain information about the goal
  42.   update(obj);
  43.  
  44. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top