mirror of
				https://github.com/samuelclay/NewsBlur.git
				synced 2025-11-01 09:09:51 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			218 lines
		
	
	
		
			No EOL
		
	
	
		
			7.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			218 lines
		
	
	
		
			No EOL
		
	
	
		
			7.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
NEWSBLUR.Views.StoryTitlesView = Backbone.View.extend({
 | 
						|
    
 | 
						|
    el: '.NB-story-titles',
 | 
						|
    
 | 
						|
    events: {
 | 
						|
        "click .NB-feed-story-premium-only a" : function(e) {
 | 
						|
            e.preventDefault();
 | 
						|
            NEWSBLUR.reader.open_feedchooser_modal();
 | 
						|
        }
 | 
						|
    },
 | 
						|
    
 | 
						|
    initialize: function() {
 | 
						|
        _.bindAll(this, 'scroll');
 | 
						|
        this.collection.bind('reset', this.render, this);
 | 
						|
        this.collection.bind('add', this.add, this);
 | 
						|
        this.collection.bind('no_more_stories', this.check_premium_river, this);
 | 
						|
        NEWSBLUR.reader.$s.$story_titles.scroll(this.scroll);
 | 
						|
    },
 | 
						|
    
 | 
						|
    // ==========
 | 
						|
    // = Render =
 | 
						|
    // ==========
 | 
						|
    
 | 
						|
    render: function() {
 | 
						|
        NEWSBLUR.reader.$s.$story_titles.scrollTop(0);
 | 
						|
        var collection = this.collection;
 | 
						|
        var $stories = this.collection.map(function(story) {
 | 
						|
            return new NEWSBLUR.Views.StoryTitleView({
 | 
						|
                model: story,
 | 
						|
                collection: collection
 | 
						|
            }).render().el;
 | 
						|
        });
 | 
						|
        this.$el.html($stories);
 | 
						|
        this.end_loading();
 | 
						|
        this.fill_out();
 | 
						|
    },
 | 
						|
    
 | 
						|
    add: function(options) {
 | 
						|
        var collection = this.collection;
 | 
						|
        if (options.added) {
 | 
						|
            var $stories = _.compact(_.map(this.collection.models.slice(-1 * options.added), function(story) {
 | 
						|
                if (story.story_title_view) return;
 | 
						|
                return new NEWSBLUR.Views.StoryTitleView({
 | 
						|
                    model: story,
 | 
						|
                    collection: collection
 | 
						|
                }).render().el;
 | 
						|
            }));
 | 
						|
            this.$el.append($stories);
 | 
						|
        }
 | 
						|
        this.end_loading();
 | 
						|
        this.fill_out();
 | 
						|
    },
 | 
						|
    
 | 
						|
    append_river_premium_only_notification: function() {
 | 
						|
        var $notice = $.make('div', { className: 'NB-feed-story-premium-only' }, [
 | 
						|
            $.make('div', { className: 'NB-feed-story-premium-only-divider'}),
 | 
						|
            $.make('div', { className: 'NB-feed-story-premium-only-text'}, [
 | 
						|
                'The full River of News is a ',
 | 
						|
                $.make('a', { href: '#', className: 'NB-splash-link' }, 'premium feature'),
 | 
						|
                '.'
 | 
						|
            ])
 | 
						|
        ]);
 | 
						|
        this.$('.NB-feed-story-premium-only').remove();
 | 
						|
        this.$el.append($notice);
 | 
						|
    },
 | 
						|
    
 | 
						|
    // ===========
 | 
						|
    // = Actions =
 | 
						|
    // ===========
 | 
						|
    
 | 
						|
    fill_out: function(options) {
 | 
						|
        this.snap_back_scroll_position();
 | 
						|
        
 | 
						|
        if (NEWSBLUR.assets.flags['no_more_stories'] || !NEWSBLUR.assets.stories.length) {
 | 
						|
            return;
 | 
						|
        }
 | 
						|
        
 | 
						|
        options = options || {};
 | 
						|
        var $last = this.$('.NB-story-title:visible:last');
 | 
						|
        var container_height = NEWSBLUR.reader.$s.$story_titles.height();
 | 
						|
 | 
						|
        if (NEWSBLUR.reader.counts['page_fill_outs'] < NEWSBLUR.reader.constants.FILL_OUT_PAGES && 
 | 
						|
            !NEWSBLUR.assets.flags['no_more_stories']) {
 | 
						|
            // NEWSBLUR.log(["fill out", $last.length && $last.position().top, container_height, $last.length, NEWSBLUR.reader.$s.$story_titles.scrollTop()]);
 | 
						|
            NEWSBLUR.reader.counts['page_fill_outs'] += 1;
 | 
						|
            _.delay(_.bind(function() {
 | 
						|
                this.scroll();
 | 
						|
            }, this), 10);
 | 
						|
        } else {
 | 
						|
            this.show_no_more_stories();
 | 
						|
        }
 | 
						|
    },
 | 
						|
    
 | 
						|
    show_loading: function(options) {
 | 
						|
        if (NEWSBLUR.assets.flags['no_more_stories']) return;
 | 
						|
        
 | 
						|
        var $story_titles = NEWSBLUR.reader.$s.$story_titles;
 | 
						|
        this.$('.NB-end-line').remove();
 | 
						|
        var $endline = $.make('div', { className: "NB-end-line NB-short" });
 | 
						|
        $endline.css({'background': '#E1EBFF'});
 | 
						|
        $story_titles.append($endline);
 | 
						|
        
 | 
						|
        $endline.animate({'backgroundColor': '#5C89C9'}, {'duration': 650})
 | 
						|
                .animate({'backgroundColor': '#E1EBFF'}, 1050);
 | 
						|
        this.feed_stories_loading = setInterval(function() {
 | 
						|
            $endline.animate({'backgroundColor': '#5C89C9'}, {'duration': 650})
 | 
						|
                    .animate({'backgroundColor': '#E1EBFF'}, 1050);
 | 
						|
        }, 1500);
 | 
						|
        
 | 
						|
        if (options.show_loading) {
 | 
						|
            this.pre_load_page_scroll_position = $('#story_titles').scrollTop();
 | 
						|
            if (this.pre_load_page_scroll_position > 0) {
 | 
						|
                this.pre_load_page_scroll_position += $endline.outerHeight();
 | 
						|
            }
 | 
						|
            $story_titles.scrollTo($endline, { 
 | 
						|
                duration: 0,
 | 
						|
                axis: 'y', 
 | 
						|
                easing: 'easeInOutQuint', 
 | 
						|
                offset: 0, 
 | 
						|
                queue: false
 | 
						|
            });
 | 
						|
            this.post_load_page_scroll_position = $('#story_titles').scrollTop();
 | 
						|
        } else {
 | 
						|
            this.pre_load_page_scroll_position = null;
 | 
						|
            this.post_load_page_scroll_position = null;
 | 
						|
        }
 | 
						|
    },
 | 
						|
    
 | 
						|
    check_premium_river: function() {
 | 
						|
        this.show_no_more_stories();
 | 
						|
        this.append_river_premium_only_notification();
 | 
						|
    },
 | 
						|
    
 | 
						|
    end_loading: function() {
 | 
						|
        var $endbar = NEWSBLUR.reader.$s.$story_titles.find('.NB-end-line');
 | 
						|
        $endbar.remove();
 | 
						|
        clearInterval(this.feed_stories_loading);
 | 
						|
 | 
						|
        if (NEWSBLUR.assets.flags['no_more_stories']) {
 | 
						|
            this.show_no_more_stories();
 | 
						|
        }
 | 
						|
    },
 | 
						|
    
 | 
						|
    show_no_more_stories: function() {
 | 
						|
        this.$('.NB-end-line').remove();
 | 
						|
        var $end_stories_line = $.make('div', { className: "NB-end-line" }, [
 | 
						|
            $.make('div', { className: 'NB-fleuron' })
 | 
						|
        ]);
 | 
						|
 | 
						|
        this.$el.append($end_stories_line);
 | 
						|
    },
 | 
						|
    
 | 
						|
    snap_back_scroll_position: function() {
 | 
						|
        var $story_titles = NEWSBLUR.reader.$s.$story_titles;
 | 
						|
        if (this.post_load_page_scroll_position == $story_titles.scrollTop() &&
 | 
						|
            this.pre_load_page_scroll_position != null &&
 | 
						|
            !NEWSBLUR.reader.flags['select_story_in_feed']) {
 | 
						|
            $story_titles.scrollTo(this.pre_load_page_scroll_position, { 
 | 
						|
                duration: 0,
 | 
						|
                axis: 'y', 
 | 
						|
                offset: 0, 
 | 
						|
                queue: false
 | 
						|
            });
 | 
						|
        }
 | 
						|
    },
 | 
						|
    
 | 
						|
    // ============
 | 
						|
    // = Bindings =
 | 
						|
    // ============
 | 
						|
    
 | 
						|
    scroll_to_selected_story: function(story, options) {
 | 
						|
        options = options || {};
 | 
						|
        var story_title_view = (story && story.story_title_view) ||
 | 
						|
                                (this.collection.active_story && this.collection.active_story.story_title_view);
 | 
						|
        if (!story_title_view) return;
 | 
						|
        
 | 
						|
        var story_title_visisble = NEWSBLUR.reader.$s.$story_titles.isScrollVisible(story_title_view.$el);
 | 
						|
        if (!story_title_visisble || options.force || 
 | 
						|
            NEWSBLUR.assets.preference('story_layout') == 'list') {
 | 
						|
            var container_offset = NEWSBLUR.reader.$s.$story_titles.position().top;
 | 
						|
            var scroll = story_title_view.$el.position().top;
 | 
						|
            var container = NEWSBLUR.reader.$s.$story_titles.scrollTop();
 | 
						|
            var height = NEWSBLUR.reader.$s.$story_titles.outerHeight();
 | 
						|
            var position = scroll+container-height/5;
 | 
						|
            
 | 
						|
            if (NEWSBLUR.assets.preference('story_layout') == 'list') {
 | 
						|
                position = scroll+container;
 | 
						|
            }
 | 
						|
 | 
						|
            NEWSBLUR.reader.$s.$story_titles.scrollTo(position, {
 | 
						|
                duration: NEWSBLUR.assets.preference('animations') ? 260 : 0,
 | 
						|
                queue: false
 | 
						|
            });
 | 
						|
        }    
 | 
						|
    },
 | 
						|
    
 | 
						|
    // ==========
 | 
						|
    // = Events =
 | 
						|
    // ==========
 | 
						|
    
 | 
						|
    scroll: function() {
 | 
						|
        if (NEWSBLUR.assets.flags['no_more_stories'] || NEWSBLUR.reader.flags['opening_feed']) {
 | 
						|
            return;
 | 
						|
        }
 | 
						|
        
 | 
						|
        var $story_titles = NEWSBLUR.reader.$s.$story_titles;
 | 
						|
        var container_offset = $story_titles.position().top;
 | 
						|
        var visible_height = $story_titles.height();
 | 
						|
        var scroll_y = $story_titles.scrollTop();
 | 
						|
        var total_height = this.$el.outerHeight(true) + NEWSBLUR.reader.$s.$feedbar.outerHeight(true);
 | 
						|
        
 | 
						|
        // console.log(["scroll titles", container_offset, visible_height, scroll_y, total_height]);
 | 
						|
        if (visible_height + scroll_y >= total_height) {
 | 
						|
            NEWSBLUR.reader.load_page_of_feed_stories();
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
}); |