NewsBlur-viq/media/js/newsblur/reader_preferences.js

100 lines
3.3 KiB
JavaScript
Raw Normal View History

NEWSBLUR.ReaderPreferences = function(options) {
var defaults = {};
this.options = $.extend({}, defaults, options);
this.model = NEWSBLUR.AssetModel.reader();
this.google_favicon_url = 'http://www.google.com/s2/favicons?domain_url=';
this.runner();
};
NEWSBLUR.ReaderPreferences.prototype = {
runner: function() {
this.make_modal();
this.handle_cancel();
this.open_modal();
this.$modal.bind('click', $.rescope(this.handle_click, this));
},
make_modal: function() {
var self = this;
this.$modal = $.make('div', { className: 'NB-modal-preferences NB-modal' }, [
$.make('h2', { className: 'NB-modal-title' }, 'Preferences'),
$.make('form', { className: 'NB-preferences-form' }, [
$.make('div', { className: 'NB-modal-submit' }, [
$.make('input', { type: 'submit', disabled: 'true', className: 'NB-disabled', value: 'Check what you like above...' }),
' or ',
$.make('a', { href: '#', className: 'NB-modal-cancel' }, 'cancel')
])
]).bind('submit', function(e) {
e.preventDefault();
self.save_preferences();
return false;
})
]);
},
open_modal: function() {
var self = this;
var $holder = $.make('div', { className: 'NB-modal-holder' }).append(this.$modal).appendTo('body').css({'visibility': 'hidden', 'display': 'block', 'width': 600});
var height = $('.NB-add', $holder).outerHeight(true);
$holder.css({'visibility': 'visible', 'display': 'none'});
var w = $.modal.impl.getDimensions();
if (height > w[0] - 70) {
height = w[0] - 70;
}
this.$modal.modal({
'minWidth': 600,
'maxHeight': height,
'overlayClose': true,
'onOpen': function (dialog) {
dialog.overlay.fadeIn(200, function () {
dialog.container.fadeIn(200);
dialog.data.fadeIn(200);
});
},
'onShow': function(dialog) {
$('#simplemodal-container').corner('6px').css({'width': 600, 'height': height});
$.modal.impl.setPosition();
},
'onClose': function(dialog) {
dialog.data.hide().empty().remove();
dialog.container.hide().empty().remove();
dialog.overlay.fadeOut(200, function() {
dialog.overlay.empty().remove();
$.modal.close();
});
$('.NB-modal-holder').empty().remove();
}
});
},
handle_cancel: function() {
var $cancel = $('.NB-modal-cancel', this.$modal);
$cancel.click(function(e) {
e.preventDefault();
$.modal.close();
});
},
// ===========
// = Actions =
// ===========
handle_click: function(elem, e) {
var self = this;
$.targetIs(e, { tagSelector: '.NB-add-url-submit' }, function($t, $p) {
e.preventDefault();
self.save_add_url();
});
}
};