diaspora/app/assets/javascripts/app/helpers/handlebars-helpers.js
Florian Staudacher 0092acd492 re-add hovercards
* added a presenter for hovercard json
* added new backbone view for handling hovercard JS
* refactoring of PeopleController

* finished the backbone js version of hovercards
* don't try to make people_controller more restfull, out of scope
  just add a new route and use that for hovercard json
* added spec for people_controller#hovercard
* add new exception for "AccountClosed" to be able to raise from anywhere

* removed legacy code, since everything got ported to backbone
  (except the "cache" stuff, but that's not strictly necessary)
2012-12-28 22:37:13 +01:00

40 lines
1.3 KiB
JavaScript

Handlebars.registerHelper('t', function(scope, values) {
return Diaspora.I18n.t(scope, values.hash)
});
Handlebars.registerHelper('imageUrl', function(path){
return app.baseImageUrl() + path;
});
Handlebars.registerHelper('linkToPerson', function(context, block) {
var html = "<a href=\"/people/" + context.guid + "\" class=\"author-name\">";
html+= block.fn(context);
html+= "</a>";
return html
});
// allow hovercards for users that are not the current user.
// returns the html class name used to trigger hovercards.
Handlebars.registerHelper('hovercardable', function(person) {
if( app.currentUser.get('guid') != person.guid ) {
return 'hovercardable';
}
return '';
});
Handlebars.registerHelper('personImage', function(person, size, imageClass) {
/* we return here if person.avatar is blank, because this happens when a
* user is unauthenticated. we don't know why this happens... */
if( _.isUndefined(person.avatar) ) { return }
size = ( !_.isString(size) ) ? "small" : size;
imageClass = ( !_.isString(imageClass) ) ? size : imageClass;
return _.template('<img src="<%= src %>" class="avatar <%= img_class %>" title="<%= title %>" />', {
'src': person.avatar[size],
'img_class': imageClass,
'title': _.escape(person.name)
});
});