2012-06-11 17:51:12 -07:00
|
|
|
NEWSBLUR.Views.FeedTitleView = Backbone.View.extend({
|
2012-05-17 20:50:08 -07:00
|
|
|
|
2012-05-21 14:35:05 -07:00
|
|
|
options: {
|
2012-05-21 20:08:27 -07:00
|
|
|
depth: 0,
|
|
|
|
selected: false
|
2012-05-21 14:35:05 -07:00
|
|
|
},
|
|
|
|
|
2013-05-06 13:22:44 -07:00
|
|
|
flags: {},
|
|
|
|
|
2012-05-18 18:13:45 -07:00
|
|
|
events: {
|
2013-05-06 13:22:44 -07:00
|
|
|
"dblclick .feed_counts" : "mark_feed_as_read",
|
|
|
|
"dblclick" : "open_feed_link",
|
2012-09-07 17:36:12 -07:00
|
|
|
"click .NB-feedbar-mark-feed-read" : "mark_feed_as_read",
|
2012-07-18 18:34:19 -07:00
|
|
|
"click .NB-feedbar-train-feed" : "open_trainer",
|
|
|
|
"click .NB-feedbar-statistics" : "open_statistics",
|
2012-07-12 15:13:51 -07:00
|
|
|
"click .NB-feedlist-manage-icon" : "show_manage_menu",
|
2013-01-25 17:29:38 -08:00
|
|
|
"click .NB-feedbar-options" : "open_options_popover",
|
2013-07-30 17:20:13 -07:00
|
|
|
"click .NB-story-title-indicator" : "show_hidden_story_titles",
|
2012-07-12 15:13:51 -07:00
|
|
|
"click" : "open",
|
|
|
|
"mouseenter" : "add_hover_inverse",
|
|
|
|
"mouseleave" : "remove_hover_inverse"
|
2012-05-18 18:13:45 -07:00
|
|
|
},
|
|
|
|
|
2012-05-21 20:08:27 -07:00
|
|
|
initialize: function() {
|
2013-01-14 12:50:00 -08:00
|
|
|
_.bindAll(this, 'render', 'delete_feed', 'changed', 'render_updated_time');
|
2012-06-15 14:49:59 -07:00
|
|
|
if (!this.options.feed_chooser) {
|
2013-01-14 12:50:00 -08:00
|
|
|
this.listenTo(this.model, 'change', this.changed);
|
|
|
|
this.listenTo(this.model, 'change:updated', this.render_updated_time);
|
2012-06-15 14:49:59 -07:00
|
|
|
}
|
2012-05-22 15:02:37 -07:00
|
|
|
|
|
|
|
if (this.model.is_social() && !this.model.get('feed_title')) {
|
|
|
|
var profile = NEWSBLUR.assets.user_profiles.get(this.model.get('user_id')) || {};
|
|
|
|
this.model.set('feed_title', profile.feed_title);
|
|
|
|
}
|
2012-05-21 20:08:27 -07:00
|
|
|
},
|
|
|
|
|
2012-05-22 15:02:37 -07:00
|
|
|
changed: function(model, options) {
|
2013-01-14 12:50:00 -08:00
|
|
|
options = options || {};
|
|
|
|
var changes = _.keys(this.model.changedAttributes());
|
|
|
|
|
|
|
|
var counts_changed = _.any(changes, function(key) {
|
2012-05-22 17:39:21 -07:00
|
|
|
return _.contains(['ps', 'nt', 'ng'], key);
|
|
|
|
});
|
2013-01-14 12:50:00 -08:00
|
|
|
var only_counts_changed = !_.any(changes, function(key) {
|
2012-05-22 15:02:37 -07:00
|
|
|
return !_.contains(['ps', 'nt', 'ng'], key);
|
|
|
|
});
|
2013-01-14 12:50:00 -08:00
|
|
|
var only_selected_changed = !_.any(changes, function(key) {
|
2012-05-24 11:54:10 -07:00
|
|
|
return key != 'selected';
|
|
|
|
});
|
2012-05-22 15:02:37 -07:00
|
|
|
|
2012-05-22 17:39:21 -07:00
|
|
|
if (only_counts_changed) {
|
2012-05-22 15:02:37 -07:00
|
|
|
this.add_extra_classes();
|
2012-05-22 17:39:21 -07:00
|
|
|
if (!options.instant) this.flash_changes();
|
2012-05-24 11:54:10 -07:00
|
|
|
} else if (only_selected_changed) {
|
|
|
|
this.select_feed();
|
2012-05-22 17:39:21 -07:00
|
|
|
} else {
|
2012-05-22 15:02:37 -07:00
|
|
|
this.render();
|
2012-05-22 17:39:21 -07:00
|
|
|
if (!options.instant && counts_changed) this.flash_changes();
|
2012-05-18 16:59:39 -07:00
|
|
|
}
|
2012-05-22 15:02:37 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var feed = this.model;
|
|
|
|
var extra_classes = this.extra_classes();
|
2013-07-02 18:26:57 -07:00
|
|
|
var $feed = $(_.template('<<%= list_type %> class="feed <% if (selected) { %>selected<% } %> <%= extra_classes %> <% if (toplevel) { %>NB-toplevel<% } %>" data-id="<%= feed.id %>">\
|
2012-05-18 16:59:39 -07:00
|
|
|
<div class="feed_counts">\
|
|
|
|
</div>\
|
2012-05-18 18:13:45 -07:00
|
|
|
<img class="feed_favicon" src="<%= $.favicon(feed) %>">\
|
2012-05-18 16:59:39 -07:00
|
|
|
<span class="feed_title">\
|
|
|
|
<%= feed.get("feed_title") %>\
|
|
|
|
<% if (type == "story") { %>\
|
2013-02-21 12:53:45 -08:00
|
|
|
<div class="NB-feedbar-mark-feed-read"></div>\
|
2012-05-18 16:59:39 -07:00
|
|
|
<% } %>\
|
|
|
|
</span>\
|
|
|
|
<% if (type == "story") { %>\
|
2013-02-11 12:35:42 -08:00
|
|
|
<div class="NB-feedbar-options-container">\
|
|
|
|
<span class="NB-feedbar-options">\
|
|
|
|
<div class="NB-icon"></div>\
|
|
|
|
<%= NEWSBLUR.assets.view_setting(feed.id, "read_filter") %>\
|
|
|
|
·\
|
|
|
|
<%= NEWSBLUR.assets.view_setting(feed.id, "order") %>\
|
|
|
|
</span>\
|
|
|
|
</div>\
|
2013-07-30 17:20:13 -07:00
|
|
|
<div class="NB-search-container"></div>\
|
|
|
|
<div class="NB-story-title-indicator">\
|
|
|
|
<div class="NB-story-title-indicator-count"></div>\
|
|
|
|
<span class="NB-story-title-indicator-text">show hidden stories</span>\
|
|
|
|
</div>\
|
2012-05-18 16:59:39 -07:00
|
|
|
<% } %>\
|
|
|
|
<div class="NB-feed-exception-icon"></div>\
|
|
|
|
<div class="NB-feed-unfetched-icon"></div>\
|
|
|
|
<div class="NB-feedlist-manage-icon"></div>\
|
2012-05-22 13:25:21 -07:00
|
|
|
<div class="NB-feed-highlight"></div>\
|
2012-05-18 16:59:39 -07:00
|
|
|
</<%= list_type %>>\
|
|
|
|
', {
|
|
|
|
feed : feed,
|
|
|
|
type : this.options.type,
|
2012-05-22 15:02:37 -07:00
|
|
|
extra_classes : extra_classes,
|
2012-05-18 16:59:39 -07:00
|
|
|
toplevel : this.options.depth == 0,
|
|
|
|
list_type : this.options.type == 'feed' ? 'li' : 'div',
|
2012-05-21 20:08:27 -07:00
|
|
|
selected : this.model.get('selected') || NEWSBLUR.reader.active_feed == this.model.id
|
|
|
|
}));
|
|
|
|
|
2013-07-30 11:34:24 -07:00
|
|
|
if (this.options.type == 'story') {
|
|
|
|
this.search_view = new NEWSBLUR.Views.FeedSearchView({
|
|
|
|
feedbar_view: this
|
|
|
|
}).render();
|
2013-07-30 17:20:13 -07:00
|
|
|
$(".NB-search-container", $feed).html(this.search_view.$el);
|
2013-07-30 11:34:24 -07:00
|
|
|
}
|
2012-12-19 14:21:46 -08:00
|
|
|
|
2012-05-22 13:25:21 -07:00
|
|
|
this.$el.replaceWith($feed);
|
2012-05-18 16:59:39 -07:00
|
|
|
this.setElement($feed);
|
2012-05-22 15:02:37 -07:00
|
|
|
this.render_counts();
|
2012-06-11 21:25:17 -07:00
|
|
|
this.setup_tooltips();
|
|
|
|
this.render_updated_time();
|
2012-05-21 20:08:27 -07:00
|
|
|
|
2013-07-25 17:05:32 -07:00
|
|
|
if (NEWSBLUR.reader.flags.search || NEWSBLUR.reader.flags.searching) {
|
2012-12-19 14:21:46 -08:00
|
|
|
var $search = this.$("input[name=feed_search]");
|
|
|
|
$search.focus();
|
|
|
|
}
|
|
|
|
|
2013-07-12 15:21:11 -07:00
|
|
|
this.$el.bind('contextmenu', _.bind(this.show_manage_menu_rightclick, this));
|
2012-08-30 18:31:44 -07:00
|
|
|
|
2012-05-17 20:50:08 -07:00
|
|
|
return this;
|
2012-05-18 18:13:45 -07:00
|
|
|
},
|
|
|
|
|
2012-05-22 15:02:37 -07:00
|
|
|
extra_classes: function() {
|
|
|
|
var feed = this.model;
|
|
|
|
var extra_classes = '';
|
2012-05-22 17:39:21 -07:00
|
|
|
|
2012-05-22 15:02:37 -07:00
|
|
|
if (feed.get('ps')) {
|
|
|
|
extra_classes += ' unread_positive';
|
|
|
|
}
|
|
|
|
if (feed.get('nt')) {
|
|
|
|
extra_classes += ' unread_neutral';
|
|
|
|
}
|
|
|
|
if (feed.get('ng')) {
|
|
|
|
extra_classes += ' unread_negative';
|
|
|
|
}
|
2012-05-22 17:39:21 -07:00
|
|
|
|
|
|
|
if (feed.is_feed()) {
|
|
|
|
if (feed.get('has_exception') && feed.get('exception_type') == 'feed') {
|
|
|
|
extra_classes += ' NB-feed-exception';
|
|
|
|
}
|
|
|
|
if (!feed.get('fetched_once') && !feed.get('has_exception')) {
|
|
|
|
extra_classes += ' NB-feed-unfetched';
|
|
|
|
}
|
|
|
|
if (!feed.get('active') && !feed.get('subscription_user_id')) {
|
|
|
|
extra_classes += ' NB-feed-inactive';
|
|
|
|
}
|
2012-05-22 15:02:37 -07:00
|
|
|
}
|
2012-05-22 17:39:21 -07:00
|
|
|
|
|
|
|
if (feed.is_social()) {
|
2012-06-27 16:46:19 -07:00
|
|
|
extra_classes += ' NB-feed-social';
|
2012-05-22 17:39:21 -07:00
|
|
|
if (feed.get('subscription_user_id') && !feed.get('shared_stories_count')) {
|
|
|
|
extra_classes += ' NB-feed-inactive';
|
|
|
|
}
|
2012-06-26 18:02:48 -07:00
|
|
|
if (feed.get('subscription_user_id') == NEWSBLUR.Globals.user_id) {
|
|
|
|
extra_classes += ' NB-feed-self-blurblog';
|
|
|
|
}
|
2012-05-22 15:02:37 -07:00
|
|
|
}
|
2012-05-24 17:32:01 -07:00
|
|
|
|
2012-05-22 15:02:37 -07:00
|
|
|
return extra_classes;
|
|
|
|
},
|
|
|
|
|
|
|
|
render_counts: function() {
|
2013-04-03 12:37:20 -07:00
|
|
|
this.counts_view = new NEWSBLUR.Views.UnreadCount({model: this.model}).render();
|
2012-05-22 15:02:37 -07:00
|
|
|
this.$('.feed_counts').html(this.counts_view.el);
|
2012-05-23 15:41:02 -07:00
|
|
|
if (this.options.type == 'story') {
|
|
|
|
this.$('.NB-story-title-indicator-count').html(this.counts_view.$el.clone());
|
|
|
|
}
|
2012-05-22 15:02:37 -07:00
|
|
|
},
|
|
|
|
|
2012-06-11 21:25:17 -07:00
|
|
|
setup_tooltips: function() {
|
|
|
|
if (this.options.type == 'story' && NEWSBLUR.assets.preference('show_tooltips')) {
|
|
|
|
this.$('.NB-feedbar-train-feed, .NB-feedbar-statistics').tipsy({
|
|
|
|
gravity: 's',
|
|
|
|
delayIn: 375
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
render_updated_time: function() {
|
|
|
|
if (this.options.type == 'story') {
|
|
|
|
var updated_text = this.model.get('updated') ?
|
|
|
|
this.model.get('updated') + ' ago' :
|
|
|
|
'Loading...';
|
|
|
|
this.$('.NB-feedbar-last-updated-date').text(updated_text);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-05-24 11:54:10 -07:00
|
|
|
select_feed: function() {
|
|
|
|
this.$el.toggleClass('selected', this.model.get('selected'));
|
|
|
|
this.$el.toggleClass('NB-selected', this.model.get('selected'));
|
2013-01-02 17:44:14 -08:00
|
|
|
|
|
|
|
_.each(this.folders, function(folder) {
|
|
|
|
folder.view.update_hidden();
|
|
|
|
});
|
2012-05-24 11:54:10 -07:00
|
|
|
},
|
|
|
|
|
2012-05-22 15:02:37 -07:00
|
|
|
flash_changes: function() {
|
2012-05-22 13:25:21 -07:00
|
|
|
var $highlight = this.$('.NB-feed-highlight');
|
2012-10-22 16:25:36 -07:00
|
|
|
$highlight.stop();
|
2012-05-22 13:25:21 -07:00
|
|
|
$highlight.css({
|
2013-01-31 15:23:17 -08:00
|
|
|
'backgroundColor': '#FED54A',
|
2012-05-22 13:25:21 -07:00
|
|
|
'display': 'block'
|
|
|
|
});
|
|
|
|
$highlight.animate({
|
|
|
|
'opacity': .7
|
|
|
|
}, {
|
|
|
|
'duration': 800,
|
|
|
|
'queue': false,
|
|
|
|
'complete': function() {
|
|
|
|
$highlight.animate({'opacity': 0}, {
|
|
|
|
'duration': 1000,
|
|
|
|
'queue': false,
|
|
|
|
'complete': function() {
|
|
|
|
$highlight.css('display', 'none');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2012-05-21 20:08:27 -07:00
|
|
|
},
|
|
|
|
|
2012-05-22 15:02:37 -07:00
|
|
|
add_extra_classes: function() {
|
|
|
|
var extra_classes = this.extra_classes();
|
|
|
|
$(this.el).removeClass("unread_positive unread_neutral unread_negative");
|
|
|
|
$(this.el).addClass(extra_classes);
|
|
|
|
},
|
|
|
|
|
2012-05-18 18:13:45 -07:00
|
|
|
// ==========
|
|
|
|
// = Events =
|
|
|
|
// ==========
|
|
|
|
|
2013-05-06 13:22:44 -07:00
|
|
|
open: function(e, options) {
|
|
|
|
options = options || {};
|
|
|
|
if (!options.ignore_double_click && $(e.target).closest('.feed_counts').length) {
|
|
|
|
_.delay(_.bind(function() {
|
|
|
|
if (!this.flags.double_click) {
|
|
|
|
this.open(e, {ignore_double_click: true});
|
|
|
|
}
|
|
|
|
}, this), 250);
|
|
|
|
return;
|
|
|
|
}
|
2012-08-31 13:20:25 -07:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2012-06-15 14:49:59 -07:00
|
|
|
if (this.options.feed_chooser) return;
|
2012-05-23 16:02:32 -07:00
|
|
|
if (this.options.type != 'feed') return;
|
2012-08-30 15:08:24 -07:00
|
|
|
if (e.which >= 2) return;
|
|
|
|
if (e.which == 1 && $('.NB-menu-manage-container:visible').length) return;
|
2012-05-23 16:02:32 -07:00
|
|
|
|
2012-05-23 17:21:06 -07:00
|
|
|
if (this.model.get('has_exception') && this.model.get('exception_type') == 'feed') {
|
|
|
|
NEWSBLUR.reader.open_feed_exception_modal(this.model.id);
|
2012-05-21 14:35:05 -07:00
|
|
|
} else if (this.model.is_social()) {
|
2012-05-23 10:02:30 -07:00
|
|
|
NEWSBLUR.reader.open_social_stories(this.model.id, {force: true, $feed: this.$el});
|
2012-05-19 10:29:27 -07:00
|
|
|
} else {
|
2012-05-23 10:02:30 -07:00
|
|
|
NEWSBLUR.reader.open_feed(this.model.id, {$feed: this.$el});
|
2012-05-19 10:29:27 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-30 15:06:30 -07:00
|
|
|
open_feed_link: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2013-01-25 16:18:30 -08:00
|
|
|
if (this.options.type == "story") return;
|
2012-07-29 00:49:34 -07:00
|
|
|
if ($('.NB-modal-feedchooser').is(':visible')) return;
|
|
|
|
|
2013-05-06 13:22:44 -07:00
|
|
|
this.flags.double_click = true;
|
|
|
|
_.delay(_.bind(function() {
|
|
|
|
this.flags.double_click = false;
|
|
|
|
}, this), 500);
|
|
|
|
|
2012-07-12 15:13:51 -07:00
|
|
|
NEWSBLUR.reader.mark_feed_as_read(this.model.id);
|
|
|
|
window.open(this.model.get('feed_link'), '_blank');
|
|
|
|
window.focus();
|
2012-10-30 15:06:30 -07:00
|
|
|
|
|
|
|
return false;
|
2012-07-12 15:13:51 -07:00
|
|
|
},
|
|
|
|
|
2012-09-07 17:36:12 -07:00
|
|
|
mark_feed_as_read: function(e) {
|
2013-03-18 18:46:17 -07:00
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2013-05-06 13:22:44 -07:00
|
|
|
}
|
|
|
|
this.flags.double_click = true;
|
|
|
|
_.delay(_.bind(function() {
|
|
|
|
this.flags.double_click = false;
|
|
|
|
}, this), 500);
|
|
|
|
NEWSBLUR.reader.mark_feed_as_read(this.model.id);
|
|
|
|
this.$('.NB-feedbar-mark-feed-read').fadeOut(400);
|
|
|
|
if (e) {
|
2013-03-18 18:46:17 -07:00
|
|
|
return false;
|
|
|
|
}
|
2012-09-07 17:36:12 -07:00
|
|
|
},
|
|
|
|
|
2013-07-12 15:21:11 -07:00
|
|
|
show_manage_menu_rightclick: function(e) {
|
|
|
|
if (!NEWSBLUR.assets.preference('show_contextmenus')) return;
|
|
|
|
|
|
|
|
return this.show_manage_menu(e);
|
|
|
|
},
|
|
|
|
|
2012-05-18 18:13:45 -07:00
|
|
|
show_manage_menu: function(e) {
|
2012-06-15 14:49:59 -07:00
|
|
|
if (this.options.feed_chooser) return;
|
2013-07-12 13:20:32 -07:00
|
|
|
|
2012-05-18 18:13:45 -07:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2012-08-30 18:31:44 -07:00
|
|
|
NEWSBLUR.log(["showing manage menu", this.model.is_social() ? 'socialfeed' : 'feed', $(this.el), this, e.which, e.button]);
|
2012-05-23 16:02:32 -07:00
|
|
|
NEWSBLUR.reader.show_manage_menu(this.model.is_social() ? 'socialfeed' : 'feed', this.$el, {
|
2012-05-21 20:08:27 -07:00
|
|
|
feed_id: this.model.id,
|
2012-08-30 18:31:44 -07:00
|
|
|
toplevel: this.options.depth == 0,
|
|
|
|
rightclick: e.which >= 2
|
2012-05-21 14:35:05 -07:00
|
|
|
});
|
2012-05-18 18:13:45 -07:00
|
|
|
return false;
|
2012-05-23 12:10:35 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
delete_feed: function() {
|
|
|
|
this.$el.slideUp(500);
|
|
|
|
|
|
|
|
if (this.model.get('selected')) {
|
|
|
|
NEWSBLUR.reader.reset_feed();
|
|
|
|
NEWSBLUR.reader.show_splash_page();
|
|
|
|
}
|
2012-05-23 16:02:32 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
add_hover_inverse: function() {
|
|
|
|
if (NEWSBLUR.app.feed_list.is_sorting()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-06 11:07:19 -07:00
|
|
|
if (this.$el.offset().top > $(window).height() - 334) {
|
2012-05-23 16:02:32 -07:00
|
|
|
this.$el.addClass('NB-hover-inverse');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
remove_hover_inverse: function() {
|
|
|
|
this.$el.removeClass('NB-hover-inverse');
|
2012-07-18 18:34:19 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
open_trainer: function() {
|
|
|
|
if (!$('.NB-task-manage').hasClass('NB-disabled')) {
|
|
|
|
NEWSBLUR.reader.open_feed_intelligence_modal(1, null, !NEWSBLUR.reader.flags.social_view);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
open_statistics: function() {
|
|
|
|
NEWSBLUR.reader.open_feed_statistics_modal();
|
|
|
|
},
|
|
|
|
|
2013-01-25 17:29:38 -08:00
|
|
|
open_options_popover: function() {
|
|
|
|
NEWSBLUR.FeedOptionsPopover.create({
|
|
|
|
anchor: this.$(".NB-feedbar-options"),
|
|
|
|
feed_id: this.model.id
|
|
|
|
});
|
2013-07-30 17:20:13 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
show_hidden_story_titles: function() {
|
|
|
|
NEWSBLUR.app.story_titles_header.show_hidden_story_titles();
|
2012-05-17 20:50:08 -07:00
|
|
|
}
|
2012-12-19 14:21:46 -08:00
|
|
|
|
2012-05-17 20:50:08 -07:00
|
|
|
});
|