PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/media/js/newsblur/models/users.js

https://github.com/samuelclay/NewsBlur
JavaScript | 45 lines | 36 code | 9 blank | 0 comment | 11 complexity | 8a4837e586db58df28aa11ee85abaf81 MD5 | raw file
Possible License(s): MIT, GPL-2.0, BSD-3-Clause
  1. NEWSBLUR.Models.User = Backbone.Model.extend({
  2. get: function(attr) {
  3. var value = Backbone.Model.prototype.get.call(this, attr);
  4. if (attr == 'photo_url' && !value) {
  5. value = NEWSBLUR.Globals.MEDIA_URL + 'img/reader/default_profile_photo.png';
  6. }
  7. return value;
  8. },
  9. photo_url: function(options) {
  10. options = options || {};
  11. var url = this.get('photo_url');
  12. if (options.size && _.string.include(url, 'graph.facebook.com')) {
  13. url += '?type=' + options.size;
  14. } else if (options.size == 'large' && _.string.include(url, 'twimg')) {
  15. url = url.replace(/_normal.(\w+)/, '.$1');
  16. }
  17. return url;
  18. },
  19. blurblog_url: function() {
  20. return [
  21. 'http://',
  22. Inflector.sluggify(this.get('username')),
  23. '.',
  24. window.location.host.replace('www.', '')
  25. ].join('');
  26. }
  27. });
  28. NEWSBLUR.Collections.Users = Backbone.Collection.extend({
  29. model : NEWSBLUR.Models.User,
  30. find: function(user_id) {
  31. return this.detect(function(user) { return user.get('user_id') == user_id; });
  32. },
  33. comparator: function(model) {
  34. return -1 * model.get('shared_stories_count');
  35. }
  36. });