Welcome to mirror list, hosted at ThFree Co, Russian Federation.

handlebars-helpers.js « helpers « app « javascripts « assets « app - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cea31311af84de4659509a78cb2f4e7f687ca7db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Handlebars.registerHelper('t', function(scope, values) {
  return Diaspora.I18n.t(scope, values.hash)
});

Handlebars.registerHelper('txtDirClass', function(str) {
  return app.helpers.txtDirection.classFor(str);
});

Handlebars.registerHelper('imageUrl', function(path){
  return ImagePaths.get(path);
});

Handlebars.registerHelper('urlTo', function(path_helper, id, data){
  if( !data ) {
    // only one argument given to helper, mangle parameters
    data = id;
    return Routes[path_helper+'_path'](data.hash);
  }
  return Routes[path_helper+'_path'](id, data.hash);
});

Handlebars.registerHelper('linkToPerson', function(context, block) {
  if( !context ) context = this;
  var html = "<a href=\"/people/" + context.guid + "\" class=\"author-name ";
      html += Handlebars.helpers.hovercardable(context);
      html += "\">";
      html += block.fn(context);
      html += "</a>";

  return html
});

// relationship indicator for profile page
Handlebars.registerHelper('sharingMessage', function(person) {
  var i18n_scope = 'people.helper.is_not_sharing';
  var icon = "circle";
  if( person.is_sharing ) {
    i18n_scope = 'people.helper.is_sharing';
    icon = "entypo check";
  }

  var title = Diaspora.I18n.t(i18n_scope, {name: person.name});
  var html = '<span class="sharing_message_container" title="'+title+'" data-placement="bottom">'+
             '  <i id="sharing_message" class="'+icon+'"></i>'+
             '</span>';
  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( !person.avatar &&
      !(person.profile && person.profile.avatar) ) return;
  var avatar = person.avatar || person.profile.avatar;

  var name = ( person.name ) ? person.name : 'avatar';
  size = ( !_.isString(size) ) ? "small" : size;
  imageClass = ( !_.isString(imageClass) ) ? size : imageClass;

  return _.template('<img src="<%= src %>" class="avatar <%= img_class %>" title="<%= title %>" alt="<%= title %>" />', {
    'src': avatar[size],
    'img_class': imageClass,
    'title': _.escape(name)
  });
});

Handlebars.registerHelper('localTime', function(timestamp) {
  return new Date(timestamp).toLocaleString();
});

Handlebars.registerHelper('fmtTags', function(tags) {
  var links = _.map(tags, function(tag) {
    return '<a class="tag" href="' + Routes.tag_path(tag) + '">' +
           '  #' + tag +
           '</a>';
  }).join(' ');
  return new Handlebars.SafeString(links);
});

Handlebars.registerHelper('fmtText', function(text) {
  return new Handlebars.SafeString(app.helpers.textFormatter(text, null));
});

Handlebars.registerHelper('isCurrentPage', function(path_helper, id, options){
  var currentPage = "/"+Backbone.history.fragment;
  if (currentPage == Handlebars.helpers.urlTo(path_helper, id, options.data)) {
    return options.fn(this);
  } else {
    return options.inverse(this);
  }
});

Handlebars.registerHelper('isCurrentProfilePage', function(id, diaspora_handle, options){
  var username = diaspora_handle.split("@")[0];
  return Handlebars.helpers.isCurrentPage('person', id, options) ||
         Handlebars.helpers.isCurrentPage('user_profile', username, options);
});