timeline.js 2.0 KB

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