(
anchor: Element | undefined,
{
before,
after,
}: Attachment<NewElement>,
)
| 13 | }, Position>; |
| 14 | |
| 15 | export default function attachElement<NewElement extends Element>( |
| 16 | anchor: Element | undefined, |
| 17 | { |
| 18 | before, |
| 19 | after, |
| 20 | }: Attachment<NewElement>, |
| 21 | ): void { |
| 22 | if (!anchor) { |
| 23 | throw new Error('Element not found'); |
| 24 | } |
| 25 | |
| 26 | const className = 'rgh-attached-' + getCallerId(); |
| 27 | if (elementExists('.' + className, anchor.parentElement!)) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | if (before) { |
| 32 | const element = before(anchor); |
| 33 | element.classList.add(className); |
| 34 | anchor.before(element); |
| 35 | } |
| 36 | |
| 37 | if (after) { |
| 38 | const element = after(anchor); |
| 39 | element.classList.add(className); |
| 40 | anchor.after(element); |
| 41 | } |
| 42 | } |
no test coverage detected