MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 56: | Line 56: | ||
// Try '#p-tb' (Tools) or '#p-navigation' (Navigation) | // Try '#p-tb' (Tools) or '#p-navigation' (Navigation) | ||
$('#p-navigation').after(customMenu); | $('#p-navigation').after(customMenu); | ||
}); | |||
/* --- SMART VIDEO MODAL SCRIPT --- */ | |||
$(document).ready(function() { | |||
// 1. Auto-Fetch Thumbnails & Handle Clicks | |||
$('.bc-video-trigger').each(function() { | |||
var $trigger = $(this); | |||
var videoID = $trigger.data('video-id'); | |||
// If no manual background is set, grab it from YouTube automatically | |||
if (videoID && !$trigger.css('background-image') || $trigger.css('background-image') === 'none') { | |||
// Try 'maxresdefault' (HD) first. | |||
// Note: If a video is very old, it might only have 'hqdefault.jpg'. | |||
var thumbUrl = "https://img.youtube.com/vi/" + videoID + "/maxresdefault.jpg"; | |||
$trigger.css('background-image', 'url("' + thumbUrl + '")'); | |||
} | |||
// Handle Click | |||
$trigger.on('click', function() { | |||
var embedUrl = "https://www.youtube.com/embed/" + videoID + "?autoplay=1&rel=0&modestbranding=1"; | |||
$('#bc-modal-iframe').attr('src', embedUrl); | |||
$('#bc-video-modal').addClass('active'); | |||
$('body').css('overflow', 'hidden'); // Lock scroll | |||
}); | |||
}); | |||
// 2. Close Modal Logic | |||
function closeModal() { | |||
$('#bc-video-modal').removeClass('active'); | |||
$('#bc-modal-iframe').attr('src', ''); | |||
$('body').css('overflow', ''); | |||
} | |||
$('.bc-modal-close').click(closeModal); | |||
$('#bc-video-modal').click(function(e) { | |||
if (e.target === this) closeModal(); | |||
}); | |||
$(document).keydown(function(e) { | |||
if (e.key === "Escape") closeModal(); | |||
}); | |||
}); | }); | ||
Revision as of 17:09, 4 February 2026
/* Any JavaScript here will be loaded for all users on every page load. */
/* Load FontAwesome 6.6.0 (Includes Butterfly & Bluesky) */
mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css', 'text/css');
/* Force all external links to open in a new tab */
$( function() {
$( 'a.external' ).attr( 'target', '_blank' );
});
window.wpDarkModeAutoToggle = true;
/* --- Inject Hero Search Bar on Main Page (Fixed Suggestions) --- */
$(function() {
// Only run this if the placeholder exists
if ($('#bc-hero-search').length) {
var searchHTML =
'<form action="/index.php" id="searchform">' +
'<input type="hidden" name="title" value="Special:Search">' +
'<div style="position: relative; max-width: 600px; margin: 0 auto;">' +
// ADDED: class="mw-searchInput"
// ADDED: accesskey="f" (Standard MediaWiki hotkey)
'<input id="heroSearchInput" class="mw-searchInput" name="search" type="search" placeholder="Search for In-Bond, ACE Manifest..." autocomplete="off" accesskey="f" style="width: 100%; padding: 15px 120px 15px 25px; border-radius: 50px; border: none; font-size: 16px; box-shadow: 0 4px 6px rgba(0,0,0,0.2); outline: none;">' +
'<button type="submit" name="go" value="Go" style="position: absolute; right: 5px; top: 5px; bottom: 5px; background: #266065; color: white; border: none; border-radius: 50px; padding: 0 25px; font-weight: bold; cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.2);">Search</button>' +
'</div>' +
'</form>';
$('#bc-hero-search').html(searchHTML);
// --- MANUALLY BIND SUGGESTIONS ---
// We wait for the module to load, then force the bind
mw.loader.using( 'mediawiki.searchSuggest', function () {
$( '#heroSearchInput' ).searchSuggest();
});
}
});
/* --- INJECT CUSTOM SIDEBAR MENU --- */
$(function() {
// Define the menu HTML
var customMenu =
'<nav class="mw-portlet mw-portlet-bc-tools vector-menu vector-menu-portal portal" aria-labelledby="p-bctools-label" role="navigation">' +
'<h3 id="p-bctools-label" class="vector-menu-heading"><span>BorderConnect Tools</span></h3>' +
'<div class="vector-menu-content">' +
'<ul class="vector-menu-content-list">' +
'<li><a href="https://www.borderconnect.com/auth/login" target="_blank">Login to System</a></li>' +
'<li><a href="https://www.borderprint.com" target="_blank">Order Labels (BorderPrint)</a></li>' +
'<li><a href="https://www.borderconnect.com/contact" target="_blank">Contact Support</a></li>' +
'</ul>' +
'</div>' +
'</nav>';
// Insert it above the "Tools" (tb) section or "Interaction" section
// Try '#p-tb' (Tools) or '#p-navigation' (Navigation)
$('#p-navigation').after(customMenu);
});
/* --- SMART VIDEO MODAL SCRIPT --- */
$(document).ready(function() {
// 1. Auto-Fetch Thumbnails & Handle Clicks
$('.bc-video-trigger').each(function() {
var $trigger = $(this);
var videoID = $trigger.data('video-id');
// If no manual background is set, grab it from YouTube automatically
if (videoID && !$trigger.css('background-image') || $trigger.css('background-image') === 'none') {
// Try 'maxresdefault' (HD) first.
// Note: If a video is very old, it might only have 'hqdefault.jpg'.
var thumbUrl = "https://img.youtube.com/vi/" + videoID + "/maxresdefault.jpg";
$trigger.css('background-image', 'url("' + thumbUrl + '")');
}
// Handle Click
$trigger.on('click', function() {
var embedUrl = "https://www.youtube.com/embed/" + videoID + "?autoplay=1&rel=0&modestbranding=1";
$('#bc-modal-iframe').attr('src', embedUrl);
$('#bc-video-modal').addClass('active');
$('body').css('overflow', 'hidden'); // Lock scroll
});
});
// 2. Close Modal Logic
function closeModal() {
$('#bc-video-modal').removeClass('active');
$('#bc-modal-iframe').attr('src', '');
$('body').css('overflow', '');
}
$('.bc-modal-close').click(closeModal);
$('#bc-video-modal').click(function(e) {
if (e.target === this) closeModal();
});
$(document).keydown(function(e) {
if (e.key === "Escape") closeModal();
});
});