-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.liveTimeAgo.min.js
7 lines (7 loc) · 2.26 KB
/
jquery.liveTimeAgo.min.js
1
2
3
4
5
6
7
/*!
liveTimeAgo - 1.0.0
Copyright © 2016 Florian Nicolas
Licensed under the MIT license.
https://github.com/ticlekiwi/jquery.liveTimeAgo.js
!*/
!function(t){t.fn.liveTimeAgo=function(a){function e(t,a){var e={},n=a-t;return n=Math.floor(n/1e3),e.sec=n%60,n=Math.floor((n-e.sec)/60),e.min=n%60,n=Math.floor((n-e.min)/60),e.hour=n%24,n=Math.floor((n-e.hour)/24),e.day=n,e.year=a.getFullYear()-t.getFullYear(),e.month=a.getMonth()+1-(t.getMonth()+1),e}function n(t){var n=e(t,new Date);return n.year>1?a.translate.years.replace("%",n.year):1==n.year?a.translate.year.replace("%",n.year):n.month>1?a.translate.months.replace("%",n.month):1==n.month?a.translate.month.replace("%",n.month):n.day>1?a.translate.days.replace("%",n.day):1==n.day?a.translate.day.replace("%",n.day):n.hour>1?a.translate.hours.replace("%",n.hour):1==n.hour?a.translate.hour.replace("%",n.hour):n.min>1?a.translate.minutes.replace("%",n.min):1==n.min?a.translate.minute.replace("%",n.min):n.sec>=1?a.translate.seconds.replace("%",n.sec):a.translate.error}function r(){t(".liveTimeAgo-active").each(function(){var a="undefined"!=typeof t(this).attr("data-lta-type")&&"timestamp"==t(this).attr("data-lta-type")?parseInt(t(this).attr("data-lta-value")):t(this).attr("data-lta-value"),e=new Date(a);t(this).text(n(e))})}function o(){null!==s&&clearTimeout(s),null!==l&&clearInterval(l);var t=new Date,a=t.getSeconds();s=setTimeout(function(){r(),l=setInterval(function(){r()},6e4)},1e3*(60-a))}var s,l=null,i={translate:{year:"% year ago",years:"% years ago",month:"% month ago",months:"% months ago",day:"% day ago",days:"% days ago",hour:"% hour ago",hours:"% hours ago",minute:"% minute ago",minutes:"% minutes ago",seconds:"few seconds ago",error:"unknow time"}};"undefined"==typeof a&&(a=i),this.each(function(){if("undefined"!=typeof t(this).attr("data-lta-value"))var a="undefined"!=typeof t(this).attr("data-lta-type")&&"timestamp"==t(this).attr("data-lta-type")?1e3*t(this).attr("data-lta-value"):t(this).attr("data-lta-value");else var a="undefined"!=typeof t(this).attr("data-lta-type")&&"timestamp"==t(this).attr("data-lta-type")?1e3*t(this).text():t(this).text();var e=new Date(a);t(this).attr("data-lta-value",a).addClass("liveTimeAgo-active").text(n(e))}),o(),window.addEventListener("focus",function(){r(),o()},!1)}}(jQuery);