Skip to content

Commit

Permalink
maint(pat-inject): Use create_uuid for generating the temporary autol…
Browse files Browse the repository at this point in the history
…oad uuid and remove it again afterwards.
  • Loading branch information
thet committed Jan 12, 2025
1 parent b0f94fb commit 8a3af53
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/pat/inject/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import events from "../../core/events";
import logging from "../../core/logging";
import Parser from "../../core/parser";
import registry from "../../core/registry";
import create_uuid from "../../core/uuid";
import utils from "../../core/utils";

const log = logging.getLogger("pat.inject");
Expand Down Expand Up @@ -136,26 +137,28 @@ const inject = {
if (!cfgs[0].delay) {
this.onTrigger({ currentTarget: el });
} else {
// generate UID
const uid = Math.random().toString(36);
el.setAttribute("data-pat-inject-uid", uid);
// generate UUID
const uuid = create_uuid();
el.setAttribute("data-pat-inject-uuid", uuid);

// function to trigger the autoload and mark as triggered
const delayed_trigger = (uid_) => {
const delayed_trigger = (uuid_) => {
// Check if the element has been removed from the dom
const still_there = document.querySelector(
`[data-pat-inject-uid="${uid_}"]`
`[data-pat-inject-uuid="${uuid_}"]`
);
if (!still_there) {
return false;
}

$el.data("pat-inject-autoloaded", true);
this.onTrigger({ currentTarget: el });
// Cleanup again.
still_there.removeAttribute("data-pat-inject-uuid");
return true;
};
window.setTimeout(
delayed_trigger.bind(null, uid),
delayed_trigger.bind(null, uuid),
cfgs[0].delay
);
}
Expand Down

0 comments on commit 8a3af53

Please sign in to comment.