mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
Merge pull request #49141 from nextcloud/feat/clipboard-fallback
This commit is contained in:
commit
deb28f5326
4 changed files with 52 additions and 3 deletions
|
|
@ -14,6 +14,7 @@ import { setUp as setUpContactsMenu } from './components/ContactsMenu.js'
|
|||
import { setUp as setUpMainMenu } from './components/MainMenu.js'
|
||||
import { setUp as setUpUserMenu } from './components/UserMenu.js'
|
||||
import { interceptRequests } from './utils/xhr-request.js'
|
||||
import { initFallbackClipboardAPI } from './utils/ClipboardFallback.ts'
|
||||
|
||||
// keep in sync with core/css/variables.scss
|
||||
const breakpointMobileWidth = 1024
|
||||
|
|
@ -58,6 +59,7 @@ moment.locale(locale)
|
|||
*/
|
||||
export const initCore = () => {
|
||||
interceptRequests()
|
||||
initFallbackClipboardAPI()
|
||||
|
||||
$(window).on('unload.main', () => { OC._unloadCalled = true })
|
||||
$(window).on('beforeunload.main', () => {
|
||||
|
|
|
|||
47
core/src/utils/ClipboardFallback.ts
Normal file
47
core/src/utils/ClipboardFallback.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
import { t } from '@nextcloud/l10n'
|
||||
|
||||
/**
|
||||
*
|
||||
* @param text
|
||||
*/
|
||||
function unsecuredCopyToClipboard(text) {
|
||||
const textArea = document.createElement('textarea')
|
||||
const textAreaContent = document.createTextNode(text)
|
||||
textArea.appendChild(textAreaContent)
|
||||
document.body.appendChild(textArea)
|
||||
|
||||
textArea.focus({ preventScroll: true })
|
||||
textArea.select()
|
||||
|
||||
try {
|
||||
// This is a fallback for browsers that do not support the Clipboard API
|
||||
// execCommand is deprecated, but it is the only way to copy text to the clipboard in some browsers
|
||||
document.execCommand('copy')
|
||||
} catch (err) {
|
||||
window.prompt(t('core', 'Clipboard not available, please copy manually'), text)
|
||||
console.error('[ERROR] core: files Unable to copy to clipboard', err)
|
||||
}
|
||||
|
||||
document.body.removeChild(textArea)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function initFallbackClipboardAPI() {
|
||||
if (!window.navigator?.clipboard?.writeText) {
|
||||
console.info('[INFO] core: Clipboard API not available, using fallback')
|
||||
Object.defineProperty(window.navigator, 'clipboard', {
|
||||
value: {
|
||||
writeText: unsecuredCopyToClipboard,
|
||||
},
|
||||
writable: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export { initFallbackClipboardAPI }
|
||||
4
dist/core-main.js
vendored
4
dist/core-main.js
vendored
File diff suppressed because one or more lines are too long
2
dist/core-main.js.map
vendored
2
dist/core-main.js.map
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue