mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Upgrading to latest Backbone and Underscore. May break shit.
This commit is contained in:
parent
d782b6106f
commit
9bcfd0ad41
11 changed files with 1075 additions and 734 deletions
|
@ -342,7 +342,7 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
|
|||
var pre_callback = function(feeds, subscriptions) {
|
||||
self.flags['favicons_fetching'] = self.feeds.any(function(feed) { return feed.get('favicons_fetching'); });
|
||||
|
||||
self.folders.reset(_.compact(subscriptions.folders));
|
||||
self.folders.reset(_.compact(subscriptions.folders), {parse: true});
|
||||
self.starred_count = subscriptions.starred_count;
|
||||
self.social_feeds.reset(subscriptions.social_feeds);
|
||||
self.user_profile.set(subscriptions.social_profile);
|
||||
|
@ -405,7 +405,6 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
|
|||
this.feed_id = feed_id;
|
||||
|
||||
if (feed_id) {
|
||||
console.log(["query", NEWSBLUR.reader.flags.search]);
|
||||
this.make_request('/reader/feed/'+feed_id,
|
||||
{
|
||||
page: page,
|
||||
|
@ -1229,8 +1228,8 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
|
|||
this.make_request('/social/load_user_friends', null, _.bind(function(data) {
|
||||
this.user_profile.set(data.user_profile);
|
||||
this.social_services = data.services;
|
||||
this.follower_profiles = new NEWSBLUR.Collections.Users(data.follower_profiles);
|
||||
this.following_profiles = new NEWSBLUR.Collections.Users(data.following_profiles);
|
||||
this.follower_profiles.reset(data.follower_profiles);
|
||||
this.following_profiles.reset(data.following_profiles);
|
||||
callback(data);
|
||||
}, this), null, {
|
||||
request_type: 'GET'
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
NEWSBLUR.Models.FeedOrFolder = Backbone.Model.extend({
|
||||
|
||||
initialize: function(model) {
|
||||
if (_.isNumber(model)) {
|
||||
this.feed = NEWSBLUR.assets.feeds.get(model);
|
||||
if (_.isNumber(model) || model['feed_id']) {
|
||||
this.feed = NEWSBLUR.assets.feeds.get(model['feed_id'] || model);
|
||||
|
||||
// The feed needs to exists as a model as well. Otherwise, toss it.
|
||||
if (this.feed) {
|
||||
|
@ -16,12 +16,20 @@ NEWSBLUR.Models.FeedOrFolder = Backbone.Model.extend({
|
|||
this.folder_views = [];
|
||||
this.folders = new NEWSBLUR.Collections.Folders([], {
|
||||
title: title,
|
||||
parent_folder: this.collection
|
||||
parent_folder: this.collection,
|
||||
parse: true
|
||||
});
|
||||
this.folders.reset(_.compact(children));
|
||||
this.folders.reset(_.compact(children), {parse: true});
|
||||
}
|
||||
},
|
||||
|
||||
parse: function(attrs) {
|
||||
if (_.isNumber(attrs)) {
|
||||
attrs = {'feed_id': attrs};
|
||||
}
|
||||
return attrs;
|
||||
},
|
||||
|
||||
is_feed: function() {
|
||||
return !!this.get('is_feed');
|
||||
},
|
||||
|
|
|
@ -10,7 +10,7 @@ NEWSBLUR.Models.Story = Backbone.Model.extend({
|
|||
this.story_title = this.get('story_title');
|
||||
},
|
||||
|
||||
populate_comments: function(story, collection, changes) {
|
||||
populate_comments: function(story, collection) {
|
||||
this.friend_comments = new NEWSBLUR.Collections.Comments(this.get('friend_comments'));
|
||||
this.public_comments = new NEWSBLUR.Collections.Comments(this.get('public_comments'));
|
||||
},
|
||||
|
@ -43,7 +43,7 @@ NEWSBLUR.Models.Story = Backbone.Model.extend({
|
|||
return NEWSBLUR.assets.stories.mark_read(this, options);
|
||||
},
|
||||
|
||||
change_selected: function(model, selected, changes) {
|
||||
change_selected: function(model, selected) {
|
||||
if (model.collection) {
|
||||
model.collection.detect_selected_story(model, selected);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,10 @@ NEWSBLUR.Collections.Users = Backbone.Collection.extend({
|
|||
|
||||
find: function(user_id) {
|
||||
return this.detect(function(user) { return user.get('user_id') == user_id; });
|
||||
},
|
||||
|
||||
comparator: function(model) {
|
||||
return -1 * model.get('shared_stories_count');
|
||||
}
|
||||
|
||||
});
|
|
@ -2208,11 +2208,7 @@
|
|||
}
|
||||
|
||||
if (NEWSBLUR.app.story_titles_header) {
|
||||
if (NEWSBLUR.app.story_titles_header.destroy) {
|
||||
NEWSBLUR.app.story_titles_header.destroy();
|
||||
} else {
|
||||
NEWSBLUR.app.story_titles_header.remove();
|
||||
}
|
||||
NEWSBLUR.app.story_titles_header.remove();
|
||||
}
|
||||
|
||||
NEWSBLUR.app.story_titles_header = new NEWSBLUR.Views.StoryTitlesHeader({
|
||||
|
|
|
@ -19,10 +19,10 @@ NEWSBLUR.Views.FeedTitleView = Backbone.View.extend({
|
|||
},
|
||||
|
||||
initialize: function() {
|
||||
_.bindAll(this, 'render', 'delete_feed');
|
||||
_.bindAll(this, 'render', 'delete_feed', 'changed', 'render_updated_time');
|
||||
if (!this.options.feed_chooser) {
|
||||
this.model.bind('change', this.changed, this);
|
||||
this.model.bind('change:updated', this.render_updated_time, this);
|
||||
this.listenTo(this.model, 'change', this.changed);
|
||||
this.listenTo(this.model, 'change:updated', this.render_updated_time);
|
||||
}
|
||||
|
||||
if (this.model.is_social() && !this.model.get('feed_title')) {
|
||||
|
@ -31,19 +31,17 @@ NEWSBLUR.Views.FeedTitleView = Backbone.View.extend({
|
|||
}
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
this.$el.empty();
|
||||
this.model.unbind(null, this);
|
||||
},
|
||||
|
||||
changed: function(model, options) {
|
||||
var counts_changed = options.changes && _.any(_.keys(options.changes), function(key) {
|
||||
options = options || {};
|
||||
var changes = _.keys(this.model.changedAttributes());
|
||||
|
||||
var counts_changed = _.any(changes, function(key) {
|
||||
return _.contains(['ps', 'nt', 'ng'], key);
|
||||
});
|
||||
var only_counts_changed = options.changes && !_.any(_.keys(options.changes), function(key) {
|
||||
var only_counts_changed = !_.any(changes, function(key) {
|
||||
return !_.contains(['ps', 'nt', 'ng'], key);
|
||||
});
|
||||
var only_selected_changed = options.changes && !_.any(_.keys(options.changes), function(key) {
|
||||
var only_selected_changed = !_.any(changes, function(key) {
|
||||
return key != 'selected';
|
||||
});
|
||||
|
||||
|
|
|
@ -268,6 +268,7 @@ NEWSBLUR.Views.StoryDetailView = Backbone.View.extend({
|
|||
},
|
||||
|
||||
toggle_selected: function(model, selected, options) {
|
||||
options = options || {};
|
||||
this.$el.toggleClass('NB-selected', !!this.model.get('selected'));
|
||||
|
||||
if (selected && options.scroll_to_comments) {
|
||||
|
|
|
@ -116,7 +116,7 @@ NEWSBLUR.Views.StoryListView = Backbone.View.extend({
|
|||
var $story = story.story_view.$el;
|
||||
$header = $('.NB-feed-story-header-feed', $story);
|
||||
var $new_header = $header.clone();
|
||||
if (this.feed_title_floater) this.feed_title_floater.destroy();
|
||||
if (this.feed_title_floater) this.feed_title_floater.remove();
|
||||
this.feed_title_floater = new NEWSBLUR.Views.StoryDetailView({
|
||||
feed_floater: true,
|
||||
model: story,
|
||||
|
@ -129,7 +129,7 @@ NEWSBLUR.Views.StoryListView = Backbone.View.extend({
|
|||
$feed_floater.toggleClass('NB-inverse', feed && feed.is_light());
|
||||
$feed_floater.width($header.outerWidth());
|
||||
} else if (!story || !story.get('story_feed_id')) {
|
||||
if (this.feed_title_floater) this.feed_title_floater.destroy();
|
||||
if (this.feed_title_floater) this.feed_title_floater.remove();
|
||||
this.cache.feed_title_floater_feed_id = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,18 +3,20 @@ NEWSBLUR.Views.StoryTitlesHeader = Backbone.View.extend({
|
|||
el: $('.NB-feedbar'),
|
||||
|
||||
render: function() {
|
||||
var $view;
|
||||
|
||||
if (NEWSBLUR.reader.active_feed == 'starred') {
|
||||
var $view = $(_.template('\
|
||||
$view = $(_.template('\
|
||||
<div class="NB-folder NB-no-hover">\
|
||||
<div class="NB-starred-icon"></div>\
|
||||
<div class="NB-feedlist-manage-icon"></div>\
|
||||
<div class="folder_title_text">Saved Stories</div>\
|
||||
</div>\
|
||||
', {}));
|
||||
var search_view = new NEWSBLUR.Views.FeedSearchView({
|
||||
this.view = new NEWSBLUR.Views.FeedSearchView({
|
||||
feedbar_view: this
|
||||
}).render();
|
||||
$view.append(search_view.$el);
|
||||
$view.append(this.view.$el);
|
||||
} else if (NEWSBLUR.reader.flags['river_view'] &&
|
||||
NEWSBLUR.reader.active_folder &&
|
||||
NEWSBLUR.reader.active_folder.get('fake')) {
|
||||
|
@ -26,7 +28,7 @@ NEWSBLUR.Views.StoryTitlesHeader = Backbone.View.extend({
|
|||
title = "All Shared Stories";
|
||||
}
|
||||
}
|
||||
var $view = $(_.template('\
|
||||
$view = $(_.template('\
|
||||
<div class="NB-folder NB-no-hover">\
|
||||
<div class="NB-story-title-indicator">\
|
||||
<div class="NB-story-title-indicator-count"></div>\
|
||||
|
@ -42,17 +44,19 @@ NEWSBLUR.Views.StoryTitlesHeader = Backbone.View.extend({
|
|||
} else if (NEWSBLUR.reader.flags['river_view'] &&
|
||||
NEWSBLUR.reader.active_folder &&
|
||||
NEWSBLUR.reader.active_folder.get('folder_title')) {
|
||||
var $view = new NEWSBLUR.Views.Folder({
|
||||
this.view = new NEWSBLUR.Views.Folder({
|
||||
model: NEWSBLUR.reader.active_folder,
|
||||
collection: NEWSBLUR.reader.active_folder.folder_view.collection,
|
||||
feedbar: true,
|
||||
only_title: true
|
||||
}).render().$el;
|
||||
}).render();
|
||||
$view = this.view.$el;
|
||||
} else {
|
||||
var $view = new NEWSBLUR.Views.FeedTitleView({
|
||||
this.view = new NEWSBLUR.Views.FeedTitleView({
|
||||
model: NEWSBLUR.assets.get_feed(this.options.feed_id),
|
||||
type: 'story'
|
||||
}).render().$el;
|
||||
}).render();
|
||||
$view = this.view.$el;
|
||||
}
|
||||
|
||||
this.$el.html($view);
|
||||
|
@ -62,6 +66,13 @@ NEWSBLUR.Views.StoryTitlesHeader = Backbone.View.extend({
|
|||
return this;
|
||||
},
|
||||
|
||||
remove: function() {
|
||||
if (this.view) {
|
||||
this.view.remove();
|
||||
}
|
||||
Backbone.View.prototype.remove.call(this);
|
||||
},
|
||||
|
||||
// ===========
|
||||
// = Actions =
|
||||
// ===========
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue