timeago.js 2.0.4 → 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 (83) hide show
  1. package/.npmignore +8 -7
  2. package/.travis.yml +2 -2
  3. package/LICENSE +20 -20
  4. package/README.md +189 -176
  5. package/README_zh.md +172 -162
  6. package/bower.json +21 -21
  7. package/demo/index.html +121 -0
  8. package/demo/index.js +25 -16
  9. package/dist/timeago.js +261 -241
  10. package/dist/timeago.locales.min.js +1 -1
  11. package/dist/timeago.min.js +1 -1
  12. package/gulpfile.js +13 -13
  13. package/index.html +185 -181
  14. package/locales/ar.js +26 -45
  15. package/locales/be.js +51 -51
  16. package/locales/bg.js +18 -18
  17. package/locales/ca.js +18 -18
  18. package/locales/da.js +18 -18
  19. package/locales/de.js +18 -18
  20. package/locales/el.js +18 -18
  21. package/locales/en.js +18 -18
  22. package/locales/en_short.js +17 -17
  23. package/locales/es.js +17 -17
  24. package/locales/eu.js +18 -18
  25. package/locales/fa.js +18 -0
  26. package/locales/fi.js +18 -18
  27. package/locales/fr.js +17 -17
  28. package/locales/he.js +18 -18
  29. package/locales/hu.js +18 -18
  30. package/locales/in_ID.js +18 -18
  31. package/locales/it.js +18 -18
  32. package/locales/ja.js +18 -18
  33. package/locales/ko.js +17 -17
  34. package/locales/locales.js +6 -6
  35. package/locales/ml.js +18 -18
  36. package/locales/my.js +18 -0
  37. package/locales/nl.js +18 -18
  38. package/locales/pl.js +34 -35
  39. package/locales/pt_BR.js +18 -18
  40. package/locales/ro.js +29 -29
  41. package/locales/ru.js +51 -51
  42. package/locales/sv.js +18 -18
  43. package/locales/ta.js +17 -17
  44. package/locales/th.js +18 -18
  45. package/locales/tr.js +18 -18
  46. package/locales/uk.js +40 -40
  47. package/locales/vi.js +18 -18
  48. package/locales/zh_CN.js +17 -17
  49. package/locales/zh_TW.js +17 -17
  50. package/package.json +49 -44
  51. package/src/timeago.js +261 -241
  52. package/src/timeago.locales.js +12 -12
  53. package/tests/locales/ar.js +66 -66
  54. package/tests/locales/be.js +63 -63
  55. package/tests/locales/bg.js +63 -63
  56. package/tests/locales/ca.js +64 -64
  57. package/tests/locales/en.js +62 -62
  58. package/tests/locales/en_short.js +62 -62
  59. package/tests/locales/eu.js +63 -63
  60. package/tests/locales/fa.js +63 -0
  61. package/tests/locales/fi.js +43 -43
  62. package/tests/locales/he.js +62 -62
  63. package/tests/locales/in_BG.js +63 -63
  64. package/tests/locales/in_HI.js +63 -63
  65. package/tests/locales/in_ID.js +62 -62
  66. package/tests/locales/ja.js +62 -62
  67. package/tests/locales/ko.js +62 -62
  68. package/tests/locales/my.js +63 -0
  69. package/tests/locales/pl.js +91 -0
  70. package/tests/locales/ro.js +61 -61
  71. package/tests/locales/ru.js +63 -63
  72. package/tests/locales/ta.js +62 -62
  73. package/tests/locales/tr.js +63 -63
  74. package/tests/locales/uk.js +63 -63
  75. package/tests/locales/vi.js +63 -63
  76. package/tests/locales/zh_CN.js +62 -62
  77. package/tests/locales_test.js +51 -51
  78. package/tests/test-builder.js +247 -247
  79. package/tests/test.js +83 -83
  80. package/tests/test_dev.js +44 -44
  81. package/tests/test_ts.ts +7 -0
  82. package/timeago.d.ts +15 -0
  83. package/webpack.config.js +10 -10
package/README_zh.md CHANGED
@@ -1,162 +1,172 @@
1
- # timeago.js
2
-
3
- > **timeago.js** 是一个非常简洁、轻量级、不到 `2kb` 的很简洁的Javascript库,用来将datetime时间转化成类似于`*** 时间前`的描述字符串,例如:“3小时前”。
4
-
5
- - 本地化支持,默认自带中文和英文语言,基本够用;
6
- - 之前 xxx 时间前、xxx 时间后;
7
- - 支持自动实时更新;
8
- - 支持npm方式和浏览器script方式;
9
- - 测试用例完善,执行良好;
10
-
11
- [Official website](http://timeago.org/)。关于Python的版本,可以看 [timeago](https://github.com/hustcc/timeago).
12
-
13
- [![Build Status](https://travis-ci.org/hustcc/timeago.js.svg?branch=master)](https://travis-ci.org/hustcc/timeago.js) [![npm](https://img.shields.io/npm/v/timeago.js.svg?style=flat-square)](https://www.npmjs.com/package/timeago.js) [![npm](https://img.shields.io/npm/dt/timeago.js.svg?style=flat-square)](https://www.npmjs.com/package/timeago.js) [![npm](https://img.shields.io/npm/l/timeago.js.svg?style=flat-square)](https://www.npmjs.com/package/timeago.js)
14
-
15
- ```
16
- 刚刚
17
- 12秒前
18
- 3分钟前
19
- 2小时前
20
- 4天前
21
- 3周前
22
- 6月前
23
- 3年前
24
-
25
- 12秒后
26
- 3分钟后
27
- 2小时后
28
- 24天后
29
- 6月后
30
- 3年后
31
- ```
32
-
33
-
34
- # 使用方法
35
-
36
- **1. 下载 timeago.js**
37
-
38
- ```sh
39
- npm install timeago.js
40
- ```
41
-
42
- **2. 引入 timeago.js**
43
-
44
-
45
- 使用import引入,然后可以得到一个全局变量: `timeago`.
46
-
47
- ```js
48
- import timeago from 'timeago.js';
49
-
50
- // 或者
51
-
52
- var timeago = require("timeago.js");
53
- ```
54
-
55
- 或者直接通过 `script` 标签引入到html文件中.
56
-
57
- ```js
58
- <script src="dist/timeago.min.js"></script>
59
- ```
60
-
61
- **3. 使用 `timeago` 类**
62
-
63
- ```js
64
- var timeago = new timeago();
65
- timeago.format('2016-06-12')
66
- ```
67
-
68
-
69
- # 高级特性使用
70
-
71
-
72
- **1. 设置相对日期**
73
-
74
- `timeago` 默认是相对于当前时间的,当然也可以自己设置相对的时间,如下所示:
75
-
76
- ```js
77
- var timeagoInstance = new timeago(null, '2016-06-10 12:12:12'); // 在这里设置相对时间
78
- timeagoInstance.format('2016-06-12', 'zh_CN');
79
- ```
80
-
81
- **2. 格式化时间戳,字符串**
82
-
83
- ```js
84
- new timeago().format(new Date().getTime() - 11 * 1000 * 60 * 60); // will get '11 hours ago'
85
- ```
86
-
87
- **3. 自动实时渲染**
88
-
89
- HTML为:
90
- ```html
91
- <div class="need_to_be_rendered" data-timeago="2016-06-30 09:20:00"></div>
92
- ```
93
- Js代码为:
94
- ```js
95
- var timeagoInstance = new timeago();
96
- timeagoInstance.render(document.querySelectorAll('.need_to_be_rendered'), 'zh_CN');
97
-
98
- // or
99
-
100
- timeagoInstance.cancel()
101
- ```
102
-
103
- API方法 `render` 可以传入一个DOM节点或者数据,标示需要实时渲染这些节点。
104
-
105
- API方法 `cancel` 调用之后会清除所有的定时器方法,并且释放所有定时器资源。
106
-
107
- 被渲染的节点必须要有 `datetime` 或者 `data-timeago` 属性,属性值为日期格式的字符串。
108
-
109
- **4. 本地化**
110
-
111
- 默认的语言是英文 **`en`**, 这个库自带语言有 `en` and `zh_CN` (英文和中文).
112
-
113
- ```js
114
- var timeagoInstance = new timeago();
115
- timeagoInstance.format('2016-06-12', 'zh_CN');
116
- ```
117
-
118
- 可以在构造函数中传入默认语言,也可以调用 `setLocale` 方法。
119
-
120
- ```js
121
- var timeagoInstance = new timeago(currentDate, 'zh_CN');
122
- // or
123
- new timeago().setLocale('zh_CN');
124
- ```
125
-
126
- **5. 注册本地语言**
127
-
128
- 你可以自己自定义注册 `register` 你自己的语言. 如下所示,所有的键值都必须存在,不然可能会出错. e.g.
129
-
130
- ```js
131
- // 本地化的字典样式
132
- var test_local_dict = function(number, index) {
133
- // number: xxx 时间前 / 后的数字;
134
- // index: 下面数组的索引号;
135
- return [
136
- ['just now', 'a while'],
137
- ['%s seconds ago', 'in %s seconds'],
138
- ['1 minute ago', 'in 1 minute'],
139
- ['%s minutes ago', 'in %s minutes'],
140
- ['1 hour ago', 'in 1 hour'],
141
- ['%s hours ago', 'in %s hours'],
142
- ['1 day ago', 'in 1 day'],
143
- ['%s days ago', 'in %s days'],
144
- ['1 week ago', 'in 1 week'],
145
- ['%s weeks ago', 'in %s weeks'],
146
- ['1 month ago', 'in 1 month'],
147
- ['%s months ago', 'in %s months'],
148
- ['1 year ago', 'in 1 year'],
149
- ['%s years ago', 'in %s years']
150
- ][index];
151
- };
152
-
153
- timeago.register('test_local', test_local_dict);
154
-
155
- var timeagoInstance = new timeago();
156
- timeagoInstance.format('2016-06-12', 'test_local');
157
- ```
158
- 欢迎发起 PR 添加一些缺失的 locale 语言,当然请注意,在 `tests/locales` 目录中添加对应的测试用例。
159
-
160
- # LICENSE
161
-
162
- MIT
1
+ # timeago.js
2
+
3
+ > **timeago.js** 是一个非常简洁、轻量级、不到 `2kb` 的很简洁的 Javascript 库,用来将 datetime 时间转化成类似于`*** 时间前`的描述字符串,例如:“3小时前”。
4
+
5
+ - 本地化支持,默认自带中文和英文语言,基本够用;
6
+ - 之前 xxx 时间前、xxx 时间后;
7
+ - 支持自动实时更新;
8
+ - 支持npm方式和浏览器script方式;
9
+ - 测试用例完善,执行良好;
10
+
11
+ [Official website](http://timeago.org/)。关于Python的版本,可以看 [timeago](https://github.com/hustcc/timeago).
12
+
13
+ [![Build Status](https://img.shields.io/travis/hustcc/timeago.js.svg?style=flat-square)](https://travis-ci.org/hustcc/timeago.js) [![CDNJS](https://img.shields.io/cdnjs/v/timeago.js.svg?style=flat-square)](https://cdnjs.com/libraries/timeago.js) [![npm](https://img.shields.io/npm/v/timeago.js.svg?style=flat-square)](https://www.npmjs.com/package/timeago.js) [![npm](https://img.shields.io/npm/dt/timeago.js.svg?style=flat-square)](https://www.npmjs.com/package/timeago.js) [![npm](https://img.shields.io/npm/l/timeago.js.svg?style=flat-square)](https://www.npmjs.com/package/timeago.js)
14
+
15
+ ```
16
+ 刚刚
17
+ 12秒前
18
+ 3分钟前
19
+ 2小时前
20
+ 4天前
21
+ 3周前
22
+ 6月前
23
+ 3年前
24
+
25
+ 12秒后
26
+ 3分钟后
27
+ 2小时后
28
+ 24天后
29
+ 6月后
30
+ 3年后
31
+ ```
32
+
33
+
34
+ # 使用方法
35
+
36
+ **1. 下载 timeago.js**
37
+
38
+ ```sh
39
+ npm install timeago.js
40
+ ```
41
+
42
+ **2. 引入 timeago.js**
43
+
44
+ 使用import引入,然后可以得到一个全局变量: `timeago`.
45
+
46
+ ```js
47
+ import timeago from 'timeago.js';
48
+
49
+ // 或者
50
+
51
+ var timeago = require("timeago.js");
52
+ ```
53
+
54
+ 或者直接通过 `script` 标签引入到html文件中.
55
+
56
+ ```js
57
+ <script src="dist/timeago.min.js"></script>
58
+ ```
59
+
60
+ 或者在 typescript 文件中引入.
61
+
62
+ ```ts
63
+ import timeago from 'timeago.js';
64
+
65
+ // or
66
+
67
+ import timeago = require("timeago.js");
68
+ ```
69
+
70
+ **3. 使用 `timeago` 类**
71
+
72
+ ```js
73
+ var timeago = timeago();
74
+ timeago.format('2016-06-12')
75
+ ```
76
+
77
+
78
+ # 高级特性使用
79
+
80
+
81
+ **1. 设置相对日期**
82
+
83
+ `timeago` 默认是相对于当前时间的,当然也可以自己设置相对的时间,如下所示:
84
+
85
+ ```js
86
+ var timeagoInstance = timeago(null, '2016-06-10 12:12:12'); // 在这里设置相对时间
87
+ timeagoInstance.format('2016-06-12', 'zh_CN');
88
+ ```
89
+
90
+ **2. 格式化时间戳,字符串**
91
+
92
+ ```js
93
+ timeago().format(Date.now() - 11 * 1000 * 60 * 60); // will get '11 hours ago'
94
+ ```
95
+
96
+ **3. 自动实时渲染**
97
+
98
+ HTML为:
99
+ ```html
100
+ <div class="need_to_be_rendered" data-timeago="2016-06-30 09:20:00"></div>
101
+ ```
102
+ Js代码为:
103
+ ```js
104
+ var timeagoInstance = timeago();
105
+ timeagoInstance.render(document.querySelectorAll('.need_to_be_rendered'), 'zh_CN');
106
+
107
+ // or
108
+
109
+ timeagoInstance.cancel()
110
+ ```
111
+
112
+ API方法 `render` 可以传入一个DOM节点或者数据,标示需要实时渲染这些节点。
113
+
114
+ API方法 `cancel` 调用之后会清除所有的定时器方法,并且释放所有定时器资源。当然也可以传入一个 node 节点,仅仅曲线这个节点的定时器方法。
115
+
116
+ 被渲染的节点必须要有 `datetime` 或者 `data-timeago` 属性,属性值为日期格式的字符串。
117
+
118
+ **4. 本地化**
119
+
120
+ 默认的语言是英文 **`en`**, 这个库自带语言有 `en` and `zh_CN` (英文和中文).
121
+
122
+ ```js
123
+ var timeagoInstance = timeago();
124
+ timeagoInstance.format('2016-06-12', 'zh_CN');
125
+ ```
126
+
127
+ 可以在构造函数中传入默认语言,也可以调用 `setLocale` 方法。
128
+
129
+ ```js
130
+ var timeagoInstance = timeago(currentDate, 'zh_CN');
131
+ // or
132
+ timeago().setLocale('zh_CN');
133
+ ```
134
+
135
+ **5. 注册本地语言**
136
+
137
+ 你可以自己自定义注册 `register` 你自己的语言。 如下所示,所有的键值都必须存在,不然可能会出错。 e.g.
138
+
139
+ ```js
140
+ // 本地化的字典样式
141
+ var test_local_dict = function(number, index, total_sec) {
142
+ // number:xxx 时间前 / 后的数字;
143
+ // index:下面数组的索引号;
144
+ // total_sec:时间间隔的总秒数;
145
+ return [
146
+ ['just now', 'a while'],
147
+ ['%s seconds ago', 'in %s seconds'],
148
+ ['1 minute ago', 'in 1 minute'],
149
+ ['%s minutes ago', 'in %s minutes'],
150
+ ['1 hour ago', 'in 1 hour'],
151
+ ['%s hours ago', 'in %s hours'],
152
+ ['1 day ago', 'in 1 day'],
153
+ ['%s days ago', 'in %s days'],
154
+ ['1 week ago', 'in 1 week'],
155
+ ['%s weeks ago', 'in %s weeks'],
156
+ ['1 month ago', 'in 1 month'],
157
+ ['%s months ago', 'in %s months'],
158
+ ['1 year ago', 'in 1 year'],
159
+ ['%s years ago', 'in %s years']
160
+ ][index];
161
+ };
162
+
163
+ timeago.register('test_local', test_local_dict);
164
+
165
+ var timeagoInstance = timeago();
166
+ timeagoInstance.format('2016-06-12', 'test_local');
167
+ ```
168
+ 欢迎发起 PR 添加一些缺失的 locale 语言,当然请注意,在 `tests/locales` 目录中添加对应的测试用例。
169
+
170
+ # LICENSE
171
+
172
+ MIT@[https://github.com/hustcc](hustcc)
package/bower.json CHANGED
@@ -1,22 +1,22 @@
1
- {
2
- "name": "timeago.js",
3
- "description": "timeago.js is a simple library (only 2kb) to used to format datetime with `*** time ago` statement. eg: '3 hours ago'. localization supported.",
4
- "main": "dist/timeago.min.js",
5
- "authors": [
6
- "Hustcc <i@hust.cc>"
7
- ],
8
- "license": "MIT",
9
- "keywords": [
10
- "timeago",
11
- "datetime",
12
- "*** time ago",
13
- "date",
14
- "javascript timeago"
15
- ],
16
- "homepage": "https://github.com/hustcc/timeago.js",
17
- "ignore": [
18
- "**/.*",
19
- "node_modules",
20
- "bower_components"
21
- ]
1
+ {
2
+ "name": "timeago.js",
3
+ "description": "timeago.js is a simple library (only 2kb) to used to format datetime with `*** time ago` statement. eg: '3 hours ago'. localization supported.",
4
+ "main": "dist/timeago.min.js",
5
+ "authors": [
6
+ "Hustcc <i@hust.cc>"
7
+ ],
8
+ "license": "MIT",
9
+ "keywords": [
10
+ "timeago",
11
+ "datetime",
12
+ "*** time ago",
13
+ "date",
14
+ "javascript timeago"
15
+ ],
16
+ "homepage": "https://github.com/hustcc/timeago.js",
17
+ "ignore": [
18
+ "**/.*",
19
+ "node_modules",
20
+ "bower_components"
21
+ ]
22
22
  }
@@ -0,0 +1,121 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5
+ <title>timeago.js: testcases.</title>
6
+ <meta name="keywords" content="timeago, timeago.js, datetime,*** time ago, javascript timeago, react-timeago, jquery-timeago, timeago.org" />
7
+ <meta name="description" content="timeago.js is a tiny(2kb) library used to format date with `*** time ago`. eg: '3 hours ago'. No dependence. and support automatically updating fuzzy timestamps." />
8
+ <link rel="shortcut icon" href="clock.png" />
9
+ <link rel="bookmark" href="clock.png" />
10
+ <style>
11
+ * { margin: 0; padding: 0; }
12
+ body { font-family: Helvetica,Arial,sans-serif; color: #333; background-color: #ccc; font-size: 16px; line-height: 24px; }
13
+ h1 { margin: 0; font-size: 60px; line-height: 100px; text-align: center; }
14
+ h2 { margin: -30px 0 40px 50px; font-size: 20px; line-height: 20px; text-align: center; color: #999; }
15
+ h3 { margin: 24px 0 6px 0; font-size: 18px; line-height: 18px; border-bottom: 1px solid #ccc; }
16
+ h1 img { vertical-align: middle; }
17
+ p { margin: 0 0 24px 0; }
18
+ p.example { margin: 0 0 12px 0; }
19
+ p.how, p.last { margin: 0; }
20
+ ul { margin: 0 24px 24px; }
21
+ li { line-height: 24px; }
22
+ input {margin: 5px;}
23
+ abbr[title], time[title] { border-bottom: 1px dotted #333; }
24
+ tt { font-size: 14px; }
25
+ a { color: #06e; padding: 1px; }
26
+ em { font-style: normal; background-color: #feb; }
27
+ a:hover { background-color: #06c; color: #fff; text-decoration: none; }
28
+ #content { margin:0 auto; padding: 24px; width:700px; background-color:#fff; border: 1px solid #999; border-width: 0 1px 1px 1px; }
29
+ #footer { margin:0 auto 24px; padding: 12px; width:700px; line-height: 24px; }
30
+ .help { font-size: 14px; color: #888; }
31
+ .strong {font-weight: bold;}
32
+ </style>
33
+ </head>
34
+ <body>
35
+ <div id="content">
36
+ <h1><img src="clock.png" /> timeago.js</h1>
37
+ <h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a tiny / simple library</h2>
38
+
39
+ <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
40
+ <!-- sorry for ad -->
41
+ <ins class="adsbygoogle"
42
+ style="display:block"
43
+ data-ad-client="ca-pub-7292810486004926"
44
+ data-ad-slot="7806394673"
45
+ data-ad-format="auto"></ins>
46
+ <script>
47
+ (adsbygoogle = window.adsbygoogle || []).push({});
48
+ </script>
49
+
50
+ <h3>What ?</h3>
51
+ <p>
52
+ <strong>timeago.js</strong> is a tiny(2kb) library used to format date with `*** time ago`. eg: '3 hours ago'. No dependency. and support automatically updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago"). <a href="https://github.com/hustcc/timeago.js">Download</a>, view the examples, and enjoy.
53
+ </p>
54
+ <div>
55
+ <input type="button" onclick="javascript:start_render_all(true);" value="Auto-render all by native." />
56
+ <input type="button" onclick="javascript:start_render_all(false);" value="Auto-render all by jquery." />
57
+
58
+ <input type="button" onclick="javascript:stop_render_all();" value="Stop all Auto-render." />
59
+ </div>
60
+ <h3>Test for native DOM</h3>
61
+ <p class="native example">
62
+ You opened this page <time class="strong single">when you opened the page</time>
63
+ <input type="button" onclick="javascript:start_single_native();" value="Start." />
64
+ <input type="button" onclick="javascript:stop_single_native();" value="Stop." />
65
+ </p>
66
+ <p class="native example">
67
+ You opened this page <time class="strong">when you opened the page</time>.
68
+ </p>
69
+
70
+ <h3>Test for Jquery DOM ?</h3>
71
+ <p class="jquery example">
72
+ You opened this page <time class="strong single">when you opened the page</time>.
73
+ <input type="button" onclick="javascript:start_single_jquery();" value="Start." />
74
+ <input type="button" onclick="javascript:stop_single_jquery();" value="Stop." />
75
+ </p>
76
+ <p class="jquery example">
77
+ You opened this page <time class="strong">when you opened the page</time>.
78
+ </p>
79
+ </div>
80
+ <div id="footer">
81
+ Copyright &copy; 2016 How to user it, see <a href="http://timeago.org/" target="_blank" rel="nofollow">timeago.js</a>.
82
+ Updated by <a href="http://Github.com/hustcc">Hustcc</a>
83
+ </div>
84
+ <script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
85
+ <script src="../dist/timeago.min.js" type="text/javascript"></script>
86
+ <script src="../dist/timeago.locales.min.js" type="text/javascript"></script>
87
+ <script src="./index.js" type="text/javascript"></script>
88
+ <script type="text/javascript">
89
+ init_test_page(); // 初始化标签上的时间
90
+
91
+ function start_render_all(native) {
92
+ var nodes = [];
93
+ if (native) {
94
+ nodes = document.querySelectorAll('.example time');
95
+ } else {
96
+ nodes = $('.example time');
97
+ }
98
+ timeago().render(nodes);
99
+ }
100
+ function stop_render_all(native) {
101
+ timeago.cancel(); // cancel all.
102
+ }
103
+
104
+ function start_single_native() {
105
+ timeago().render(document.querySelector('.native .single', 'zh_CN'));
106
+ }
107
+
108
+ function stop_single_native() {
109
+ timeago.cancel(document.querySelector('.native .single'));
110
+ }
111
+
112
+ function start_single_jquery() {
113
+ new timeago().render($('.jquery .single'));
114
+ }
115
+
116
+ function stop_single_jquery() {
117
+ timeago.cancel($('.jquery .single'));
118
+ }
119
+ </script>
120
+ </body>
121
+ </html>
package/demo/index.js CHANGED
@@ -1,16 +1,25 @@
1
- function iso8601(date) {
2
- return date.getUTCFullYear()
3
- + "-" + (date.getUTCMonth()+1)
4
- + "-" + date.getUTCDate()
5
- + "T" + date.getUTCHours()
6
- + ":" + date.getUTCMinutes()
7
- + ":" + date.getUTCSeconds() + "Z";
8
- }
9
-
10
- document.querySelector('.load_time').setAttribute('datetime', iso8601(new Date()));
11
- new timeago(null, navigator.language.replace('-', '_')).render(document.querySelectorAll('.need_to_be_rendered'));
12
-
13
- // 2. demo
14
- document.getElementById('demo_now').innerHTML = new timeago().format(new Date());
15
- document.getElementById('demo_20160907').innerHTML = new timeago(null, 'zh_CN').format('2016-09-07');
16
- document.getElementById('demo_timestamp').innerHTML = new timeago().format(1473245023718);
1
+ function iso8601(date) {
2
+ return date.getUTCFullYear()
3
+ + "-" + (date.getUTCMonth()+1)
4
+ + "-" + date.getUTCDate()
5
+ + "T" + date.getUTCHours()
6
+ + ":" + date.getUTCMinutes()
7
+ + ":" + date.getUTCSeconds() + "Z";
8
+ }
9
+
10
+ function init_index_page() {
11
+ document.querySelector('.load_time').setAttribute('datetime', iso8601(new Date()));
12
+ var timeagoInstance = timeago(null, navigator.language.replace('-', '_'));
13
+ timeagoInstance.render(document.querySelectorAll('.need_to_be_rendered'));
14
+
15
+ // 2. demo
16
+ document.getElementById('demo_now').innerHTML = timeago().format(new Date());
17
+ document.getElementById('demo_20160907').innerHTML = timeago(null, 'zh_CN').format('2016-09-07');
18
+ document.getElementById('demo_timestamp').innerHTML = timeago().format(1473245023718);
19
+ }
20
+
21
+ function init_test_page() {
22
+ $('.native time').attr('datetime', iso8601(new Date()));
23
+ $('.jquery time').attr('data-timeago', iso8601(new Date()));
24
+ }
25
+