Comments (9)
I managed to get this working by using the callback. Basically, it grabs the new rows and new pagination from the last 'jscroll-added' div, replaces the old pagination, and appends the new rows to the table's tbody. Overly commented code below:
callback: function () {
var newRows = $('.jscroll-added:last table tbody').html(), // Get new rows
newPage = $('.jscroll-added:last .pagination').html(); // Get new pagination
$('.jscroll-added:last').remove(); // Remove the newly added 'jscroll-added' div
$('.pagination').html(newPage); // Replace existing pagination with newPage
$('table > tbody').append(newRows); // Append the new rows to the table's tbody
}
from jscroll.
@darkred - For nextSelector
you can use the following string instead of creating a jQuery object:
nextSelector: 'a:has(img[src="https://piratebay.org/img/next.gif"])'
Let me take a look into the other issues and I will get back to you.
from jscroll.
@darkred - Unfortunately, jScroll isn't currently designed to work within tables. It will add <div>
elements within your table elements, creating invalid HTML. I would say your best option at this time is to call jScroll on #main-content
and load each subsequent <table>
from the jScroll payload underneath one another.
I do see the utility in having jScroll work within tables, however; so I will mark this as an enhancement.
from jscroll.
Thanks a lot for your replies.
For
nextSelector
you can use the following string instead of creating a jQuery object:nextSelector: 'a:has(img[src="https://piratebay.org/img/next.gif"])'
Unfortunately the relational pseudo-class :has()
(a Level 4 selector) is still not supported by FIrefox 39 (nor in Chrome 43).
Browser CSS-Selector-Test
Your other suggestion (about calling jScroll on #main-content
and using table
as contentSelector
) is indeed the best current option. Thanks!
from jscroll.
:has()
is not supported natively by all browsers, but it is a jQuery selector and is normalized for unsupported browsers.
See: http://api.jquery.com/has-selector/
from jscroll.
Sorry for the misunderstanding, but I thought that it wasn't a jQuery selector but a CSS one,
because you wrote it without a $
in front
i.e. not nextSelector: $('a:has(img[src="https://piratebay.org/img/next.gif"])')
But, unfortunately it doesn't work either way: it only appends page 2.
Please try it yourself:
// ==UserScript==
// @name thepiratebay jScroll
// @include https://thepiratebay.*/browse/*
// @version 1
// @grant none
// @require http://code.jquery.com/jquery-2.1.4.min.js
// @require https://cdn.rawgit.com/pklauzinski/jscroll/master/jquery.jscroll.min.js
// ==/UserScript==
$('#main-content').jscroll({
nextSelector: 'a:has(img[src="https://piratebay.org/img/next.gif"])',
contentSelector: 'table'
});
The problem:
in the end of the table (i.e. appended page 2) the last row (which contains the "Next" link) is missing
(though it's contained inside the table
element)
therefore jScroll cannot continue with page 3.
from jscroll.
is this going to be solved anytime soon?
from jscroll.
That's it! Thank you, @kmkroski
from jscroll.
I tried kmkroski's solution, but found two problems.
First, the next button only worked once - probably has something to do with copying html instead of dom objects with attached events. Solution: Replace pagination element.
Second, on the last page, there would be an additional table which was not merged. Solution: Use a selector for the table and use :first and :last.
Working solution, assuming table class="my-list":
callback: function () {
// Append new results to existing table
$('.my-list:last > tbody tr').detach().appendTo($('.my-list:first > tbody'));
// Replace existing pagination with new while keeping attached events
$('.pagination:first').replaceWith($('.pagination:last'));
// Remove the newly added 'jscroll-added' div, as well as the remaining unwrapped table on the last page
$('.jscroll-added,.my-list:nth(1)').remove();
}
from jscroll.
Related Issues (20)
- click trigger isn´t disabled
- Issue with JScroll
- Callback to tell if there are more pages HOT 1
- Button Trigger Example HOT 1
- Can't have multiple jscrolls on page HOT 1
- contentSelector load all DOM
- change url - SEO
- Parceljs
- _load not triggered when page is zoomed in or out at certain levels HOT 3
- jscroll does not load the new content all the time HOT 4
- is there a vinilla js alternative? HOT 1
- Add Support for Error Callback HOT 1
- Support sending URL params. HOT 2
- Not working on mobile HOT 2
- documentation - detecting and destroying jscroll
- jscroll is not a function HOT 1
- loadingHtml not workig correctly with pjax
- CSS display problens
- HOw to impememnt a link or button to load manually the content
- page formatting messing up nextSelector href HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jscroll.