Skip to content

Commit d599351

Browse files
committed
modify README and support Wiki with lightbox
1 parent 5436963 commit d599351

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Redmine Lightbox 3
22

3+
![Redmine](https://img.shields.io/badge/Redmine-6.0-brightgreen)
4+
[![Software License](https://img.shields.io/badge/license-MIT-blueviolet.svg)](LICENSE)
5+
36
This plugin lets you preview image (JPG, GIF, PNG, BMP) and PDF attachments in a lightbox.
47

58
This is a fork of paginagmbh's [redmine_lightbox2](https://github.com/paginagmbh/redmine_lightbox2) plugin.

app/assets/javascripts/lightbox.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/*
2-
* Lightbox3 for Redmine 6 - The Truly Final Version
2+
* Lightbox3 for Redmine 6 - Final Hybrid Version
33
*
4-
* This script is the definitive solution based on all previous debugging sessions.
5-
* It works without ERB overrides and handles all known contexts (main attachments,
6-
* journal attachments, images, and PDFs).
4+
* This version incorporates the correct selector (`a.thumbnail`) for Wiki pages
75
*/
86
$(document).ready(function() {
97

@@ -12,7 +10,6 @@ $(document).ready(function() {
1210
var $link = $(linkElement);
1311
var href = $link.attr('href');
1412

15-
// Ignore links that we know shouldn't have a lightbox (like delete buttons)
1613
if (!href || $link.hasClass('delete') || $link.hasClass('icon-del')) {
1714
return;
1815
}
@@ -31,35 +28,51 @@ $(document).ready(function() {
3128
// --- Apply the logic to DIFFERENT sections of Redmine ---
3229

3330
// 1. Main Attachment Block (top of issue, documents, files, etc.)
34-
// This targets all links inside the main attachments block.
3531
$('div.attachments a').each(function() {
3632
applyLightbox(this);
3733
});
3834

39-
// 2. Journal / Notes Section - a special case with broken links
40-
// It has two types of links that need fixing before applying lightbox.
41-
42-
// 2a. Journal Thumbnails & Filename links
35+
// 2. Journal / Notes Section
4336
$('div.journal div.thumbnails a, div.journal ul.details a[href*="/attachments/"]:not(.icon-download)').each(function() {
4437
var $link = $(this);
45-
var wrongHref = $link.attr('href'); // e.g., /attachments/8
38+
var wrongHref = $link.attr('href');
4639
var filename = $link.find('img').attr('title') || $link.text().trim();
4740

4841
if (wrongHref && filename) {
4942
var attachmentId = wrongHref.split('/')[2];
5043
if ($.isNumeric(attachmentId)) {
51-
// First, rewrite the broken href to the correct download path
5244
var correctHref = '/attachments/download/' + attachmentId + '/' + filename;
5345
$link.attr('href', correctHref);
54-
// After fixing the link, process it to see if it needs a lightbox
46+
applyLightbox(this);
47+
}
48+
}
49+
});
50+
51+
// 3. UPDATED - Wiki Embedded Thumbnails (Using the correct selector now)
52+
// This targets images embedded with the {{thumbnail()}} macro using the `a.thumbnail` class.
53+
$('div.wiki a.thumbnail').each(function() {
54+
var $link = $(this);
55+
var wrongHref = $link.attr('href');
56+
var $image = $link.find('img');
57+
58+
// For these wiki thumbnails, the filename is in the 'alt' attribute.
59+
var filename = $image.attr('alt');
60+
61+
if (wrongHref && filename) {
62+
var attachmentId = wrongHref.split('/')[2];
63+
if ($.isNumeric(attachmentId)) {
64+
// Rebuild the href to point to the correct download path
65+
var correctHref = '/attachments/download/' + attachmentId + '/' + filename;
66+
$link.attr('href', correctHref);
67+
68+
// After fixing the link, process it to add the lightbox class.
5569
applyLightbox(this);
5670
}
5771
}
5872
});
5973

6074

6175
// --- Precautionary fix for the duplicate icon mystery ---
62-
// This will clean up any duplicate download icons, regardless of their source.
6376
$('div.journal ul.details li:contains("File")').each(function() {
6477
var $downloadIcons = $(this).find('a.icon-download');
6578
if ($downloadIcons.length > 1) {
@@ -69,10 +82,9 @@ $(document).ready(function() {
6982

7083

7184
// --- INITIALIZE LIGHTBOX ---
72-
// Finally, after all links have been corrected and classes applied, initialize fancybox.
7385
$('a.lightbox').fancybox({
7486
iframe: {
75-
preload: false // Recommended setting for PDFs
87+
preload: false
7688
}
7789
});
7890

0 commit comments

Comments
 (0)