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 (ROBUST METHOD) */
/* ======================================================= */
 
$( function () {
// Wait forDefine the menu to beinjection availablelogic
var mobileMenuAddLink = function injectBizBooks() {
// FindTarget the mainspecific menuMinerva list (usually the first UL in the menusidebar container)
var// $menuIt =is $(usually '.menuID ul' ).first();mw-mf-page-left'
var $newLinksidebar = $( '<a>#mw-mf-page-left' );
// CheckFind ifthe ourmain linknavigation alreadylist existsinside tothe preventsidebar duplicates(usually the first UL)
if (var $menu.length > 0 &&= $menusidebar.find( '#mobile-nav-biz-booksul' ).length === 0 first() {;
 
// Safety check: Ensure menu exists and we haven't added the link yet
if ($menu.length > 0 && $menu.find('#mobile-nav-biz-books').length === 0) {
// Create the new list item
var $newItem = $( '<li>' )
.addClass( 'mw-ui-icon-extra' ) // Standard mobile class
.attr( 'id', 'mobile-nav-biz-books' );
 
// Create the link
// Note: If the 'book' icon is blank, change 'mw-ui-icon-minerva-book' to 'mw-ui-icon-minerva-list'
var $newLink = $( '<a>' )
var $newLink = $('<a>')
.attr( 'href', '/wiki/Biz/Books' ) // Ensure this path matches your wiki's URL structure
.addClass( 'mw-ui-icon mw-ui-icon-before mw-ui-icon-minerva-book' ) // Adds a book icon if available
.textaddClass( 'Bizmw-ui-icon Booksmw-ui-icon-before mw-ui-icon-minerva-book' ); // The text to display
.text('Biz Books');
 
// Append link to item, and item to menu
$newItem.append( $newLink );
$menu.append( $newItem );
// Insert into the menu
// We append it to the end of the list.
// If you want it at the top, change .append() to .prepend()
$menu.append($newItem);
} ); }
}
 
// 1. Run immediately (just in case the menu is already rendered)
injectBizBooks();
 
// 2. Set up a MutationObserver
// This watches the webpage for new elements (like the sidebar opening)
var observer = new MutationObserver(function(mutations) {
// Loop through changes to see if nodes were added
var nodesAdded = false;
for (var i = 0; i < mutations.length; i++) {
if (mutations[i].addedNodes.length > 0) {
nodesAdded = true;
break;
}
}
// If the DOM changed, try to inject the link
if (nodesAdded) {
injectBizBooks();
}
});
 
// RunStart onwatching pagethe loadbody for changes
observer.observe(document.body, { childList: true, subtree: true });
mobileMenuAddLink();
} );
// Re-run if the menu is opened (sometimes needed if the menu is lazy-loaded)
$( '.header-container' ).on( 'click', '.mw-ui-icon-minerva-mainmenu', function() {
setTimeout( mobileMenuAddLink, 100 );
} );
} );