2013-01-29 16:47:44 -08:00
|
|
|
NEWSBLUR.InteractionsPopover = NEWSBLUR.ReaderPopover.extend({
|
|
|
|
|
|
|
|
className: "NB-interactions-popover",
|
|
|
|
|
|
|
|
options: {
|
|
|
|
'width': 336,
|
|
|
|
'anchor': '.NB-feeds-header-user-interactions',
|
2013-01-29 18:35:24 -08:00
|
|
|
'placement': '-bottom',
|
2013-01-29 16:47:44 -08:00
|
|
|
'overlay_top': true,
|
|
|
|
offset: {
|
2013-01-29 18:35:24 -08:00
|
|
|
top: 36,
|
2013-01-29 16:47:44 -08:00
|
|
|
left: -1
|
2013-01-29 18:35:24 -08:00
|
|
|
},
|
|
|
|
'tab': 'interactions'
|
2013-01-29 16:47:44 -08:00
|
|
|
},
|
|
|
|
|
2013-01-29 18:35:24 -08:00
|
|
|
page: 0,
|
|
|
|
|
2013-01-29 16:47:44 -08:00
|
|
|
events: {
|
2013-01-29 18:35:24 -08:00
|
|
|
"click .NB-tab" : "switch_tab"
|
2013-01-29 16:47:44 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function(options) {
|
|
|
|
this.options = _.extend({}, this.options, options);
|
2013-01-29 18:35:24 -08:00
|
|
|
NEWSBLUR.ReaderPopover.prototype.initialize.call(this);
|
|
|
|
|
2013-01-29 16:47:44 -08:00
|
|
|
this.model = NEWSBLUR.assets;
|
2013-01-29 18:35:24 -08:00
|
|
|
this.render();
|
|
|
|
this.show_loading();
|
|
|
|
|
|
|
|
$(".NB-feeds-header-user-notifications").addClass('NB-active');
|
2013-01-29 16:47:44 -08:00
|
|
|
|
2013-01-29 18:35:24 -08:00
|
|
|
this.fetch_next_page();
|
2013-01-29 16:47:44 -08:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
close: function() {
|
|
|
|
$(".NB-feeds-header-user-notifications").removeClass('NB-active');
|
2013-01-29 18:35:24 -08:00
|
|
|
NEWSBLUR.ReaderPopover.prototype.close.call(this);
|
2013-01-29 16:47:44 -08:00
|
|
|
},
|
|
|
|
|
2013-01-29 18:35:24 -08:00
|
|
|
render: function() {
|
2013-01-29 16:47:44 -08:00
|
|
|
var self = this;
|
|
|
|
|
2013-01-29 18:35:24 -08:00
|
|
|
if (!this._on_page) {
|
|
|
|
NEWSBLUR.ReaderPopover.prototype.render.call(this);
|
|
|
|
this._on_page = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var $tab = $.make('div', [
|
|
|
|
$.make('div', { className: 'NB-interactions-header' }, [
|
|
|
|
$.make("div", { className: "NB-tab NB-tab-interactions" }, [
|
|
|
|
$.make('span', "Interactions")
|
|
|
|
]),
|
|
|
|
$.make("div", { className: "NB-tab NB-tab-activities" }, [
|
|
|
|
$.make('span', "Activities")
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-interactions-container ' + (this.options.tab == 'interactions' && 'NB-active') }),
|
|
|
|
$.make('div', { className: 'NB-activities-container ' + (this.options.tab == 'activities' && 'NB-active') })
|
|
|
|
]);
|
|
|
|
|
|
|
|
console.log(["render", this.$el, $tab]);
|
|
|
|
this.$el.html($tab);
|
|
|
|
this.$el.removeClass("NB-active-interactions");
|
|
|
|
this.$el.removeClass("NB-active-activities");
|
|
|
|
this.$el.addClass("NB-active-" + this.options.tab);
|
2013-01-29 16:47:44 -08:00
|
|
|
|
|
|
|
return this;
|
2013-01-29 18:35:24 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
// ===========
|
|
|
|
// = Actions =
|
|
|
|
// ===========
|
|
|
|
|
|
|
|
show_loading: function() {
|
|
|
|
this.hide_loading();
|
|
|
|
|
|
|
|
var $loading = $.make('div', { className: "NB-loading" });
|
|
|
|
this.$(".NB-"+this.options.tab+"-container").append($loading);
|
|
|
|
},
|
|
|
|
|
|
|
|
hide_loading: function() {
|
|
|
|
this.$(".NB-loading").remove();
|
|
|
|
},
|
|
|
|
|
|
|
|
fetch_next_page: function() {
|
|
|
|
this.page += 1;
|
|
|
|
this.show_loading();
|
|
|
|
|
|
|
|
this.model['load_'+this.options.tab+'_page'](this.page, _.bind(function(resp) {
|
|
|
|
this.hide_loading();
|
|
|
|
this.$(".NB-"+this.options.tab+"-container").append($(resp));
|
|
|
|
}, this));
|
|
|
|
},
|
2013-01-29 16:47:44 -08:00
|
|
|
|
|
|
|
// ==========
|
|
|
|
// = Events =
|
|
|
|
// ==========
|
|
|
|
|
2013-01-29 18:35:24 -08:00
|
|
|
switch_tab: function(e) {
|
|
|
|
var $tab = $(e.currentTarget);
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
if ($tab.hasClass("NB-tab-interactions")) {
|
|
|
|
this.options.tab = "interactions";
|
|
|
|
this.page = 0;
|
|
|
|
this.render();
|
|
|
|
this.fetch_next_page();
|
|
|
|
} else if ($tab.hasClass("NB-tab-activities")) {
|
|
|
|
this.options.tab = "activities";
|
|
|
|
this.page = 0;
|
|
|
|
this.render();
|
|
|
|
this.fetch_next_page();
|
|
|
|
}
|
|
|
|
}
|
2013-01-29 16:47:44 -08:00
|
|
|
|
|
|
|
});
|