Skip to content

Commit

Permalink
Attach controls in entire HTML body.
Browse files Browse the repository at this point in the history
We won't limit to a root element - I feel like convenience outweighs scoping in this.
  • Loading branch information
bennothommo committed Feb 29, 2024
1 parent 6047e5f commit 8387801
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions packages/controls/src/lib/ControlHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,15 @@ import { Singleton } from '@wintercms/snowboard';
export default class ControlHandler extends Singleton {
/**
* Constructor.
*
* @param {HTMLElement} rootElement Defines the root element to watch for controls.
*/
construct(rootElement = document.body) {
construct() {
/**
* Registered controls.
* @type {Array.<{
* name: String, pluginName: String, control: Control, callback: Function
* }>}
*/
this.registeredControls = [];
/**
* The root element to watch for controls.
* @type {HTMLElement}
*/
this.rootElement = rootElement;
/**
* The elements where controls have been initialized.
* @type {Array.<{element: HTMLElement, control: String, instance: Control}>}}
Expand Down Expand Up @@ -65,15 +58,15 @@ export default class ControlHandler extends Singleton {
/**
* Ready handler.
*
* Initializes controls within the entire root element.
* Initializes controls within the entire HTML body.
*/
onReady() {
this.initializeControls(this.rootElement);
this.initializeControls(document.body);

// Register a DOM observer and watch for any removed nodes
if (!this.observer) {
this.observer = new MutationObserver(this.events.mutate);
this.observer.observe(this.rootElement, {
this.observer.observe(document.body, {
childList: true,
subtree: true,
});
Expand Down

0 comments on commit 8387801

Please sign in to comment.