added: ts type checking for js files; updated: custom contextmenu now show only when needed, GUI users must use keyboard shortcuts for cut/copy/paste
This commit is contained in:
parent
c51c4789db
commit
b063bff64d
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,7 +3,6 @@ __pycache__
|
||||
|
||||
.DS_Store
|
||||
node_modules
|
||||
jsconfig.json
|
||||
|
||||
# pyinstaller build dirs
|
||||
/dist
|
||||
|
File diff suppressed because one or more lines are too long
@ -36,7 +36,7 @@ export default {
|
||||
const options = {
|
||||
cut: {
|
||||
label: this.$t('globals.cut'),
|
||||
show: true,
|
||||
show: false,
|
||||
position: 1,
|
||||
action: () => {
|
||||
document.execCommand('Cut')
|
||||
@ -44,7 +44,7 @@ export default {
|
||||
},
|
||||
copy: {
|
||||
label: this.$t('globals.copy'),
|
||||
show: true,
|
||||
show: false,
|
||||
position: 2,
|
||||
action: () => {
|
||||
document.execCommand('Copy')
|
||||
@ -55,9 +55,6 @@ export default {
|
||||
show: false,
|
||||
position: 3,
|
||||
action: () => {
|
||||
// navigator.clipboard.writeText(this.generalHref).catch(err => {
|
||||
// console.error('Link copying failed', err)
|
||||
// })
|
||||
copyToClipboard(this.generalHref)
|
||||
}
|
||||
},
|
||||
@ -66,9 +63,6 @@ export default {
|
||||
show: false,
|
||||
position: 4,
|
||||
action: () => {
|
||||
// navigator.clipboard.writeText(this.imgSrc).catch(err => {
|
||||
// console.error('Image copying failed', err)
|
||||
// })
|
||||
copyToClipboard(this.imgSrc)
|
||||
}
|
||||
},
|
||||
@ -77,20 +71,22 @@ export default {
|
||||
show: false,
|
||||
position: 5,
|
||||
action: () => {
|
||||
// navigator.clipboard.writeText(this.deezerHref).catch(err => {
|
||||
// console.error('Deezer link copying failed', err)
|
||||
// })
|
||||
copyToClipboard(this.deezerHref)
|
||||
}
|
||||
},
|
||||
paste: {
|
||||
label: this.$t('globals.paste'),
|
||||
show: !window.clientMode,
|
||||
show: false,
|
||||
position: 6,
|
||||
action: () => {
|
||||
// Paste does not always work
|
||||
if (clipboard in navigator) {
|
||||
navigator.clipboard.readText().then(text => {
|
||||
document.execCommand('insertText', undefined, text)
|
||||
})
|
||||
} else {
|
||||
document.execCommand('paste')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -108,9 +104,13 @@ export default {
|
||||
|
||||
return options
|
||||
},
|
||||
// This computed property is used for rendering the options in the wanted order
|
||||
// while keeping the options computed property an Object to make the properties
|
||||
// accessible via property name (es this.options.copyLink)
|
||||
/**
|
||||
* This computed property is used for rendering the options in the wanted order
|
||||
* while keeping the options computed property an Object to make the properties
|
||||
* accessible via property name (es this.options.copyLink)
|
||||
*
|
||||
* @return {object[]} Options in order according to position property
|
||||
*/
|
||||
sortedOptions() {
|
||||
return Object.values(this.options).sort((first, second) => {
|
||||
return first.position < second.position ? -1 : 1
|
||||
@ -123,28 +123,13 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
showMenu(contextMenuEvent) {
|
||||
contextMenuEvent.preventDefault()
|
||||
|
||||
// contextMenuEvent.preventDefault()
|
||||
const { pageX, pageY, target: elementClicked } = contextMenuEvent
|
||||
|
||||
const path = generatePath(elementClicked)
|
||||
|
||||
this.positionMenu(pageX, pageY)
|
||||
|
||||
// Show 'Copy Link' option
|
||||
if (elementClicked.matches('a')) {
|
||||
this.generalHref = elementClicked.href
|
||||
this.options.copyLink.show = true
|
||||
}
|
||||
|
||||
// Show 'Copy Image Link' option
|
||||
if (elementClicked.matches('img')) {
|
||||
this.imgSrc = elementClicked.src
|
||||
this.options.copyImageLink.show = true
|
||||
}
|
||||
|
||||
let deezerLink = null
|
||||
|
||||
// Searching for the first element with a data-link attribute
|
||||
// let deezerLink = this.searchForDataLink(...)
|
||||
for (let i = 0; i < path.length; i++) {
|
||||
if (path[i] == document) break
|
||||
|
||||
@ -154,13 +139,33 @@ export default {
|
||||
}
|
||||
}
|
||||
|
||||
// Show 'Copy Deezer Link' option
|
||||
const isLink = elementClicked.matches('a')
|
||||
const isImage = elementClicked.matches('img')
|
||||
const hasDeezerLink = !!deezerLink
|
||||
|
||||
if (!isLink && !isImage && !hasDeezerLink) return
|
||||
|
||||
contextMenuEvent.preventDefault()
|
||||
this.menuOpen = true
|
||||
this.positionMenu(pageX, pageY)
|
||||
|
||||
if (isLink) {
|
||||
// Show 'Copy Link' option
|
||||
this.generalHref = elementClicked.href
|
||||
this.options.copyLink.show = true
|
||||
}
|
||||
|
||||
if (isImage) {
|
||||
// Show 'Copy Image Link' option
|
||||
this.imgSrc = elementClicked.src
|
||||
this.options.copyImageLink.show = true
|
||||
}
|
||||
|
||||
if (deezerLink) {
|
||||
// Show 'Copy Deezer Link' option
|
||||
this.deezerHref = deezerLink
|
||||
this.showDeezerOptions()
|
||||
}
|
||||
|
||||
this.menuOpen = true
|
||||
},
|
||||
hideMenu() {
|
||||
if (!this.menuOpen) return
|
||||
|
12
src/jsconfig.json
Normal file
12
src/jsconfig.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"checkJs": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./*"],
|
||||
"@js/*": ["./js/*"],
|
||||
"@components/*": ["./components/*"]
|
||||
}
|
||||
},
|
||||
"exclude": ["assets/**/*", "styles/**/*"]
|
||||
}
|
Loading…
Reference in New Issue
Block a user