Skip to content

Commit

Permalink
added support for image and pdf preview in 'Files' module // fixes #72
Browse files Browse the repository at this point in the history
  • Loading branch information
tofi86 committed Nov 2, 2019
1 parent 3f838f8 commit a39f66c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions assets/javascripts/lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']";

Expand Down Expand Up @@ -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',
Expand All @@ -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({
Expand Down

0 comments on commit a39f66c

Please sign in to comment.