11$ ( document ) . ready ( function ( ) {
2+ // the file extension regex matching on supported image and pdf types
3+ var extensionRegex = / \. ( p n g | j p e ? g | g i f | p d f ) $ / 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 ( / ( p n g | j p e ? g | g i f | p d f ) $ / i ) ) {
12+ if ( $ ( this ) . attr ( 'href' ) . match ( extensionRegex ) ) {
1113 return v . replace ( / \/ a t t a c h m e n t s \/ ( \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 ( / \. ( p n g | j p e ? g | g i f | p d f ) $ / i ) ) {
21+ if ( $ ( this ) . attr ( 'href' ) . match ( extensionRegex ) ) {
2022 var icon = $ ( this ) . clone ( ) . attr ( 'class' , function ( i , v ) {
2123 return v . replace ( / - d o w n l o a d / 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 ( / \. p d f $ / 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