timeago_js 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/assets/javascripts/timeago/locales/ar.js +26 -26
  3. data/assets/javascripts/timeago/locales/be.js +51 -51
  4. data/assets/javascripts/timeago/locales/bg.js +17 -17
  5. data/assets/javascripts/timeago/locales/ca.js +17 -17
  6. data/assets/javascripts/timeago/locales/da.js +17 -17
  7. data/assets/javascripts/timeago/locales/de.js +17 -17
  8. data/assets/javascripts/timeago/locales/el.js +17 -17
  9. data/assets/javascripts/timeago/locales/en.js +17 -17
  10. data/assets/javascripts/timeago/locales/en_short.js +17 -17
  11. data/assets/javascripts/timeago/locales/es.js +17 -17
  12. data/assets/javascripts/timeago/locales/eu.js +17 -17
  13. data/assets/javascripts/timeago/locales/fa.js +18 -0
  14. data/assets/javascripts/timeago/locales/fi.js +17 -17
  15. data/assets/javascripts/timeago/locales/fr.js +17 -17
  16. data/assets/javascripts/timeago/locales/he.js +17 -17
  17. data/assets/javascripts/timeago/locales/hu.js +17 -17
  18. data/assets/javascripts/timeago/locales/in_ID.js +17 -17
  19. data/assets/javascripts/timeago/locales/it.js +17 -17
  20. data/assets/javascripts/timeago/locales/ja.js +17 -17
  21. data/assets/javascripts/timeago/locales/ko.js +17 -17
  22. data/assets/javascripts/timeago/locales/ml.js +17 -17
  23. data/assets/javascripts/timeago/locales/my.js +18 -0
  24. data/assets/javascripts/timeago/locales/nl.js +17 -17
  25. data/assets/javascripts/timeago/locales/pl.js +34 -34
  26. data/assets/javascripts/timeago/locales/pt_BR.js +17 -17
  27. data/assets/javascripts/timeago/locales/ro.js +28 -28
  28. data/assets/javascripts/timeago/locales/ru.js +51 -51
  29. data/assets/javascripts/timeago/locales/sv.js +17 -17
  30. data/assets/javascripts/timeago/locales/ta.js +17 -17
  31. data/assets/javascripts/timeago/locales/th.js +17 -17
  32. data/assets/javascripts/timeago/locales/tr.js +17 -17
  33. data/assets/javascripts/timeago/locales/uk.js +40 -40
  34. data/assets/javascripts/timeago/locales/vi.js +17 -17
  35. data/assets/javascripts/timeago/locales/zh_CN.js +17 -17
  36. data/assets/javascripts/timeago/locales/zh_TW.js +17 -17
  37. data/assets/javascripts/timeago.js +261 -258
  38. data/assets/javascripts/timeago.locales.js +1 -1
  39. data/lib/timeago_js/version.rb +1 -1
  40. metadata +4 -2
@@ -1,258 +1,261 @@
1
- /**
2
- * Copyright (c) 2016 hustcc
3
- * License: MIT
4
- * Version: v3.0.0
5
- * https://github.com/hustcc/timeago.js
6
- **/
7
- /* jshint expr: true */
8
- !function (root, factory) {
9
- if (typeof module === 'object' && module.exports) {
10
- module.exports = factory(root); // nodejs support
11
- module.exports['default'] = module.exports; // es6 support
12
- }
13
- else
14
- root.timeago = factory(root);
15
- }(typeof window !== 'undefined' ? window : this,
16
- function () {
17
- var indexMapEn = 'second_minute_hour_day_week_month_year'.split('_'),
18
- indexMapZh = '秒_分钟_小时_天_周_月_年'.split('_'),
19
- // build-in locales: en & zh_CN
20
- locales = {
21
- 'en': function(number, index) {
22
- if (index === 0) return ['just now', 'right now'];
23
- var unit = indexMapEn[parseInt(index / 2)];
24
- if (number > 1) unit += 's';
25
- return [number + ' ' + unit + ' ago', 'in ' + number + ' ' + unit];
26
- },
27
- 'zh_CN': function(number, index) {
28
- if (index === 0) return ['刚刚', '片刻后'];
29
- var unit = indexMapZh[parseInt(index / 2)];
30
- return [number + unit + '前', number + unit + '后'];
31
- }
32
- },
33
- // second, minute, hour, day, week, month, year(365 days)
34
- SEC_ARRAY = [60, 60, 24, 7, 365/7/12, 12],
35
- SEC_ARRAY_LEN = 6,
36
- ATTR_DATETIME = 'datetime',
37
- ATTR_DATA_TID = 'data-tid',
38
- timers = {}; // real-time render timers
39
-
40
- // format Date / string / timestamp to Date instance.
41
- function toDate(input) {
42
- if (input instanceof Date) return input;
43
- if (!isNaN(input)) return new Date(toInt(input));
44
- if (/^\d+$/.test(input)) return new Date(toInt(input));
45
- input = (input || '').trim().replace(/\.\d+/, '') // remove milliseconds
46
- .replace(/-/, '/').replace(/-/, '/')
47
- .replace(/(\d)T(\d)/, '$1 $2').replace(/Z/, ' UTC') // 2017-2-5T3:57:52Z -> 2017-2-5 3:57:52UTC
48
- .replace(/([\+\-]\d\d)\:?(\d\d)/, ' $1$2'); // -04:00 -> -0400
49
- return new Date(input);
50
- }
51
- // change f into int, remove decimal. Just for code compression
52
- function toInt(f) {
53
- return parseInt(f);
54
- }
55
- // format the diff second to *** time ago, with setting locale
56
- function formatDiff(diff, locale, defaultLocale) {
57
- // if locale is not exist, use defaultLocale.
58
- // if defaultLocale is not exist, use build-in `en`.
59
- // be sure of no error when locale is not exist.
60
- locale = locales[locale] ? locale : (locales[defaultLocale] ? defaultLocale : 'en');
61
- // if (! locales[locale]) locale = defaultLocale;
62
- var i = 0,
63
- agoin = diff < 0 ? 1 : 0, // timein or timeago
64
- total_sec = diff = Math.abs(diff);
65
-
66
- for (; diff >= SEC_ARRAY[i] && i < SEC_ARRAY_LEN; i++) {
67
- diff /= SEC_ARRAY[i];
68
- }
69
- diff = toInt(diff);
70
- i *= 2;
71
-
72
- if (diff > (i === 0 ? 9 : 1)) i += 1;
73
- return locales[locale](diff, i, total_sec)[agoin].replace('%s', diff);
74
- }
75
- // calculate the diff second between date to be formated an now date.
76
- function diffSec(date, nowDate) {
77
- nowDate = nowDate ? toDate(nowDate) : new Date();
78
- return (nowDate - toDate(date)) / 1000;
79
- }
80
- /**
81
- * nextInterval: calculate the next interval time.
82
- * - diff: the diff sec between now and date to be formated.
83
- *
84
- * What's the meaning?
85
- * diff = 61 then return 59
86
- * diff = 3601 (an hour + 1 second), then return 3599
87
- * make the interval with high performace.
88
- **/
89
- function nextInterval(diff) {
90
- var rst = 1, i = 0, d = Math.abs(diff);
91
- for (; diff >= SEC_ARRAY[i] && i < SEC_ARRAY_LEN; i++) {
92
- diff /= SEC_ARRAY[i];
93
- rst *= SEC_ARRAY[i];
94
- }
95
- // return leftSec(d, rst);
96
- d = d % rst;
97
- d = d ? rst - d : rst;
98
- return Math.ceil(d);
99
- }
100
- // get the datetime attribute, jQuery and DOM
101
- function getDateAttr(node) {
102
- if(node.dataset.timeago) return node.dataset.timeago; // data-timeago supported
103
- return getAttr(node, ATTR_DATETIME);
104
- }
105
- function getAttr(node, name) {
106
- if(node.getAttribute) return node.getAttribute(name); // native
107
- if(node.attr) return node.attr(name); // jquery
108
- }
109
- function setTidAttr(node, val) {
110
- if(node.setAttribute) return node.setAttribute(ATTR_DATA_TID, val); // native
111
- if(node.attr) return node.attr(ATTR_DATA_TID, val); // jquery
112
- }
113
- function getTidFromNode(node) {
114
- return getAttr(node, ATTR_DATA_TID);
115
- }
116
- /**
117
- * timeago: the function to get `timeago` instance.
118
- * - nowDate: the relative date, default is new Date().
119
- * - defaultLocale: the default locale, default is en. if your set it, then the `locale` parameter of format is not needed of you.
120
- *
121
- * How to use it?
122
- * var timeagoLib = require('timeago.js');
123
- * var timeago = timeagoLib(); // all use default.
124
- * var timeago = timeagoLib('2016-09-10'); // the relative date is 2016-09-10, so the 2016-09-11 will be 1 day ago.
125
- * var timeago = timeagoLib(null, 'zh_CN'); // set default locale is `zh_CN`.
126
- * var timeago = timeagoLib('2016-09-10', 'zh_CN'); // the relative date is 2016-09-10, and locale is zh_CN, so the 2016-09-11 will be 1天前.
127
- **/
128
- function Timeago(nowDate, defaultLocale) {
129
- this.nowDate = nowDate;
130
- // if do not set the defaultLocale, set it with `en`
131
- this.defaultLocale = defaultLocale || 'en'; // use default build-in locale
132
- // for dev test
133
- // this.nextInterval = nextInterval;
134
- }
135
- // what the timer will do
136
- Timeago.prototype.doRender = function(node, date, locale) {
137
- var diff = diffSec(date, this.nowDate),
138
- self = this,
139
- tid;
140
- // delete previously assigned timeout's id to node
141
- node.innerHTML = formatDiff(diff, locale, this.defaultLocale);
142
- // waiting %s seconds, do the next render
143
- timers[tid = setTimeout(function() {
144
- self.doRender(node, date, locale);
145
- delete timers[tid];
146
- }, Math.min(nextInterval(diff) * 1000, 0x7FFFFFFF))] = 0; // there is no need to save node in object.
147
- // set attribute date-tid
148
- setTidAttr(node, tid);
149
- };
150
- /**
151
- * format: format the date to *** time ago, with setting or default locale
152
- * - date: the date / string / timestamp to be formated
153
- * - locale: the formated string's locale name, e.g. en / zh_CN
154
- *
155
- * How to use it?
156
- * var timeago = require('timeago.js')();
157
- * timeago.format(new Date(), 'pl'); // Date instance
158
- * timeago.format('2016-09-10', 'fr'); // formated date string
159
- * timeago.format(1473473400269); // timestamp with ms
160
- **/
161
- Timeago.prototype.format = function(date, locale) {
162
- return formatDiff(diffSec(date, this.nowDate), locale, this.defaultLocale);
163
- };
164
- /**
165
- * render: render the DOM real-time.
166
- * - nodes: which nodes will be rendered.
167
- * - locale: the locale name used to format date.
168
- *
169
- * How to use it?
170
- * var timeago = require('timeago.js')();
171
- * // 1. javascript selector
172
- * timeago.render(document.querySelectorAll('.need_to_be_rendered'));
173
- * // 2. use jQuery selector
174
- * timeago.render($('.need_to_be_rendered'), 'pl');
175
- *
176
- * Notice: please be sure the dom has attribute `datetime`.
177
- **/
178
- Timeago.prototype.render = function(nodes, locale) {
179
- if (nodes.length === undefined) nodes = [nodes];
180
- for (var i = 0, len = nodes.length; i < len; i++) {
181
- this.doRender(nodes[i], getDateAttr(nodes[i]), locale); // render item
182
- }
183
- };
184
- /**
185
- * setLocale: set the default locale name.
186
- *
187
- * How to use it?
188
- * var timeago = require('timeago.js')();
189
- * timeago.setLocale('fr');
190
- **/
191
- Timeago.prototype.setLocale = function(locale) {
192
- this.defaultLocale = locale;
193
- };
194
- /**
195
- * timeago: the function to get `timeago` instance.
196
- * - nowDate: the relative date, default is new Date().
197
- * - defaultLocale: the default locale, default is en. if your set it, then the `locale` parameter of format is not needed of you.
198
- *
199
- * How to use it?
200
- * var timeagoFactory = require('timeago.js');
201
- * var timeago = timeagoFactory(); // all use default.
202
- * var timeago = timeagoFactory('2016-09-10'); // the relative date is 2016-09-10, so the 2016-09-11 will be 1 day ago.
203
- * var timeago = timeagoFactory(null, 'zh_CN'); // set default locale is `zh_CN`.
204
- * var timeago = timeagoFactory('2016-09-10', 'zh_CN'); // the relative date is 2016-09-10, and locale is zh_CN, so the 2016-09-11 will be 1天前.
205
- **/
206
- function timeagoFactory(nowDate, defaultLocale) {
207
- return new Timeago(nowDate, defaultLocale);
208
- }
209
- /**
210
- * register: register a new language locale
211
- * - locale: locale name, e.g. en / zh_CN, notice the standard.
212
- * - localeFunc: the locale process function
213
- *
214
- * How to use it?
215
- * var timeagoFactory = require('timeago.js');
216
- *
217
- * timeagoFactory.register('the locale name', the_locale_func);
218
- * // or
219
- * timeagoFactory.register('pl', require('timeago.js/locales/pl'));
220
- **/
221
- timeagoFactory.register = function(locale, localeFunc) {
222
- locales[locale] = localeFunc;
223
- };
224
-
225
- /**
226
- * cancel: cancels one or all the timers which are doing real-time render.
227
- *
228
- * How to use it?
229
- * For canceling all the timers:
230
- * var timeagoFactory = require('timeago.js');
231
- * var timeago = timeagoFactory();
232
- * timeago.render(document.querySelectorAll('.need_to_be_rendered'));
233
- * timeagoFactory.cancel(); // will stop all the timers, stop render in real time.
234
- *
235
- * For canceling single timer on specific node:
236
- * var timeagoFactory = require('timeago.js');
237
- * var timeago = timeagoFactory();
238
- * var nodes = document.querySelectorAll('.need_to_be_rendered');
239
- * timeago.render(nodes);
240
- * timeagoFactory.cancel(nodes[0]); // will clear a timer attached to the first node, stop render in real time.
241
- **/
242
- timeagoFactory.cancel = function(node) {
243
- var tid;
244
- // assigning in if statement to save space
245
- if (node) {
246
- tid = getTidFromNode(node);
247
- if (tid) {
248
- clearTimeout(tid);
249
- delete timers[tid];
250
- }
251
- } else {
252
- for (tid in timers) clearTimeout(tid);
253
- timers = {};
254
- }
255
- };
256
-
257
- return timeagoFactory;
258
- });
1
+ /**
2
+ * Copyright (c) 2016 hustcc
3
+ * License: MIT
4
+ * Version: v3.0.2
5
+ * https://github.com/hustcc/timeago.js
6
+ **/
7
+ /* jshint expr: true */
8
+ !function (root, factory) {
9
+ if (typeof module === 'object' && module.exports) {
10
+ module.exports = factory(root); // nodejs support
11
+ module.exports['default'] = module.exports; // es6 support
12
+ }
13
+ else
14
+ root.timeago = factory(root);
15
+ }(typeof window !== 'undefined' ? window : this,
16
+ function () {
17
+ var indexMapEn = 'second_minute_hour_day_week_month_year'.split('_'),
18
+ indexMapZh = '秒_分钟_小时_天_周_月_年'.split('_'),
19
+ // build-in locales: en & zh_CN
20
+ locales = {
21
+ 'en': function(number, index) {
22
+ if (index === 0) return ['just now', 'right now'];
23
+ var unit = indexMapEn[parseInt(index / 2)];
24
+ if (number > 1) unit += 's';
25
+ return [number + ' ' + unit + ' ago', 'in ' + number + ' ' + unit];
26
+ },
27
+ 'zh_CN': function(number, index) {
28
+ if (index === 0) return ['刚刚', '片刻后'];
29
+ var unit = indexMapZh[parseInt(index / 2)];
30
+ return [number + unit + '前', number + unit + '后'];
31
+ }
32
+ },
33
+ // second, minute, hour, day, week, month, year(365 days)
34
+ SEC_ARRAY = [60, 60, 24, 7, 365/7/12, 12],
35
+ SEC_ARRAY_LEN = 6,
36
+ // ATTR_DATETIME = 'datetime',
37
+ ATTR_DATA_TID = 'data-tid',
38
+ timers = {}; // real-time render timers
39
+
40
+ // format Date / string / timestamp to Date instance.
41
+ function toDate(input) {
42
+ if (input instanceof Date) return input;
43
+ if (!isNaN(input)) return new Date(toInt(input));
44
+ if (/^\d+$/.test(input)) return new Date(toInt(input));
45
+ input = (input || '').trim().replace(/\.\d+/, '') // remove milliseconds
46
+ .replace(/-/, '/').replace(/-/, '/')
47
+ .replace(/(\d)T(\d)/, '$1 $2').replace(/Z/, ' UTC') // 2017-2-5T3:57:52Z -> 2017-2-5 3:57:52UTC
48
+ .replace(/([\+\-]\d\d)\:?(\d\d)/, ' $1$2'); // -04:00 -> -0400
49
+ return new Date(input);
50
+ }
51
+ // change f into int, remove decimal. Just for code compression
52
+ function toInt(f) {
53
+ return parseInt(f);
54
+ }
55
+ // format the diff second to *** time ago, with setting locale
56
+ function formatDiff(diff, locale, defaultLocale) {
57
+ // if locale is not exist, use defaultLocale.
58
+ // if defaultLocale is not exist, use build-in `en`.
59
+ // be sure of no error when locale is not exist.
60
+ locale = locales[locale] ? locale : (locales[defaultLocale] ? defaultLocale : 'en');
61
+ // if (! locales[locale]) locale = defaultLocale;
62
+ var i = 0,
63
+ agoin = diff < 0 ? 1 : 0, // timein or timeago
64
+ total_sec = diff = Math.abs(diff);
65
+
66
+ for (; diff >= SEC_ARRAY[i] && i < SEC_ARRAY_LEN; i++) {
67
+ diff /= SEC_ARRAY[i];
68
+ }
69
+ diff = toInt(diff);
70
+ i *= 2;
71
+
72
+ if (diff > (i === 0 ? 9 : 1)) i += 1;
73
+ return locales[locale](diff, i, total_sec)[agoin].replace('%s', diff);
74
+ }
75
+ // calculate the diff second between date to be formated an now date.
76
+ function diffSec(date, nowDate) {
77
+ nowDate = nowDate ? toDate(nowDate) : new Date();
78
+ return (nowDate - toDate(date)) / 1000;
79
+ }
80
+ /**
81
+ * nextInterval: calculate the next interval time.
82
+ * - diff: the diff sec between now and date to be formated.
83
+ *
84
+ * What's the meaning?
85
+ * diff = 61 then return 59
86
+ * diff = 3601 (an hour + 1 second), then return 3599
87
+ * make the interval with high performace.
88
+ **/
89
+ function nextInterval(diff) {
90
+ var rst = 1, i = 0, d = Math.abs(diff);
91
+ for (; diff >= SEC_ARRAY[i] && i < SEC_ARRAY_LEN; i++) {
92
+ diff /= SEC_ARRAY[i];
93
+ rst *= SEC_ARRAY[i];
94
+ }
95
+ // return leftSec(d, rst);
96
+ d = d % rst;
97
+ d = d ? rst - d : rst;
98
+ return Math.ceil(d);
99
+ }
100
+ // get the datetime attribute, `data-timeagp` / `datetime` are supported.
101
+ function getDateAttr(node) {
102
+ return getAttr(node, 'data-timeago') || getAttr(node, 'datetime');
103
+ }
104
+ // get the node attribute, native DOM and jquery supported.
105
+ function getAttr(node, name) {
106
+ if(node.getAttribute) return node.getAttribute(name); // native
107
+ if(node.attr) return node.attr(name); // jquery
108
+ }
109
+ // set the node attribute, native DOM and jquery supported.
110
+ function setTidAttr(node, val) {
111
+ if(node.setAttribute) return node.setAttribute(ATTR_DATA_TID, val); // native
112
+ if(node.attr) return node.attr(ATTR_DATA_TID, val); // jquery
113
+ }
114
+ // get the timer id of node.
115
+ // remove the function, can save some bytes.
116
+ // function getTidFromNode(node) {
117
+ // return getAttr(node, ATTR_DATA_TID);
118
+ // }
119
+ /**
120
+ * timeago: the function to get `timeago` instance.
121
+ * - nowDate: the relative date, default is new Date().
122
+ * - defaultLocale: the default locale, default is en. if your set it, then the `locale` parameter of format is not needed of you.
123
+ *
124
+ * How to use it?
125
+ * var timeagoLib = require('timeago.js');
126
+ * var timeago = timeagoLib(); // all use default.
127
+ * var timeago = timeagoLib('2016-09-10'); // the relative date is 2016-09-10, so the 2016-09-11 will be 1 day ago.
128
+ * var timeago = timeagoLib(null, 'zh_CN'); // set default locale is `zh_CN`.
129
+ * var timeago = timeagoLib('2016-09-10', 'zh_CN'); // the relative date is 2016-09-10, and locale is zh_CN, so the 2016-09-11 will be 1天前.
130
+ **/
131
+ function Timeago(nowDate, defaultLocale) {
132
+ this.nowDate = nowDate;
133
+ // if do not set the defaultLocale, set it with `en`
134
+ this.defaultLocale = defaultLocale || 'en'; // use default build-in locale
135
+ // for dev test
136
+ // this.nextInterval = nextInterval;
137
+ }
138
+ // what the timer will do
139
+ Timeago.prototype.doRender = function(node, date, locale) {
140
+ var diff = diffSec(date, this.nowDate),
141
+ self = this,
142
+ tid;
143
+ // delete previously assigned timeout's id to node
144
+ node.innerHTML = formatDiff(diff, locale, this.defaultLocale);
145
+ // waiting %s seconds, do the next render
146
+ timers[tid = setTimeout(function() {
147
+ self.doRender(node, date, locale);
148
+ delete timers[tid];
149
+ }, Math.min(nextInterval(diff) * 1000, 0x7FFFFFFF))] = 0; // there is no need to save node in object.
150
+ // set attribute date-tid
151
+ setTidAttr(node, tid);
152
+ };
153
+ /**
154
+ * format: format the date to *** time ago, with setting or default locale
155
+ * - date: the date / string / timestamp to be formated
156
+ * - locale: the formated string's locale name, e.g. en / zh_CN
157
+ *
158
+ * How to use it?
159
+ * var timeago = require('timeago.js')();
160
+ * timeago.format(new Date(), 'pl'); // Date instance
161
+ * timeago.format('2016-09-10', 'fr'); // formated date string
162
+ * timeago.format(1473473400269); // timestamp with ms
163
+ **/
164
+ Timeago.prototype.format = function(date, locale) {
165
+ return formatDiff(diffSec(date, this.nowDate), locale, this.defaultLocale);
166
+ };
167
+ /**
168
+ * render: render the DOM real-time.
169
+ * - nodes: which nodes will be rendered.
170
+ * - locale: the locale name used to format date.
171
+ *
172
+ * How to use it?
173
+ * var timeago = require('timeago.js')();
174
+ * // 1. javascript selector
175
+ * timeago.render(document.querySelectorAll('.need_to_be_rendered'));
176
+ * // 2. use jQuery selector
177
+ * timeago.render($('.need_to_be_rendered'), 'pl');
178
+ *
179
+ * Notice: please be sure the dom has attribute `datetime`.
180
+ **/
181
+ Timeago.prototype.render = function(nodes, locale) {
182
+ if (nodes.length === undefined) nodes = [nodes];
183
+ for (var i = 0, len = nodes.length; i < len; i++) {
184
+ this.doRender(nodes[i], getDateAttr(nodes[i]), locale); // render item
185
+ }
186
+ };
187
+ /**
188
+ * setLocale: set the default locale name.
189
+ *
190
+ * How to use it?
191
+ * var timeago = require('timeago.js')();
192
+ * timeago.setLocale('fr');
193
+ **/
194
+ Timeago.prototype.setLocale = function(locale) {
195
+ this.defaultLocale = locale;
196
+ };
197
+ /**
198
+ * timeago: the function to get `timeago` instance.
199
+ * - nowDate: the relative date, default is new Date().
200
+ * - defaultLocale: the default locale, default is en. if your set it, then the `locale` parameter of format is not needed of you.
201
+ *
202
+ * How to use it?
203
+ * var timeagoFactory = require('timeago.js');
204
+ * var timeago = timeagoFactory(); // all use default.
205
+ * var timeago = timeagoFactory('2016-09-10'); // the relative date is 2016-09-10, so the 2016-09-11 will be 1 day ago.
206
+ * var timeago = timeagoFactory(null, 'zh_CN'); // set default locale is `zh_CN`.
207
+ * var timeago = timeagoFactory('2016-09-10', 'zh_CN'); // the relative date is 2016-09-10, and locale is zh_CN, so the 2016-09-11 will be 1天前.
208
+ **/
209
+ function timeagoFactory(nowDate, defaultLocale) {
210
+ return new Timeago(nowDate, defaultLocale);
211
+ }
212
+ /**
213
+ * register: register a new language locale
214
+ * - locale: locale name, e.g. en / zh_CN, notice the standard.
215
+ * - localeFunc: the locale process function
216
+ *
217
+ * How to use it?
218
+ * var timeagoFactory = require('timeago.js');
219
+ *
220
+ * timeagoFactory.register('the locale name', the_locale_func);
221
+ * // or
222
+ * timeagoFactory.register('pl', require('timeago.js/locales/pl'));
223
+ **/
224
+ timeagoFactory.register = function(locale, localeFunc) {
225
+ locales[locale] = localeFunc;
226
+ };
227
+
228
+ /**
229
+ * cancel: cancels one or all the timers which are doing real-time render.
230
+ *
231
+ * How to use it?
232
+ * For canceling all the timers:
233
+ * var timeagoFactory = require('timeago.js');
234
+ * var timeago = timeagoFactory();
235
+ * timeago.render(document.querySelectorAll('.need_to_be_rendered'));
236
+ * timeagoFactory.cancel(); // will stop all the timers, stop render in real time.
237
+ *
238
+ * For canceling single timer on specific node:
239
+ * var timeagoFactory = require('timeago.js');
240
+ * var timeago = timeagoFactory();
241
+ * var nodes = document.querySelectorAll('.need_to_be_rendered');
242
+ * timeago.render(nodes);
243
+ * timeagoFactory.cancel(nodes[0]); // will clear a timer attached to the first node, stop render in real time.
244
+ **/
245
+ timeagoFactory.cancel = function(node) {
246
+ var tid;
247
+ // assigning in if statement to save space
248
+ if (node) {
249
+ tid = getAttr(node, ATTR_DATA_TID); // get the timer of DOM node(native / jq).
250
+ if (tid) {
251
+ clearTimeout(tid);
252
+ delete timers[tid];
253
+ }
254
+ } else {
255
+ for (tid in timers) clearTimeout(tid);
256
+ timers = {};
257
+ }
258
+ };
259
+
260
+ return timeagoFactory;
261
+ });