2012-05-18 16:59:39 -07:00
|
|
|
NEWSBLUR.Views.FeedCount = Backbone.View.extend({
|
|
|
|
|
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');
|
|
|
|
this.model.bind('change:ps', this.render);
|
|
|
|
this.model.bind('change:nt', this.render);
|
|
|
|
this.model.bind('change:ng', this.render);
|
|
|
|
},
|
|
|
|
|
2012-05-18 16:59:39 -07:00
|
|
|
render: function() {
|
2012-05-21 20:08:27 -07:00
|
|
|
$(this.el).html($(this.render_to_string()));
|
2012-05-18 16:59:39 -07:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
render_to_string: function() {
|
|
|
|
var feed = this.model;
|
|
|
|
var unread_class = "";
|
|
|
|
if (feed.get('ps')) {
|
|
|
|
unread_class += ' unread_positive';
|
|
|
|
}
|
|
|
|
if (feed.get('nt')) {
|
|
|
|
unread_class += ' unread_neutral';
|
|
|
|
}
|
|
|
|
if (feed.get("ng")) {
|
|
|
|
unread_class += ' unread_negative';
|
|
|
|
}
|
|
|
|
|
|
|
|
var $floater = _.template('\
|
2012-05-23 14:11:42 -07:00
|
|
|
<div class="<%= unread_class %>">\
|
2012-05-18 16:59:39 -07:00
|
|
|
<span class="unread_count unread_count_positive <% if (feed.get("ps")) { %>unread_count_full<% } else { %>unread_count_empty<% } %>">\
|
|
|
|
<%= feed.get("ps") %>\
|
|
|
|
</span>\
|
|
|
|
<span class="unread_count unread_count_neutral <% if (feed.get("nt")) { %>unread_count_full<% } else { %>unread_count_empty<% } %>">\
|
|
|
|
<%= feed.get("nt") %>\
|
|
|
|
</span>\
|
|
|
|
<span class="unread_count unread_count_negative <% if (feed.get("ng")) { %>unread_count_full<% } else { %>unread_count_empty<% } %>">\
|
|
|
|
<%= feed.get("ng") %>\
|
|
|
|
</span>\
|
|
|
|
</div>\
|
|
|
|
', {
|
|
|
|
feed : feed,
|
|
|
|
unread_class : unread_class
|
|
|
|
});
|
|
|
|
|
|
|
|
return $floater;
|
2012-05-23 14:11:42 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ===========
|
|
|
|
// = Actions =
|
|
|
|
// ===========
|
|
|
|
|
|
|
|
center: function() {
|
|
|
|
var i_width = this.$el.width();
|
|
|
|
var o_width = NEWSBLUR.reader.$s.$story_taskbar.width();
|
|
|
|
var left = (o_width / 2.0) - (i_width / 2.0);
|
|
|
|
console.log(["center", left, i_width, o_width]);
|
|
|
|
this.$el.css({'left': left});
|
|
|
|
},
|
|
|
|
|
|
|
|
flash: function() {
|
|
|
|
var $floater = this.$el;
|
|
|
|
|
|
|
|
_.defer(function() {
|
|
|
|
$floater.animate({'opacity': 1}, {'duration': 250, 'queue': false});
|
|
|
|
_.delay(function() {
|
|
|
|
$floater.animate({'opacity': .2}, {'duration': 250, 'queue': false});
|
|
|
|
}, 400);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
fall: function() {
|
|
|
|
var $floater = this.$el;
|
|
|
|
|
|
|
|
_.delay(function() {
|
|
|
|
$floater.animate({
|
|
|
|
'top': $('#story_taskbar').height()
|
|
|
|
}, {
|
|
|
|
'duration': 500,
|
|
|
|
'queue': false,
|
|
|
|
'easing': 'easeOutQuint'
|
|
|
|
});
|
|
|
|
}, 500);
|
2012-05-18 16:59:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|