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 (ROBUSTBRUTE FORCE METHOD) */
/* ======================================================= */
 
$mw.loader.using( 'mobile.startup', function () {
$( function injectBizBooks() {
// Define the injection logic
function injectBizBooks() {
// Target the specific Minerva sidebar container
// It is usually ID 'mw-mf-page-left'
var $sidebar = $('#mw-mf-page-left');
// FindDefine the mainfunction navigationthat list insideinserts the sidebar (usually the first UL)link
varfunction $menu = $sidebar.findinsertCustomLink('ul').first(); {
// Create1. theFind newthe listsidebar itemdrawer
// It is usually IDvar $drawer = $( '#mw-mf-page-left' );
if ( $drawer.length === 0 ) return false;
 
// Safety2. check:Find Ensurethe menunavigation existslist and(First weUL haven't addedinside the link yetdrawer)
if ($menu.length > 0 &&var $menu = $drawer.find( '#mobile-nav-biz-booksul' ).length === 0first() {;
if ( $menu.length === 0 ) return false;
// Create the new list item
var $newItem = $('<li>')
.addClass('mw-ui-icon-extra')
.attr('id', 'mobile-nav-biz-books');
 
// Create3. theCheck if link already exists
if ( $menu.find( '#mobile-nav-biz-books' ).length > 0 ) return true;
// Note: If the 'book' icon is blank, change 'mw-ui-icon-minerva-book' to 'mw-ui-icon-minerva-list'
var $newLink = $('<a>')
.attr('href', '/wiki/Biz/Books')
.addClass('mw-ui-icon mw-ui-icon-before mw-ui-icon-minerva-book')
.text('Biz Books');
 
//console.log( Append'BizSlash linkDebug: toMenu found. Inserting link...' item);
 
$newItem.append($newLink);
// 4. Create the List Item
var $sidebarnewItem = $( '#mw-mf-page-left<li>' );
.addClass( 'mw-ui-icon-extra') )
.attr( 'id', 'mobile-nav-biz-books' );
 
// We5. append it toCreate the end of the list. Link
// We use 'mw-ui-icon-minerva-home' first because we KNOW it exists.
// We also add a temporary red border to ensure you can see it.
var $newItemnewLink = $( '<lia>' )
.attr( 'href', '/wiki/Biz/Books' )
// Note: If the .addClass( 'book' mw-ui-icon is blank, change 'mw-ui-icon-minerva-book'before to 'mw-ui-icon-minerva-listhome' )
.text( 'Biz Books' );
.css( 'border', '1px solid red' ); // DEBUG STYLE: Remove this line later
 
var$newItem.append( $newLink = $('<a>');
}
// If6. youPrepend wantto put it at the topTOP, changeAppend .append()for to .prepend()BOTTOM
$newItemmenu.append( $newLinknewItem );
//return Insert into the menutrue;
// 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 immediatelyonce (juston inload case(for thesome menuskins isthat alreadypreload renderedthe menu)
injectBizBooks insertCustomLink();
 
// LISTEN FOR CLICK on the Hamburger Button
// 2. Set up a MutationObserver
$( 'body' ).on( 'click', '.mw-ui-icon-minerva-mainmenu', function() {
// This watches the webpage for new elements (like the sidebar opening)
console.log( 'BizSlash Debug: Hamburger clicked. Starting search...' );
var observer = new MutationObserver(function(mutations) {
// Loop through changes to see if nodes were added
// Retry every 50ms for 2 seconds (handles lazy loading)
var nodesAdded = false;
for ( var iattempts = 0; i < mutations.length; i++) {
ifvar (mutations[i].addedNodes.lengthpoller >= 0setInterval( function() {
nodesAddedvar success = trueinsertCustomLink();
breakattempts++;
}
// Stop if successful or after 40 attempts (2 seconds)
}
if ( success || attempts > 40 ) {
// If the DOM changed, try to inject the link clearInterval( poller );
if (nodesAdded) { }
injectBizBooks(}, 50 );
});
});
} );
 
// Start watching the body for changes
observer.observe(document.body, { childList: true, subtree: true });
});