PageSourceSearch

https://www.northernexpress.com/static/northern-express/js/public_news/infiniteScroll.js

js northernexpress.com collected 2026-10-02 06:20:58 UTC 3,000 bytes, 115 lines download raw bytes

1function initFeaturedInfiniteScroll(options) {	
2	var win = $(window);
3	var currentPageNumber = options.currentPageNumber;
4	var numPages = options.numPages;
5	var storyListUrlPrefix = options.storyListUrl;
6
7
8	init();
9
10	// Convenience init method
11	function init() {
12		_hideLoadingIcon();
13		hideSidebarStories();
14	}
15
16	// Each time the user scrolls
17	win.data('ajaxready', true).scroll(function(e) {
18	    if ($(window).data('ajaxready') == false) return;
19
20	    if(!isLast(currentPageNumber, numPages)) {
21	    	// End of the document reached?		   
22			if ($(document).height() - win.height() == win.scrollTop()) {
23		        $(window).data('ajaxready', false);
24			    var stories = getStories(currentPageNumber);
25			    if(stories) {
26					currentPageNumber += 1;
27			    }
28			}
29	    } 
30	});
31
32	// Last page already rendered?
33	function isLast(currentPageNumber, numPages) {
34	    return currentPageNumber == numPages;
35	}
36
37	// Get next page of stories & sidebar stories
38	function getStories(currentPageNumber) {
39	    _showLoadingIcon();		
40	    var storyListUrl = storyListUrlPrefix + (currentPageNumber + 1);
41
42	    $.ajax({
43			url: storyListUrl,
44			dataType: 'json',
45			success: function(returned_json) {
46				var insert = insertOnPage(returned_json);
47				if (insert) {
48	    				init();
49				} else {	
50					alert('Oops! Something went wrong. Please try refreshing the page.');
51				}
52				$(window).data('ajaxready', true);
53			}
54	    });
55	    return true;
56	}
57
58	// Insert returned json to template
59	function insertOnPage(returned_json) {
60		var stories_html = returned_json.stories;
61		var sidebar_html = returned_json.sidebar;
62		$('#story-list-container').append(stories_html);
63		$('#sidebar-list-container').append(sidebar_html);
64		return true;
65	}
66
67	function _hideLoadingIcon() {
68	    $('#loading-icon').hide();                    
69	}
70
71	function _showLoadingIcon() {
72	    $('#loading-icon').show();                    
73	}
74
75	// Hide stories whose bottoms aren't below
76	function hideSidebarStories() {
77        var stories = document.getElementsByClassName("contentSideBox");
78        for(var i = 0; i < stories.length; i++)
79        {
80            $(stories.item(i)).show();
81            calcStory(stories.item(i));
82        }
83    }
84
85    // Calculate story diff from load more button
86    function calcStory(story) {
87        if(_hideStory(story)) {
88            $(story).hide();
89        }
90        return true;
91    }
92
93    // Get distance from top for a sidebar story and compare it to the
94    // distance of the load more button
95    function _hideStory(story) {
96
97
98        var storiesOffset = $('#stories-spacer-item').offset().top;
99
100        var sidebarStoryId = $(story).attr('data-sidebarstoryid');
101        var sidebarStorySpacer = $('.sidebarStorySpacer[data-sidebarstoryspacerid="'+sidebarStoryId+'"]');
102
103		if(!sidebarStoryId) {
104			return false;
105		}
106
107        var sidebarStoryOffset = $(sidebarStorySpacer).offset().top;
108
109        var difference = (storiesOffset - sidebarStoryOffset);
110
111        return difference < 0;
112
113    }
114
115}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.