mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
Merge commit 'a024bc7d76fcc5e49e8210f9b0896db9ef21861a'
This commit is contained in:
36
docs/assets/js/alpinejs/magics/helpers.js
Normal file
36
docs/assets/js/alpinejs/magics/helpers.js
Normal file
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
export function registerMagics(Alpine) {
|
||||
Alpine.magic('copy', (currentEl) => {
|
||||
return function (el) {
|
||||
if (!el) {
|
||||
el = currentEl;
|
||||
}
|
||||
|
||||
// Select the element to copy.
|
||||
let range = document.createRange();
|
||||
range.selectNode(el);
|
||||
window.getSelection().removeAllRanges();
|
||||
window.getSelection().addRange(range);
|
||||
|
||||
// Remove the selection after some time.
|
||||
setTimeout(() => {
|
||||
window.getSelection().removeAllRanges();
|
||||
}, 500);
|
||||
|
||||
// Trim whitespace.
|
||||
let text = el.textContent.trim();
|
||||
|
||||
navigator.clipboard.writeText(text);
|
||||
};
|
||||
});
|
||||
|
||||
Alpine.magic('isScrollX', (currentEl) => {
|
||||
return function (el) {
|
||||
if (!el) {
|
||||
el = currentEl;
|
||||
}
|
||||
return el.clientWidth < el.scrollWidth;
|
||||
};
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user