timeline.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. $(document).ready(function() {
  2. $('.pagination').hide();
  3. $('.container.timeline-container').removeClass('d-none');
  4. let elem = document.querySelector('.timeline-feed');
  5. let type = elem.getAttribute('data-timeline');
  6. $('.timeline-sidenav .nav-link[data-type="'+type+'"]').addClass('active');
  7. pixelfed.readmore();
  8. pixelfed.fetchLikes();
  9. $('video').on('play', function() {
  10. activated = this;
  11. $('video').each(function() {
  12. if(this != activated) this.pause();
  13. });
  14. });
  15. let infScroll = new InfiniteScroll( elem, {
  16. path: '.pagination__next',
  17. append: '.timeline-feed',
  18. status: '.page-load-status',
  19. history: false,
  20. });
  21. infScroll.on( 'append', function( response, path, items ) {
  22. pixelfed.hydrateLikes();
  23. $('.status-card > .card-footer').each(function() {
  24. var el = $(this);
  25. if(!el.hasClass('d-none') && !el.find('input[name="comment"]').val()) {
  26. $(this).addClass('d-none');
  27. }
  28. });
  29. $('video').on('play', function() {
  30. activated = this;
  31. $('video').each(function() {
  32. if(this != activated) this.pause();
  33. });
  34. });
  35. });
  36. });
  37. $(document).on("DOMContentLoaded", function() {
  38. var active = false;
  39. var lazyLoad = function() {
  40. pixelfed.readmore();
  41. if (active === false) {
  42. active = true;
  43. var lazyImages = [].slice.call(document.querySelectorAll("img.lazy"));
  44. lazyImages.forEach(function(lazyImage) {
  45. if ((lazyImage.getBoundingClientRect().top <= window.innerHeight && lazyImage.getBoundingClientRect().bottom >= 0) && getComputedStyle(lazyImage).display !== "none") {
  46. lazyImage.src = lazyImage.dataset.src;
  47. lazyImage.srcset = lazyImage.dataset.srcset;
  48. lazyImage.classList.remove("lazy");
  49. lazyImages = lazyImages.filter(function(image) {
  50. return image !== lazyImage;
  51. });
  52. }
  53. });
  54. active = false;
  55. };
  56. }
  57. document.addEventListener("scroll", lazyLoad);
  58. window.addEventListener("resize", lazyLoad);
  59. window.addEventListener("orientationchange", lazyLoad);
  60. });