From a39f66c16758f0e775098751f8eda22347725e37 Mon Sep 17 00:00:00 2001 From: Tobias Fischer Date: Sat, 2 Nov 2019 20:32:55 +0100 Subject: [PATCH] added support for image and pdf preview in 'Files' module // fixes #72 --- assets/javascripts/lightbox.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/assets/javascripts/lightbox.js b/assets/javascripts/lightbox.js index ee5bcb0..61694e4 100644 --- a/assets/javascripts/lightbox.js +++ b/assets/javascripts/lightbox.js @@ -33,6 +33,21 @@ $(document).ready(function() { }); + // #72 support for Files module + $("table.list.files td.filename a").each(function(i, obj) { + var href = $(this).attr('href'); + // Also support PDF preview in lightbox + var isPdf = href.match(/\.pdf$/i); + // only apply thumbnail class to image and pdf links + if(href.match(extensionRegexAll)) { + $(this) + .attr('href', href.replace(/\/attachments\/(\d+)/g,'/attachments/download/$1')) + .addClass(isPdf ? 'lightbox pdf' : 'lightbox') + .attr('data-fancybox-type', isPdf ? 'iframe' : 'image'); + } + }); + + // DMSF support var dmsf_link_selector = "a[data-downloadurl][href^='/dmsf/files/'][href$='/view']"; @@ -119,6 +134,7 @@ $(document).ready(function() { .add("div.wiki a.thumbnail") .add(".controller-dmsf #browser a.lightbox") .add(".avatar a") + .add("table.list.files td.filename a.lightbox") .fancybox({ prevEffect : 'none', nextEffect : 'none', @@ -128,6 +144,7 @@ $(document).ready(function() { // Add Fancybox to PDF links $("div.attachments a.pdf") + .add("table.list.files td.filename a.lightbox.pdf") .add( $("div.journal ul.details a:not(.icon-download)").filter(function(index,elem) { return $(elem).attr('href').match(/\.pdf$/i) }) ) .add( $("div.journal div.thumbnails a").filter(function(index,elem) { return $(elem).attr('href').match(/\.pdf$/i) }) ) .fancybox({