2011-03-28 10:08:10 -04:00
|
|
|
NEWSBLUR.Modal = function(options) {
|
2013-01-06 15:55:24 -08:00
|
|
|
var defaults = {
|
|
|
|
width: 600
|
|
|
|
};
|
2011-03-28 10:08:10 -04:00
|
|
|
|
2013-01-06 15:55:24 -08:00
|
|
|
this.options = _.extend({}, defaults, options);
|
2012-05-17 18:40:46 -07:00
|
|
|
this.model = NEWSBLUR.assets;
|
2011-03-28 10:08:10 -04:00
|
|
|
this.runner();
|
2012-03-12 18:11:13 -07:00
|
|
|
this.flags = {};
|
2011-03-28 10:08:10 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
NEWSBLUR.Modal.prototype = {
|
2011-05-11 12:27:28 -04:00
|
|
|
|
|
|
|
runner: function() {},
|
2011-03-28 10:08:10 -04:00
|
|
|
|
2011-09-29 22:12:46 -07:00
|
|
|
open_modal: function(callback) {
|
2011-03-28 10:08:10 -04:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.$modal.modal({
|
2013-01-06 15:55:24 -08:00
|
|
|
'minWidth': this.options.width || 600,
|
|
|
|
'maxWidth': this.options.width || 600,
|
2011-03-28 10:08:10 -04:00
|
|
|
'overlayClose': true,
|
|
|
|
'onOpen': function (dialog) {
|
2012-03-12 18:11:13 -07:00
|
|
|
self.flags.open = true;
|
2011-03-28 10:08:10 -04:00
|
|
|
dialog.overlay.fadeIn(200, function () {
|
2013-02-01 17:17:16 -08:00
|
|
|
dialog.container.addClass(self.options.modal_container_class);
|
2011-03-28 10:08:10 -04:00
|
|
|
dialog.container.fadeIn(200);
|
2011-09-21 17:49:26 -07:00
|
|
|
dialog.data.fadeIn(200, function() {
|
|
|
|
if (self.options.onOpen) {
|
|
|
|
self.options.onOpen();
|
|
|
|
}
|
2013-04-24 14:40:23 -07:00
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
2011-09-21 17:49:26 -07:00
|
|
|
});
|
2011-03-28 10:08:10 -04:00
|
|
|
setTimeout(function() {
|
|
|
|
$(window).resize();
|
2013-04-10 17:36:32 -07:00
|
|
|
self.flags.modal_loaded = true;
|
2011-03-28 10:08:10 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
'onShow': function(dialog) {
|
|
|
|
$('#simplemodal-container').corner('6px');
|
2011-09-21 17:49:26 -07:00
|
|
|
if (self.options.onShow) {
|
|
|
|
self.options.onShow();
|
|
|
|
}
|
2011-03-28 10:08:10 -04:00
|
|
|
},
|
2011-07-27 09:33:34 -07:00
|
|
|
'onClose': function(dialog, callback) {
|
2012-03-12 18:11:13 -07:00
|
|
|
self.flags.open = false;
|
2011-03-28 10:08:10 -04:00
|
|
|
dialog.data.hide().empty().remove();
|
|
|
|
dialog.container.hide().empty().remove();
|
|
|
|
dialog.overlay.fadeOut(200, function() {
|
|
|
|
dialog.overlay.empty().remove();
|
2011-07-27 09:33:34 -07:00
|
|
|
$.modal.close(callback);
|
2011-03-28 10:08:10 -04:00
|
|
|
});
|
|
|
|
$('.NB-modal-holder').empty().remove();
|
|
|
|
}
|
|
|
|
});
|
2011-05-06 10:06:13 -04:00
|
|
|
},
|
|
|
|
|
2011-05-07 21:12:13 -04:00
|
|
|
resize: function() {
|
|
|
|
$(window).trigger('resize.simplemodal');
|
|
|
|
},
|
|
|
|
|
2011-07-27 09:33:34 -07:00
|
|
|
close: function(callback) {
|
2011-05-07 17:58:53 -04:00
|
|
|
$('.NB-modal-loading', this.$modal).removeClass('NB-active');
|
2011-07-27 09:33:34 -07:00
|
|
|
$.modal.close(callback);
|
2011-11-12 18:19:57 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
make_feed_chooser: function() {
|
|
|
|
var $chooser = $.make('select', { name: 'feed', className: 'NB-modal-feed-chooser' });
|
2012-05-21 20:08:27 -07:00
|
|
|
var current_feed_id = this.feed_id;
|
|
|
|
this.feeds = this.model.get_feeds();
|
2011-11-12 18:19:57 -08:00
|
|
|
|
2012-05-21 20:08:27 -07:00
|
|
|
this.feeds.each(function(feed) {
|
|
|
|
var $option = $.make('option', { value: feed.id }, feed.get('feed_title'));
|
2011-11-12 18:19:57 -08:00
|
|
|
$option.appendTo($chooser);
|
|
|
|
|
2012-05-21 20:08:27 -07:00
|
|
|
if (feed.id == current_feed_id) {
|
2011-11-12 18:19:57 -08:00
|
|
|
$option.attr('selected', true);
|
|
|
|
}
|
2012-05-21 20:08:27 -07:00
|
|
|
});
|
2011-11-12 18:19:57 -08:00
|
|
|
|
|
|
|
$('option', $chooser).tsort();
|
|
|
|
return $chooser;
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize_feed: function(feed_id) {
|
|
|
|
this.feed_id = feed_id;
|
|
|
|
this.feed = this.model.get_feed(feed_id);
|
2012-05-21 20:08:27 -07:00
|
|
|
this.options.social_feed = this.feed.is_social();
|
2011-11-12 18:19:57 -08:00
|
|
|
|
2012-01-26 18:59:40 -08:00
|
|
|
$('.NB-modal-subtitle .NB-modal-feed-image', this.$modal).attr('src', $.favicon(this.feed));
|
2012-05-21 20:08:27 -07:00
|
|
|
$('.NB-modal-subtitle .NB-modal-feed-title', this.$modal).html(this.feed.get('feed_title'));
|
|
|
|
$('.NB-modal-subtitle .NB-modal-feed-subscribers', this.$modal).html(Inflector.pluralize(' subscriber', this.feed.get('num_subscribers'), true));
|
2013-04-11 16:50:18 -07:00
|
|
|
},
|
2011-03-28 10:08:10 -04:00
|
|
|
|
2013-04-11 16:50:18 -07:00
|
|
|
switch_tab: function(newtab) {
|
|
|
|
var $modal_tabs = $('.NB-modal-tab', this.$modal);
|
|
|
|
var $tabs = $('.NB-tab', this.$modal);
|
|
|
|
|
|
|
|
$modal_tabs.removeClass('NB-active');
|
|
|
|
$tabs.removeClass('NB-active');
|
|
|
|
|
|
|
|
$modal_tabs.filter('.NB-modal-tab-'+newtab).addClass('NB-active');
|
|
|
|
$tabs.filter('.NB-tab-'+newtab).addClass('NB-active');
|
|
|
|
}
|
2011-11-12 18:19:57 -08:00
|
|
|
|
2011-03-28 10:08:10 -04:00
|
|
|
};
|