2012-03-02 17:51:28 -08:00
|
|
|
NEWSBLUR.ReaderIntro = function(options) {
|
|
|
|
var defaults = {};
|
2012-06-14 17:21:51 -07:00
|
|
|
var intro_page = NEWSBLUR.assets.preference('intro_page');
|
2012-03-02 17:51:28 -08:00
|
|
|
|
2012-03-12 18:11:13 -07:00
|
|
|
_.bindAll(this, 'close', 'start_import_from_google_reader', 'post_connect');
|
2012-03-02 17:51:28 -08:00
|
|
|
this.options = $.extend({
|
2012-03-12 12:33:54 -07:00
|
|
|
'page_number': intro_page && _.isNumber(intro_page) && intro_page <= 4 ? intro_page : 1
|
2012-03-02 17:51:28 -08:00
|
|
|
}, defaults, options);
|
2012-03-06 11:41:57 -08:00
|
|
|
this.services = {
|
|
|
|
'twitter': {},
|
|
|
|
'facebook': {}
|
|
|
|
};
|
2012-07-20 19:43:28 -07:00
|
|
|
this.flags = {};
|
2012-03-06 11:41:57 -08:00
|
|
|
this.autofollow = true;
|
|
|
|
|
2012-03-02 17:51:28 -08:00
|
|
|
this.page_number = this.options.page_number;
|
|
|
|
this.slider_value = 0;
|
|
|
|
this.intervals = {};
|
|
|
|
this.runner();
|
|
|
|
};
|
|
|
|
|
|
|
|
NEWSBLUR.ReaderIntro.prototype = new NEWSBLUR.Modal;
|
|
|
|
NEWSBLUR.ReaderIntro.prototype.constructor = NEWSBLUR.ReaderIntro;
|
|
|
|
|
|
|
|
_.extend(NEWSBLUR.ReaderIntro.prototype, {
|
|
|
|
|
|
|
|
runner: function() {
|
|
|
|
this.make_modal();
|
2012-03-06 11:41:57 -08:00
|
|
|
this.make_find_friends_and_services();
|
2012-03-02 17:51:28 -08:00
|
|
|
this.open_modal();
|
|
|
|
this.page(this.page_number);
|
2012-03-06 11:41:57 -08:00
|
|
|
this.fetch_friends();
|
2012-03-02 17:51:28 -08:00
|
|
|
|
|
|
|
this.$modal.bind('click', $.rescope(this.handle_click, this));
|
2012-03-05 19:18:40 -08:00
|
|
|
this.$modal.bind('change', $.rescope(this.handle_change, this));
|
2012-03-02 17:51:28 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
make_modal: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.$modal = $.make('div', { className: 'NB-modal-intro NB-modal' }, [
|
|
|
|
$.make('div', { className: 'NB-modal-page' }),
|
2012-03-06 11:41:57 -08:00
|
|
|
$.make('span', { className: 'NB-modal-loading NB-spinner'}),
|
2012-03-06 19:03:04 -08:00
|
|
|
$.make('h2', { className: 'NB-modal-title' }, 'Welcome to NewsBlur'),
|
2012-03-02 17:51:28 -08:00
|
|
|
$.make('img', { className: 'NB-intro-spinning-logo', src: NEWSBLUR.Globals.MEDIA_URL + 'img/logo_512.png' }),
|
|
|
|
$.make('div', { className: 'NB-page NB-page-1' }, [
|
|
|
|
$.make('h4', { className: 'NB-page-1-started' }, "So much time and so little to do. Strike that! Reverse it.")
|
|
|
|
]),
|
2012-07-30 21:39:21 -07:00
|
|
|
$.make('div', { className: 'NB-page NB-page-2' }, [
|
|
|
|
$.make('div', { className: 'carousel slide'}, [
|
|
|
|
$.make('div', { className: 'carousel-inner NB-intro-imports' }, [
|
|
|
|
$.make('div', { className: 'item NB-intro-imports-start' }, [
|
|
|
|
$.make('h4', { className: 'NB-page-2-started' }, "Let's get some sites to read."),
|
|
|
|
$.make('div', { className: 'NB-intro-import NB-intro-import-google' }, [
|
|
|
|
$.make('h3', [
|
|
|
|
'Import from',
|
|
|
|
$.make('br'),
|
|
|
|
$.make('img', { src: NEWSBLUR.Globals.MEDIA_URL + 'img/reader/google-reader-logo.gif' })
|
|
|
|
]),
|
|
|
|
$.make('a', { href: NEWSBLUR.URLs['google-reader-authorize'], className: 'NB-google-reader-oauth NB-modal-submit-green NB-modal-submit-button' }, [
|
|
|
|
'Connect to Google'
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-error' })
|
2012-03-05 19:18:40 -08:00
|
|
|
]),
|
2012-07-30 21:39:21 -07:00
|
|
|
$.make('div', { className: 'NB-intro-import NB-intro-import-opml' }, [
|
|
|
|
$.make('h3', ['Upload an', $.make('br'), 'OPML file']),
|
|
|
|
$.make('form', { method: 'post', enctype: 'multipart/form-data', encoding: 'multipart/form-data', className: 'NB-opml-upload-form' }, [
|
|
|
|
$.make('div', { href: '#', className: 'NB-intro-upload-opml NB-modal-submit-green NB-modal-submit-button' }, [
|
|
|
|
'Upload OPML File',
|
|
|
|
$.make('input', { type: 'file', name: 'file', id: 'NB-intro-upload-opml-button', className: 'NB-intro-upload-opml-button' })
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-error' })
|
|
|
|
])
|
2012-03-02 17:51:28 -08:00
|
|
|
]),
|
2012-07-30 21:39:21 -07:00
|
|
|
$.make('div', { className: 'item NB-intro-imports-progress' }, [
|
|
|
|
$.make('h4', { className: 'NB-page-2-started' }, "Importing your sites..."),
|
|
|
|
$.make('div', { className: 'NB-loading' })
|
2012-07-20 19:43:28 -07:00
|
|
|
]),
|
2012-07-30 21:39:21 -07:00
|
|
|
$.make('div', { className: 'item NB-intro-imports-sites' }, [
|
|
|
|
$.make('h4'),
|
|
|
|
$.make('div', { className: 'NB-intro-import-restart NB-modal-submit-grey NB-modal-submit-button' }, [
|
|
|
|
'« Restart and re-import your sites'
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-intro-import-delayed' }, [
|
|
|
|
'There are too many sites to process...',
|
|
|
|
$.make('br'),
|
|
|
|
'You will be emailed within a minute or three.'
|
|
|
|
])
|
2012-03-05 19:18:40 -08:00
|
|
|
])
|
2012-03-02 17:51:28 -08:00
|
|
|
])
|
|
|
|
]),
|
2012-03-16 20:40:48 -07:00
|
|
|
$.make('div', { className: 'NB-intro-bookmarklet NB-intro-section' }, [
|
2012-03-02 17:51:28 -08:00
|
|
|
NEWSBLUR.generate_bookmarklet(),
|
|
|
|
$.make('div', { className: 'NB-intro-bookmarklet-arrow' }, '←'),
|
|
|
|
$.make('div', { className: 'NB-intro-bookmarklet-info' }, 'Install the bookmarklet')
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-page NB-page-3' }, [
|
2012-03-06 11:41:57 -08:00
|
|
|
$.make('h4', { className: 'NB-page-3-started' }, "Connect with friends"),
|
|
|
|
$.make('div', { className: 'NB-intro-services' })
|
2012-03-02 17:51:28 -08:00
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-page NB-page-4' }, [
|
2012-03-16 20:40:48 -07:00
|
|
|
$.make('h4', { className: 'NB-page-4-started' }, "Keep up-to-date with NewsBlur"),
|
|
|
|
$.make('div', { className: 'NB-intro-section' }, [
|
2012-03-20 11:15:40 -07:00
|
|
|
$.make('div', { className: 'NB-intro-uptodate-follow NB-intro-uptodate-follow-twitter NB-right' }, [
|
2012-03-16 20:40:48 -07:00
|
|
|
$.make('input', { type: 'checkbox', id: 'NB-intro-uptodate-follow-newsblur' }),
|
|
|
|
$.make('label', { 'for': 'NB-intro-uptodate-follow-newsblur' }, [
|
2012-03-19 17:51:54 -07:00
|
|
|
$.make('img', { src: NEWSBLUR.Globals.MEDIA_URL + 'img/reader/new-window-icon.png', className: 'NB-intro-uptodate-newwindow' }),
|
2012-07-12 12:57:35 -07:00
|
|
|
$.make('img', { src: 'http://a0.twimg.com/profile_images/1268996309/logo_128_normal.png', style: 'border-color: #505050;' }),
|
2012-03-16 20:40:48 -07:00
|
|
|
$.make('span', [
|
|
|
|
'Follow @newsblur on',
|
|
|
|
$.make('br'),
|
|
|
|
$.make('img', { src: NEWSBLUR.Globals.MEDIA_URL + 'img/reader/twitter_icon.png' }),
|
|
|
|
'Twitter'
|
|
|
|
])
|
|
|
|
])
|
|
|
|
]),
|
2012-03-20 11:15:40 -07:00
|
|
|
$.make('div', { className: 'NB-intro-uptodate-follow NB-intro-uptodate-follow-twitter' }, [
|
2012-03-16 20:40:48 -07:00
|
|
|
$.make('input', { type: 'checkbox', id: 'NB-intro-uptodate-follow-samuelclay' }),
|
|
|
|
$.make('label', { 'for': 'NB-intro-uptodate-follow-samuelclay' }, [
|
2012-03-19 17:51:54 -07:00
|
|
|
$.make('img', { src: NEWSBLUR.Globals.MEDIA_URL + 'img/reader/new-window-icon.png', className: 'NB-intro-uptodate-newwindow' }),
|
2012-07-12 12:57:35 -07:00
|
|
|
$.make('img', { src: 'http://a0.twimg.com/profile_images/1382021023/Campeche_Steps_normal.jpg', style: 'border-color: #505050;' }),
|
2012-03-16 20:40:48 -07:00
|
|
|
$.make('span', [
|
|
|
|
'Follow @samuelclay on',
|
|
|
|
$.make('br'),
|
|
|
|
$.make('img', { src: NEWSBLUR.Globals.MEDIA_URL + 'img/reader/twitter_icon.png' }),
|
|
|
|
'Twitter'
|
|
|
|
])
|
|
|
|
])
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-intro-section' }, [
|
|
|
|
$.make('div', { className: 'NB-intro-uptodate-follow NB-right' }, [
|
|
|
|
$.make('input', { type: 'checkbox', id: 'NB-intro-uptodate-follow-popular' }),
|
|
|
|
$.make('label', { 'for': 'NB-intro-uptodate-follow-popular' }, [
|
|
|
|
$.make('span', [
|
|
|
|
'Subscribe to',
|
|
|
|
$.make('br'),
|
|
|
|
$.make('img', { src: '/media/img/favicon.png' }),
|
|
|
|
'Popular Shared Stories'
|
|
|
|
])
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-intro-uptodate-follow' }, [
|
|
|
|
$.make('input', { type: 'checkbox', id: 'NB-intro-uptodate-follow-blog' }),
|
|
|
|
$.make('label', { 'for': 'NB-intro-uptodate-follow-blog' }, [
|
|
|
|
$.make('span', [
|
|
|
|
'Subscribe to',
|
|
|
|
$.make('br'),
|
|
|
|
$.make('img', { src: '/media/img/favicon.png' }),
|
|
|
|
'The NewsBlur Blog'
|
|
|
|
])
|
|
|
|
])
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-intro-section' }, [
|
2012-03-19 11:15:26 -07:00
|
|
|
"You're ready to go! Hope you enjoy NewsBlur."
|
2012-03-16 20:40:48 -07:00
|
|
|
])
|
2012-03-02 17:51:28 -08:00
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-modal-submit' }, [
|
|
|
|
$.make('div', { className: 'NB-page-next NB-modal-submit-button NB-modal-submit-green NB-modal-submit-save' }, [
|
|
|
|
$.make('span', { className: 'NB-tutorial-next-page-text' }, "Let's Get Started "),
|
|
|
|
$.make('span', { className: 'NB-raquo' }, '»')
|
|
|
|
])
|
|
|
|
])
|
|
|
|
]);
|
2012-03-05 19:18:40 -08:00
|
|
|
|
2012-03-12 18:11:13 -07:00
|
|
|
$('.carousel', this.$modal).carousel({});
|
2012-03-02 17:51:28 -08:00
|
|
|
},
|
|
|
|
|
2012-03-06 11:41:57 -08:00
|
|
|
// ==========
|
|
|
|
// = Social =
|
|
|
|
// ==========
|
|
|
|
|
|
|
|
fetch_friends: function(callback) {
|
|
|
|
$('.NB-modal-loading', this.$modal).addClass('NB-active');
|
2012-06-14 17:21:51 -07:00
|
|
|
NEWSBLUR.assets.fetch_friends(_.bind(function(data) {
|
|
|
|
this.profile = NEWSBLUR.assets.user_profile;
|
2012-03-06 11:41:57 -08:00
|
|
|
this.services = data.services;
|
|
|
|
this.autofollow = data.autofollow;
|
|
|
|
this.make_find_friends_and_services();
|
|
|
|
callback && callback();
|
|
|
|
}, this));
|
|
|
|
},
|
|
|
|
|
|
|
|
make_find_friends_and_services: function() {
|
|
|
|
$('.NB-modal-loading', this.$modal).removeClass('NB-active');
|
|
|
|
var $services = $('.NB-intro-services', this.$modal).empty();
|
2012-07-13 15:32:27 -07:00
|
|
|
var service_syncing = false;
|
2012-03-06 11:41:57 -08:00
|
|
|
|
|
|
|
_.each(['twitter', 'facebook'], _.bind(function(service) {
|
|
|
|
var $service;
|
2012-07-11 00:43:53 -07:00
|
|
|
if (this.services && this.services[service][service+'_uid'] && !this.services[service].syncing) {
|
2012-03-06 11:41:57 -08:00
|
|
|
$service = $.make('div', { className: 'NB-friends-service NB-connected NB-friends-service-'+service }, [
|
|
|
|
$.make('div', { className: 'NB-friends-service-title' }, _.string.capitalize(service)),
|
|
|
|
$.make('div', { className: 'NB-friends-service-connected' }, [
|
|
|
|
$.make('img', { src: NEWSBLUR.Globals.MEDIA_URL + '/img/reader/' + service + '_icon.png' }),
|
|
|
|
'Connected'
|
|
|
|
])
|
|
|
|
]);
|
2012-07-11 00:43:53 -07:00
|
|
|
|
2012-03-06 11:41:57 -08:00
|
|
|
} else {
|
2012-07-11 00:43:53 -07:00
|
|
|
var syncing = this.services && this.services[service] && this.services[service].syncing;
|
2012-07-13 15:32:27 -07:00
|
|
|
if (syncing) service_syncing = true;
|
|
|
|
|
2012-07-12 22:26:49 -07:00
|
|
|
$service = $.make('div', { className: 'NB-friends-service NB-friends-service-'+service + (syncing ? ' NB-friends-service-syncing' : '') }, [
|
2012-03-06 11:41:57 -08:00
|
|
|
$.make('div', { className: 'NB-friends-service-title' }, _.string.capitalize(service)),
|
2012-07-12 22:26:49 -07:00
|
|
|
$.make('div', { className: 'NB-friends-service-connect NB-modal-submit-button ' + (syncing ? 'NB-modal-submit-grey' : 'NB-modal-submit-green') }, [
|
2012-03-06 11:41:57 -08:00
|
|
|
$.make('img', { src: NEWSBLUR.Globals.MEDIA_URL + '/img/reader/' + service + '_icon.png' }),
|
2012-07-11 00:43:53 -07:00
|
|
|
(syncing ? 'Fetching...' : 'Find ' + _.string.capitalize(service) + ' Friends')
|
2012-03-06 11:41:57 -08:00
|
|
|
])
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
$services.append($service);
|
|
|
|
}, this));
|
|
|
|
|
2012-03-06 18:34:59 -08:00
|
|
|
var $autofollow = $.make('div', { className: 'NB-friends-autofollow'}, [
|
2012-03-06 11:41:57 -08:00
|
|
|
$.make('input', { type: 'checkbox', className: 'NB-friends-autofollow-checkbox', id: 'NB-friends-autofollow-checkbox', checked: this.autofollow ? 'checked' : null }),
|
|
|
|
$.make('label', { className: 'NB-friends-autofollow-label', 'for': 'NB-friends-autofollow-checkbox' }, 'and auto-follow them')
|
|
|
|
]);
|
|
|
|
$services.prepend($autofollow);
|
|
|
|
|
2012-03-07 15:01:44 -08:00
|
|
|
if (!this.services.twitter.twitter_uid || !this.services.facebook.facebook_uid) {
|
2012-03-06 19:03:04 -08:00
|
|
|
var $note = $.make('div', { className: 'NB-note'}, [
|
|
|
|
'Feel comfortable connecting to these services.',
|
|
|
|
$.make('br'),
|
2012-03-20 11:15:40 -07:00
|
|
|
'Nothing happens without your permission.'
|
2012-03-06 19:03:04 -08:00
|
|
|
]);
|
|
|
|
$services.append($note);
|
|
|
|
}
|
2012-03-06 11:41:57 -08:00
|
|
|
if (this.services.twitter.twitter_uid || this.services.facebook.facebook_uid) {
|
2012-03-06 19:03:04 -08:00
|
|
|
var $stats = $.make('div', { className: 'NB-services-stats' });
|
|
|
|
_.each(['following', 'follower'], _.bind(function(follow) {
|
|
|
|
var $stat = $.make('div', { className: 'NB-intro-services-stats-count' }, [
|
|
|
|
$.make('div', { className: 'NB-intro-services-stats-count-number' }, this.profile.get(follow+'_count')),
|
|
|
|
$.make('div', { className: 'NB-intro-services-stats-count-description' }, Inflector.pluralize(follow, this.profile.get(follow+'_count')))
|
2012-03-06 18:34:59 -08:00
|
|
|
]);
|
2012-03-06 19:03:04 -08:00
|
|
|
$stats.append($stat);
|
2012-03-06 18:34:59 -08:00
|
|
|
}, this));
|
2012-03-06 19:03:04 -08:00
|
|
|
$services.append($stats);
|
2012-03-06 11:41:57 -08:00
|
|
|
$('.NB-tutorial-next-page-text', this.$modal).text('Next step ');
|
|
|
|
}
|
2012-07-13 15:32:27 -07:00
|
|
|
|
|
|
|
if (service_syncing) {
|
2012-08-10 19:20:08 -07:00
|
|
|
clearInterval(this.sync_interval);
|
|
|
|
this.sync_interval = setInterval(_.bind(function() {
|
|
|
|
this.fetch_friends();
|
|
|
|
}, this), 3000);
|
2012-07-13 15:32:27 -07:00
|
|
|
}
|
2012-03-06 11:41:57 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
connect: function(service) {
|
|
|
|
var options = "location=0,status=0,width=800,height=500";
|
2012-03-19 11:15:26 -07:00
|
|
|
var url = "/oauth/" + service + "_connect";
|
2012-03-06 11:41:57 -08:00
|
|
|
this.connect_window = window.open(url, '_blank', options);
|
2012-08-10 19:20:08 -07:00
|
|
|
this.connect_window_timer = setInterval(_.bind(function() {
|
|
|
|
console.log(["post connect window?", this.connect_window, this.connect_window.closed, this.connect_window.location]);
|
|
|
|
try {
|
|
|
|
if (!this.connect_window ||
|
|
|
|
!this.connect_window.location ||
|
|
|
|
this.connect_window.closed) {
|
|
|
|
this.post_connect({});
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
this.post_connect({});
|
|
|
|
}
|
|
|
|
}, this), 1000);
|
2012-07-12 22:26:49 -07:00
|
|
|
_gaq.push(['_trackEvent', 'reader_intro', 'Connect to ' + service.name + ' attempt']);
|
2012-03-06 11:41:57 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
disconnect: function(service) {
|
|
|
|
var $service = $('.NB-friends-service-'+service, this.$modal);
|
|
|
|
$('.NB-friends-service-connect', $service).text('Disconnecting...');
|
2012-07-12 22:26:49 -07:00
|
|
|
_gaq.push(['_trackEvent', 'reader_intro', 'Disconnect from ' + service.name]);
|
2012-06-14 17:21:51 -07:00
|
|
|
NEWSBLUR.assets.disconnect_social_service(service, _.bind(function(data) {
|
2012-03-06 11:41:57 -08:00
|
|
|
this.services = data.services;
|
|
|
|
this.make_find_friends_and_services();
|
|
|
|
this.make_profile_section();
|
|
|
|
this.make_profile_tab();
|
|
|
|
}, this));
|
|
|
|
},
|
|
|
|
|
|
|
|
post_connect: function(data) {
|
2012-07-12 22:26:49 -07:00
|
|
|
console.log(["Intro post_connect", data]);
|
2012-08-10 19:20:08 -07:00
|
|
|
clearInterval(this.connect_window_timer);
|
2012-03-06 11:41:57 -08:00
|
|
|
$('.NB-error', this.$modal).remove();
|
|
|
|
if (data.error) {
|
|
|
|
var $error = $.make('div', { className: 'NB-error' }, [
|
|
|
|
$.make('span', { className: 'NB-raquo' }, '» '),
|
|
|
|
data.error
|
2012-03-06 17:33:02 -08:00
|
|
|
]).css({'opacity': 0});
|
|
|
|
$('.NB-intro-services', this.$modal).append($error);
|
2012-03-06 11:41:57 -08:00
|
|
|
$error.animate({'opacity': 1}, {'duration': 1000});
|
|
|
|
this.resize();
|
2012-07-12 22:26:49 -07:00
|
|
|
_gaq.push(['_trackEvent', 'reader_intro', 'Connect to service error']);
|
2012-03-06 11:41:57 -08:00
|
|
|
} else {
|
|
|
|
this.fetch_friends();
|
2012-07-12 22:26:49 -07:00
|
|
|
_gaq.push(['_trackEvent', 'reader_intro', 'Connect to service success']);
|
2012-03-06 11:41:57 -08:00
|
|
|
}
|
2012-06-14 17:21:51 -07:00
|
|
|
NEWSBLUR.assets.preference('has_found_friends', true);
|
2012-03-19 14:15:38 -07:00
|
|
|
NEWSBLUR.reader.check_hide_getting_started();
|
2012-03-06 11:41:57 -08:00
|
|
|
},
|
|
|
|
|
2012-03-02 17:51:28 -08:00
|
|
|
// ==========
|
|
|
|
// = Paging =
|
|
|
|
// ==========
|
|
|
|
|
|
|
|
next_page: function() {
|
2012-07-12 12:57:35 -07:00
|
|
|
return this.page(this.page_number+1, this.page_number);
|
2012-03-02 17:51:28 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
previous_page: function() {
|
2012-07-12 12:57:35 -07:00
|
|
|
return this.page(this.page_number-1, this.page_number);
|
2012-03-02 17:51:28 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
page: function(page_number, from_page) {
|
|
|
|
if (page_number == null) {
|
|
|
|
return this.page_number;
|
|
|
|
}
|
|
|
|
var page_count = $('.NB-page', this.$modal).length;
|
|
|
|
this.page_number = page_number;
|
|
|
|
|
|
|
|
if (page_number == page_count) {
|
|
|
|
$('.NB-tutorial-next-page-text', this.$modal).text('All Done ');
|
|
|
|
} else if (page_number > page_count) {
|
2012-06-14 17:21:51 -07:00
|
|
|
NEWSBLUR.assets.preference('has_setup_feeds', true);
|
2012-03-19 14:15:38 -07:00
|
|
|
NEWSBLUR.reader.check_hide_getting_started();
|
2012-07-20 19:43:28 -07:00
|
|
|
this.close(_.bind(function() {
|
|
|
|
NEWSBLUR.reader.open_dialog_after_feeds_loaded({delayed_import: this.flags.delayed_import});
|
|
|
|
}, this));
|
2012-03-12 12:33:54 -07:00
|
|
|
return;
|
2012-03-02 17:51:28 -08:00
|
|
|
} else if (page_number == 1) {
|
|
|
|
$('.NB-tutorial-next-page-text', this.$modal).text("Let's Get Started ");
|
|
|
|
} else {
|
2012-03-06 11:41:57 -08:00
|
|
|
$('.NB-tutorial-next-page-text', this.$modal).text('Skip this step ');
|
2012-03-02 17:51:28 -08:00
|
|
|
}
|
|
|
|
$('.NB-page', this.$modal).css({'display': 'none'});
|
|
|
|
$('.NB-page-'+this.page_number, this.$modal).css({'display': 'block'});
|
|
|
|
$('.NB-modal-page', this.$modal).html($.make('div', [
|
|
|
|
'Step ',
|
|
|
|
$.make('b', this.page_number),
|
|
|
|
' of ',
|
|
|
|
$.make('b', page_count)
|
|
|
|
]));
|
|
|
|
if (page_number > 1) {
|
|
|
|
$('.NB-intro-spinning-logo', this.$modal).css({'top': 0, 'left': 0, 'width': 48, 'height': 48});
|
|
|
|
$('.NB-modal-title', this.$modal).css({'paddingLeft': 42});
|
|
|
|
}
|
|
|
|
|
2012-03-05 19:18:40 -08:00
|
|
|
if (page_number == 2) {
|
|
|
|
this.advance_import_carousel();
|
|
|
|
}
|
2012-03-06 19:03:04 -08:00
|
|
|
if (page_number == 3) {
|
|
|
|
this.make_find_friends_and_services();
|
|
|
|
}
|
2012-03-19 17:51:54 -07:00
|
|
|
if (page_number == 4) {
|
|
|
|
this.show_twitter_follow_buttons();
|
|
|
|
}
|
2012-07-12 12:57:35 -07:00
|
|
|
|
2012-08-10 19:20:08 -07:00
|
|
|
clearInterval(this.sync_interval);
|
2012-07-28 23:02:35 -07:00
|
|
|
NEWSBLUR.assets.preference('intro_page', page_number);
|
2012-07-12 12:57:35 -07:00
|
|
|
_gaq.push(['_trackEvent', 'reader_intro', 'Page ' + this.page_number]);
|
2012-03-05 19:18:40 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
advance_import_carousel: function(page) {
|
|
|
|
var $carousel = $('.carousel', this.$modal);
|
|
|
|
$carousel.carousel('pause');
|
2012-08-10 23:15:16 -07:00
|
|
|
console.log(["Advancing import carousel", page, !_.isNumber(page), NEWSBLUR.assets.feeds.size(), !this.options.force_import]);
|
2012-03-05 19:18:40 -08:00
|
|
|
if (!_.isNumber(page)) {
|
2012-06-14 17:21:51 -07:00
|
|
|
if (NEWSBLUR.assets.feeds.size() && !this.options.force_import) {
|
2012-03-05 19:18:40 -08:00
|
|
|
page = 2;
|
|
|
|
$('.NB-intro-imports-sites', this.$modal).addClass('active');
|
2012-07-20 19:43:28 -07:00
|
|
|
$('.NB-intro-import-delayed', this.$modal).hide();
|
2012-03-05 19:18:40 -08:00
|
|
|
} else {
|
|
|
|
page = 0;
|
|
|
|
$('.NB-intro-imports-start', this.$modal).addClass('active');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 11:41:57 -08:00
|
|
|
if (page >= 2) {
|
|
|
|
$('.NB-tutorial-next-page-text', this.$modal).text('Next step ');
|
|
|
|
}
|
|
|
|
|
2012-08-10 23:15:16 -07:00
|
|
|
$carousel.carousel(page && parseInt(page, 10) || 0);
|
2012-03-05 19:18:40 -08:00
|
|
|
$carousel.carousel('pause');
|
2012-08-12 19:16:21 -07:00
|
|
|
_.defer(function() {
|
|
|
|
$carousel.carousel(page && parseInt(page, 10) || 0);
|
|
|
|
$carousel.carousel('pause');
|
|
|
|
});
|
2012-03-05 19:18:40 -08:00
|
|
|
this.count_feeds();
|
|
|
|
},
|
|
|
|
|
2012-07-20 19:43:28 -07:00
|
|
|
count_feeds: function(fake_feed_count) {
|
|
|
|
var feed_count = fake_feed_count || NEWSBLUR.assets.feeds.size();
|
2012-03-19 16:35:56 -07:00
|
|
|
|
2012-03-05 19:18:40 -08:00
|
|
|
$(".NB-intro-imports-sites h4", this.$modal).text([
|
|
|
|
'You are subscribed to ',
|
2012-07-20 19:43:28 -07:00
|
|
|
(fake_feed_count && 'at least '),
|
2012-03-19 16:35:56 -07:00
|
|
|
Inflector.pluralize(' site', feed_count, true),
|
2012-03-05 19:18:40 -08:00
|
|
|
'.'
|
|
|
|
].join(""));
|
2012-03-19 16:35:56 -07:00
|
|
|
|
|
|
|
if (feed_count) {
|
|
|
|
NEWSBLUR.reader.check_hide_getting_started();
|
|
|
|
}
|
2012-03-02 17:51:28 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
fade_out_logo: function() {
|
|
|
|
var self = this;
|
|
|
|
var $logo = $('.NB-intro-spinning-logo', this.$modal);
|
|
|
|
var $page1 = $('.NB-page-1', this.$modal);
|
|
|
|
var $page2 = $('.NB-page-2', this.$modal);
|
|
|
|
var $submit = $('.NB-modal-submit', this.$modal);
|
|
|
|
var $title = $('.NB-modal-title', this.$modal);
|
|
|
|
|
|
|
|
$submit.animate({'opacity': 0}, {'duration': 800, 'easing': 'easeInOutQuad'});
|
|
|
|
$page1.animate({'opacity': 0}, {
|
|
|
|
'duration': 800,
|
|
|
|
'easing': 'easeInOutQuint',
|
|
|
|
'complete': function() {
|
|
|
|
$logo.animate({'top': 0, 'left': 0, 'width': 48, 'height': 48}, {
|
2012-03-05 19:18:40 -08:00
|
|
|
'duration': 1160,
|
2012-03-02 17:51:28 -08:00
|
|
|
'easing': 'easeInOutCubic',
|
|
|
|
'complete': function() {
|
|
|
|
$page2.css({'opacity': 0});
|
|
|
|
self.page(2);
|
|
|
|
$page2.animate({'opacity': 1}, {'duration': 1000, 'easing': 'easeInOutQuad'});
|
|
|
|
$submit.animate({'opacity': 1}, {'duration': 1000, 'easing': 'easeInOutQuad'});
|
|
|
|
}
|
|
|
|
});
|
2012-03-05 19:18:40 -08:00
|
|
|
$title.animate({'paddingLeft': 42}, {'duration': 1100, 'easing': 'easeInOutQuart'});
|
2012-03-02 17:51:28 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
close_and_load_newsblur_blog: function() {
|
|
|
|
this.close();
|
2012-04-19 22:38:00 -07:00
|
|
|
NEWSBLUR.reader.load_feed_in_tryfeed_view(this.newsblur_feed.id, {'feed': this.newsblur_feed});
|
2012-03-02 17:51:28 -08:00
|
|
|
},
|
|
|
|
|
2012-03-03 09:51:38 -08:00
|
|
|
// ==========
|
|
|
|
// = Import =
|
|
|
|
// ==========
|
|
|
|
|
2012-03-05 19:18:40 -08:00
|
|
|
google_reader_connect: function() {
|
|
|
|
var options = "location=0,status=0,width=800,height=500";
|
|
|
|
var url = "/import/authorize?modal=true";
|
|
|
|
this.connect_window = window.open(url, '_blank', options);
|
2012-08-10 19:20:08 -07:00
|
|
|
this.connect_window_timer = setInterval(_.bind(function() {
|
|
|
|
console.log(["post connect window?", this.connect_window, this.connect_window.closed, this.connect_window.location]);
|
|
|
|
try {
|
|
|
|
if (!this.connect_window ||
|
|
|
|
!this.connect_window.location ||
|
|
|
|
this.connect_window.closed) {
|
|
|
|
this.start_import_from_google_reader({});
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
this.start_import_from_google_reader({});
|
|
|
|
}
|
|
|
|
}, this), 1000);
|
|
|
|
|
2012-03-05 19:18:40 -08:00
|
|
|
NEWSBLUR.reader.flags.importing_from_google_reader = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
start_import_from_google_reader: function(data) {
|
2012-08-10 19:20:08 -07:00
|
|
|
clearInterval(this.connect_window_timer);
|
2012-03-05 19:18:40 -08:00
|
|
|
var $error = $('.NB-intro-gitgoogle .NB-error', this.$modal);
|
|
|
|
var $loading = $('.NB-intro-imports-progress .NB-loading', this.$modal);
|
2012-03-12 18:11:13 -07:00
|
|
|
if (data && data.error) {
|
2012-03-05 19:18:40 -08:00
|
|
|
$error.show().text(data.error);
|
|
|
|
this.advance_import_carousel(0);
|
|
|
|
} else {
|
|
|
|
$error.hide();
|
|
|
|
NEWSBLUR.reader.flags.importing_from_google_reader = false;
|
|
|
|
this.advance_import_carousel(1);
|
|
|
|
$loading.addClass('NB-active');
|
2012-06-14 17:21:51 -07:00
|
|
|
NEWSBLUR.assets.start_import_from_google_reader($.rescope(this.finish_import_from_google_reader, this));
|
2012-03-05 19:18:40 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
finish_import_from_google_reader: function() {
|
|
|
|
var $loading = $('.NB-intro-imports-progress .NB-loading', this.$modal);
|
|
|
|
|
2012-06-15 14:49:59 -07:00
|
|
|
NEWSBLUR.assets.load_feeds(_.bind(function() {
|
2012-03-12 18:11:13 -07:00
|
|
|
$loading.removeClass('NB-active');
|
2012-03-05 19:18:40 -08:00
|
|
|
this.advance_import_carousel(2);
|
|
|
|
}, this));
|
|
|
|
},
|
|
|
|
|
2012-03-03 09:51:38 -08:00
|
|
|
handle_opml_upload: function() {
|
|
|
|
var self = this;
|
2012-03-05 19:18:40 -08:00
|
|
|
var $loading = $('.NB-intro-imports-progress .NB-loading', this.$modal);
|
2012-03-03 09:51:38 -08:00
|
|
|
var $error = $('.NB-intro-import-opml .NB-error', this.$modal);
|
2012-03-05 19:18:40 -08:00
|
|
|
var $file = $('.NB-intro-upload-opml-button', this.$modal);
|
2012-03-03 09:51:38 -08:00
|
|
|
$error.slideUp(300);
|
|
|
|
$loading.addClass('NB-active');
|
|
|
|
|
|
|
|
if (NEWSBLUR.Globals.is_anonymous) {
|
|
|
|
var $error = $('.NB-error', '.NB-fieldset.NB-add-opml');
|
|
|
|
$error.text("Please create an account. Not much to do without an account.");
|
|
|
|
$error.slideDown(300);
|
|
|
|
$loading.removeClass('NB-active');
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-05 19:18:40 -08:00
|
|
|
|
|
|
|
this.advance_import_carousel(1);
|
|
|
|
|
2012-03-03 09:51:38 -08:00
|
|
|
// NEWSBLUR.log(['Uploading']);
|
2012-07-12 23:44:30 -07:00
|
|
|
var params = {
|
2012-03-05 19:18:40 -08:00
|
|
|
url: NEWSBLUR.URLs['opml-upload'],
|
|
|
|
type: 'POST',
|
2012-07-20 19:43:28 -07:00
|
|
|
dataType: 'json',
|
2012-03-03 09:51:38 -08:00
|
|
|
success: function (data, status) {
|
2012-06-15 14:49:59 -07:00
|
|
|
NEWSBLUR.assets.load_feeds(function() {
|
2012-03-12 18:11:13 -07:00
|
|
|
$loading.removeClass('NB-active');
|
2012-03-05 19:18:40 -08:00
|
|
|
self.advance_import_carousel(2);
|
2012-07-20 19:43:28 -07:00
|
|
|
if (data.payload.delayed) {
|
|
|
|
NEWSBLUR.reader.flags.delayed_import = true;
|
|
|
|
self.count_feeds(data.payload.feed_count);
|
|
|
|
$('.NB-intro-import-delayed', self.$modal).show();
|
|
|
|
}
|
2012-03-05 19:18:40 -08:00
|
|
|
});
|
2012-03-03 09:51:38 -08:00
|
|
|
NEWSBLUR.reader.load_recommended_feed();
|
|
|
|
},
|
2012-03-05 19:18:40 -08:00
|
|
|
error: function (data, status, e) {
|
|
|
|
self.advance_import_carousel(0);
|
2012-03-03 09:51:38 -08:00
|
|
|
$loading.removeClass('NB-active');
|
|
|
|
NEWSBLUR.log(['Error', data, status, e]);
|
2012-06-20 18:37:46 -07:00
|
|
|
$error.text("There was a problem uploading your OPML file. Try e-mailing it to samuel@newsblur.com.");
|
2012-03-03 09:51:38 -08:00
|
|
|
$error.slideDown(300);
|
2012-03-05 19:18:40 -08:00
|
|
|
},
|
|
|
|
cache: false,
|
|
|
|
contentType: false,
|
|
|
|
processData: false
|
2012-07-12 23:44:30 -07:00
|
|
|
};
|
|
|
|
if (window.FormData) {
|
|
|
|
var formData = new FormData($file.closest('form')[0]);
|
|
|
|
params['data'] = formData;
|
|
|
|
|
|
|
|
$.ajax(params);
|
|
|
|
} else {
|
|
|
|
// IE9 has no FormData
|
|
|
|
params['secureuri'] = false;
|
|
|
|
params['fileElementId'] = 'NB-intro-upload-opml-button';
|
|
|
|
params['dataType'] = 'json';
|
|
|
|
|
|
|
|
$.ajaxFileUpload(params);
|
|
|
|
}
|
2012-03-03 09:51:38 -08:00
|
|
|
|
2012-03-05 19:18:40 -08:00
|
|
|
$file.replaceWith($file.clone());
|
|
|
|
|
2012-03-03 09:51:38 -08:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2012-03-16 20:40:48 -07:00
|
|
|
// ===================
|
|
|
|
// = Stay Up To Date =
|
|
|
|
// ===================
|
|
|
|
|
2012-03-19 17:51:54 -07:00
|
|
|
show_twitter_follow_buttons: function() {
|
2012-03-20 11:15:40 -07:00
|
|
|
$('.NB-intro-uptodate-follow', this.$modal).toggleClass('NB-intro-uptodate-twitter-inactive', !this.services.twitter.twitter_uid);
|
2012-03-19 17:51:54 -07:00
|
|
|
},
|
|
|
|
|
2012-03-16 20:40:48 -07:00
|
|
|
follow_twitter_account: function(username) {
|
|
|
|
var $input = $('#NB-intro-uptodate-follow-'+username, this.$modal);
|
|
|
|
var $button = $input.closest('.NB-intro-uptodate-follow');
|
|
|
|
|
|
|
|
if ($input.is(':checked')) {
|
|
|
|
$button.addClass('NB-active');
|
2012-03-19 17:51:54 -07:00
|
|
|
if (this.services.twitter.twitter_uid) {
|
2012-06-14 17:21:51 -07:00
|
|
|
NEWSBLUR.assets.follow_twitter_account(username);
|
2012-03-19 17:51:54 -07:00
|
|
|
} else {
|
|
|
|
window.open('http://twitter.com/'+username, '_blank');
|
|
|
|
}
|
2012-03-16 20:40:48 -07:00
|
|
|
} else {
|
|
|
|
$button.removeClass('NB-active');
|
2012-03-19 17:51:54 -07:00
|
|
|
if (this.services.twitter.twitter_uid) {
|
2012-06-14 17:21:51 -07:00
|
|
|
NEWSBLUR.assets.unfollow_twitter_account(username);
|
2012-03-19 17:51:54 -07:00
|
|
|
}
|
2012-03-16 20:40:48 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
subscribe_to_feed: function(feed) {
|
|
|
|
var $input = $('#NB-intro-uptodate-follow-'+feed, this.$modal);
|
|
|
|
var $button = $input.closest('.NB-intro-uptodate-follow');
|
2012-03-19 17:16:59 -07:00
|
|
|
var blog_url = 'http://blog.newsblur.com/';
|
|
|
|
var popular_username = 'social:popular';
|
2012-03-16 20:40:48 -07:00
|
|
|
|
|
|
|
if ($input.is(':checked')) {
|
|
|
|
$button.addClass('NB-active');
|
2012-03-19 17:16:59 -07:00
|
|
|
if (feed == 'blog') {
|
2012-06-14 17:21:51 -07:00
|
|
|
NEWSBLUR.assets.save_add_url(blog_url, "", function() {
|
2012-06-15 14:49:59 -07:00
|
|
|
NEWSBLUR.assets.load_feeds();
|
2012-03-19 17:16:59 -07:00
|
|
|
}, {auto_active: false});
|
|
|
|
} else if (feed == 'popular') {
|
2012-06-14 17:21:51 -07:00
|
|
|
NEWSBLUR.assets.follow_user(popular_username, function() {
|
2012-06-15 14:49:59 -07:00
|
|
|
NEWSBLUR.app.feed_list.make_social_feeds();
|
2012-03-19 17:16:59 -07:00
|
|
|
});
|
|
|
|
}
|
2012-03-16 20:40:48 -07:00
|
|
|
} else {
|
|
|
|
$button.removeClass('NB-active');
|
2012-03-19 17:16:59 -07:00
|
|
|
if (feed == 'blog') {
|
2012-06-14 17:21:51 -07:00
|
|
|
NEWSBLUR.assets.delete_feed_by_url(blog_url, "", function() {
|
2012-06-15 14:49:59 -07:00
|
|
|
NEWSBLUR.assets.load_feeds();
|
2012-03-19 17:16:59 -07:00
|
|
|
});
|
|
|
|
} else if (feed == 'popular') {
|
2012-06-14 17:21:51 -07:00
|
|
|
NEWSBLUR.assets.unfollow_user(popular_username, function() {
|
2012-05-17 18:40:46 -07:00
|
|
|
NEWSBLUR.app.feed_list.make_social_feeds();
|
2012-03-19 17:16:59 -07:00
|
|
|
});
|
|
|
|
}
|
2012-03-16 20:40:48 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-02 17:51:28 -08:00
|
|
|
// ===========
|
|
|
|
// = Actions =
|
|
|
|
// ===========
|
|
|
|
|
|
|
|
handle_click: function(elem, e) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$.targetIs(e, { tagSelector: '.NB-page-next' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
if (self.page_number == 1) {
|
|
|
|
self.fade_out_logo();
|
|
|
|
} else {
|
|
|
|
self.next_page();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$.targetIs(e, { tagSelector: '.NB-tutorial-finish-newsblur-blog' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
self.close_and_load_newsblur_blog();
|
|
|
|
});
|
|
|
|
|
2012-03-05 19:18:40 -08:00
|
|
|
$.targetIs(e, { tagSelector: '.NB-google-reader-oauth' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
self.google_reader_connect();
|
|
|
|
});
|
|
|
|
$.targetIs(e, { tagSelector: '.NB-intro-import-restart' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
self.advance_import_carousel(0);
|
|
|
|
});
|
2012-03-03 09:51:38 -08:00
|
|
|
$.targetIs(e, { tagSelector: '.NB-intro-upload-opml' }, function($t, $p) {
|
|
|
|
// e.preventDefault();
|
|
|
|
// return false;
|
|
|
|
});
|
2012-03-02 17:51:28 -08:00
|
|
|
$.targetIs(e, { tagSelector: '.NB-goodies-bookmarklet-button' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
alert('Drag this button to your bookmark toolbar.');
|
|
|
|
});
|
2012-03-06 11:41:57 -08:00
|
|
|
$.targetIs(e, { tagSelector: '.NB-friends-service-connect' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2012-03-05 19:18:40 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
handle_change: function(elem, e) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$.targetIs(e, { tagSelector: '.NB-intro-upload-opml-button' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
self.handle_opml_upload();
|
|
|
|
});
|
2012-03-07 16:32:02 -08:00
|
|
|
$.targetIs(e, { tagSelector: '.NB-friends-autofollow-checkbox' }, function($t, $p) {
|
2012-08-12 16:49:14 -07:00
|
|
|
NEWSBLUR.assets.preference('autofollow_friends', $t.is(':checked'));
|
2012-03-07 16:32:02 -08:00
|
|
|
});
|
2012-03-16 20:40:48 -07:00
|
|
|
$.targetIs(e, { tagSelector: '#NB-intro-uptodate-follow-newsblur' }, function($t, $p) {
|
|
|
|
self.follow_twitter_account('newsblur');
|
|
|
|
});
|
|
|
|
$.targetIs(e, { tagSelector: '#NB-intro-uptodate-follow-samuelclay' }, function($t, $p) {
|
|
|
|
self.follow_twitter_account('samuelclay');
|
|
|
|
});
|
|
|
|
$.targetIs(e, { tagSelector: '#NB-intro-uptodate-follow-blog' }, function($t, $p) {
|
|
|
|
self.subscribe_to_feed('blog');
|
|
|
|
});
|
|
|
|
$.targetIs(e, { tagSelector: '#NB-intro-uptodate-follow-popular' }, function($t, $p) {
|
|
|
|
self.subscribe_to_feed('popular');
|
|
|
|
});
|
2012-03-02 17:51:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|