The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/lib/utils/createAnchor.ts

18 lines
537 B

import { registerAnchor } from './deleteAnchor';
type T = keyof HTMLElementTagNameMap;
export const createAnchor: {
(id: string, tag?: T): T extends undefined ? HTMLElementTagNameMap['div'] : HTMLElementTagNameMap[T];
} = (id: string, tag = 'div') => {
const anchor = document.getElementById(id);
if (anchor && anchor.tagName.toLowerCase() === tag) {
return anchor as any;
}
const a = document.createElement(tag);
a.id = id;
document.body.appendChild(a);
registerAnchor(a, () => document.body.removeChild(a));
return a;
};