Skip to content

Commit e7d6551

Browse files
committed
bugfix for DMSF support: only show lightbox for image and PDF assets
1 parent ee8d4a5 commit e7d6551

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

assets/javascripts/lightbox.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
$(document).ready(function() {
2+
// the file extension regex matching on supported image and pdf types
3+
var extensionRegex = /\.(png|jpe?g|gif|pdf)$/i;
24

35
// modify thumbnail links in wiki content -> add filename from ./img/@alt to url to support fancybox preview
46
$("div.wiki a.thumbnail").attr('href', function(i, v){
@@ -7,7 +9,7 @@ $(document).ready(function() {
79

810
// modify thumbnails and magnifier links in journal details -> add filename to url to support fancybox preview
911
$("div.journal div.thumbnails a, div.journal ul.details li a:not([title])").attr('href', function(i, v){
10-
if($(this).attr('href').match(/(png|jpe?g|gif|pdf)$/i)) {
12+
if($(this).attr('href').match(extensionRegex)) {
1113
return v.replace(/\/attachments\/(\d+)/g,'/attachments/download/$1');
1214
} else {
1315
return v;
@@ -16,7 +18,7 @@ $(document).ready(function() {
1618

1719
// add a magnifier icon before download icon for images and pdf
1820
$("div.journal ul.details li a.icon-download").each(function(i, obj) {
19-
if($(this).attr('href').match(/\.(png|jpe?g|gif|pdf)$/i)) {
21+
if($(this).attr('href').match(extensionRegex)) {
2022
var icon = $(this).clone().attr('class', function(i, v){
2123
return v.replace(/-download/g,'-magnifier');
2224
});
@@ -31,11 +33,18 @@ $(document).ready(function() {
3133

3234
// #40 DMSF support: add class="thumbnail" to DMSF macro thumbnails
3335
$("a[data-downloadurl][href^='/dmsf/files/'][href$='/view']").each(function(i, obj) {
34-
$(this).attr('class', 'thumbnail')
35-
.attr('data-fancybox-type', 'image')
36-
.attr('title', $(this).attr('data-downloadurl').split(':')[1])
37-
.removeAttr('target')
38-
.removeAttr('data-downloadurl');
36+
var filename = $(this).attr('data-downloadurl').split(':')[1];
37+
// Also support PDF preview in lightbox
38+
var isPdf = filename.match(/\.pdf$/i);
39+
// Bugfix: only apply thumbnail class to image and pdf links
40+
if(filename.match(extensionRegex)) {
41+
$(this)
42+
.attr('class', 'thumbnail')
43+
.attr('data-fancybox-type', isPdf ? 'iframe' : 'image')
44+
.attr('title', filename)
45+
.removeAttr('target')
46+
.removeAttr('data-downloadurl');
47+
}
3948
});
4049

4150
// Add Fancybox to image links

0 commit comments

Comments
 (0)