Replace Ember app with Mithril app

This commit is contained in:
Toby Zerner
2015-04-25 22:28:39 +09:30
parent 6f67b8c247
commit b68a4711dc
377 changed files with 5641 additions and 7330 deletions

26
js/lib/helpers/avatar.js Normal file
View 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)
}

View 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);
}

View 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
View File

@ -0,0 +1,3 @@
export default function icon(icon) {
return m('i.fa.fa-fw.fa-'+icon)
}

View 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), ' ']);
};

View File

@ -0,0 +1,5 @@
export default function username(user) {
var username = (user && user.username()) || '[deleted]';
return m('span.username', username);
}