mirror of
https://github.com/flarum/framework.git
synced 2025-01-10 13:03:43 +08:00
c28307903b
HTMLBars goodness! Since there was some breakage and a lot of fiddling around to get some things working, I took this opportunity to do a big cleanup of the whole Ember app. I accidentally worked on some new features too :3 Note that the app is still broken right now, pending on https://github.com/emberjs/ember.js/issues/10401 Cleanup: - Restructuring of components - Consolidation of some stuff into mixins, cleanup of some APIs that will be public - Change all instances of .property() / .observes() / .on() to Ember.computed() / Ember.observer() / Ember.on() respectively (I think it is more readable) - More comments - Start conforming to a code style (2 spaces for indentation) New features: - Post hiding/restoring - Mark individual discussions as read by clicking - Clicking on a read discussion jumps to the end - Mark all discussions as read - Progressively mark the discussion as read as the page is scrolled - Unordered list post formatting - Post permalink popup Demo once that Ember regression is fixed!
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
import Ember from 'ember';
|
|
|
|
function hsvToRgb(h, s, v) {
|
|
var r, g, b, i, f, p, q, t;
|
|
if (h && s === undefined && v === undefined) {
|
|
s = h.s; v = h.v; h = h.h;
|
|
}
|
|
i = Math.floor(h * 6);
|
|
f = h * 6 - i;
|
|
p = v * (1 - s);
|
|
q = v * (1 - f * s);
|
|
t = v * (1 - (1 - f) * s);
|
|
switch (i % 6) {
|
|
case 0: r = v; g = t; b = p; break;
|
|
case 1: r = q; g = v; b = p; break;
|
|
case 2: r = p; g = v; b = t; break;
|
|
case 3: r = p; g = q; b = v; break;
|
|
case 4: r = t; g = p; b = v; break;
|
|
case 5: r = v; g = p; b = q; break;
|
|
}
|
|
return {
|
|
r: Math.floor(r * 255),
|
|
g: Math.floor(g * 255),
|
|
b: Math.floor(b * 255)
|
|
};
|
|
}
|
|
|
|
export default Ember.Handlebars.makeBoundHelper(function(user, options) {
|
|
if (!user) {
|
|
return;
|
|
}
|
|
|
|
// var number;
|
|
// if (number = user.get('avatarNumber')) {
|
|
// number = number + '';
|
|
// var filename = number.length >= 3 ? number : new Array(3 - number.length + 1).join('0') + number;
|
|
// return new Ember.Handlebars.SafeString('<img src="/packages/flarum/core/avatars/'+filename+'.jpg" class="avatar '+options.hash.class+'">');
|
|
// }
|
|
|
|
var username = user.get('username');
|
|
if (!username) {
|
|
username = '?';
|
|
}
|
|
|
|
var letter = username.charAt(0).toUpperCase();
|
|
|
|
var num = 0;
|
|
for (var i = 0; i < username.length; i++) {
|
|
num += username.charCodeAt(i) * 13;
|
|
}
|
|
|
|
var hue = num % 360;
|
|
var rgb = hsvToRgb(hue / 360, 100 / 255, 200 / 255);
|
|
var bg = ''+rgb.r.toString(16)+rgb.g.toString(16)+rgb.b.toString(16);
|
|
return new Ember.Handlebars.SafeString('<span class="avatar '+options.hash.class+'" style="background:#'+bg+'" title="'+username+'">'+letter+'</span>');
|
|
});
|
|
|