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 (BRUTE FORCEPERSISTENT METHOD) */
/* ======================================================= */
 
mw.loader.using$( 'mobile.startup', function () {
$(// function () {Configuration
var linkId .attr( 'id',= 'mobile-nav-biz-books' );
var linkHref = '/wiki/Biz/Books'; // Change if your URL structure is different
// Define the function that inserts the link
var linkText = 'Biz Books';
function insertCustomLink() {
// 1. Find the sidebar drawer
var $drawer = $( '#mw-mf-page-left' );
if ( $drawer.length === 0 ) return false;
 
// Define theThe function that insertsenforces the link's existence
// 2. Find the navigation list (First UL inside the drawer)
function insertCustomLinkenforceBizBooksLink() {
var $menu = $drawer.find( 'ul' ).first();
// 1. Target the sidebar container (confirmed by your CSS to be #mw-mf-page-left)
if ( $menu.length === 0 ) return false;
var $drawersidebar = $( '#mw-mf-page-left' );
 
// 32. CheckOnly proceed if linkthe sidebar is actually in the alreadyDOM exists(rendered)
if ( $menu.find( '#mobile-nav-biz-books' )sidebar.length >=== 0 ) return true;
 
// 3. Find the console.log(menu 'BizSlashlist Debug:(first MenuUL found.inside Inserting link...'the sidebar);
var $menu = $drawersidebar.find( 'ul' ).first();
if ( $drawermenu.length === 0 ) return false;
 
// 4. CreateCheck if our thelink Listis Itemmissing
if var $newItem = ($menu.find( '<li>#' + linkId).length === 0) {
.addClass( 'mw-ui-icon-extra' )
console.log( 'BizSlash Debug: HamburgerSidebar clicked.detected, Startinginjecting searchBiz Books link...' );
.attr( 'id', 'mobile-nav-biz-books' );
 
// 5. Create the Linkitem
var attempts$newItem = 0;$('<li>')
// We use 'mw-ui-icon-minerva-home' first because we KNOW it exists.
.addClass( 'mw-ui-icon mw-ui-icon-before mw-ui-icon-minerva-homeextra' )
// We also add a temporary red border to ensure you can see it.
var $newLink = $( .attr('<a>id', linkId);
.attr( 'href', '/wiki/Biz/Books' )
.addClass( 'mw-ui-icon mw-ui-icon-before mw-ui-icon-minerva-home' )
.text( 'Biz Books' )
.css( 'border', '1px solid red' ); // DEBUG STYLE: Remove this line later
 
$newItem.append(// $newLinkCreate );the link
// Using 'mw-ui-icon-minerva-book' (Standard) or fallback to 'mw-ui-icon-minerva-list'
//var 6.$newLink Prepend= to put it at the TOP, Append for BOTTOM$('<a>')
$menu .appendattr('href', $newItem linkHref);
.addClass('mw-ui-icon mw-ui-icon-before mw-ui-icon-minerva-book')
return true .text(linkText);
 
$newItem.append($newLink);
 
// 15. FindAppend theto sidebarthe drawermenu
$menu.append($newItem);
}
}
 
// Run onceimmediately on load (for some skins that preload the menu)
insertCustomLinkenforceBizBooksLink();
 
// Run every 500ms forever.
// LISTEN FOR CLICK on the Hamburger Button
// This ensures that if the user closes and re-opens the menu (which wipes the DOM),
$( 'body' ).on( 'click', '.mw-ui-icon-minerva-mainmenu', function() {
// the link is re-added immediately.
console.log( 'BizSlash Debug: Hamburger clicked. Starting search...' );
setInterval(enforceBizBooksLink, 500);
} );
// Retry every 50ms for 2 seconds (handles lazy loading)
var attempts = 0;
var poller = setInterval( function() {
var success = insertCustomLink();
attempts++;
// Stop if successful or after 40 attempts (2 seconds)
if ( success || attempts > 40 ) {
clearInterval( poller );
}
}, 50 );
});
});
} );