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
/* ======================================================= */
$(
//
//
//
// 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 = $(
.addClass(
.attr(
// 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(
.
.text('Biz Books');
// Append link to item
$newItem.append(
// 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();
}
});
//
observer.observe(document.body, { childList: true, subtree: true });
▲ } );
▲} );
| |||