MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 26: | Line 26: | ||
mw.loader.using(['jquery'], function() { | mw.loader.using(['jquery'], function() { | ||
function processPopup($popup) { | function processPopup($popup) { | ||
// | // 1. Update any <strong> title tags that are not already links. | ||
$popup.find('strong').each(function() { | $popup.find('strong').each(function() { | ||
var titleText = $(this).text().trim(); | var titleText = $(this).text().trim(); | ||
| Line 38: | Line 38: | ||
}); | }); | ||
// | // 2. Get the popup's HTML content. | ||
var htmlContent = $popup.html(); | var htmlContent = $popup.html(); | ||
// 3. Replace wiki-style link markup [PageName] with clickable links, | |||
// skipping any that start with 'img:' so they can be handled separately. | |||
var newContent = htmlContent.replace(/\[([^\]]+)\]/g, function(match, p1) { | var newContent = htmlContent.replace(/\[([^\]]+)\]/g, function(match, p1) { | ||
if (p1.trim().toLowerCase().startsWith('img:')) { | |||
return match; | |||
} | |||
var pageName = p1.replace(/ /g, '_'); | var pageName = p1.replace(/ /g, '_'); | ||
return '<a href="/' + encodeURIComponent(pageName) + '" target="_blank">' + p1 + '</a>'; | return '<a href="/' + encodeURIComponent(pageName) + '" target="_blank">' + p1 + '</a>'; | ||
}); | }); | ||
// 4. Replace custom image markup [img:...] with an actual image element. | |||
newContent = newContent.replace(/\[img:([^\]]+)\]/gi, function(match, p1) { | |||
var imageFile = p1.trim(); | |||
var src; | |||
// If the markup is a full URL, use it as is. | |||
if (/^https?:\/\//.test(imageFile)) { | |||
src = imageFile; | |||
} else { | |||
src = '/images/' + encodeURIComponent(imageFile); | |||
} | |||
return '<img src="' + src + '" alt="' + imageFile + '" style="max-width:100%; display:block; margin-top:5px;">'; | |||
}); | |||
// 5. Update the popup content. | |||
$popup.html(newContent); | $popup.html(newContent); | ||
} | } | ||