Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
4bd1b550
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4bd1b550
编写于
2月 07, 2017
作者:
A
Alfredo Sumaran
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'timeago-perf' into 'master'
Improved timeago performance Closes #25728 See merge request !8231
上级
f7d900aa
1c7cce9e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
128 addition
and
0 deletion
+128
-0
app/assets/javascripts/application.js
app/assets/javascripts/application.js
+2
-0
app/assets/javascripts/lib/utils/datetime_utility.js.es6
app/assets/javascripts/lib/utils/datetime_utility.js.es6
+126
-0
未找到文件。
app/assets/javascripts/application.js
浏览文件 @
4bd1b550
...
...
@@ -247,5 +247,7 @@ window.ES6Promise.polyfill();
new
Aside
();
// bind sidebar events
new
gl
.
Sidebar
();
gl
.
utils
.
initTimeagoTimeout
();
});
}).
call
(
this
);
app/assets/javascripts/lib/utils/datetime_utility.js
→
app/assets/javascripts/lib/utils/datetime_utility.js
.es6
浏览文件 @
4bd1b550
...
...
@@ -8,6 +8,8 @@ window.dateFormat = require('vendor/date.format');
(function() {
(function(w) {
var base;
var timeagoInstance;
if (w.gl == null) {
w.gl = {};
}
...
...
@@ -24,49 +26,51 @@ window.dateFormat = require('vendor/date.format');
return this.days[date.getDay()];
};
w
.
gl
.
utils
.
localTimeAgo
=
function
(
$timeagoEls
,
setTimeago
)
{
if
(
setTimeago
==
null
)
{
setTimeago
=
true
;
}
$timeagoEls
.
filter
(
'
:not([data-timeago-rendered])
'
).
each
(
function
()
{
var
$el
=
$
(
this
);
$el
.
attr
(
'
title
'
,
gl
.
utils
.
formatDate
(
$el
.
attr
(
'
datetime
'
)));
w.gl.utils.localTimeAgo = function($timeagoEls, setTimeago = true) {
$timeagoEls.each((i, el) => {
el.setAttribute('title', gl.utils.formatDate(el.getAttribute('datetime')));
if (setTimeago) {
// Recreate with custom template
$
el
.
tooltip
({
$
(el)
.tooltip({
template: '<div class="tooltip local-timeago" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
});
}
$el
.
attr
(
'
data-timeago-rendered
'
,
true
);
gl
.
utils
.
renderTimeago
(
$el
);
el.classList.add('js-timeago-render');
});
gl.utils.renderTimeago($timeagoEls);
};
w.gl.utils.getTimeago = function() {
var
locale
=
function
(
number
,
index
)
{
return
[
[
'
less than a minute ago
'
,
'
a while
'
],
[
'
less than a minute ago
'
,
'
in %s seconds
'
],
[
'
about a minute ago
'
,
'
in 1 minute
'
],
[
'
%s minutes ago
'
,
'
in %s minutes
'
],
[
'
about an hour ago
'
,
'
in 1 hour
'
],
[
'
about %s hours ago
'
,
'
in %s hours
'
],
[
'
a day ago
'
,
'
in 1 day
'
],
[
'
%s days ago
'
,
'
in %s days
'
],
[
'
a week ago
'
,
'
in 1 week
'
],
[
'
%s weeks ago
'
,
'
in %s weeks
'
],
[
'
a month ago
'
,
'
in 1 month
'
],
[
'
%s months ago
'
,
'
in %s months
'
],
[
'
a year ago
'
,
'
in 1 year
'
],
[
'
%s years ago
'
,
'
in %s years
'
]
][
index
];
};
timeago
.
register
(
'
gl_en
'
,
locale
);
return
timeago
();
var locale;
if (!timeagoInstance) {
locale = function(number, index) {
return [
['less than a minute ago', 'a while'],
['less than a minute ago', 'in %s seconds'],
['about a minute ago', 'in 1 minute'],
['%s minutes ago', 'in %s minutes'],
['about an hour ago', 'in 1 hour'],
['about %s hours ago', 'in %s hours'],
['a day ago', 'in 1 day'],
['%s days ago', 'in %s days'],
['a week ago', 'in 1 week'],
['%s weeks ago', 'in %s weeks'],
['a month ago', 'in 1 month'],
['%s months ago', 'in %s months'],
['a year ago', 'in 1 year'],
['%s years ago', 'in %s years']
][index];
};
timeago.register('gl_en', locale);
timeagoInstance = timeago();
}
return timeagoInstance;
};
w.gl.utils.timeFor = function(time, suffix, expiredLabel) {
...
...
@@ -85,9 +89,30 @@ window.dateFormat = require('vendor/date.format');
return timefor;
};
w
.
gl
.
utils
.
renderTimeago
=
function
(
$element
)
{
var
timeagoInstance
=
gl
.
utils
.
getTimeago
();
timeagoInstance
.
render
(
$element
,
'
gl_en
'
);
w.gl.utils.cachedTimeagoElements = [];
w.gl.utils.renderTimeago = function($els) {
if (!$els && !w.gl.utils.cachedTimeagoElements.length) {
w.gl.utils.cachedTimeagoElements = [].slice.call(document.querySelectorAll('.js-timeago-render'));
} else if ($els) {
w.gl.utils.cachedTimeagoElements = w.gl.utils.cachedTimeagoElements.concat($els.toArray());
}
w.gl.utils.cachedTimeagoElements.forEach(gl.utils.updateTimeagoText);
};
w.gl.utils.updateTimeagoText = function(el) {
const timeago = gl.utils.getTimeago();
const formattedDate = timeago.format(el.getAttribute('datetime'), 'gl_en');
if (el.textContent !== formattedDate) {
el.textContent = formattedDate;
}
};
w.gl.utils.initTimeagoTimeout = function() {
gl.utils.renderTimeago();
gl.utils.timeagoTimeout = setTimeout(gl.utils.initTimeagoTimeout, 1000);
};
w.gl.utils.getDayDifference = function(a, b) {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录