Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2878 from andytuba/multireddit-menu
Multireddit quicklinks menu
- Loading branch information
Showing
8 changed files
with
166 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
addModule('multiredditNavbar', (module, moduleID) => { | ||
module.moduleName = 'Multireddit Navigation'; | ||
module.description = 'Enhance the navigation bar shown on the left side of the frontpage.'; | ||
module.category = 'Subreddits'; | ||
|
||
module.includes = [ | ||
RESUtils.regexes.frontpage | ||
]; | ||
|
||
module.options = { | ||
sectionMenu: { | ||
type: 'boolean', | ||
value: true, | ||
description: 'Show a menu linking to various sections of the multireddit when hovering your mouse over the link.' | ||
}, | ||
sectionLinks: { | ||
dependsOn: 'sectionMenu', | ||
type: 'table', | ||
addRowText: '+add multireddit section shortcut', | ||
fields: [{ | ||
name: 'label', | ||
type: 'text' | ||
}, { | ||
name: 'url', | ||
type: 'text' | ||
}], | ||
value: [ | ||
['new', './new'], | ||
['rising', './rising'], | ||
['controversial', './controversial'], | ||
['top', './top'], | ||
['top this month', './top?t=month'], | ||
['gilded', './gilded'], | ||
['promoted', './ads'] | ||
] | ||
}, | ||
hoverDelay: { | ||
dependsOn: 'sectionMenu', | ||
type: 'text', | ||
value: 1000, | ||
description: 'Delay, in milliseconds, before hover tooltip loads. Default is 1000.', | ||
advanced: true | ||
}, | ||
fadeDelay: { | ||
dependsOn: 'sectionMenu', | ||
type: 'text', | ||
value: 200, | ||
description: 'Delay, in milliseconds, before hover tooltip fades away. Default is 200.', | ||
advanced: true | ||
}, | ||
fadeSpeed: { | ||
dependsOn: 'sectionMenu', | ||
type: 'text', | ||
value: 0.7, | ||
description: 'Fade animation\'s speed (in seconds). Default is 0.7.', | ||
advanced: true | ||
} | ||
}; | ||
|
||
module.go = function() { | ||
const $multis = $('.listing-chooser .multis'); | ||
|
||
if (module.options.sectionMenu.value) { | ||
$multis.on('mouseover', 'li', onMouseoverMultiLink); | ||
} | ||
}; | ||
|
||
function onMouseoverMultiLink(e) { | ||
const link = e.currentTarget.querySelector('a[href^="/me/m"]'); | ||
if (!link) { | ||
return; | ||
} | ||
modules['hover'].dropdownList(moduleID) | ||
.target(e.currentTarget) | ||
.options({ | ||
openDelay: module.options.hoverDelay.value, | ||
fadeDelay: module.options.fadeDelay.value, | ||
fadeSpeed: module.options.fadeSpeed.value, | ||
pin: modules['hover'].pin.right, | ||
offsetWidth: -10, | ||
offsetHeight: 1, | ||
bottomPadding: 0 | ||
}) | ||
.populateWith(() => populateSectionMenu(link.href)) | ||
.begin(); | ||
} | ||
|
||
const populateSectionMenu = baseUrl => [ | ||
module.options.sectionLinks.value | ||
.map(link => populateSectionItem(baseUrl, link)) | ||
.reduce((prev, curr) => (curr ? prev.add(curr) : prev), $()) | ||
.add(populateSectionItem('.', [ | ||
`<i>${module.moduleName}</i>`, | ||
modules['settingsNavigation'].makeUrlHash(moduleID, 'sectionMenu') | ||
])) | ||
]; | ||
|
||
function populateSectionItem(baseUrl, link) { | ||
if (!(link && link.length >= 2)) { | ||
return false; | ||
} | ||
|
||
const label = link[0] || ''; | ||
const url = link[1] || ''; | ||
const $link = $('<a />') | ||
.safeHtml(label) | ||
.attr('href', `${baseUrl}/${url}`); | ||
|
||
if (url.indexOf('#!settings') !== -1) { | ||
$link.append('<span class="RESMenuItemButton gearIcon" />'); | ||
} | ||
|
||
$link.on('click', () => modules['hover'].dropdownList(moduleID).close()); | ||
|
||
return $('<li />').append($link); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters