Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/coloris.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
clearLabel: 'Clear',
closeButton: false,
closeLabel: 'Close',
domTree: document,
onChange: () => undefined,
a11y: {
open: 'Open color picker',
Expand Down Expand Up @@ -63,6 +64,9 @@
if (typeof options !== 'object') {
return;
}
if (options.domTree) {
settings.domTree = options.domTree
}

for (const key in options) {
switch (key) {
Expand All @@ -73,7 +77,10 @@
}
break;
case 'parent':
container = options.parent instanceof HTMLElement ? options.parent : document.querySelector(options.parent);
container =
options.parent instanceof HTMLElement
? options.parent
: settings.domTree.querySelector(options.parent);
if (container) {
container.appendChild(picker);
settings.parent = options.parent;
Expand Down Expand Up @@ -455,7 +462,7 @@
} else if (Array.isArray(selector)) {
selector.forEach(wrapColorField);
} else {
document.querySelectorAll(selector).forEach(wrapColorField);
settings.domTree.querySelectorAll(selector).forEach(wrapColorField);
}
}

Expand Down Expand Up @@ -751,7 +758,9 @@
}

// Select the current format in the format switcher
document.querySelector(`.clr-format [value="${format}"]`).checked = true;
settings.domTree.querySelector(
`.clr-format [value="${format}"]`
).checked = true;
}

/**
Expand Down