The version of vichan running on lainchan.org
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

93 lignes
2.0KB

  1. /*
  2. * infinite-scroll.js
  3. * https://github.com/vichan-devel/vichan/blob/master/js/infinite-scroll.js
  4. *
  5. * Released under the MIT license
  6. * Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
  7. *
  8. * Usage:
  9. * $config['additional_javascript'][] = 'js/jquery.min.js';
  10. * $config['additional_javascript'][] = 'js/infinite-scroll.js';
  11. *
  12. */
  13. $(function() {
  14. if (active_page == 'index') {
  15. var loading = false;
  16. var activate = function() {
  17. if (document.location.hash != '#all') return false;
  18. $(window).on("scroll", function() {
  19. scrolltest();
  20. });
  21. scrolltest();
  22. return true;
  23. };
  24. var scrolltest = function() {
  25. if ($(window).scrollTop() + $(window).height() + 1000 > $(document).height() && !loading) {
  26. load_next_page();
  27. }
  28. };
  29. var load_next_page = function() {
  30. if (loading) return;
  31. loading = true;
  32. var this_page = $(".pages a.selected:last");
  33. var next_page = this_page.next();
  34. var href = next_page.prop("href");
  35. if (!href) return;
  36. var boardheader = $('<h2>'+_('Page')+' '+next_page.html()+'</h2>');
  37. var loading_ind = $('<h2>'+_('Loading...')+'</h2>').insertBefore('#post-moderation-fields');
  38. $.get(href, function(data) {
  39. var doc = $(data);
  40. loading_ind.remove();
  41. boardheader.insertBefore('#post-moderation-fields');
  42. var i = 0;
  43. doc.find('div[id*="thread_"]').each(function() {
  44. var checkout = $(this).attr('id').replace('thread_', '');
  45. var $this = this;
  46. if ($('div#thread_' + checkout).length == 0) {
  47. // Delay DOM insertion to lessen the lag.
  48. setTimeout(function() {
  49. $($this).insertBefore('#post-moderation-fields');
  50. $(document).trigger('new_post', $this);
  51. $($this).hide().slideDown();
  52. }, 500*i);
  53. i++;
  54. }
  55. });
  56. setTimeout(function() {
  57. loading = false;
  58. scrolltest();
  59. }, 500*(i+1));
  60. next_page.addClass('selected');
  61. });
  62. };
  63. var button = $("<a href='#all'>"+_("All")+" </a>").prependTo(".pages");
  64. $(window).on("hashchange", function() {
  65. return !activate();
  66. });
  67. activate();
  68. }
  69. });