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
|
|
|
"contextmenu" : "show_manage_menu",
|
|
|
|
"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",
|
|
|
|
"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() {
|
2012-06-07 13:56:54 -07:00
|
|
|
_.bindAll(this, 'update_title', 'update_selected', 'delete_folder', 'check_collapsed');
|
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);
|
2012-05-23 21:07:01 -07:00
|
|
|
this.model.bind('delete', this.delete_folder);
|
2012-06-11 22:43:29 -07:00
|
|
|
this.model.folder_view = this;
|
2012-05-23 20:20:11 -07:00
|
|
|
}
|
2012-06-15 14:49:59 -07:00
|
|
|
|
|
|
|
if (this.collection && !this.options.feed_chooser) {
|
2012-06-11 22:25:20 -07:00
|
|
|
this.collection.bind('change:counts', this.check_collapsed);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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-08-01 20:30:16 -07:00
|
|
|
this.$el.html($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});
|
|
|
|
|
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('\
|
|
|
|
<% 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>\
|
|
|
|
</div>\
|
|
|
|
<% } %>\
|
|
|
|
<ul class="folder <% if (root) { %>NB-root<% } %>" <% if (is_collapsed) { %>style="display: none"<% } %>>\
|
|
|
|
</ul>\
|
|
|
|
', {
|
|
|
|
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-05-18 16:59:39 -07:00
|
|
|
root : this.options.root
|
|
|
|
});
|
|
|
|
|
|
|
|
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'));
|
|
|
|
},
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var $counts = new NEWSBLUR.Views.FolderCount({collection: this.collection}).render().$el;
|
|
|
|
$folder_title.prepend($counts.css({
|
|
|
|
'opacity': 0
|
|
|
|
}));
|
|
|
|
$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-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-05-23 16:02:32 -07:00
|
|
|
|
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-06-11 22:25:20 -07:00
|
|
|
folder_title: this.options.folder_title
|
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;
|
|
|
|
}
|
|
|
|
|
2012-07-06 11:07:19 -07:00
|
|
|
if (this.$el.offset().top > $(window).height() - 194) {
|
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-05-17 20:50:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|