Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
For some reason I cannot get the plugin to work (using latest dev version of views 6.x-3.x).
I keep getting this error:
content.offset() is undefined
Which happens in jquery.autopager module. I have tried listing both nodes and as fields, but keep getting the same error messsage.
This is the bit that goes wrong:
function loadOnScroll() {
if (content.offset().top + content.height() < $(document).scrollTop() + $(window).height()) {
$.autopager.load();
}
}
Comments
Comment #1
Remon CreditAttribution: Remon commentedPlease use Views 3 alpha-3 and latest Views Infinite Scroll dev snapshot and tell me if you still face this problem.
Comment #2
Remon CreditAttribution: Remon commentedComment #3
kenneth@fiil.eu CreditAttribution: kenneth@fiil.eu commentedHey,
I'm using Views 6.x-3.0-alpha3 and Views Infinite Scroll 6.x-1.x-dev and still get this error:
jquery.autopager-1.0.0.js:136 - Uncaught TypeError: Cannot read property 'top' of undefined
Any idea why?
Comment #4
Remon CreditAttribution: Remon commentedos? browser? browser-version? please.
Comment #5
kenneth@fiil.eu CreditAttribution: kenneth@fiil.eu commentedOS: Mac OS X Leopard - Snow Leopard
Browers: Chrome 12.0.742.112, Safari 5.0.5 and Firefox 3.6.13
Comment #6
kenneth@fiil.eu CreditAttribution: kenneth@fiil.eu commentedIf i do a content.toSource() before the if i get
({length:0, prevObject:{length:0, prevObject:{0:({}), length:1}}})
If i do a JSON.stringify(content, null, 4) before the if i get
Hope it helps!
Comment #7
goivvy CreditAttribution: goivvy commentedyou probably rewrite default style output, ie views-view-table--[you view's name].tpl.php for table format.
going through views_plugin_pager_infinite_scroll.inc reveals must have tags for every style output:
switch ($this->view->plugin_name) {
case 'default':
$content_selector = 'div.view-content';
$items_selector = '.views-row';
break;
case 'grid':
$content_selector = 'div.view-content tbody';
$items_selector = 'tr';
break;
case 'list':
$content_selector = 'div.view-content .item-list > *';
$items_selector = '.views-row';
break;
case 'table':
$content_selector = 'div.view-content tbody';
$items_selector = 'tr';
break;
}
long story short: jquery cant find your content, delete *.tpl.php files in your theme template directory and let me know if everything is back to normal
Comment #8
Will Igetit CreditAttribution: Will Igetit commentedsame issue on chrome
Comment #9
Carlitus CreditAttribution: Carlitus commentedi've have the same issue in the 7 version using with views_fluid_grid.
Then i add a new case for the switch:
case 'views_fluidgrid':
$content_selector = 'div.views_fluidgrid_listado_general_page';
$items_selector = '.views-fluidgrid-item';
break;
But i doesn't work, a new javascript error appears:
last.offset() is null
content.offset() is null
http://nedukame.local.pc/sites/all/libraries/autopager/jquery.autopager-...
Line 134
It seems that views_fluid_grid doesn't ouput the last class to the last item...
Comment #10
Carlitus CreditAttribution: Carlitus commentedUpppss, i've put the css selector wrong.
This works but the masonry isn't applied
Comment #11
Carlitus CreditAttribution: Carlitus commentedA not elegant method.
Put after the 47 line of views_infinite_scroll.js
Before
After
I'm sure this is dirty code, i think it must be a Drupal behaviours job and only when the masonry is active, maybe someone can improve it?
Comment #12
funature CreditAttribution: funature commented@Carlitus, i have the overlap issue with your code, do you have any idea what cause that and if there is a solution. and it is suggested to use the appended method to work with infinite scroll together, http://masonry.desandro.com/demos/infinite-scroll.html. is there any solution to implement the appended method?
Comment #13
Carlitus CreditAttribution: Carlitus commentedIt's curious because i hacked my views infinite scroll to work with jquery infinite scroll using the code of your link.
What i did:
I've put the jquery.infinitescroll.min.js (https://github.com/paulirish/infinitescroll) in the js module directory
in views_infinite_scroll_theme.inc i added in the line 100:
In views_infinite_scroll.js:
Comment #14
funature CreditAttribution: funature commented@Carlitus, thank you very much! i think it works. but this module use the autopager plugin from http://lagoscript.org/jquery/autopager, and for me the infinitescroll plugin from paulirish is better, it is also recommend by the masonry plugin. i'm not sure if it is appropriate to use it instead. i mean is it possible to keep using autopager plugin unless the maintainer decide to switch to infinitescroll plugin?
Comment #15
Carlitus CreditAttribution: Carlitus commented@euroba, yes, you need to remove the line where the module loads the autopager plugin.
Comment #16
funature CreditAttribution: funature commented@Carlitus, i still have one problem here, everything works great with your code except the trigger. now the trigger will be executed immediately if i scroll the mouse, it should be triggered at the bottom of the page. maybe you know what the problem is? thanks
Comment #17
Carlitus CreditAttribution: Carlitus commented@euroba, look out the bufferPx variable. this variable is used to load the new items x pixels before the bottom. I like more with 200px but you maybe want to be at 0 (or just remove it)
Comment #18
funature CreditAttribution: funature commentedi don't think that caused the problem, i changed bufferPx variable to 0, but the autopager still starts once I scroll. I'm still looking for the real reason, i appreciate your help, if you find something, please tell me, thanks
Comment #19
funature CreditAttribution: funature commentedmaybe there is something wrong with the trigger, because i'm using the the infinitescroll plugin not the autopager? handle.autopager('load'); is this piece of code still suitable?
Comment #20
Carlitus CreditAttribution: Carlitus commentedI didn't remove this and it worked but no always (in the first page with apache Solr didn't work in my project). May be your problem is another. Look out at this:
https://github.com/paulirish/infinite-scroll/issues/145
Comment #21
anairamzapHi all, I'm not using the masonry module and still getting this js error when I try to use the autoscroll in a view.
The line in which the error is spotted is
if(last.offset().top + last.height() < $(document).scrollTop() + $(window).height()) {
of the jquery.autopager-1.0.0.js
The autoscroll is not working as expected, I get the "normal" pager even if I select "Infinite scroll" under Pager settings in the view.
I'm using "HTML list" format.
I thought that maybe some template was rewriting the pager, and therefore the autoscroll is not loading.
But when I comment the $pager in my views-view.tpl.php I get no pager at all and the autoscroll is not displaying either.
Is there something I am missing?
please let me know if you need more details.
Thanks!
m
Comment #22
suraj2012 CreditAttribution: suraj2012 commentedGetting an error after setting Infinite Scroll pager in a view..using drupal 7..The error is
"Uncaught TypeError: Cannot read property 'top' of null"
in line 52 of views_infinite_scroll.js, using views_infinite_scroll version 7.x.1.1.
using console.log i printed the value of variable last...its empty..
Comment #23
maharag CreditAttribution: maharag commentedgreat solution thank you Carlitus,
evereything works except loading gif is not in place...
I found that loading img is showing up in the top left corner of the screen, its loading very quickly and I can't find any css for the loading gif.
How can I place it at the bottom of the page?
Comment #24
SpikeX CreditAttribution: SpikeX commentedmaharag: Please refrain from editing the title of an issue unless it needs to be updated to better reflect the overall topic being discussed. Thanks! :)
I'm getting this issue, too, after installing this module on the latest Views 3 stable build.
Comment #25
peter.milan CreditAttribution: peter.milan commentedI was getting the same issue also, but after updating of jQuery, it seems to work with jQuery v. 1.8.
Comment #26
mishradileep CreditAttribution: mishradileep commentedI was facing same issue but I get it resolved.
If you are theaming you view output tpl you need to set selector according to your html structure.
got to views_plugin_pager_infinite_scroll.inc and set selector as per your HTML under
I am using TABLE format and I replaced below code
with
If you still face problem please check views_infinite_scroll.js file and work around items_selector. It depends on your HTML structure butt for me it works when I removed > from selector.
Comment #27
grisendo CreditAttribution: grisendo commentedPatch attached
Comment #28
grisendo CreditAttribution: grisendo commentedBad patch! Attaching new one
Comment #29
jnicola CreditAttribution: jnicola commentedIssue exists for me. Trying to make sense of solutions in here...
Updating to critical. This simply doesn't work right now when this bug is encountered.
Comment #30
jnicola CreditAttribution: jnicola commentedAlso I checked out the second patch from grisendo... not sure that has any impact upon the issue what-so-ever
Comment #31
grisendo CreditAttribution: grisendo commentedWith that patch I can avoid errors. Then, with custom JS and custom theming in my theme, I can make it work.
Comment #32
jnicola CreditAttribution: jnicola commentedCould you elaborate upon the customing themeing and custom JS? Perhaps I can abstract the cause of the problem, how to reproduce the problem, and then a patchable solution.
Comment #33
krecu CreditAttribution: krecu commentedSome develop used no "Wrapper class" and use "List class"
Comment #34
ordermind CreditAttribution: ordermind commentedThe reason for this error is that the css selector in the theme variable "content_selector" is not always correct, which leads to the jquery plugin not finding the element it's looking for. This variable is defined in the "render" method in views_plugin_pager_infinite_scroll.inc. In my case I was using Views Bulk Operations which alters the markup in a way that this module can't handle. What I did to create a workaround for this was to create a custom module to alter that variable before it's passed to the theme function:
Comment #35
jnicola CreditAttribution: jnicola commentedYour post reminded me to come back here :)
I was able to figure out my issue. It was that the view was broken up into the view content and view pager in panels.
All of these are custom use cases where the view starts to break down. I'm not sure this can be all account for, but perhaps patches for particular situations can be contributed. In my case, I added a conditional case for when ctools was used, and adjusted the selectors used. I'll try and come up with a patch and submit it back when time allows, although the patch will be use case specific, not really a safe larger contribution to the module itself.
Comment #36
Honza Pobořil CreditAttribution: Honza Pobořil as a volunteer commented