2013-04-03 12:37:20 -07:00
|
|
|
NEWSBLUR.Views.UnreadCount = Backbone.View.extend({
|
2012-05-18 16:59:39 -07:00
|
|
|
|
2012-05-23 14:11:42 -07:00
|
|
|
className: 'feed_counts_floater',
|
|
|
|
|
2012-05-21 20:08:27 -07:00
|
|
|
initialize: function() {
|
|
|
|
_.bindAll(this, 'render');
|
2014-07-24 17:16:03 -07:00
|
|
|
if (!this.options.stale && !this.options.feed_chooser) {
|
2013-04-03 12:37:20 -07:00
|
|
|
if (this.model) {
|
2014-05-28 16:54:51 -07:00
|
|
|
var starred_feed = NEWSBLUR.assets.starred_feeds.get_feed(this.model.id);
|
|
|
|
if (starred_feed) {
|
|
|
|
starred_feed.bind('change:count', this.render, this);
|
|
|
|
}
|
2014-02-04 11:49:56 -08:00
|
|
|
this.model.bind('change:ps', this.render, this);
|
|
|
|
this.model.bind('change:nt', this.render, this);
|
|
|
|
this.model.bind('change:ng', this.render, this);
|
2020-06-09 11:59:07 -04:00
|
|
|
this.model.bind('change:active', this.render, this);
|
2013-04-03 12:37:20 -07:00
|
|
|
} else if (this.collection) {
|
2014-02-04 11:49:56 -08:00
|
|
|
this.collection.bind('change:counts', this.render, this);
|
2013-04-03 12:37:20 -07:00
|
|
|
}
|
2012-05-23 15:41:02 -07:00
|
|
|
}
|
2012-05-21 20:08:27 -07:00
|
|
|
},
|
|
|
|
|
2012-06-07 13:56:54 -07:00
|
|
|
// ==========
|
|
|
|
// = Render =
|
|
|
|
// ==========
|
|
|
|
|
2012-05-18 16:59:39 -07:00
|
|
|
render: function() {
|
|
|
|
var unread_class = "";
|
2013-04-03 12:37:20 -07:00
|
|
|
var counts;
|
2020-06-09 11:59:07 -04:00
|
|
|
var muted = false;
|
2013-04-03 12:37:20 -07:00
|
|
|
if (this.model) {
|
|
|
|
counts = this.model.unread_counts();
|
2020-06-09 11:59:07 -04:00
|
|
|
if (!this.model.get('active')) muted = true;
|
2013-04-03 12:37:20 -07:00
|
|
|
} else if (this.collection) {
|
|
|
|
counts = this.collection.unread_counts();
|
|
|
|
}
|
2012-05-23 15:41:02 -07:00
|
|
|
|
|
|
|
if (counts['ps']) {
|
2012-05-18 16:59:39 -07:00
|
|
|
unread_class += ' unread_positive';
|
|
|
|
}
|
2012-05-23 15:41:02 -07:00
|
|
|
if (counts['nt']) {
|
2012-05-18 16:59:39 -07:00
|
|
|
unread_class += ' unread_neutral';
|
|
|
|
}
|
2012-05-23 15:41:02 -07:00
|
|
|
if (counts['ng']) {
|
2012-05-18 16:59:39 -07:00
|
|
|
unread_class += ' unread_negative';
|
|
|
|
}
|
2014-05-28 16:54:51 -07:00
|
|
|
if ((counts['st'] && this.options.include_starred) || (this.model && this.model.is_starred())) {
|
|
|
|
unread_class += ' unread_starred';
|
|
|
|
}
|
2020-06-09 11:59:07 -04:00
|
|
|
if (muted) {
|
|
|
|
unread_class += ' NB-muted-count';
|
|
|
|
}
|
2012-05-18 16:59:39 -07:00
|
|
|
|
2012-06-02 16:33:44 -07:00
|
|
|
this.$el.html(this.template({
|
2014-10-09 20:58:03 -07:00
|
|
|
ps : this.options.feed_chooser ? "On" : counts['ps'],
|
2012-06-02 16:33:44 -07:00
|
|
|
nt : counts['nt'],
|
2014-10-09 20:58:03 -07:00
|
|
|
ng : this.options.feed_chooser ? "Off" : counts['ng'],
|
2020-06-09 11:59:07 -04:00
|
|
|
muted : muted,
|
2014-05-28 16:54:51 -07:00
|
|
|
st : this.options.include_starred && counts['st'],
|
2012-06-02 16:33:44 -07:00
|
|
|
unread_class : unread_class
|
|
|
|
}));
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2013-12-16 12:11:16 -08:00
|
|
|
destroy: function() {
|
|
|
|
if (this.model) {
|
|
|
|
this.model.unbind(null, null, this);
|
|
|
|
} else if (this.collection) {
|
|
|
|
this.collection.unbind(null, null, this);
|
|
|
|
}
|
|
|
|
this.remove();
|
|
|
|
},
|
|
|
|
|
2012-06-02 16:33:44 -07:00
|
|
|
template: _.template('\
|
2012-05-23 14:11:42 -07:00
|
|
|
<div class="<%= unread_class %>">\
|
2012-05-23 15:41:02 -07:00
|
|
|
<span class="unread_count unread_count_positive <% if (ps) { %>unread_count_full<% } else { %>unread_count_empty<% } %>">\
|
|
|
|
<%= ps %>\
|
2012-05-18 16:59:39 -07:00
|
|
|
</span>\
|
2012-05-23 15:41:02 -07:00
|
|
|
<span class="unread_count unread_count_neutral <% if (nt) { %>unread_count_full<% } else { %>unread_count_empty<% } %>">\
|
|
|
|
<%= nt %>\
|
2012-05-18 16:59:39 -07:00
|
|
|
</span>\
|
2012-05-23 15:41:02 -07:00
|
|
|
<span class="unread_count unread_count_negative <% if (ng) { %>unread_count_full<% } else { %>unread_count_empty<% } %>">\
|
|
|
|
<%= ng %>\
|
2012-05-18 16:59:39 -07:00
|
|
|
</span>\
|
2020-06-09 11:59:07 -04:00
|
|
|
<% if (muted) { %>\
|
|
|
|
<span class="NB-muted-icon"></span>\
|
|
|
|
<% } %>\
|
2014-05-28 16:54:51 -07:00
|
|
|
<% if (st) { %>\
|
|
|
|
<span class="unread_count unread_count_starred <% if (st) { %>unread_count_full<% } else { %>unread_count_empty<% } %>">\
|
|
|
|
<%= st %>\
|
|
|
|
</span>\
|
|
|
|
<% } %>\
|
2012-05-18 16:59:39 -07:00
|
|
|
</div>\
|
2012-06-02 16:33:44 -07:00
|
|
|
'),
|
2012-05-23 14:11:42 -07:00
|
|
|
|
|
|
|
// ===========
|
|
|
|
// = Actions =
|
|
|
|
// ===========
|
|
|
|
|
|
|
|
center: function() {
|
2013-04-03 12:37:20 -07:00
|
|
|
var count_width = this.$el.width();
|
|
|
|
var left_buttons_offset = $('.NB-taskbar-view').outerWidth(true);
|
2014-05-28 16:54:51 -07:00
|
|
|
var right_buttons_offset = $(".NB-taskbar-options-container").position().left;
|
2013-04-03 12:37:20 -07:00
|
|
|
var usable_space = right_buttons_offset - left_buttons_offset;
|
|
|
|
var left = (usable_space / 2) - (count_width / 2) + left_buttons_offset;
|
|
|
|
|
|
|
|
// console.log(["Unread count offset", count_width, left, left_buttons_offset, right_buttons_offset]);
|
|
|
|
|
|
|
|
if (count_width + 12 > usable_space) {
|
2013-01-09 11:22:07 -08:00
|
|
|
this.$el.hide();
|
|
|
|
}
|
|
|
|
|
2012-05-23 14:11:42 -07:00
|
|
|
this.$el.css({'left': left});
|
|
|
|
},
|
|
|
|
|
|
|
|
flash: function() {
|
|
|
|
var $floater = this.$el;
|
|
|
|
|
2012-05-23 17:21:06 -07:00
|
|
|
if (!NEWSBLUR.assets.preference('animations')) return;
|
|
|
|
|
2012-05-23 14:11:42 -07:00
|
|
|
_.defer(function() {
|
|
|
|
$floater.animate({'opacity': 1}, {'duration': 250, 'queue': false});
|
|
|
|
_.delay(function() {
|
|
|
|
$floater.animate({'opacity': .2}, {'duration': 250, 'queue': false});
|
|
|
|
}, 400);
|
|
|
|
});
|
2012-05-18 16:59:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|