mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-09 23:27:51 +00:00
35 lines
967 B
JavaScript
35 lines
967 B
JavaScript
/**
|
|
* Checks if the target is the same as the provided element of that the element
|
|
* contains the target. Returns true is this is the case.
|
|
*
|
|
* @returns boolean
|
|
*/
|
|
export const isElement = (element, target) => {
|
|
return element === target || element.contains(target)
|
|
}
|
|
|
|
/**
|
|
* This function will focus a contenteditable and place the cursor at the end.
|
|
*
|
|
* @param element
|
|
*/
|
|
export const focusEnd = element => {
|
|
element.focus()
|
|
|
|
if (
|
|
typeof window.getSelection !== 'undefined' &&
|
|
typeof document.createRange !== 'undefined'
|
|
) {
|
|
const range = document.createRange()
|
|
range.selectNodeContents(element)
|
|
range.collapse(false)
|
|
const sel = window.getSelection()
|
|
sel.removeAllRanges()
|
|
sel.addRange(range)
|
|
} else if (typeof document.body.createTextRange !== 'undefined') {
|
|
const textRange = document.body.createTextRange()
|
|
textRange.moveToElementText(element)
|
|
textRange.collapse(false)
|
|
textRange.select()
|
|
}
|
|
}
|