From 444a4b9306f861e18fa8ec4df2679eb90156390f Mon Sep 17 00:00:00 2001 From: j Date: Tue, 25 Mar 2025 22:32:01 +0000 Subject: [PATCH] use compress move js --- camp/static/js/app.js | 37 ++++++++++++ camp/static/js/slideshow.js | 65 +++++++++++++++++++++ content/templates/base.html | 113 +++--------------------------------- 3 files changed, 110 insertions(+), 105 deletions(-) create mode 100644 camp/static/js/slideshow.js diff --git a/camp/static/js/app.js b/camp/static/js/app.js index 670111a..67bd2f8 100644 --- a/camp/static/js/app.js +++ b/camp/static/js/app.js @@ -15,3 +15,40 @@ function getCookie(name) { } return cookieValue; } + +var restrictedElements = []; +function removeBehaviorsRestrictions(event) { +if (restrictedElements.length > 0) { + var rElements = restrictedElements; + restrictedElements = []; + rElements.forEach(function(video) { + if (video.autoplay && video.paused) { + video.load() + video.play() + if (video.paused) { + restrictedElements.push(video) + } + } else if (video.readyState < 4) { + video.load() + } + }); +} +} + +if (document.querySelector('video')) { + let video = document.createElement('video'); + video.muted = true + video.play(); + if (video.paused) { + restrictedElements = document.querySelectorAll('video.gif') + window.addEventListener('keydown', removeBehaviorsRestrictions); + window.addEventListener('mousedown', removeBehaviorsRestrictions); + window.addEventListener('touchstart', removeBehaviorsRestrictions); + restrictedElements.forEach(video => { + if (!video.poster) { + video.poster = video.src.replace('.mp4', '.jpg') + video.muted = true + } + }) + } +} diff --git a/camp/static/js/slideshow.js b/camp/static/js/slideshow.js new file mode 100644 index 0000000..4ccfedc --- /dev/null +++ b/camp/static/js/slideshow.js @@ -0,0 +1,65 @@ +var startSlide = 0; +if (document.querySelectorAll('.select-image').length && document.location.hash.length) { + startSlide = parseInt(document.location.hash.slice(1)) - 1 +} +function loadSlideshow() { + $('a.original-link').bind('touchstart MSPointerDown pointerdown', function(event) { + event.stopPropagation() + }); + $('a.original-link').on({ + mousedown: function(event) { + event.stopPropagation() + }, + }) + slider = $('.slider1').show().bxSlider({ + startSlide: startSlide, + preloadImages: 'all', + adaptiveHeight : true, + pager : false, +}); + +var images = $('.slider1 img'), count = images.length; +images.on({load: function(event) { + setTimeout(function() { + slider.resize() + slider.redrawSlider() + }, 100) +}}) + +document.querySelectorAll('.select-image').forEach(function(a) { + a.onclick = function(event) { + event.preventDefault(); + slider.goToSlide(parseInt(this.dataset.id) - 1) + document.location.hash = '#' + this.dataset.id; + }; +}); + +/* +if (document.querySelectorAll('.select-image').length && document.location.hash.length) { + var slide = parseInt(document.location.hash.slice(1)) + if (slide) { + slider.goToSlide(slide - 1) + slider.resize() + slider.redrawSlider() + setTimeout(function() { + slider.resize() + slider.redrawSlider() + }, 2000) + } +} +*/ + +$(document).keydown(function(e){ + if (e.keyCode == 39) // Right arrow + { + slider && slider.goToNextSlide(); + return false; + } + else if (e.keyCode == 37) // left arrow + { + slider && slider.goToPrevSlide(); + return false; + } + }); +} +$(document).ready(loadSlideshow); diff --git a/content/templates/base.html b/content/templates/base.html index f4fca86..0408f53 100644 --- a/content/templates/base.html +++ b/content/templates/base.html @@ -1,4 +1,4 @@ -{% load available_content static %} +{% load available_content static compress sass_tags %} @@ -11,8 +11,11 @@ + {% compress css file site %} + + {% endcompress %} @@ -45,115 +48,15 @@ {% endblock %} - {% load static %} + {} + {% compress js file base %} - + + {% endcompress %} {% block end %} {% endblock %}