Replaced QualityModal with ContextMenu on searchbar

This commit is contained in:
RemixDev 2020-12-16 18:17:42 +01:00
parent 3afdb45d29
commit eda80c1359
No known key found for this signature in database
GPG key ID: B33962B465BDB51C
3 changed files with 70 additions and 57 deletions

File diff suppressed because one or more lines are too long

View file

@ -151,7 +151,7 @@ export default defineComponent({
if (isSearchingURL) {
if (isCtrlPressed) {
this.$root.$emit('QualityModal:open', term)
this.$root.$emit('ContextMenu:searchbar', term)
return
}
@ -186,5 +186,3 @@ export default defineComponent({
}
})
</script>

View file

@ -118,10 +118,24 @@ export default {
}
},
mounted() {
this.$root.$on('ContextMenu:searchbar', this.showSearchbarMenu)
document.body.addEventListener('contextmenu', this.showMenu)
document.body.addEventListener('click', this.hideMenu)
},
methods: {
showSearchbarMenu(url) {
console.log(url)
let searchbar = document.getElementById("searchbar")
searchbar.dataset.cmLink = url
let contextMenuEvent = {
pageX: 115,
pageY: 57,
target: searchbar,
dummy: true
}
this.showMenu(contextMenuEvent)
delete searchbar.dataset.cmLink
},
showMenu(contextMenuEvent) {
const { pageX, pageY, target: elementClicked } = contextMenuEvent
const path = generatePath(elementClicked)
@ -145,11 +159,12 @@ export default {
const isLink = elementClicked.matches('a')
const isImage = elementClicked.matches('img')
const isSearchbar = elementClicked.matches('input#searchbar')
const hasDeezerLink = !!deezerLink
if (!isLink && !isImage && !hasDeezerLink) return
contextMenuEvent.preventDefault()
if (!contextMenuEvent.dummy) contextMenuEvent.preventDefault()
this.menuOpen = true
this.positionMenu(pageX, pageY)
@ -168,7 +183,7 @@ export default {
if (deezerLink) {
// Show 'Copy Deezer Link' option
this.deezerHref = deezerLink
this.showDeezerOptions()
this.showDeezerOptions(isSearchbar)
}
},
hideMenu() {
@ -211,8 +226,8 @@ export default {
}
})
},
showDeezerOptions() {
this.options.copyDeezerLink.show = true
showDeezerOptions(isSearchbar) {
if (!isSearchbar) this.options.copyDeezerLink.show = true
downloadQualities.forEach(quality => {
this.options[quality.objName].show = true