/media/js/newsblur/reader/reader.js
JavaScript | 5494 lines | 4719 code | 588 blank | 187 comment | 1056 complexity | 532f19f2d3a17b9fd9db0a9280b807df MD5 | raw file
Possible License(s): MIT
Large files files are truncated, but you can click here to view the full file
- (function($) {
- NEWSBLUR.Reader = Backbone.Router.extend({
-
- init: function(options) {
-
- var defaults = {};
-
- // ===========
- // = Globals =
- // ===========
-
- NEWSBLUR.assets = new NEWSBLUR.AssetModel();
- this.model = NEWSBLUR.assets;
- this.story_view = 'page';
- this.options = _.extend({}, defaults, options);
- this.$s = {
- $body: $('body'),
- $layout: $('.NB-layout'),
- $sidebar: $('.NB-sidebar'),
- $feed_lists: $('.NB-feedlists'),
- $feed_list: $('#feed_list'),
- $social_feeds: $('.NB-socialfeeds-folder'),
- $story_titles: $('#story_titles'),
- $content_pane: $('.content-pane'),
- $story_taskbar: $('#story_taskbar'),
- $story_pane: $('#story_pane .NB-story-pane-container'),
- $feed_view: $('.NB-feed-story-view'),
- $feed_stories: $('.NB-feed-stories'),
- $feed_iframe: $('.NB-feed-iframe'),
- $story_iframe: $('.NB-story-iframe'),
- $intelligence_slider: $('.NB-intelligence-slider'),
- $mouse_indicator: $('#mouse-indicator'),
- $feed_link_loader: $('#NB-feeds-list-loader'),
- $feeds_progress: $('#NB-progress'),
- $dashboard: $('.NB-feeds-header-dashboard'),
- $river_sites_header: $('.NB-feeds-header-river-sites'),
- $river_blurblogs_header: $('.NB-feeds-header-river-blurblogs'),
- $river_global_header: $('.NB-feeds-header-river-global'),
- $starred_header: $('.NB-feeds-header-starred'),
- $tryfeed_header: $('.NB-feeds-header-tryfeed'),
- $taskbar: $('.taskbar_nav'),
- $feed_floater: $('.NB-feed-story-view-floater'),
- $feedbar: $('.NB-feedbar')
- };
- this.flags = {
- 'bouncing_callout': false,
- 'has_unfetched_feeds': false,
- 'count_unreads_after_import_working': false,
- 'import_from_google_reader_working': false,
- 'sidebar_closed': this.options.hide_sidebar
- };
- this.locks = {};
- this.counts = {
- 'page': 1,
- 'feature_page': 0,
- 'unfetched_feeds': 0,
- 'fetched_feeds': 0,
- 'page_fill_outs': 0,
- 'recommended_feed_page': 0,
- 'interactions_page': 1,
- 'activities_page': 1
- };
- this.cache = {
- 'iframe_story_positions': {},
- 'feed_view_story_positions': {},
- 'iframe_story_positions_keys': [],
- 'feed_view_story_positions_keys': [],
- 'river_feeds_with_unreads': [],
- '$feed_in_social_feed_list': {}
- };
- this.views = {};
- this.layout = {};
- this.constants = {
- FEED_REFRESH_INTERVAL: (1000 * 60) * 1, // 1 minute
- FILL_OUT_PAGES: 50,
- FIND_NEXT_UNREAD_STORY_TRIES: 12,
- RIVER_STORIES_FOR_STANDARD_ACCOUNT: 5,
- MIN_FEED_LIST_SIZE: 206
- };
-
- // ==================
- // = Event Handlers =
- // ==================
-
- $(window).bind('resize.reader', _.throttle($.rescope(this.resize_window, this), 1000));
- this.$s.$body.bind('click.reader', $.rescope(this.handle_clicks, this));
- this.$s.$body.bind('keyup.reader', $.rescope(this.handle_keyup, this));
- this.handle_keystrokes();
-
- // ============
- // = Bindings =
- // ============
-
- _.bindAll(this, 'show_stories_error');
-
- // ==================
- // = Initialization =
- // ==================
-
- var refresh_page = this.check_and_load_ssl();
- if (refresh_page) return;
- this.load_javascript_elements_on_page();
- this.apply_resizable_layout();
- this.add_body_classes();
- if (NEWSBLUR.Flags['start_import_from_google_reader']) {
- this.start_import_from_google_reader();
- }
- NEWSBLUR.app.sidebar_header = new NEWSBLUR.Views.SidebarHeader({collection: NEWSBLUR.assets.feeds});
- NEWSBLUR.app.sidebar = new NEWSBLUR.Views.Sidebar();
- NEWSBLUR.app.feed_list = new NEWSBLUR.Views.FeedList({el: this.$s.$feed_list[0]});
- NEWSBLUR.app.story_titles = new NEWSBLUR.Views.StoryTitlesView({collection: NEWSBLUR.assets.stories});
- NEWSBLUR.app.story_list = new NEWSBLUR.Views.StoryListView({collection: NEWSBLUR.assets.stories});
- NEWSBLUR.app.original_tab_view = new NEWSBLUR.Views.OriginalTabView({collection: NEWSBLUR.assets.stories});
- NEWSBLUR.app.story_tab_view = new NEWSBLUR.Views.StoryTabView({collection: NEWSBLUR.assets.stories});
- NEWSBLUR.app.feed_selector = new NEWSBLUR.Views.FeedSelector();
- NEWSBLUR.app.follow_requests_module = new NEWSBLUR.Views.FollowRequestsModule();
-
- this.load_intelligence_slider();
- this.handle_mouse_indicator_hover();
- this.position_mouse_indicator();
- this.handle_login_and_signup_forms();
- this.apply_story_styling();
- this.apply_tipsy_titles();
- this.load_recommended_feeds();
- this.setup_dashboard_graphs();
- this.setup_feedback_table();
- this.setup_howitworks_hovers();
- this.setup_interactions_module();
- this.setup_activities_module();
- this.setup_unfetched_feed_check();
- },
- // ========
- // = Page =
- // ========
-
- check_and_load_ssl: function() {
- if (window.location.protocol == 'http:' && this.model.preference('ssl')) {
- window.location.href = window.location.href.replace('http:', 'https:');
- return true;
- }
- },
-
- load_javascript_elements_on_page: function() {
- $('.NB-javascript').removeClass('NB-javascript');
- },
-
- resize_window: function() {
- var flag;
- var view = this.story_view;
-
- if (this.flags['page_view_showing_feed_view']) {
- view = 'feed';
- flag = 'page';
- } else if (this.flags['feed_view_showing_story_view']) {
- view = 'story';
- flag = 'story';
- }
-
- this.flags.scrolling_by_selecting_story_title = true;
- clearTimeout(this.locks.scrolling);
- this.locks.scrolling = _.delay(_.bind(function() {
- this.flags.scrolling_by_selecting_story_title = false;
- }, this), 1000);
- this.make_story_titles_pane_counter();
- this.position_mouse_indicator();
-
- this.switch_taskbar_view(view, {
- skip_save_type: flag,
- resize: true
- });
- NEWSBLUR.app.story_titles.fill_out();
- this.flags.fetch_story_locations_in_feed_view = this.flags.fetch_story_locations_in_feed_view ||
- _.throttle(function() {
- NEWSBLUR.app.story_list.reset_story_positions();
- }, 2000);
- this.flags.fetch_story_locations_in_feed_view();
-
- if ((NEWSBLUR.reader.layout.contentLayout.panes.north &&
- NEWSBLUR.reader.layout.contentLayout.panes.north.width() < 600) ||
- (NEWSBLUR.reader.layout.contentLayout.panes.center &&
- NEWSBLUR.reader.layout.contentLayout.panes.center.width() < 700)) {
- this.$s.$feed_view.addClass('NB-feed-story-view-narrow');
- } else {
- this.$s.$feed_view.removeClass('NB-feed-story-view-narrow');
- }
- },
-
- apply_resizable_layout: function(refresh) {
- var story_anchor = this.model.preference('story_pane_anchor');
- var right_pane_hidden = !$('.right-pane').is(':visible');
-
- if (refresh) {
- this.layout.contentLayout && this.layout.contentLayout.destroy();
- this.layout.rightLayout && this.layout.rightLayout.destroy();
- this.layout.leftCenterLayout && this.layout.leftCenterLayout.destroy();
- this.layout.leftLayout && this.layout.leftLayout.destroy();
- this.layout.outerLayout && this.layout.outerLayout.destroy();
- var feed_stories_bin = $.make('div').append(this.$s.$feed_stories.children());
- var story_titles_bin = $.make('div').append(this.$s.$story_titles.children());
- }
-
- $('.right-pane').removeClass('NB-story-pane-west')
- .removeClass('NB-story-pane-north')
- .removeClass('NB-story-pane-south')
- .addClass('NB-story-pane-'+story_anchor);
-
- this.layout.outerLayout = this.$s.$layout.layout({
- zIndex: 2,
- fxName: "slideOffscreen",
- fxSettings: { duration: 560, easing: "easeInOutQuint" },
- center__paneSelector: ".right-pane",
- west__paneSelector: ".left-pane",
- west__size: this.model.preference('feed_pane_size'),
- west__minSize: this.constants.MIN_FEED_LIST_SIZE,
- west__onresize_end: $.rescope(this.save_feed_pane_size, this),
- // west__initHidden: this.options.hide_sidebar,
- west__spacing_open: this.options.hide_sidebar ? 1 : 6,
- resizerDragOpacity: 0.6,
- resizeWhileDragging: true,
- enableCursorHotkey: false
- });
-
- if (this.model.preference('feed_pane_size') < 240) {
- this.layout.outerLayout.resizeAll();
- }
-
- this.layout.leftLayout = $('.left-pane').layout({
- closable: false,
- resizeWhileDragging: true,
- fxName: "slideOffscreen",
- fxSettings: { duration: 560, easing: "easeInOutQuint" },
- animatePaneSizing: true,
- north__paneSelector: ".left-north",
- north__size: 18,
- north__resizeable: false,
- north__spacing_open: 0,
- center__paneSelector: ".left-center",
- center__resizable: false,
- south__paneSelector: ".left-south",
- south__size: 31,
- south__resizable: false,
- south__spacing_open: 0,
- enableCursorHotkey: false
- });
-
- this.layout.leftCenterLayout = $('.left-center').layout({
- closable: false,
- slidable: false,
- resizeWhileDragging: true,
- center__paneSelector: ".left-center-content",
- center__resizable: false,
- south__paneSelector: ".left-center-footer",
- south__size: 'auto',
- south__resizable: false,
- south__slidable: true,
- south__spacing_open: 0,
- south__spacing_closed: 0,
- south__closable: true,
- south__initClosed: true,
- fxName: "slideOffscreen",
- fxSettings: { duration: 560, easing: "easeInOutQuint" },
- enableCursorHotkey: false
- });
-
- var rightLayoutOptions = {
- resizeWhileDragging: true,
- center__paneSelector: ".content-pane",
- spacing_open: story_anchor == 'west' ? 4 : 10,
- resizerDragOpacity: 0.6,
- enableCursorHotkey: false,
- fxName: "slideOffscreen",
- fxSettings: { duration: 560, easing: "easeInOutQuint" }
- };
- rightLayoutOptions[story_anchor+'__paneSelector'] = '.right-north';
- rightLayoutOptions[story_anchor+'__size'] = this.model.preference('story_titles_pane_size');
- rightLayoutOptions[story_anchor+'__onresize_end'] = $.rescope(this.save_story_titles_pane_size, this);
- rightLayoutOptions[story_anchor+'__onclose_start'] = $.rescope(this.toggle_story_titles_pane, this);
- rightLayoutOptions[story_anchor+'__onopen_start'] = $.rescope(this.toggle_story_titles_pane, this);
- this.layout.rightLayout = $('.right-pane').layout(rightLayoutOptions);
- var contentLayoutOptions = {
- resizeWhileDragging: true,
- center__paneSelector: ".content-center",
- spacing_open: 0,
- resizerDragOpacity: 0.6,
- enableCursorHotkey: false
- };
- if (story_anchor == 'west') {
- contentLayoutOptions['north__paneSelector'] = '.content-north';
- contentLayoutOptions['north__size'] = 30;
- } else {
- contentLayoutOptions[story_anchor+'__paneSelector'] = '.content-north';
- contentLayoutOptions[story_anchor+'__size'] = 30;
- }
- this.layout.contentLayout = this.$s.$content_pane.layout(contentLayoutOptions);
- if (!refresh) {
- $('.right-pane').hide();
- } else {
- this.$s.$feed_stories.append(feed_stories_bin.children());
- this.$s.$story_titles.append(story_titles_bin.children());
- this.resize_window();
- if (right_pane_hidden) {
- $('.right-pane').hide();
- }
- }
- },
-
- apply_tipsy_titles: function() {
- if (this.model.preference('show_tooltips')) {
- $('.NB-taskbar-sidebar-toggle-close').tipsy({
- gravity: 'se',
- delayIn: 375
- });
- $('.NB-taskbar-sidebar-toggle-open').tipsy({
- gravity: 'sw',
- delayIn: 375
- });
- $('.NB-task-add').tipsy({
- gravity: 'sw',
- delayIn: 375
- });
- $('.NB-task-manage').tipsy({
- gravity: 's',
- delayIn: 375
- });
- } else {
- $('.NB-taskbar-sidebar-toggle-close').tipsy('disable');
- $('.NB-taskbar-sidebar-toggle-open').tipsy('disable');
- $('.NB-task-add').tipsy('disable');
- $('.NB-task-manage').tipsy('disable');
- }
- $('.NB-module-content-account-realtime').tipsy({
- gravity: 'se',
- delayIn: 0
- });
- },
-
- save_feed_pane_size: function(w, pane, $pane, state, options, name) {
- var feed_pane_size = state.size;
-
- $('#NB-splash').css('left', feed_pane_size);
- $pane.toggleClass("NB-narrow", this.layout.outerLayout.state.west.size < 240);
- this.flags.set_feed_pane_size = this.flags.set_feed_pane_size || _.debounce( _.bind(function() {
- var feed_pane_size = this.layout.outerLayout.state.west.size;
- this.model.preference('feed_pane_size', feed_pane_size);
- this.flags.set_feed_pane_size = null;
- }, this), 1000);
- this.flags.set_feed_pane_size();
- },
-
- save_story_titles_pane_size: function(w, pane, $pane, state, options, name) {
- this.flags.scrolling_by_selecting_story_title = true;
- clearTimeout(this.locks.scrolling);
-
- var offset = 0;
- if (this.story_view == 'feed') {
- offset = this.$s.$feed_iframe.width();
- } else if (this.story_view == 'story') {
- offset = 2 * this.$s.$feed_iframe.width();
- }
- this.$s.$story_pane.css('left', -1 * offset);
-
- this.flags.set_story_titles_size = this.flags.set_story_titles_size || _.debounce( _.bind(function() {
- var story_titles_size = this.layout.rightLayout.state[this.model.preference('story_pane_anchor')].size;
- this.model.preference('story_titles_pane_size', story_titles_size);
- this.flags.set_story_titles_size = null;
- this.locks.scrolling = _.delay(_.bind(function() {
- this.flags.scrolling_by_selecting_story_title = false;
- }, this), 100);
- }, this), 1000);
- this.flags.set_story_titles_size();
-
- this.flags.resize_window = this.flags.resize_window || _.debounce( _.bind(function() {
- this.resize_window();
- this.flags.resize_window = null;
- }, this), 10);
- this.flags.resize_window();
-
- },
-
- add_body_classes: function() {
- this.$s.$body.toggleClass('NB-is-premium', NEWSBLUR.Globals.is_premium);
- this.$s.$body.toggleClass('NB-is-anonymous', NEWSBLUR.Globals.is_anonymous);
- this.$s.$body.toggleClass('NB-is-authenticated', NEWSBLUR.Globals.is_authenticated);
- this.$s.$body.toggleClass('NB-pref-hide-changes', !!this.model.preference('hide_story_changes'));
- },
-
- hide_splash_page: function() {
- var self = this;
- var resize = false;
- if (!$('.right-pane').is(':visible')) {
- resize = true;
- }
- $('.right-pane').show();
- $('#NB-splash,.NB-splash').hide();
- $('.NB-splash-info').hide();
- $('#NB-splash-overlay').hide();
- this.$s.$dashboard.addClass('NB-active');
- if (resize) {
- this.$s.$layout.layout().resizeAll();
- }
- if (NEWSBLUR.Globals.is_anonymous) {
- this.setup_ftux_signup_callout();
- }
- },
-
- show_splash_page: function(skip_router) {
- this.reset_feed();
- $('.right-pane').hide();
- $('.NB-splash-info').show();
- $('#NB-splash,.NB-splash').show();
- $('#NB-splash-overlay').show();
- this.$s.$dashboard.removeClass('NB-active');
- if (!skip_router) {
- NEWSBLUR.router.navigate('');
- }
- this.model.preference('dashboard_date', new Date);
- },
-
- add_url_from_querystring: function() {
- if (this.flags['added_url_from_querystring']) return;
-
- var url = $.getQueryString('url');
- this.flags['added_url_from_querystring'] = true;
- if (url) {
- this.open_add_feed_modal({url: url});
- }
- },
-
- animate_progress_bar: function($bar, seconds, percentage) {
- var self = this;
- percentage = percentage || 0;
- seconds = parseFloat(Math.max(1, parseInt(seconds, 10)), 10);
-
- if (percentage > 90) {
- time = seconds;
- } else if (percentage > 80) {
- time = seconds / 8;
- } else if (percentage > 70) {
- time = seconds / 16;
- } else if (percentage > 60) {
- time = seconds / 40;
- } else if (percentage > 50) {
- time = seconds / 80;
- } else if (percentage > 40) {
- time = seconds / 160;
- } else if (percentage > 30) {
- time = seconds / 200;
- } else if (percentage > 20) {
- time = seconds / 300;
- } else if (percentage > 10) {
- time = seconds / 400;
- } else {
- time = seconds / 500;
- }
-
- if (percentage <= 100) {
- this.locks['animate_progress_bar'] = setTimeout(function() {
- percentage += 1;
- $bar.progressbar({value: percentage});
- self.animate_progress_bar($bar, seconds, percentage);
- }, time * 1000);
- }
- },
-
- blur_to_page: function(options) {
- options = options || {};
-
- if (options.manage_menu) {
- $('.NB-menu-manage :focus').blur();
- } else {
- $(':focus').blur();
- }
- },
-
- // ==============
- // = Navigation =
- // ==============
-
- show_next_story: function(direction) {
- var story = NEWSBLUR.assets.stories.get_next_story(direction, {
- score: this.get_unread_view_score()
- });
-
- if (story) {
- story.set('selected', true);
- }
- },
-
- show_next_unread_story: function() {
- var unread_count = this.get_unread_count(true);
-
- if (unread_count) {
- var next_story = NEWSBLUR.assets.stories.get_next_unread_story();
- if (next_story) {
- this.counts['find_next_unread_on_page_of_feed_stories_load'] = 0;
- next_story.set('selected', true);
- } else if (this.counts['find_next_unread_on_page_of_feed_stories_load'] <
- this.constants.FIND_NEXT_UNREAD_STORY_TRIES &&
- !this.model.flags['no_more_stories']) {
- // Nothing up, nothing down, but still unread. Load 1 page then find it.
- this.counts['find_next_unread_on_page_of_feed_stories_load'] += 1;
- this.load_page_of_feed_stories();
- } else if (this.counts['find_next_unread_on_page_of_feed_stories_load'] >=
- this.constants.FIND_NEXT_UNREAD_STORY_TRIES) {
- this.open_next_unread_story_across_feeds(true);
- }
- }
- },
-
- open_next_unread_story_across_feeds: function(force_next_feed) {
- var unread_count = !force_next_feed && this.active_feed && this.get_unread_count(true);
-
- if (!unread_count) {
- if (this.flags.river_view && !this.flags.social_view) {
- var $next_folder = this.get_next_unread_folder(1);
- var folder = NEWSBLUR.assets.folders.get_view($next_folder);
- if (folder != this.active_folder) {
- this.open_river_stories($next_folder, folder && folder.model);
- }
- } else {
- // Find next feed with unreads
- var $next_feed = this.get_next_unread_feed(1);
- if (!$next_feed || !$next_feed.length) return;
- var next_feed_id = $next_feed.data('id');
- if (next_feed_id == this.active_feed) return;
-
- if (NEWSBLUR.utils.is_feed_social(next_feed_id)) {
- this.open_social_stories(next_feed_id, {force: true, $feed_link: $next_feed});
- } else {
- next_feed_id = parseInt(next_feed_id, 10);
- this.open_feed(next_feed_id, {force: true, $feed_link: $next_feed});
- }
- }
- }
- this.show_next_unread_story();
- },
-
- show_last_unread_story: function() {
- var unread_count = this.get_unread_count(true);
-
- if (unread_count) {
- var last_story = NEWSBLUR.assets.stories.get_last_unread_story(unread_count);
-
- if (last_story) {
- this.counts['find_last_unread_on_page_of_feed_stories_load'] = 0;
- last_story.set('selected', true);
- } else if (this.counts['find_last_unread_on_page_of_feed_stories_load'] < this.constants.FILL_OUT_PAGES &&
- !this.model.flags['no_more_stories']) {
- // Nothing up, nothing down, but still unread. Load 1 page then find it.
- this.counts['find_last_unread_on_page_of_feed_stories_load'] += 1;
- this.load_page_of_feed_stories();
- }
- }
- },
-
- select_story_in_feed: function() {
- var story_id = this.flags['select_story_in_feed'];
- var story = NEWSBLUR.assets.stories.get(story_id);
- // NEWSBLUR.log(['select_story_in_feed', story_id, story, this.story_view, this.counts['select_story_in_feed'], this.flags['no_more_stories']]);
-
- if (story) {
- this.counts['select_story_in_feed'] = 0;
- this.flags['select_story_in_feed'] = null;
- _.delay(_.bind(function() {
- // Even though a story_id is specified, this just means go to the comments.
- // Refactor when stories can be scrolled to separately from comments.
- story.set('selected', true, {scroll_to_comments: true});
- }, this), 100);
- } else if (this.counts['select_story_in_feed'] < this.constants.FILL_OUT_PAGES &&
- !this.model.flags['no_more_stories']) {
- // Nothing up, nothing down, but still not found. Load 1 page then find it.
- this.counts['select_story_in_feed'] += 1;
- this.load_page_of_feed_stories();
- } else {
- this.counts['select_story_in_feed'] = 0;
- this.flags['select_story_in_feed'] = null;
- }
- },
-
- show_previous_story: function() {
- NEWSBLUR.assets.stories.select_previous_story();
- },
-
- show_next_feed: function(direction, $current_feed) {
- var $feed_list = this.$s.$feed_list.add(this.$s.$social_feeds);
-
- if (this.flags.river_view && !this.flags.social_view) {
- return this.show_next_folder(direction, $current_feed);
- }
-
- var $next_feed = this.get_next_feed(direction, $current_feed, {include_selected: true});
- var next_feed_id = $next_feed.data('id');
- if (next_feed_id && next_feed_id == this.active_feed) {
- this.show_next_feed(direction, $next_feed);
- } else if (NEWSBLUR.utils.is_feed_social(next_feed_id)) {
- this.open_social_stories(next_feed_id, {force: true, $feed_link: $next_feed});
- } else {
- next_feed_id = parseInt(next_feed_id, 10);
- this.open_feed(next_feed_id, {force: true, $feed_link: $next_feed});
- }
- },
-
- show_next_folder: function(direction, $current_folder) {
- var $next_folder = this.get_next_folder(direction, $current_folder);
- var folder = NEWSBLUR.assets.folders.get_view($next_folder);
- this.open_river_stories($next_folder, folder && folder.model);
- },
-
- get_next_feed: function(direction, $current_feed, options) {
- options = options || {};
- var self = this;
- var $feed_list = this.$s.$feed_list.add(this.$s.$social_feeds);
- var $current_feed = $current_feed || $('.selected', $feed_list);
- var $next_feed,
- scroll;
- var $feeds = $('.feed:visible:not(.NB-empty)', $feed_list);
- if (!$current_feed.length) {
- if (options.include_selected) {
- $feeds = $feeds.add('.NB-feedlists .feed.NB-selected');
- }
- $current_feed = $('.feed:visible:not(.NB-empty)', $feed_list)[direction==-1?'last':'first']();
- $next_feed = $current_feed;
- } else {
- var current_feed = 0;
- $feeds.each(function(i) {
- if (this == $current_feed[0]) {
- current_feed = i;
- return false;
- }
- });
- $next_feed = $feeds.eq((current_feed+direction) % ($feeds.length));
- }
-
- return $next_feed;
- },
-
- get_next_folder: function(direction, $current_folder) {
- var self = this;
- var $feed_list = this.$s.$feed_list.add(this.$s.$social_feeds);
- var $current_folder = $('.folder.NB-selected', $feed_list);
- var $folders = $('li.folder:visible:not(.NB-empty)', $feed_list);
- var current_folder = 0;
- $folders.each(function(i) {
- if (this == $current_folder[0]) {
- current_folder = i;
- return false;
- }
- });
-
- var next_folder_index = (current_folder+direction) % ($folders.length);
- var $next_folder = $folders.eq(next_folder_index);
-
- return $next_folder;
- },
- get_next_unread_feed: function(direction, $current_feed) {
- var self = this;
- var $feed_list = this.$s.$feed_list.add(this.$s.$social_feeds);
- $current_feed = $current_feed || $('.selected', $feed_list);
- var unread_view = this.get_unread_view_name();
- var $next_feed;
- var current_feed;
-
- var $feeds = $('.feed:visible:not(.NB-empty)', $feed_list).filter(function() {
- var $this = $(this);
- if (unread_view == 'positive') {
- return $this.is('.unread_positive');
- } else if (unread_view == 'neutral') {
- return $this.is('.unread_positive,.unread_neutral');
- } else if (unread_view == 'negative') {
- return $this.is('.unread_positive,.unread_neutral,.unread_negative');
- }
- }).add('.NB-feedlists .feed.NB-selected');
- if (!$current_feed.length) {
- $next_feed = $feeds.first();
- } else {
- $feeds.each(function(i) {
- if (this == $current_feed[0]) {
- current_feed = i;
- return false;
- }
- });
- $next_feed = $feeds.eq((current_feed+direction) % ($feeds.length));
- }
-
- return $next_feed;
- },
-
- get_next_unread_folder: function(direction) {
- var self = this;
- var $feed_list = this.$s.$feed_list.add(this.$s.$social_feeds);
- var $current_folder = $('.folder.NB-selected', $feed_list);
- var unread_view = this.get_unread_view_name();
- var $next_folder;
- var current_folder = 0;
- var $folders = $('li.folder:visible:not(.NB-empty)', $feed_list);
-
- $folders = $folders.filter(function() {
- var $this = $(this);
- var folder_view = NEWSBLUR.assets.folders.get_view($current_folder);
- var folder_model = folder_view && folder_view.model;
- if (!folder_model) return false;
-
- var counts = folder_model.collection.unread_counts();
-
- if (this == $current_folder[0]) return true;
-
- if (unread_view == 'positive') {
- return counts.ps;
- } else if (unread_view == 'neutral') {
- return counts.ps + counts.nt;
- } else if (unread_view == 'negative') {
- return counts.ps + counts.nt + counts.ng;
- }
- });
- $folders.each(function(i) {
- if (this == $current_folder[0]) {
- current_folder = i;
- return false;
- }
- });
- $next_folder = $folders.eq((current_folder+direction) % ($folders.length));
- return $next_folder;
- },
-
- page_in_story: function(amount, direction) {
- var page_height = this.$s.$story_pane.height();
- var scroll_height = parseInt(page_height * amount, 10);
- var dir = '+';
- if (direction == -1) {
- dir = '-';
- }
- // NEWSBLUR.log(['page_in_story', this.$s.$story_pane, direction, page_height, scroll_height]);
- if (this.story_view == 'page' && !this.flags['page_view_showing_feed_view']) {
- this.$s.$feed_iframe.scrollTo({
- top: dir+'='+scroll_height,
- left:'+=0'
- }, 230, {queue: false});
- } else if (this.story_view == 'feed' || this.flags['page_view_showing_feed_view']) {
- this.$s.$feed_stories.scrollTo({
- top: dir+'='+scroll_height,
- left:'+=0'
- }, 230, {queue: false});
- }
-
- this.show_mouse_indicator();
- // _.delay(_.bind(this.hide_mouse_indicator, this), 350);
- },
-
- find_story_with_action_preference_on_open_feed: function() {
- var open_feed_action = this.model.preference('open_feed_action');
- if (!this.active_story && open_feed_action == 'newest') {
- this.show_next_unread_story();
- }
- },
-
- // =============
- // = Feed Pane =
- // =============
-
- sort_feeds: function($feeds) {
- $('.feed', $feeds).tsort('', {sortFunction: NEWSBLUR.Collections.Folders.comparator});
- $('.folder', $feeds).tsort('.folder_title_text');
- },
-
- load_sortable_feeds: function() {
- var self = this;
-
- this.$s.$feed_list.sortable({
- items: '.feed,li.folder',
- connectWith: 'ul.folder,.feed.NB-empty',
- placeholder: 'NB-feeds-list-highlight',
- axis: 'y',
- distance: 4,
- cursor: 'move',
- containment: '#feed_list',
- tolerance: 'pointer',
- scrollSensitivity: 35,
- start: function(e, ui) {
- self.flags['sorting_feed'] = true;
- ui.placeholder.attr('class', ui.item.attr('class') + ' NB-feeds-list-highlight');
- NEWSBLUR.app.feed_list.start_sorting();
- ui.item.addClass('NB-feed-sorting');
- ui.placeholder.data('id', ui.item.data('id'));
- if (ui.item.is('.folder')) {
- ui.placeholder.html(ui.item.children().clone());
- ui.item.data('previously_collapsed', ui.item.data('collapsed'));
- self.collapse_folder(ui.item.children('.folder_title'), true);
- self.collapse_folder(ui.placeholder.children('.folder_title'), true);
- ui.item.css('height', ui.item.children('.folder_title').outerHeight(true) + 'px');
- ui.helper.css('height', ui.helper.children('.folder_title').outerHeight(true) + 'px');
- } else {
- ui.placeholder.html(ui.item.children().clone());
- }
- },
- change: function(e, ui) {
- var $feeds = ui.placeholder.closest('ul.folder');
- self.sort_feeds($feeds);
- },
- stop: function(e, ui) {
- setTimeout(function() {
- self.flags['sorting_feed'] = false;
- }, 100);
- ui.item.removeClass('NB-feed-sorting');
- NEWSBLUR.app.feed_list.end_sorting();
- self.sort_feeds(e.target);
- self.save_feed_order();
- ui.item.css({'backgroundColor': '#D7DDE6'})
- .animate({'backgroundColor': '#F0F076'}, {'duration': 800})
- .animate({'backgroundColor': '#D7DDE6'}, {'duration': 1000});
- if (ui.item.is('.folder') && !ui.item.data('previously_collapsed')) {
- self.collapse_folder(ui.item.children('.folder_title'));
- self.collapse_folder(ui.placeholder.children('.folder_title'));
- }
- }
- });
- },
-
- save_feed_order: function() {
- var combine_folders = function($folder) {
- var folders = [];
- var $items = $folder.children('li.folder, .feed');
-
- for (var i=0, i_count=$items.length; i < i_count; i++) {
- var $item = $items.eq(i);
- if ($item.hasClass('feed')) {
- var feed_id = parseInt($item.data('id'), 10);
- if (feed_id) {
- folders.push(feed_id);
- }
- } else if ($item.hasClass('folder')) {
- var folder_title = $item.find('.folder_title_text').eq(0).text();
- var child_folders = {};
- child_folders[folder_title] = combine_folders($item.children('ul.folder').eq(0));
- folders.push(child_folders);
- }
- }
-
- return folders;
- };
-
- var combined_folders = combine_folders(this.$s.$feed_list);
- // NEWSBLUR.log(['Save new folder/feed order', {'combined': combined_folders}]);
- this.model.save_feed_order(combined_folders);
- },
-
- show_feed_chooser_button: function() {
- var self = this;
- var $progress = this.$s.$feeds_progress;
- var $bar = $('.NB-progress-bar', $progress);
- var percentage = 0;
-
- $('.NB-progress-title', $progress).text('Get Started');
- $('.NB-progress-counts', $progress).hide();
- $('.NB-progress-percentage', $progress).hide();
- $progress.addClass('NB-progress-error').addClass('NB-progress-big');
- $('.NB-progress-link', $progress).html($.make('div', {
- className: 'NB-modal-submit-button NB-modal-submit-green NB-menu-manage-feedchooser'
- }, ['Choose your 64 sites']));
-
- this.show_progress_bar();
- },
-
- hide_feed_chooser_button: function() {
- var $progress = this.$s.$feeds_progress;
- var $bar = $('.NB-progress-bar', $progress);
- $progress.removeClass('NB-progress-error').removeClass('NB-progress-big');
-
- this.hide_progress_bar();
- },
-
- open_dialog_after_feeds_loaded: function(options) {
- options = options || {};
- if (!NEWSBLUR.Globals.is_authenticated) return;
-
- if (!NEWSBLUR.assets.folders.length ||
- !NEWSBLUR.assets.preference('has_setup_feeds')) {
- if (options.delayed_import || this.flags.delayed_import) {
- this.setup_ftux_add_feed_callout("Check your email...");
- } else if (NEWSBLUR.assets.preference('has_setup_feeds')) {
- this.setup_ftux_add_feed_callout();
- } else if (!NEWSBLUR.intro || !NEWSBLUR.intro.flags.open) {
- _.defer(_.bind(this.open_intro_modal, this), 100);
- }
- } else if (!NEWSBLUR.assets.flags['has_chosen_feeds'] &&
- NEWSBLUR.assets.folders.length) {
- _.defer(_.bind(this.open_feedchooser_modal, this), 100);
- } else if (!NEWSBLUR.Globals.is_premium &&
- NEWSBLUR.assets.feeds.active().length > 64) {
- _.defer(_.bind(this.open_feedchooser_modal, this), 100);
- }
- },
-
- // ================
- // = Progress Bar =
- // ================
-
- check_feed_fetch_progress: function() {
- $.extend(this.counts, {
- 'unfetched_feeds': 0,
- 'fetched_feeds': 0
- });
-
- var counts = this.model.count_unfetched_feeds();
- this.counts['unfetched_feeds'] = counts['unfetched_feeds'];
- this.counts['fetched_feeds'] = counts['fetched_feeds'];
- if (this.counts['unfetched_feeds'] == 0) {
- this.flags['has_unfetched_feeds'] = false;
- this.hide_unfetched_feed_progress();
- } else {
- this.flags['has_unfetched_feeds'] = true;
- this.show_unfetched_feed_progress();
- }
- },
-
- show_progress_bar: function() {
- var $layout = this.$s.$feeds_progress.parents('.left-center').layout();
- if (!this.flags['showing_progress_bar']) {
- this.flags['showing_progress_bar'] = true;
- $layout.open('south');
- }
- $layout.sizePane('south');
- },
- hide_progress_bar: function(permanent) {
- var self = this;
-
- if (permanent) {
- this.model.preference('hide_fetch_progress', true);
- }
-
- this.flags['showing_progress_bar'] = false;
- this.$s.$feeds_progress.parents('.left-center').layout().close('south');
- },
-
- show_unfetched_feed_progress: function() {
- var self = this;
- var $progress = this.$s.$feeds_progress;
- var percentage = parseInt(this.counts['fetched_feeds'] / (this.counts['unfetched_feeds'] + this.counts['fetched_feeds']) * 100, 10);
- $('.NB-progress-title', $progress).text('Fetching your feeds');
- $('.NB-progress-counts', $progress).show();
- $('.NB-progress-counts-fetched', $progress).text(this.counts['fetched_feeds']);
- $('.NB-progress-counts-total', $progress).text(this.counts['unfetched_feeds'] + this.counts['fetched_feeds']);
- $('.NB-progress-percentage', $progress).show().text(percentage + '%');
- $('.NB-progress-bar', $progress).progressbar({
- value: percentage
- });
-
- if (!$progress.is(':visible') && !this.model.preference('hide_fetch_progress')) {
- setTimeout(function() {
- self.show_progress_bar();
- }, 1000);
- }
-
- this.setup_feed_refresh(true);
- },
-
- hide_unfetched_feed_progress: function(permanent) {
- if (permanent) {
- this.model.preference('hide_fetch_progress', true);
- }
-
- this.setup_feed_refresh();
- this.hide_progress_bar();
- },
-
- // ===============================
- // = Feed bar - Individual Feeds =
- // ===============================
-
- reset_feed: function(options) {
- options = options || {};
-
- $.extend(this.flags, {
- 'scrolling_by_selecting_story_title': false,
- 'page_view_showing_feed_view': false,
- 'feed_view_showing_story_view': false,
- 'story_titles_loaded': false,
- 'iframe_prevented_from_loading': false,
- 'pause_feed_refreshing': false,
- 'feed_list_showing_manage_menu': false,
- 'unread_threshold_temporarily': null,
- 'river_view': false,
- 'social_view': false,
- 'non_premium_river_view': false,
- 'select_story_in_feed': null,
- 'global_blurblogs': false
- });
-
- $.extend(this.cache, {
- 'iframe': {},
- 'iframe_stories': {},
- 'iframe_story_positions': {},
- 'feed_view_story_positions': {},
- 'iframe_story_positions_keys': [],
- 'feed_view_story_positions_keys': [],
- 'river_feeds_with_unreads': [],
- 'prefetch_last_story': 0,
- 'prefetch_iteration': 0,
- 'feed_title_floater_story_id': null,
- '$feed_in_social_feed_list': {}
- });
-
- $.extend(this.counts, {
- 'page': 1,
- 'page_fill_outs': 0,
- 'find_next_unread_on_page_of_feed_stories_load': 0,
- 'find_last_unread_on_page_of_feed_stories_load': 0,
- 'select_story_in_feed': 0
- });
-
- if (_.isUndefined(options.search)) {
- delete this.flags.search;
- }
- this.model.flags['no_more_stories'] = false;
- this.$s.$feed_stories.scrollTop(0);
- this.$s.$starred_header.removeClass('NB-selected');
- this.$s.$river_sites_header.removeClass('NB-selected');
- this.$s.$river_blurblogs_header.removeClass('NB-selected');
- this.$s.$river_global_header.removeClass('NB-selected');
- this.$s.$tryfeed_header.removeClass('NB-selected');
- this.model.feeds.deselect();
- if (_.string.contains(this.active_feed, 'social:')) {
- this.model.social_feeds.deselect();
- }
- if (_.string.contains(this.active_feed, 'river:')) {
- this.model.folders.deselect();
- }
- this.$s.$body.removeClass('NB-view-river');
- $('.task_view_page', this.$s.$taskbar).removeClass('NB-disabled');
- $('.task_view_story', this.$s.$taskbar).removeClass('NB-disabled');
- $('.task_view_page', this.$s.$taskbar).removeClass('NB-task-return');
- clearTimeout(this.flags['next_fetch']);
-
- if (this.flags['showing_feed_in_tryfeed_view'] || this.flags['showing_social_feed_in_tryfeed_view']) {
- this.hide_tryfeed_view();
- }
- if (NEWSBLUR.Globals.is_anonymous) {
- if (options.router) {
- this.$s.$layout.layout().show('west', true);
- this.$s.$layout.show();
- }
- this.hide_tryout_signup_button();
- }
-
- this.active_folder = null;
- this.active_feed = null;
- this.active_story = null;
-
- NEWSBLUR.assets.stories.reset();
- NEWSBLUR.app.feed_selector.hide_feed_selector();
- NEWSBLUR.app.original_tab_view.unload_feed_iframe();
- NEWSBLUR.app.story_tab_view.unload_story_iframe();
- },
-
- reload_feed: function(options) {
- options = options || {};
-
- if (this.active_feed == 'starred') {
- this.open_starred_stories(options);
- } else if (this.flags['social_view'] &&
- this.active_feed == 'river:blurblogs') {
- this.open_river_blurblogs_stories();
- } else if (this.flags['social_view'] &&
- this.active_feed == 'river:global') {
- this.open_river_blurblogs_stories({'global': true});
- } else if (this.flags['social_view']) {
- this.open_social_stories(this.active_feed);
- } else if (this.flags['river_view']) {
- this.open_river_stories(this.active_folder &&
- this.active_folder.folder_view &&
- this.active_folder.folder_view.$el,
- this.active_folder);
- } else {
- this.open_feed(this.active_feed, options);
- }
- },
-
- open_feed: function(feed_id, options) {
- options = options || {};
- var self = this;
- var $story_titles = this.$s.$story_titles;
- var feed = this.model.get_feed(feed_id) || options.feed;
- var temp = feed && (feed.get('temp') || !feed.get('subscribed'));
-
- if (!feed || (temp && !options.try_feed)) {
- // Setup tryfeed views first, then come back here.
- options.feed = options.feed && options.feed.attributes;
- return this.load_feed_in_tryfeed_view(feed_id, options);
- }
- this.flags['opening_feed'] = true;
-
- if (options.try_feed || feed) {
- this.reset_feed(options);
- this.hide_splash_page();
- if (options.story_id) {
- this.flags['select_story_in_feed'] = options.story_id;
- }
-
- this.active_feed = feed.id;
- this.next_feed = feed.id;
-
- feed.set('selec…
Large files files are truncated, but you can click here to view the full file