<commit_before>NEWSBLUR.Views.StoryListView = Backbone.View.extend({
    
    el: '.NB-feed-stories',
    
    initialize: function() {
        _.bindAll(this, 'check_feed_view_scrolled_to_bottom', 'scroll');
        this.collection.bind('reset', this.reset_flags, this);
        this.collection.bind('reset', this.render, this);
        this.collection.bind('reset', this.reset_story_positions, this);
        this.collection.bind('add', this.add, this);
        this.collection.bind('add', this.reset_story_positions, this);
        this.collection.bind('no_more_stories', this.show_no_more_stories, this);
        this.collection.bind('change:selected', this.show_only_selected_story, this);
        this.collection.bind('change:selected', this.check_feed_view_scrolled_to_bottom, this);
        this.$el.bind('mousemove', _.bind(this.handle_mousemove_feed_view, this));
        NEWSBLUR.reader.$s.$feed_scroll.scroll(this.scroll);
        this.reset_flags();
    },
    
    reset_flags: function() {
        this.clear();
        this.cache = {
            story_pane_position: null,
            feed_title_floater_feed_id: null,
            feed_view_story_positions: {},
            feed_view_story_positions_keys: []
        };
        this.flags = {
            feed_view_images_loaded: {},
            mousemove_timeout: false
        };
        this.counts = {
            positions_timer: 0
        };
    },
    
    // ==========
    // = Render =
    // ==========
    
    render: function() {
        // console.log(["Rendering story list", NEWSBLUR.assets.preference('story_layout')]);
        if (!_.contains(['split', 'full'], NEWSBLUR.assets.preference('story_layout'))) return;
        
        var collection = this.collection;
        var stories = this.collection.map(function(story) {
            return new NEWSBLUR.Views.StoryDetailView({
                model: story,
                collection: collection
            }).render();
        });
        if (NEWSBLUR.assets.preference('feed_view_single_story')) {
            this.show_explainer_single_story_mode();
        } else {
            this.$el.html(_.pluck(stories, 'el'));
        }
        _.invoke(stories, 'watch_images_for_story_height');
        this.show_correct_feed_in_feed_title_floater();
        this.stories = stories;
        _.defer(this.check_feed_view_scrolled_to_bottom);
        this.end_loading();
    },
    
    add: function(options) {
        if (!_.contains(['split', 'full'], NEWSBLUR.assets.preference('story_layout'))) return;
        
        if (options.added) {
            var collection = this.collection;
            var added = this.collection.models.slice(-1 * options.added);
            var stories = _.compact(_.map(added, function(story) {
                return new NEWSBLUR.Views.StoryDetailView({
                    model: story,
                    collection: collection
                }).render();
            }));
            if (!NEWSBLUR.assets.preference('feed_view_single_story')) {
                this.$el.append(_.pluck(stories, 'el'));
            }
            _.invoke(stories, 'watch_images_for_story_height');
            
            this.stories = this.stories.concat(stories);
            _.defer(this.check_feed_view_scrolled_to_bottom);
        } else {
            this.show_no_more_stories();
        }

        this.end_loading();
    },
    
    clear: function() {
        // console.log(["Clearing story list"]);
        _.invoke(this.stories, 'destroy');
        this.$el.empty();
    },
    
    show_explainer_single_story_mode: function() {
        var $empty = $.make("div", { className: "NB-story-list-empty" }, [
            'Select a story to read'
        ]);

        this.$el.append($empty);
    },
    
    // ===========
    // = Actions =
    // ===========
    
    scroll_to_selected_story: function(story, options) {
        options = options || {};
        if (!story) story = NEWSBLUR.reader.active_story;
        if (!story || !story.story_view) return;
        var $story = story.story_view.$el;

        if (NEWSBLUR.assets.preference('feed_view_single_story')) {
            options.immediate = true;
        }
        if (!NEWSBLUR.assets.preference('animations')) options.immediate = true;
        if (options.scroll_to_comments) {
            $story = $('.NB-feed-story-comments', $story);
        }
        
        if (options.only_if_hidden && NEWSBLUR.reader.$s.$feed_scroll.isScrollVisible($story, true)) {
            return;
        }
        
        clearTimeout(NEWSBLUR.reader.locks.scrolling);
        NEWSBLUR.reader.flags.scrolling_by_selecting_story_title = true;
        NEWSBLUR.reader.$s.$feed_scroll._scrollable().stop();
        var scroll_to = options.scroll_to_top ? 0 : $story;
        NEWSBLUR.reader.$s.$feed_scroll.scrollTo(scroll_to, { 
            duration: options.immediate ? 0 : 340,
            axis: 'y', 
            easing: 'easeInOutQuint', 
            offset: options.scroll_offset || 0,
            queue: false, 
            onAfter: function() {
                NEWSBLUR.reader.locks.scrolling = setTimeout(function() {
                    NEWSBLUR.reader.flags.scrolling_by_selecting_story_title = false;
                }, 100);
            }
        });
    },
    
    show_only_selected_story: function() {
        if (!NEWSBLUR.assets.preference('feed_view_single_story')) return;
        if (!_.contains(['split', 'full'], NEWSBLUR.assets.preference('story_layout'))) return;
        
        this.collection.any(_.bind(function(story) {
            if (story && story.get('selected') && story.story_view) {
                this.$el.html(story.story_view.el);
                story.story_view.setElement(story.story_view.el);
                return true;
            }
        }, this));
        
        this.show_no_more_stories();
    },
    
    show_no_more_stories: function() {
        if (!NEWSBLUR.assets.flags['no_more_stories']) return;
        
        var pane_height = NEWSBLUR.reader.$s.$story_pane.height();
        var indicator_position = NEWSBLUR.assets.preference('lock_mouse_indicator');
        var endbar_height = 20;
        if (indicator_position) {
            var last_visible_story = _.last(NEWSBLUR.assets.stories.visible());
            var last_story_height = last_visible_story && last_visible_story.story_view.$el.height() || 100;
            var last_story_offset = _.last(this.cache.feed_view_story_positions_keys);
            endbar_height = pane_height - indicator_position - last_story_height;
            if (endbar_height <= 20) endbar_height = 20;

            var empty_space = pane_height - last_story_offset - last_story_height - endbar_height;
            if (empty_space > 0) endbar_height += empty_space + 1;
        }
        <commit_msg>Fixing empty story explainer (for single story mode).<commit_after>NEWSBLUR.Views.StoryListView = Backbone.View.extend({
    
    el: '.NB-feed-stories',
    
    initialize: function() {
        _.bindAll(this, 'check_feed_view_scrolled_to_bottom', 'scroll');
        this.collection.bind('reset', this.reset_flags, this);
        this.collection.bind('reset', this.render, this);
        this.collection.bind('reset', this.reset_story_positions, this);
        this.collection.bind('add', this.add, this);
        this.collection.bind('add', this.reset_story_positions, this);
        this.collection.bind('no_more_stories', this.show_no_more_stories, this);
        this.collection.bind('change:selected', this.show_only_selected_story, this);
        this.collection.bind('change:selected', this.check_feed_view_scrolled_to_bottom, this);
        this.$el.bind('mousemove', _.bind(this.handle_mousemove_feed_view, this));
        NEWSBLUR.reader.$s.$feed_scroll.scroll(this.scroll);
        this.reset_flags();
    },
    
    reset_flags: function() {
        this.clear();
        this.cache = {
            story_pane_position: null,
            feed_title_floater_feed_id: null,
            feed_view_story_positions: {},
            feed_view_story_positions_keys: []
        };
        this.flags = {
            feed_view_images_loaded: {},
            mousemove_timeout: false
        };
        this.counts = {
            positions_timer: 0
        };
    },
    
    // ==========
    // = Render =
    // ==========
    
    render: function() {
        // console.log(["Rendering story list", NEWSBLUR.assets.preference('story_layout')]);
        if (!_.contains(['split', 'full'], NEWSBLUR.assets.preference('story_layout'))) return;
        
        var collection = this.collection;
        var stories = this.collection.map(function(story) {
            return new NEWSBLUR.Views.StoryDetailView({
                model: story,
                collection: collection
            }).render();
        });
        if (NEWSBLUR.assets.preference('feed_view_single_story')) {
            this.show_explainer_single_story_mode();
        } else {
            this.$el.html(_.pluck(stories, 'el'));
        }
        _.invoke(stories, 'watch_images_for_story_height');
        this.show_correct_feed_in_feed_title_floater();
        this.stories = stories;
        _.defer(this.check_feed_view_scrolled_to_bottom);
        this.end_loading();
    },
    
    add: function(options) {
        if (!_.contains(['split', 'full'], NEWSBLUR.assets.preference('story_layout'))) return;
        
        if (options.added) {
            var collection = this.collection;
            var added = this.collection.models.slice(-1 * options.added);
            var stories = _.compact(_.map(added, function(story) {
                return new NEWSBLUR.Views.StoryDetailView({
                    model: story,
                    collection: collection
                }).render();
            }));
            if (!NEWSBLUR.assets.preference('feed_view_single_story')) {
                this.$el.append(_.pluck(stories, 'el'));
            }
            _.invoke(stories, 'watch_images_for_story_height');
            
            this.stories = this.stories.concat(stories);
            _.defer(this.check_feed_view_scrolled_to_bottom);
        } else {
            this.show_no_more_stories();
        }

        this.end_loading();
    },
    
    clear: function() {
        // console.log(["Clearing story list"]);
        _.invoke(this.stories, 'destroy');
        this.$el.empty();
    },
    
    show_explainer_single_story_mode: function() {
        if (NEWSBLUR.reader.active_story) return;
        
        var $empty = $.make("div", { className: "NB-story-list-empty" }, [
            'Select a story to read'
        ]);

        var $container = this.$el.closest(".NB-feed-stories-container");
        $(".NB-story-list-empty", $container).remove();
        $container.append($empty);
    },
    
    // ===========
    // = Actions =
    // ===========
    
    scroll_to_selected_story: function(story, options) {
        options = options || {};
        if (!story) story = NEWSBLUR.reader.active_story;
        if (!story || !story.story_view) return;
        var $story = story.story_view.$el;

        if (NEWSBLUR.assets.preference('feed_view_single_story')) {
            options.immediate = true;
        }
        if (!NEWSBLUR.assets.preference('animations')) options.immediate = true;
        if (options.scroll_to_comments) {
            $story = $('.NB-feed-story-comments', $story);
        }
        
        if (options.only_if_hidden && NEWSBLUR.reader.$s.$feed_scroll.isScrollVisible($story, true)) {
            return;
        }
        
        clearTimeout(NEWSBLUR.reader.locks.scrolling);
        NEWSBLUR.reader.flags.scrolling_by_selecting_story_title = true;
        NEWSBLUR.reader.$s.$feed_scroll._scrollable().stop();
        var scroll_to = options.scroll_to_top ? 0 : $story;
        NEWSBLUR.reader.$s.$feed_scroll.scrollTo(scroll_to, { 
            duration: options.immediate ? 0 : 340,
            axis: 'y', 
            easing: 'easeInOutQuint', 
            offset: options.scroll_offset || 0,
            queue: false, 
            onAfter: function() {
                NEWSBLUR.reader.locks.scrolling = setTimeout(function() {
                    NEWSBLUR.reader.flags.scrolling_by_selecting_story_title = false;
                }, 100);
            }
        });
    },
    
    show_only_selected_story: function() {
        var $container = this.$el.closest(".NB-feed-stories-container");
        $(".NB-story-list-empty", $container).remove();
        
        if (!NEWSBLUR.assets.preference('feed_view_single_story')) return;
        if (!_.contains(['split', 'full'], NEWSBLUR.assets.preference('story_layout'))) return;
        
        this.collection.any(_.bind(function(story) {
            if (story && story.get('selected') && story.story_view) {
                this.$el.html(story.story_view.el);
                story.story_view.setElement(story.story_view.el);
                return true;
            }
        }, this));
        
        this.show_no_more_stories();
    },
    
    show_no_more_stories: function() {
        if (!NEWSBLUR.assets.flags['no_more_stories']) return;
        
        var pane_height = NEWSBLUR.reader.$s.$story_pane.height();
        var indicator_position = NEWSBLUR.assets.preference('lock_mouse_indicator');
        var endbar_height = 20;
        if (indicator_position) {
            var last_visible_story = _.last(NEWSBLUR.assets.stories.visible());
            var last_story_height = last_visible_story && last_visible_story.story_view.$el.height() || 100;
            var last_story_offset = _.last(this.cache.feed_view_story_positions_keys);
            endbar_height = pane_height - indicator_position - last_story_height;
            if (endbar_height <= 20) endbar_height = 20;

            var empty_space = pane_height - last_story_offset - last_story_height - endbar_height;
            if (empty_space > 0) endbar_height += empty_space + 1;
        }
        
{'fraction_non_alphanumeric': 0.13383297644539616, 'fraction_numerical': 0.003140613847251963, 'mean_word_length': 2.1648972215947593, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6259919', 'n_tokens_mistral': 4254, 'n_tokens_neox': 4099, 'n_words': 598}