mirror of
https://github.com/flarum/framework.git
synced 2025-05-22 06:39:57 +08:00
Replace Ember app with Mithril app
This commit is contained in:
26
js/lib/helpers/avatar.js
Normal file
26
js/lib/helpers/avatar.js
Normal file
@ -0,0 +1,26 @@
|
||||
export default function avatar(user, args) {
|
||||
args = args || {}
|
||||
args.className = 'avatar '+(args.className || '')
|
||||
var content = ''
|
||||
|
||||
var title = typeof args.title === 'undefined' || args.title
|
||||
if (!title) { delete args.title }
|
||||
|
||||
if (user) {
|
||||
var username = user.username() || '?'
|
||||
|
||||
if (title) { args.title = args.title || username }
|
||||
|
||||
var avatarUrl = user.avatarUrl()
|
||||
if (avatarUrl) {
|
||||
args.src = avatarUrl
|
||||
return m('img', args)
|
||||
}
|
||||
|
||||
content = username.charAt(0).toUpperCase()
|
||||
args.style = {background: user.color()}
|
||||
}
|
||||
|
||||
if (!args.title) { delete args.title }
|
||||
return m('span', args, content)
|
||||
}
|
7
js/lib/helpers/full-time.js
Normal file
7
js/lib/helpers/full-time.js
Normal file
@ -0,0 +1,7 @@
|
||||
export default function fullTime(time) {
|
||||
var time = moment(time);
|
||||
var datetime = time.format();
|
||||
var full = time.format('LLLL');
|
||||
|
||||
return m('time', {pubdate: '', datetime}, full);
|
||||
}
|
11
js/lib/helpers/human-time.js
Normal file
11
js/lib/helpers/human-time.js
Normal file
@ -0,0 +1,11 @@
|
||||
import humanTime from 'flarum/utils/human-time';
|
||||
|
||||
export default function humanTimeHelper(time) {
|
||||
var time = moment(time);
|
||||
var datetime = time.format();
|
||||
var full = time.format('LLLL');
|
||||
|
||||
var ago = humanTime(time);
|
||||
|
||||
return m('time', {pubdate: '', datetime, title: full, 'data-humantime': ''}, ago);
|
||||
}
|
3
js/lib/helpers/icon.js
Normal file
3
js/lib/helpers/icon.js
Normal file
@ -0,0 +1,3 @@
|
||||
export default function icon(icon) {
|
||||
return m('i.fa.fa-fw.fa-'+icon)
|
||||
}
|
21
js/lib/helpers/list-items.js
Normal file
21
js/lib/helpers/list-items.js
Normal file
@ -0,0 +1,21 @@
|
||||
import Separator from 'flarum/components/separator';
|
||||
|
||||
function isSeparator(item) {
|
||||
return item && item.component === Separator;
|
||||
}
|
||||
|
||||
export default function listItems(array, noWrap) {
|
||||
// Remove duplicate/unnecessary separators
|
||||
var prevItem;
|
||||
var newArray = [];
|
||||
array.forEach(function(item, i) {
|
||||
if ((!prevItem || isSeparator(prevItem) || i === array.length - 1) && isSeparator(item)) {
|
||||
|
||||
} else {
|
||||
prevItem = item;
|
||||
newArray.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
return newArray.map(item => [(noWrap && !isSeparator(item)) ? item : m('li', {className: (item.props && item.props.wrapperClass) || (item.component && item.component.wrapperClass) || ''}, item), ' ']);
|
||||
};
|
5
js/lib/helpers/username.js
Normal file
5
js/lib/helpers/username.js
Normal file
@ -0,0 +1,5 @@
|
||||
export default function username(user) {
|
||||
var username = (user && user.username()) || '[deleted]';
|
||||
|
||||
return m('span.username', username);
|
||||
}
|
Reference in New Issue
Block a user