2011-12-21 18:23:53 -08:00
|
|
|
NEWSBLUR.ReaderFriends = function(options) {
|
|
|
|
var defaults = {
|
|
|
|
width: 780
|
|
|
|
};
|
|
|
|
|
|
|
|
this.options = $.extend({}, defaults, options);
|
|
|
|
this.model = NEWSBLUR.AssetModel.reader();
|
|
|
|
|
|
|
|
this.runner();
|
|
|
|
};
|
|
|
|
|
|
|
|
NEWSBLUR.ReaderFriends.prototype = new NEWSBLUR.Modal;
|
|
|
|
|
|
|
|
_.extend(NEWSBLUR.ReaderFriends.prototype, {
|
|
|
|
|
|
|
|
runner: function() {
|
|
|
|
this.make_modal();
|
|
|
|
this.open_modal();
|
2011-12-22 13:36:03 -08:00
|
|
|
this.fetch_friends();
|
2011-12-21 18:23:53 -08:00
|
|
|
|
|
|
|
this.$modal.bind('click', $.rescope(this.handle_click, this));
|
|
|
|
this.handle_change();
|
|
|
|
},
|
|
|
|
|
|
|
|
make_modal: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.$modal = $.make('div', { className: 'NB-modal NB-modal-friends' }, [
|
|
|
|
$.make('div', { className: 'NB-modal-tabs' }, [
|
2011-12-22 13:36:03 -08:00
|
|
|
$.make('div', { className: 'NB-modal-loading' }),
|
|
|
|
$.make('div', { className: 'NB-modal-tab NB-active NB-modal-tab-findfriends' }, 'Find Friends'),
|
|
|
|
$.make('div', { className: 'NB-modal-tab NB-modal-tab-following' }, 'I\'m Following'),
|
|
|
|
$.make('div', { className: 'NB-modal-tab NB-modal-tab-followers' }, 'Following Me')
|
2011-12-21 18:23:53 -08:00
|
|
|
]),
|
|
|
|
$.make('h2', { className: 'NB-modal-title' }, 'Friends and Followers'),
|
2011-12-22 13:36:03 -08:00
|
|
|
$.make('div', { className: 'NB-tab NB-tab-findfriends NB-active' }, [
|
2011-12-24 00:30:37 -08:00
|
|
|
$.make('fieldset', [
|
|
|
|
$.make('legend', 'Social Connections'),
|
|
|
|
$.make('div', { className: 'NB-modal-section NB-friends-services'})
|
|
|
|
]),
|
|
|
|
$.make('fieldset', [
|
|
|
|
$.make('legend', 'Profile picture'),
|
|
|
|
$.make('div', { className: 'NB-modal-section NB-friends-profile'})
|
|
|
|
]),
|
|
|
|
$.make('fieldset', [
|
|
|
|
$.make('legend', 'People I Know'),
|
|
|
|
$.make('div', { className: 'NB-modal-section NB-friends-findlist'}, [
|
|
|
|
$.make('div', { className: 'NB-ghost' }, 'You\'re auto-following new friends, so no need to manually follow them. Yay!')
|
|
|
|
])
|
2011-12-24 12:46:41 -08:00
|
|
|
]),
|
|
|
|
$.make('fieldset', [
|
|
|
|
$.make('legend', 'Search for friends'),
|
|
|
|
$.make('div', { className: 'NB-modal-section NB-friends-search'}, [
|
|
|
|
$.make('label', { 'for': 'NB-friends-search-input' }, 'Username or email:'),
|
|
|
|
$.make('input', { type: 'text', className: 'NB-input', id: 'NB-friends-search-input' })
|
|
|
|
])
|
2011-12-24 00:30:37 -08:00
|
|
|
])
|
2011-12-22 13:36:03 -08:00
|
|
|
]),
|
2011-12-23 18:28:16 -08:00
|
|
|
$.make('div', { className: 'NB-tab NB-tab-following' }),
|
|
|
|
$.make('div', { className: 'NB-tab NB-tab-followers' })
|
2011-12-21 18:23:53 -08:00
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
2011-12-22 13:36:03 -08:00
|
|
|
fetch_friends: function() {
|
2011-12-23 18:28:16 -08:00
|
|
|
$('.NB-modal-loading', this.$modal).addClass('NB-active');
|
|
|
|
this.model.fetch_friends(_.bind(function(data) {
|
|
|
|
this.make_friends(data);
|
2011-12-24 00:30:37 -08:00
|
|
|
this.make_profile(data);
|
2011-12-23 18:28:16 -08:00
|
|
|
this.make_followers(data);
|
|
|
|
this.make_following(data);
|
|
|
|
}, this));
|
2011-12-22 13:36:03 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
make_friends: function(data) {
|
|
|
|
console.log(["data", data]);
|
2011-12-23 18:28:16 -08:00
|
|
|
$('.NB-modal-loading', this.$modal).removeClass('NB-active');
|
2011-12-22 13:36:03 -08:00
|
|
|
var $services = $('.NB-friends-services', this.$modal).empty();
|
|
|
|
|
|
|
|
_.each(['twitter', 'facebook'], function(service) {
|
|
|
|
var $service;
|
|
|
|
if (data.services[service][service+'_uid']) {
|
2011-12-24 00:30:37 -08:00
|
|
|
$service = $.make('div', { className: 'NB-friends-service NB-connected NB-friends-service-'+service }, [
|
2011-12-22 13:36:03 -08:00
|
|
|
$.make('div', { className: 'NB-friends-service-title' }, _.capitalize(service)),
|
|
|
|
$.make('div', { className: 'NB-friends-service-connect NB-modal-submit-button NB-modal-submit-close' }, 'Disconnect')
|
|
|
|
]);
|
|
|
|
} else {
|
2011-12-24 00:30:37 -08:00
|
|
|
$service = $.make('div', { className: 'NB-friends-service NB-friends-service-'+service }, [
|
2011-12-22 13:36:03 -08:00
|
|
|
$.make('div', { className: 'NB-friends-service-title' }, _.capitalize(service)),
|
2011-12-23 18:28:16 -08:00
|
|
|
$.make('div', { className: 'NB-friends-service-connect NB-modal-submit-button NB-modal-submit-green' }, [
|
|
|
|
$.make('img', { src: NEWSBLUR.Globals.MEDIA_URL + '/img/reader/' + service + '_icon.png' }),
|
|
|
|
'Connect to ' + _.capitalize(service)
|
|
|
|
])
|
2011-12-22 13:36:03 -08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
$services.append($service);
|
|
|
|
});
|
|
|
|
|
|
|
|
$autofollow = $.make('div', { className: 'NB-friends-service NB-friends-autofollow'}, [
|
|
|
|
$.make('input', { type: 'checkbox', className: 'NB-friends-autofollow-checkbox', id: 'NB-friends-autofollow-checkbox', checked: data.autofollow ? 'checked' : null }),
|
|
|
|
$.make('label', { className: 'NB-friends-autofollow-label', 'for': 'NB-friends-autofollow-checkbox' }, [
|
|
|
|
'Auto-follow',
|
|
|
|
$.make('br'),
|
|
|
|
'my friends'
|
|
|
|
])
|
|
|
|
]);
|
2011-12-24 00:30:37 -08:00
|
|
|
$services.prepend($autofollow);
|
2011-12-23 18:28:16 -08:00
|
|
|
this.resize();
|
|
|
|
},
|
|
|
|
|
2011-12-24 00:30:37 -08:00
|
|
|
make_profile: function(data) {
|
|
|
|
var $profiles = $('.NB-friends-profile', this.$modal).empty();
|
|
|
|
|
|
|
|
_.each(['upload', 'twitter', 'facebook', 'gravatar'], function(service) {
|
|
|
|
var $profile = $.make('div', { className: 'NB-friends-profile-photo-group NB-friends-photo-'+service }, [
|
|
|
|
$.make('div', { className: 'NB-friends-photo-title' }, [
|
|
|
|
$.make('input', { type: 'radio', name: 'profile_photo_service', value: service, id: 'NB-profile-photo-service-'+service }),
|
|
|
|
$.make('label', { 'for': 'NB-profile-photo-service-'+service }, _.capitalize(service))
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-friends-photo-image' }, [
|
|
|
|
$.make('label', { 'for': 'NB-profile-photo-service-'+service }, [
|
|
|
|
$.make('div', { className: 'NB-photo-loader' }),
|
|
|
|
$.make('img', { src: data.services[service][service+'_picture_url'] })
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
(service == 'upload' && $.make('div', { className: 'NB-photo-link' }, [
|
|
|
|
$.make('a', { href: '#', className: 'NB-photo-upload-link NB-splash-link' }, 'Upload picture'),
|
|
|
|
$.make('input', { type: 'file', name: 'photo' })
|
|
|
|
])),
|
|
|
|
(service == 'gravatar' && $.make('div', { className: 'NB-gravatar-link' }, [
|
|
|
|
$.make('a', { href: 'http://www.gravatar.com', className: 'NB-splash-link', target: '_blank' }, 'gravatar.com')
|
|
|
|
]))
|
|
|
|
]);
|
|
|
|
$profiles.append($profile);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-12-23 18:28:16 -08:00
|
|
|
make_followers: function(data) {
|
|
|
|
if (!data.followers || !data.followers.length) {
|
2011-12-24 00:30:37 -08:00
|
|
|
var $ghost = $.make('div', { className: 'NB-ghost NB-modal-section' }, 'Nobody has yet to subscribe to your shared stories.');
|
2011-12-23 18:28:16 -08:00
|
|
|
$('.NB-tab-followers', this.$modal).empty().append($ghost);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
make_following: function(data) {
|
|
|
|
if (!data.following || !data.following.length) {
|
|
|
|
var $ghost = $.make('div', { className: 'NB-ghost NB-modal-section' }, 'You are not yet subscribing to anybody\'s shared stories.');
|
|
|
|
$('.NB-tab-following', this.$modal).empty().append($ghost);
|
|
|
|
}
|
2011-12-22 13:36:03 -08:00
|
|
|
},
|
|
|
|
|
2011-12-21 18:23:53 -08:00
|
|
|
open_modal: function(callback) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.$modal.modal({
|
|
|
|
'minWidth': 740,
|
|
|
|
'maxWidth': 740,
|
|
|
|
'overlayClose': true,
|
|
|
|
'onOpen': function (dialog) {
|
|
|
|
dialog.overlay.fadeIn(200, function () {
|
|
|
|
dialog.container.fadeIn(200);
|
|
|
|
dialog.data.fadeIn(200, function() {
|
|
|
|
if (self.options.onOpen) {
|
|
|
|
self.options.onOpen();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
setTimeout(function() {
|
|
|
|
$(window).resize();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
'onShow': function(dialog) {
|
|
|
|
$('#simplemodal-container').corner('6px');
|
|
|
|
if (self.options.onShow) {
|
|
|
|
self.options.onShow();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'onClose': function(dialog, callback) {
|
|
|
|
dialog.data.hide().empty().remove();
|
|
|
|
dialog.container.hide().empty().remove();
|
|
|
|
dialog.overlay.fadeOut(200, function() {
|
|
|
|
dialog.overlay.empty().remove();
|
|
|
|
$.modal.close(callback);
|
|
|
|
});
|
|
|
|
$('.NB-modal-holder').empty().remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-12-22 13:36:03 -08: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-12-23 18:28:16 -08:00
|
|
|
connect: function(service) {
|
|
|
|
var options = "location=0,status=0,width=800,height=500";
|
|
|
|
var url = "/social/" + service + "_connect";
|
|
|
|
this.connect_window = window.open(url, '_blank', options);
|
|
|
|
},
|
|
|
|
|
2011-12-22 13:36:03 -08:00
|
|
|
disconnect: function(service) {
|
|
|
|
var $service = $('.NB-friends-service-'+service, this.$modal);
|
|
|
|
$('.NB-friends-service-connect', $service).text('Disconnecting...');
|
2011-12-24 00:30:37 -08:00
|
|
|
this.model.disconnect_social_service(service, _.bind(function(data) {
|
|
|
|
this.make_friends(data);
|
|
|
|
this.make_profile(data);
|
|
|
|
}, this));
|
2011-12-22 13:36:03 -08:00
|
|
|
},
|
|
|
|
|
2011-12-23 18:28:16 -08:00
|
|
|
post_connect: function(data) {
|
2011-12-24 00:30:37 -08:00
|
|
|
$('.NB-error', this.$modal).remove();
|
2011-12-23 18:28:16 -08:00
|
|
|
if (data.error) {
|
2011-12-24 00:30:37 -08:00
|
|
|
var $error = $.make('div', { className: 'NB-error' }, [
|
|
|
|
$.make('span', { className: 'NB-raquo' }, '» '),
|
|
|
|
data.error
|
|
|
|
]).css('opacity', 0);
|
2011-12-23 18:28:16 -08:00
|
|
|
$('.NB-friends-services', this.$modal).append($error);
|
2011-12-24 00:30:37 -08:00
|
|
|
$error.animate({'opacity': 1}, {'duration': 1000});
|
|
|
|
this.resize();
|
2011-12-23 18:28:16 -08:00
|
|
|
} else {
|
|
|
|
this.fetch_friends();
|
2011-12-24 00:30:37 -08:00
|
|
|
NEWSBLUR.reader.hide_find_friends();
|
2011-12-23 18:28:16 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-12-21 18:23:53 -08:00
|
|
|
// ===========
|
|
|
|
// = Actions =
|
|
|
|
// ===========
|
|
|
|
|
|
|
|
handle_click: function(elem, e) {
|
|
|
|
var self = this;
|
|
|
|
|
2011-12-22 13:36:03 -08:00
|
|
|
$.targetIs(e, { tagSelector: '.NB-modal-tab' }, function($t, $p) {
|
2011-12-21 18:23:53 -08:00
|
|
|
e.preventDefault();
|
2011-12-22 13:36:03 -08:00
|
|
|
var newtab;
|
|
|
|
if ($t.hasClass('NB-modal-tab-findfriends')) {
|
|
|
|
newtab = 'findfriends';
|
|
|
|
} else if ($t.hasClass('NB-modal-tab-followers')) {
|
|
|
|
newtab = 'followers';
|
|
|
|
} else if ($t.hasClass('NB-modal-tab-following')) {
|
|
|
|
newtab = 'following';
|
|
|
|
}
|
|
|
|
self.switch_tab(newtab);
|
2011-12-21 18:23:53 -08:00
|
|
|
});
|
2011-12-22 13:36:03 -08:00
|
|
|
$.targetIs(e, { tagSelector: '.NB-friends-service-connect' }, function($t, $p) {
|
2011-12-21 18:23:53 -08:00
|
|
|
e.preventDefault();
|
2011-12-22 13:36:03 -08:00
|
|
|
var service;
|
|
|
|
var $service = $t.closest('.NB-friends-service');
|
|
|
|
if ($service.hasClass('NB-friends-service-twitter')) {
|
|
|
|
service = 'twitter';
|
|
|
|
} else if ($service.hasClass('NB-friends-service-facebook')) {
|
|
|
|
service = 'facebook';
|
|
|
|
}
|
|
|
|
if ($service.hasClass('NB-connected')) {
|
|
|
|
self.disconnect(service);
|
|
|
|
} else {
|
|
|
|
self.connect(service);
|
|
|
|
}
|
2011-12-21 18:23:53 -08:00
|
|
|
});
|
|
|
|
$.targetIs(e, { tagSelector: '.NB-modal-cancel' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
self.close();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
handle_cancel: function() {
|
|
|
|
var $cancel = $('.NB-modal-cancel', this.$modal);
|
|
|
|
|
|
|
|
$cancel.click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$.modal.close();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
handle_change: function() {
|
|
|
|
$('input[type=radio],input[type=checkbox],select,input', this.$modal).bind('change', _.bind(this.enable_save, this));
|
|
|
|
$('input', this.$modal).bind('keydown', _.bind(this.enable_save, this));
|
|
|
|
},
|
|
|
|
|
|
|
|
enable_save: function() {
|
|
|
|
$('input[type=submit]', this.$modal).removeAttr('disabled').removeClass('NB-disabled').val('Save My Account');
|
|
|
|
},
|
|
|
|
|
|
|
|
disable_save: function() {
|
|
|
|
this.resize();
|
|
|
|
$('input[type=submit]', this.$modal).attr('disabled', true).addClass('NB-disabled').val('Change what you like above...');
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|