mirror of
https://github.com/sissbruecker/linkding
synced 2024-11-22 19:33:05 +00:00
be789ea9e6
* Extract bookmark view contexts * Implement basic partial updates for bookmark list and tag cloud * Refactor confirm button JS into web component * Refactor bulk edit JS into web component * Refactor tag autocomplete JS into web component * Refactor bookmark page JS into web component * Refactor global shortcuts JS into web component * Update tests * Add E2E test for partial updates * Add partial updates for archived bookmarks * Add partial updates for shared bookmarks * Cleanup helpers * Improve naming in bulk edit * Refactor shared components into behaviors * Refactor bulk edit components into behaviors * Refactor bookmark list components into behaviors * Update tests * Combine all scripts into bundle * Fix E2E CI
36 lines
928 B
JavaScript
36 lines
928 B
JavaScript
const behaviorRegistry = {};
|
|
|
|
export function registerBehavior(name, behavior) {
|
|
behaviorRegistry[name] = behavior;
|
|
applyBehaviors(document, [name]);
|
|
}
|
|
|
|
export function applyBehaviors(container, behaviorNames = null) {
|
|
if (!behaviorNames) {
|
|
behaviorNames = Object.keys(behaviorRegistry);
|
|
}
|
|
|
|
behaviorNames.forEach((behaviorName) => {
|
|
const behavior = behaviorRegistry[behaviorName];
|
|
const elements = container.querySelectorAll(`[${behaviorName}]`);
|
|
|
|
elements.forEach((element) => {
|
|
element.__behaviors = element.__behaviors || [];
|
|
const hasBehavior = element.__behaviors.some(
|
|
(b) => b instanceof behavior,
|
|
);
|
|
|
|
if (hasBehavior) {
|
|
return;
|
|
}
|
|
|
|
const behaviorInstance = new behavior(element);
|
|
element.__behaviors.push(behaviorInstance);
|
|
});
|
|
});
|
|
}
|
|
|
|
export function swap(element, html) {
|
|
element.innerHTML = html;
|
|
applyBehaviors(element);
|
|
}
|