Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Endless Scrolling #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions js/hn.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,13 @@ var hn = {

hn.endless_loading = true;

var $temp = $('<div/>');
var MORE_SEL = '.morelink'
, MORE_ROW = '.morespace, .morespace + tr'
, $temp = $('<div/>');


// find the 'More' link and add a loading class
var $more = $('td.title a[href^="/x"]').last().addClass('endless_loading');
var $more = $(MORE_SEL).last().addClass('endless_loading');
var $morerow = $more.parent().parent();

// extract the URL for the next page
Expand All @@ -174,10 +177,17 @@ var hn = {
// load next page
$temp.load(url, function(){
// find the first news title and jump up two levels to get news table body
$temp = $temp.find('td.title:first-child').parent().parent().html();
$temp = ( $temp.find('td.title:first-child').parent().parent().html()
// otherwise find a comhead or morelink and then table containing it,
// and a row containg the table
|| ($temp.find('.comhead, ' + MORE_SEL).closest('table').closest('tr')
// to what that finds, add a morespace from $temp to the collection
.add('.morespace', $temp)
)
);

// add extra options to stories before appending to DOM
$morerow.after($temp);
$morerow.last().after($temp);
$morerow.remove();

hn.endless_loading = false;
Expand Down