MediaWiki:Mobile.js: Difference between revisions

Content deleted Content added
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 158:
 
/* ======================================================= */
/* ADD 'BIZ BOOKS' TO MOBILE SIDEBAR (PERSISTENTUNIVERSAL METHOD) */
/* ======================================================= */
 
$mw.loader.using( ['mediawiki.util', 'jquery'], function () {
//$( Configurationfunction () {
}
var linkId = 'mobile-nav-biz-books';
var linkHref = '/wiki/Biz/Books'; // Change if your URL structure is different
var linkTextlinkHref = '/wiki/Biz /Books';
var $newItemlinkText = $('<li>Biz Books');
 
// TheHelper function thatto enforcesfind the link'scorrect menu existencelist
function enforceBizBooksLinkfindTargetMenu() {
// 1. Look for the standard Minerva menu class
// 1. Target the sidebar container (confirmed by your CSS to be #mw-mf-page-left)
var $sidebarlists = $( '#mw.menu ul, .navigation-mf-page-leftdrawer ul' );
 
// 2. OnlyFilter proceedto iffind the sidebarlist isthat actually incontains the DOM"Home" or "Random" (rendered)links
// This prevents us from injecting into the wrong list (like the user settings)
if ($sidebar.length === 0) return;
var $target = $lists.filter(function() {
// Look for links to Main_Page or Random inside this UL
return $(this).find('a[href*="Main_Page"], a[href*="Random"]').length > 0;
.text(linkText});
 
// 3.If Findfound, return the menufirst listmatch. If not, fallback to the (first UL insidein the sidebar)drawer.
var return $menutarget.length =? $sidebartarget.findfirst('ul') : $lists.first();
if ($menu.length === 0) return;}
 
function injectLink() {
// 4. Check if our link is missing
if ( var $menu.find('#' + linkId).length === 0findTargetMenu() {;
console.log('BizSlash:// SidebarIf detectedno menu is found, injectingor Bizif Booksour link already exists, stop...');
if ( $menu.length === 0 || $menu.find( '#' + linkId ).length > 0 ) return;
 
//console.log( Create'BizSlash: theValid itemmenu found. Injecting...' );
var $newItem = $('<li>')
.addClass('mw-ui-icon-extra')
.attr('id', linkId);
 
//var Create$newItem the= link$( '<li>' )
// Using 'mw-ui-icon-minerva-book' .addClass(Standard) or fallback to 'mw-ui-icon-minerva-listextra' )
var $newLink = $ .attr( '<a>id', linkId );
.attr('href', linkHref)
.addClass('mw-ui-icon mw-ui-icon-before mw-ui-icon-minerva-book')
.text(linkText);
 
$newItem.append(var $newLink = $( '<a>' );
.attr( 'idhref', linkIdlinkHref );
// We use 'mw-ui-icon-minerva-list' as a fallback icon because it exists in all versions
.addClass( 'mw-ui-icon mw-ui-icon-before mw-ui-icon-minerva-extralist' )
.attrtext('href', linkHreflinkText )
// Force visibility in case classes fail
.css({
'display': 'block',
'font-weight': 'bold'
});
 
// 5$newItem.append( Append to the$newLink menu);
$menu.append($newItem);
// PREPEND puts it at the TOP of the menu so you can't miss it
$menu.prepend( $newItem );
}
}
 
// Run1. immediatelyRun on load
enforceBizBooksLink injectLink();
 
// 2. Run whenever the drawer is opened (Click listener)
// We listen on the document body for clicks on the hamburger icon
$( 'body' ).on( 'click', '.mw-ui-icon-minerva-mainmenu, #mw-mf-main-menu-button', function() {
// Retry multiple times as the menu slides in
var count = 0;
var interval = setInterval(function() {
injectLink();
count++;
if (count > 20) clearInterval(interval); // Stop after 2 seconds
}, 100);
});
 
// 3. MutationObserver (The Backup)
// Run every 500ms forever.
// This ensures that if the user closes// andWatch re-opensfor the menudrawer (whichappearing wipesin the DOM),
var observer = new MutationObserver(function(mutations) {
// the link is re-added immediately.
injectLink();
setInterval(enforceBizBooksLink, 500);
});
// Start observing the body for added nodes
observer.observe(document.body, { childList: true, subtree: true });
} );
} );