theme: optimize page load for images

This commit is contained in:
Sören Weber 2022-11-06 16:26:11 +01:00
parent 54df05b91d
commit 08fb5c4b22
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
6 changed files with 58 additions and 77 deletions
static/js

View file

@ -450,61 +450,6 @@ function initMenuScrollbar(){
adjustContentWidth();
}
function initLightbox(){
// wrap image inside a lightbox (to get a full size view in a popup)
var images = $("main#body-inner img").not(".inline");
images.wrap(function(){
var image =$(this);
var o = getUrlParameter(image[0].src);
var f = o['featherlight'];
// IF featherlight is false, do not use feather light
if (f != 'false') {
if (!image.parent("a").length) {
var html = $( "<a>" ).attr("href", image[0].src).attr("data-featherlight", "image").get(0).outerHTML;
return html;
}
}
});
$('a[rel="lightbox"]').featherlight({
root: 'div#body'
});
}
function initImageStyles(){
// change image styles, depending on parameters set to the image
var images = $("main#body-inner img").not(".inline");
images.each(function(index){
var image = $(this)
var o = getUrlParameter(image[0].src);
if (typeof o !== "undefined") {
var h = o["height"];
var w = o["width"];
var c = o["classes"];
image.css("width", function() {
if (typeof w !== "undefined") {
return w;
} else {
return "auto";
}
});
image.css("height", function() {
if (typeof h !== "undefined") {
return h;
} else {
return "auto";
}
});
if (typeof c !== "undefined") {
var classes = c.split(',');
for (i = 0; i < classes.length; i++) {
image.addClass(classes[i]);
}
}
}
});
}
function sidebarEscapeHandler( event ){
if( event.key == "Escape" ){
var b = document.querySelector( 'body' );
@ -813,22 +758,6 @@ function initSearch() {
$('#body-inner a:not(:has(img)):not(.btn):not(a[rel="footnote"])').addClass('highlight');
}
// Get Parameters from some url
function getUrlParameter(sPageURL) {
var url = sPageURL.split('?');
var obj = {};
if (url.length == 2) {
var sURLVariables = url[1].split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
obj[sParameterName[0]] = sParameterName[1];
}
}
return obj;
};
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
(function($, sr) {
@ -865,8 +794,6 @@ jQuery(function() {
initMenuScrollbar();
scrollToActiveMenu();
scrollToFragment();
initLightbox();
initImageStyles();
initToc();
initAnchorClipboard();
initCodeClipboard();