2012-05-17 20:50:08 -07:00
|
|
|
NEWSBLUR.Views.Folder = Backbone.View.extend({
|
|
|
|
|
2012-05-18 16:59:39 -07:00
|
|
|
className: 'folder',
|
2012-05-17 20:50:08 -07:00
|
|
|
|
2012-05-18 16:59:39 -07:00
|
|
|
tagName: 'li',
|
|
|
|
|
|
|
|
options: {
|
|
|
|
depth: 0,
|
|
|
|
collapsed: false,
|
|
|
|
title: '',
|
|
|
|
root: false
|
2012-05-17 20:50:08 -07:00
|
|
|
},
|
|
|
|
|
2012-05-23 16:02:32 -07:00
|
|
|
events: {
|
2012-06-07 13:56:54 -07:00
|
|
|
"click .NB-feedlist-manage-icon" : "show_manage_menu",
|
2012-06-11 22:25:20 -07:00
|
|
|
"click .folder_title" : "open",
|
2012-06-07 13:56:54 -07:00
|
|
|
"click .NB-feedlist-collapse-icon" : "collapse_folder",
|
2012-09-07 17:36:12 -07:00
|
|
|
"click .NB-feedbar-settings" : "open_settings",
|
|
|
|
"click .NB-feedbar-mark-feed-read" : "mark_folder_as_read",
|
|
|
|
"click .NB-story-title-indicator" : "show_hidden_story_titles",
|
2012-06-07 13:56:54 -07:00
|
|
|
"mouseenter" : "add_hover_inverse",
|
|
|
|
"mouseleave" : "remove_hover_inverse"
|
2012-05-23 16:02:32 -07:00
|
|
|
},
|
|
|
|
|
2012-05-23 20:20:11 -07:00
|
|
|
initialize: function() {
|
2013-01-02 17:44:14 -08:00
|
|
|
_.bindAll(this, 'update_title', 'update_selected', 'delete_folder', 'check_collapsed',
|
|
|
|
'update_hidden');
|
2012-08-01 20:30:16 -07:00
|
|
|
|
2012-06-15 14:49:59 -07:00
|
|
|
this.options.folder_title = this.model && this.model.get('folder_title');
|
|
|
|
|
|
|
|
if (this.model && !this.options.feed_chooser) {
|
2012-05-23 20:20:11 -07:00
|
|
|
// Root folder does not have a model.
|
|
|
|
this.model.bind('change:folder_title', this.update_title);
|
2012-05-24 11:54:10 -07:00
|
|
|
this.model.bind('change:selected', this.update_selected);
|
2013-01-02 17:44:14 -08:00
|
|
|
this.model.bind('change:selected', this.update_hidden);
|
|
|
|
this.collection.bind('change:feed_selected', this.update_hidden);
|
|
|
|
this.collection.bind('change:counts', this.update_hidden);
|
2012-05-23 21:07:01 -07:00
|
|
|
this.model.bind('delete', this.delete_folder);
|
2012-09-07 17:36:12 -07:00
|
|
|
if (!this.options.feedbar) {
|
|
|
|
this.model.folder_view = this;
|
|
|
|
}
|
2012-05-23 20:20:11 -07:00
|
|
|
}
|
2012-06-11 22:25:20 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
if (this.model) {
|
|
|
|
this.model.unbind(null, this);
|
|
|
|
}
|
|
|
|
this.$el.remove();
|
2012-05-23 20:20:11 -07:00
|
|
|
},
|
|
|
|
|
2012-05-17 20:50:08 -07:00
|
|
|
render: function() {
|
2012-05-18 16:59:39 -07:00
|
|
|
var depth = this.options.depth;
|
2012-06-11 22:25:20 -07:00
|
|
|
var folder_title = this.options.folder_title;
|
2012-06-15 14:49:59 -07:00
|
|
|
var feed_chooser = this.options.feed_chooser;
|
2012-08-01 20:30:16 -07:00
|
|
|
var folder_collection = this.collection;
|
2012-06-11 22:25:20 -07:00
|
|
|
this.options.collapsed = folder_title && _.contains(NEWSBLUR.Preferences.collapsed_folders, folder_title);
|
2012-05-18 16:59:39 -07:00
|
|
|
var $folder = this.render_folder();
|
2012-06-11 22:25:20 -07:00
|
|
|
|
|
|
|
if (!this.options.only_title) {
|
2012-08-01 20:30:16 -07:00
|
|
|
var $feeds = _.compact(this.collection.map(function(item) {
|
2012-06-11 22:25:20 -07:00
|
|
|
if (item.is_feed()) {
|
|
|
|
var feed_title_view = new NEWSBLUR.Views.FeedTitleView({
|
|
|
|
model: item.feed,
|
|
|
|
type: 'feed',
|
|
|
|
depth: depth,
|
|
|
|
folder_title: folder_title,
|
2012-08-01 20:30:16 -07:00
|
|
|
folder: folder_collection,
|
2012-06-15 14:49:59 -07:00
|
|
|
feed_chooser: feed_chooser
|
2012-06-11 22:25:20 -07:00
|
|
|
}).render();
|
|
|
|
item.feed.views.push(feed_title_view);
|
2012-08-01 20:30:16 -07:00
|
|
|
item.feed.folders.push(folder_collection);
|
2012-06-11 22:25:20 -07:00
|
|
|
return feed_title_view.el;
|
|
|
|
} else if (item.is_folder()) {
|
|
|
|
var folder_view = new NEWSBLUR.Views.Folder({
|
|
|
|
model: item,
|
|
|
|
collection: item.folders,
|
2012-06-15 14:49:59 -07:00
|
|
|
depth: depth + 1,
|
|
|
|
feed_chooser: feed_chooser
|
2012-06-11 22:25:20 -07:00
|
|
|
}).render();
|
|
|
|
item.folder_views.push(folder_view);
|
|
|
|
return folder_view.el;
|
2012-08-01 20:30:16 -07:00
|
|
|
} else {
|
|
|
|
console.log(["Not a feed or folder", item]);
|
2012-06-11 22:25:20 -07:00
|
|
|
}
|
2012-08-01 20:30:16 -07:00
|
|
|
}));
|
|
|
|
$feeds.push(this.make('li', { 'class': 'feed NB-empty' }));
|
2012-06-11 22:25:20 -07:00
|
|
|
this.$('.folder').append($feeds);
|
|
|
|
}
|
|
|
|
|
2012-06-07 13:56:54 -07:00
|
|
|
this.check_collapsed({skip_animation: true});
|
2013-01-02 17:44:14 -08:00
|
|
|
this.update_hidden();
|
2012-08-30 18:31:44 -07:00
|
|
|
this.$('.folder_title').eq(0).bind('contextmenu', _.bind(this.show_manage_menu, this));
|
2012-06-07 13:56:54 -07:00
|
|
|
|
2012-05-17 20:50:08 -07:00
|
|
|
return this;
|
2012-05-18 16:59:39 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
render_folder: function($feeds) {
|
|
|
|
var $folder = _.template('\
|
2012-09-07 17:36:12 -07:00
|
|
|
<<%= list_type %> class="folder NB-folder">\
|
2012-05-18 16:59:39 -07:00
|
|
|
<% if (!root) { %>\
|
2012-05-23 16:02:32 -07:00
|
|
|
<div class="folder_title <% if (depth <= 1) { %>NB-toplevel<% } %>">\
|
2012-05-18 16:59:39 -07:00
|
|
|
<div class="NB-folder-icon"></div>\
|
|
|
|
<div class="NB-feedlist-collapse-icon" title="<% if (is_collapsed) { %>Expand Folder<% } else {%>Collapse Folder<% } %>"></div>\
|
|
|
|
<div class="NB-feedlist-manage-icon"></div>\
|
|
|
|
<span class="folder_title_text"><%= folder_title %></span>\
|
2012-09-07 17:36:12 -07:00
|
|
|
<% if (feedbar) { %>\
|
|
|
|
<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>\
|
|
|
|
<span class="NB-feedbar-settings" title="Site settings"></span>\
|
|
|
|
<div class="NB-feedbar-mark-feed-read">Mark All as Read</div>\
|
|
|
|
<% } %>\
|
2012-05-18 16:59:39 -07:00
|
|
|
</div>\
|
|
|
|
<% } %>\
|
2012-09-07 17:36:12 -07:00
|
|
|
<% if (!feedbar) { %>\
|
|
|
|
<ul class="folder <% if (root) { %>NB-root<% } %>" <% if (is_collapsed) { %>style="display: none"<% } %>>\
|
|
|
|
</ul>\
|
|
|
|
<% } %>\
|
|
|
|
</<%= list_type %>>\
|
2012-05-18 16:59:39 -07:00
|
|
|
', {
|
|
|
|
depth : this.options.depth,
|
2012-06-11 22:25:20 -07:00
|
|
|
folder_title : this.options.folder_title,
|
2012-06-18 15:59:31 -07:00
|
|
|
is_collapsed : this.options.collapsed && !this.options.feed_chooser,
|
2012-09-07 17:36:12 -07:00
|
|
|
root : this.options.root,
|
|
|
|
feedbar : this.options.feedbar,
|
|
|
|
list_type : this.options.feedbar ? 'div' : 'li'
|
2012-05-18 16:59:39 -07:00
|
|
|
});
|
|
|
|
|
2012-09-07 17:36:12 -07:00
|
|
|
this.$el.replaceWith($folder);
|
|
|
|
this.setElement($folder);
|
|
|
|
|
|
|
|
if (this.options.feedbar) {
|
|
|
|
this.show_collapsed_folder_count();
|
|
|
|
}
|
2012-05-18 16:59:39 -07:00
|
|
|
return $folder;
|
2012-05-23 16:02:32 -07:00
|
|
|
},
|
|
|
|
|
2012-05-23 20:20:11 -07:00
|
|
|
update_title: function() {
|
2012-06-11 22:25:20 -07:00
|
|
|
this.$('.folder_title_text').eq(0).html(this.options.folder_title);
|
2012-05-23 20:20:11 -07:00
|
|
|
},
|
|
|
|
|
2012-05-24 11:54:10 -07:00
|
|
|
update_selected: function() {
|
|
|
|
this.$el.toggleClass('NB-selected', this.model.get('selected'));
|
|
|
|
},
|
|
|
|
|
2013-01-02 17:44:14 -08:00
|
|
|
update_hidden: function() {
|
|
|
|
if (!this.model) return;
|
|
|
|
|
|
|
|
var has_unreads = this.model.has_unreads({include_selected: true});
|
2013-01-02 18:37:15 -08:00
|
|
|
if (!has_unreads && NEWSBLUR.assets.preference('hide_read_feeds')) {
|
2013-01-02 17:44:14 -08:00
|
|
|
this.$el.addClass('NB-hidden');
|
2013-01-02 18:00:14 -08:00
|
|
|
} else {
|
|
|
|
this.$el.removeClass('NB-hidden');
|
2013-01-02 17:44:14 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-06-07 13:56:54 -07:00
|
|
|
// ===========
|
|
|
|
// = Actions =
|
|
|
|
// ===========
|
|
|
|
|
|
|
|
check_collapsed: function(options) {
|
|
|
|
options = options || {};
|
|
|
|
var self = this;
|
2012-06-11 22:25:20 -07:00
|
|
|
if (!this.options.folder_title || !this.options.folder_title.length) return;
|
2012-06-07 13:56:54 -07:00
|
|
|
|
|
|
|
var show_folder_counts = NEWSBLUR.assets.preference('folder_counts');
|
2012-06-11 22:25:20 -07:00
|
|
|
var collapsed = _.contains(NEWSBLUR.Preferences.collapsed_folders, this.options.folder_title);
|
2012-06-07 13:56:54 -07:00
|
|
|
if (collapsed || show_folder_counts) {
|
|
|
|
this.show_collapsed_folder_count(options);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
show_collapsed_folder_count: function(options) {
|
|
|
|
options = options || {};
|
|
|
|
var $folder_title = this.$('.folder_title').eq(0);
|
|
|
|
var $counts = $('.feed_counts_floater', $folder_title);
|
|
|
|
var $river = $('.NB-feedlist-collapse-icon', $folder_title);
|
|
|
|
|
2012-06-14 15:03:20 -07:00
|
|
|
this.$el.addClass('NB-folder-collapsed');
|
2012-06-07 13:56:54 -07:00
|
|
|
$counts.remove();
|
|
|
|
|
|
|
|
if ($folder_title.hasClass('NB-hover')) {
|
|
|
|
$river.animate({'opacity': 0}, {'duration': options.skip_animation ? 0 : 100});
|
|
|
|
$folder_title.addClass('NB-feedlist-folder-title-recently-collapsed');
|
|
|
|
$folder_title.one('mouseover', function() {
|
|
|
|
$river.css({'opacity': ''});
|
|
|
|
$folder_title.removeClass('NB-feedlist-folder-title-recently-collapsed');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-01-02 17:44:14 -08:00
|
|
|
this.folder_count = new NEWSBLUR.Views.FolderCount({
|
|
|
|
collection: this.collection
|
|
|
|
}).render();
|
|
|
|
var $counts = this.folder_count.$el;
|
2012-09-07 17:36:12 -07:00
|
|
|
if (this.options.feedbar) {
|
|
|
|
this.$('.NB-story-title-indicator-count').html($counts.clone());
|
|
|
|
} else {
|
|
|
|
$folder_title.prepend($counts.css({
|
|
|
|
'opacity': 0
|
|
|
|
}));
|
|
|
|
}
|
2012-06-07 13:56:54 -07:00
|
|
|
$counts.animate({'opacity': 1}, {'duration': options.skip_animation ? 0 : 400});
|
|
|
|
},
|
|
|
|
|
|
|
|
hide_collapsed_folder_count: function() {
|
|
|
|
var $folder_title = this.$('.folder_title').eq(0);
|
|
|
|
var $counts = $('.feed_counts_floater', $folder_title);
|
|
|
|
var $river = $('.NB-feedlist-collapse-icon', $folder_title);
|
|
|
|
|
|
|
|
$counts.animate({'opacity': 0}, {
|
|
|
|
'duration': 300
|
|
|
|
});
|
|
|
|
|
|
|
|
$river.animate({'opacity': .6}, {'duration': 400});
|
|
|
|
$folder_title.removeClass('NB-feedlist-folder-title-recently-collapsed');
|
|
|
|
$folder_title.one('mouseover', function() {
|
|
|
|
$river.css({'opacity': ''});
|
|
|
|
$folder_title.removeClass('NB-feedlist-folder-title-recently-collapsed');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-05-23 16:02:32 -07:00
|
|
|
// ==========
|
|
|
|
// = Events =
|
|
|
|
// ==========
|
|
|
|
|
|
|
|
open: function(e) {
|
2012-09-05 12:43:31 -07:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2012-06-15 14:49:59 -07:00
|
|
|
if (this.options.feed_chooser) return;
|
2012-06-11 22:25:20 -07:00
|
|
|
var $folder = $(e.currentTarget).closest('li.folder');
|
|
|
|
if ($folder[0] != this.el) return;
|
|
|
|
if ($(e.currentTarget)[0] != this.$('.folder_title')[0]) 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-06-11 22:25:20 -07:00
|
|
|
NEWSBLUR.reader.open_river_stories(this.$el, this.model);
|
2012-05-23 16:02:32 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
show_manage_menu: function(e) {
|
2012-06-15 14:49:59 -07:00
|
|
|
if (this.options.feed_chooser) return;
|
2012-05-23 16:02:32 -07:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2012-06-11 22:25:20 -07:00
|
|
|
|
2012-05-23 16:02:32 -07:00
|
|
|
NEWSBLUR.reader.show_manage_menu('folder', this.$el, {
|
2012-05-25 18:54:04 -07:00
|
|
|
toplevel: this.options.depth == 0,
|
2012-08-30 18:31:44 -07:00
|
|
|
folder_title: this.options.folder_title,
|
|
|
|
rightclick: e.which >= 2
|
2012-05-23 16:02:32 -07:00
|
|
|
});
|
2012-06-11 22:25:20 -07:00
|
|
|
|
2012-05-23 16:02:32 -07:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
add_hover_inverse: function() {
|
|
|
|
if (NEWSBLUR.app.feed_list.is_sorting()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-10 15:40:43 -08:00
|
|
|
if (this.$el.offset().top > $(window).height() - 246) {
|
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-05-23 21:07:01 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
delete_folder: function() {
|
|
|
|
this.$el.slideUp(500);
|
|
|
|
|
|
|
|
var feed_ids_in_folder = this.model.feed_ids_in_folder();
|
|
|
|
if (_.contains(feed_ids_in_folder, NEWSBLUR.reader.active_feed)) {
|
|
|
|
NEWSBLUR.reader.reset_feed();
|
|
|
|
NEWSBLUR.reader.show_splash_page();
|
|
|
|
}
|
2012-06-07 13:56:54 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
collapse_folder: function(e, options) {
|
2012-06-11 22:25:20 -07:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2012-06-07 13:56:54 -07:00
|
|
|
options = options || {};
|
|
|
|
var self = this;
|
|
|
|
var $children = this.$el.children('ul.folder');
|
|
|
|
var $folder = $(e.currentTarget).closest('li.folder');
|
|
|
|
if ($folder[0] != this.el) return;
|
|
|
|
|
|
|
|
// Hiding / Collapsing
|
|
|
|
if (options.force_collapse ||
|
|
|
|
($children.length &&
|
|
|
|
$children.eq(0).is(':visible') &&
|
|
|
|
!this.collection.collapsed)) {
|
2012-07-10 15:26:34 -07:00
|
|
|
NEWSBLUR.log(["hiding folder", $children, this.collection, this.options.folder_title]);
|
2012-06-11 22:25:20 -07:00
|
|
|
NEWSBLUR.assets.collapsed_folders(this.options.folder_title, true);
|
2012-06-07 13:56:54 -07:00
|
|
|
this.collection.collapsed = true;
|
|
|
|
this.$el.addClass('NB-folder-collapsed');
|
|
|
|
$children.animate({'opacity': 0}, {
|
|
|
|
'queue': false,
|
|
|
|
'duration': options.force_collapse ? 0 : 200,
|
|
|
|
'complete': function() {
|
|
|
|
self.show_collapsed_folder_count();
|
|
|
|
$children.slideUp({
|
|
|
|
'duration': 270,
|
|
|
|
'easing': 'easeOutQuart'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Showing / Expanding
|
|
|
|
else if ($children.length &&
|
|
|
|
(this.collection.collapsed || !$children.eq(0).is(':visible'))) {
|
2012-07-10 15:26:34 -07:00
|
|
|
NEWSBLUR.log(["showing folder", this.collection, this.options.folder_title]);
|
2012-06-11 22:25:20 -07:00
|
|
|
NEWSBLUR.assets.collapsed_folders(this.options.folder_title, false);
|
2012-06-07 13:56:54 -07:00
|
|
|
this.collection.collapsed = false;
|
|
|
|
this.$el.removeClass('NB-folder-collapsed');
|
|
|
|
if (!NEWSBLUR.assets.preference('folder_counts')) {
|
|
|
|
this.hide_collapsed_folder_count();
|
|
|
|
}
|
|
|
|
$children.css({'opacity': 0}).slideDown({
|
|
|
|
'duration': 240,
|
|
|
|
'easing': 'easeInOutCubic',
|
|
|
|
'complete': function() {
|
|
|
|
$children.animate({'opacity': 1}, {'queue': false, 'duration': 200});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-09-07 17:36:12 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
open_settings: function(e) {
|
|
|
|
this.show_manage_menu(e);
|
|
|
|
},
|
|
|
|
|
|
|
|
mark_folder_as_read: function() {
|
|
|
|
NEWSBLUR.reader.mark_folder_as_read();
|
|
|
|
this.$('.NB-feedbar-mark-feed-read').fadeOut(400);
|
|
|
|
},
|
|
|
|
|
|
|
|
show_hidden_story_titles: function() {
|
|
|
|
NEWSBLUR.app.story_titles_header.show_hidden_story_titles();
|
2012-05-17 20:50:08 -07:00
|
|
|
}
|
2012-09-07 17:36:12 -07:00
|
|
|
|
2012-05-17 20:50:08 -07:00
|
|
|
|
|
|
|
});
|