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 (
/* ======================================================= */
var linkId = 'mobile-nav-biz-books';
var
//
function
// 1. Look for the standard Minerva menu class
var $
// 2.
// This prevents us from injecting into the wrong list (like the user settings)
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;
//
function injectLink() {
if ( $menu.length === 0 || $menu.find( '#' + linkId ).length > 0 ) return;
▲ var $newItem = $('<li>')
.addClass('mw-ui-icon-extra')▼
.attr('id', linkId);▼
.attr('href', linkHref)▼
▲ .text(linkText);
// We use 'mw-ui-icon-minerva-list' as a fallback icon because it exists in all versions
// Force visibility in case classes fail
.css({
'display': 'block',
'font-weight': 'bold'
});
// PREPEND puts it at the TOP of the menu so you can't miss it
$menu.prepend( $newItem );
}
▲ }
//
// 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)
var observer = new MutationObserver(function(mutations) {
injectLink();
});
// Start observing the body for added nodes
observer.observe(document.body, { childList: true, subtree: true });
} );
} );
| |||