diff --git a/.babelrc b/.babelrc index 37e07ef..d80de8f 100644 --- a/.babelrc +++ b/.babelrc @@ -11,7 +11,7 @@ "Want to add custom links? See [[meta:MoreMenu#Customization]].", "", "Script: MoreMenu.js", - "Version: 5.1.3", + "Version: 5.1.4", "Author: MusikAnimal", "License: MIT", "Documentation: [[meta:MoreMenu]]", diff --git a/dist/MoreMenu.js b/dist/MoreMenu.js index 7f92da3..4c5a853 100644 --- a/dist/MoreMenu.js +++ b/dist/MoreMenu.js @@ -6,7 +6,7 @@ * Want to add custom links? See [[meta:MoreMenu#Customization]]. * * Script: MoreMenu.js -* Version: 5.1.3 +* Version: 5.1.4 * Author: MusikAnimal * License: MIT * Documentation: [[meta:MoreMenu]] @@ -687,10 +687,9 @@ $(function () { addListeners(); } /** - * Monobook and Modern have 'History' and 'Watch' links as tabs. To conserve space, they are added to the Page menu. + * Monobook and Modern have 'History' and 'Watch' links as tabs. To conserve space, they are moved to the Page menu. * This method is called before and after the menus are drawn, to ensure positioning is calculated correctly. - * Additionally, we move the native Move link instead of producing it ourselves, to preserve listeners added by - * other gadgets and scripts. + * Listeners on these links are preserved, but we do change the element IDs to our pattern (e.g. `mm-page-history`). * @param {Boolean} [replace] True to replace the links in .mm-page with the native links, false just hides them. */ @@ -704,11 +703,11 @@ $(function () { if (replace) { if (monobookModern) { - $('#mm-page-watch').replaceWith($watchLink.addClass('mm-item').show()); - $('#mm-page-history').replaceWith($histLink.addClass('mm-item').show()); + $('#mm-page-watch').replaceWith($watchLink.addClass('mm-item').prop('id', 'mm-page-watch').show()); + $('#mm-page-history').replaceWith($histLink.addClass('mm-item').prop('id', 'mm-page-history').show()); } - $('#mm-page-move-page').replaceWith($moveLink.addClass('mm-item').show()); + $('#mm-page-move-page').replaceWith($moveLink.addClass('mm-item').prop('id', 'mm-page-move-page').show()); return; } /** No need to ask for translations when these already live on the page. */ @@ -912,6 +911,24 @@ $(function () { mw.hook('moremenu.ready').fire(config); }); } + /** + * Get the ID of the menu item preceding the given item. + * @param {String} menu The parent menu the item lives (or will live) under. + * @param {String} [submenu] The given item lives (or will live) under this submenu. + * @param {Boolean|String} [insertAfter] The preceding item should be this one. + * @returns {jQuery} + */ + + + function getBeforeItem(menu, submenu, insertAfter) { + /** Normalize to native IDs if necessary */ + if (-1 !== ['history', 'move', 'watch'].indexOf(insertAfter)) { + return $("#ca-".concat(insertAfter)); + } + + var beforeItemKey = getItemId(menu, insertAfter || '', submenu); + return $("#".concat(beforeItemKey)); + } /** * PUBLIC METHODS */ @@ -958,8 +975,7 @@ $(function () { var $html = $(getMenuHtml(menu, items, submenu)); /** Check if insertAfter ID is valid. */ - var beforeItemKey = getItemId(menu, insertAfter || '', submenu); - var $beforeItem = $("#".concat(beforeItemKey)); + var $beforeItem = getBeforeItem(menu, submenu, insertAfter); var isSubmenuItem = $beforeItem.parents('.mm-submenu').length; if ($beforeItem.length && (!submenu || submenu && isSubmenuItem)) { diff --git a/dist/MoreMenu.messages.en.js b/dist/MoreMenu.messages.en.js index e0c0cf2..6f3f963 100644 --- a/dist/MoreMenu.messages.en.js +++ b/dist/MoreMenu.messages.en.js @@ -6,7 +6,7 @@ * Want to add custom links? See [[meta:MoreMenu#Customization]]. * * Script: MoreMenu.js -* Version: 5.1.3 +* Version: 5.1.4 * Author: MusikAnimal * License: MIT * Documentation: [[meta:MoreMenu]] diff --git a/dist/MoreMenu.page.js b/dist/MoreMenu.page.js index dd580f3..258819c 100644 --- a/dist/MoreMenu.page.js +++ b/dist/MoreMenu.page.js @@ -6,7 +6,7 @@ * Want to add custom links? See [[meta:MoreMenu#Customization]]. * * Script: MoreMenu.js -* Version: 5.1.3 +* Version: 5.1.4 * Author: MusikAnimal * License: MIT * Documentation: [[meta:MoreMenu]] diff --git a/dist/MoreMenu.user.js b/dist/MoreMenu.user.js index cafbf5d..2a00495 100644 --- a/dist/MoreMenu.user.js +++ b/dist/MoreMenu.user.js @@ -6,7 +6,7 @@ * Want to add custom links? See [[meta:MoreMenu#Customization]]. * * Script: MoreMenu.js -* Version: 5.1.3 +* Version: 5.1.4 * Author: MusikAnimal * License: MIT * Documentation: [[meta:MoreMenu]] diff --git a/package.json b/package.json index 59cd6b4..ebd44c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moremenu", - "version": "5.1.3", + "version": "5.1.4", "description": "Dropdown menus with links to common tasks, user and page analytic tools and logs.", "private": true, "scripts": {