Replace fomantic popup module with tippy.js (#20428)

- replace fomantic popup module with tippy.js
- fix chaining and add comment
- add 100ms delay to tooltips
- stopwatch improvments, raise default maxWidth
- update web_src/js/features/common-global.js
- use type=submit instead of js
This commit is contained in:
silverwind 2022-08-09 14:37:34 +02:00 committed by GitHub
parent 36f9ee5813
commit 1b2cd4c4e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 199 additions and 2129 deletions

View file

@ -1,24 +1,15 @@
import $ from 'jquery';
import {showTemporaryTooltip} from '../modules/tippy.js';
const {copy_success, copy_error} = window.config.i18n;
function onSuccess(btn) {
btn.setAttribute('data-variation', 'inverted tiny');
$(btn).popup('destroy');
const oldContent = btn.getAttribute('data-content');
btn.setAttribute('data-content', copy_success);
$(btn).popup('show');
btn.setAttribute('data-content', oldContent || '');
export async function copyToClipboard(text) {
try {
await navigator.clipboard.writeText(text);
} catch {
return fallbackCopyToClipboard(text);
}
return true;
}
function onError(btn) {
btn.setAttribute('data-variation', 'inverted tiny');
const oldContent = btn.getAttribute('data-content');
$(btn).popup('destroy');
btn.setAttribute('data-content', copy_error);
$(btn).popup('show');
btn.setAttribute('data-content', oldContent || '');
}
// Fallback to use if navigator.clipboard doesn't exist. Achieved via creating
// a temporary textarea element, selecting the text, and using document.execCommand
@ -60,16 +51,8 @@ export default function initGlobalCopyToClipboardListener() {
e.preventDefault();
(async() => {
try {
await navigator.clipboard.writeText(text);
onSuccess(target);
} catch {
if (fallbackCopyToClipboard(text)) {
onSuccess(target);
} else {
onError(target);
}
}
const success = await copyToClipboard(text);
showTemporaryTooltip(target, success ? copy_success : copy_error);
})();
break;