highlightjs-badge icon indicating copy to clipboard operation
highlightjs-badge copied to clipboard

recommend an option for a `root`

Open gillyspy opened this issue 3 years ago • 0 comments

current it is assumed that contentSelector will be applied to document. this is a fine assumption but i suggest that you be able to specify root as an option so that the badge can be added by those using an adhoc approach (e.g. a mutationObserver).

  • in options set the root by default to document.
  • suggest a check in loadto make sure root is eligible:
if(root !== document || !(root instanceof Element))
            throw new TypeError('root element is neither document nor an element')
  • There are only a couple of lines where you would need to change document.querySelector to root.querySelector

gillyspy avatar Feb 01 '22 15:02 gillyspy