Skip to content

Commit cdf0193

Browse files
author
James R Glasgow
committed
Fixes #3 - Limiting the scop of 'once' to just the .c2pa-wrapper elements and the current context (the items added to the page)
1 parent df43c36 commit cdf0193

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

js/c2pa.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ import {
55
} from "https://cdn.jsdelivr.net/npm/[email protected]/+esm";
66
import "https://cdn.jsdelivr.net/npm/[email protected]/+esm";
77

8-
((Drupal, once) => {
8+
((Drupal, once, drupalSettings) => {
99
Drupal.behaviors.c2pa = {
10-
async attach() {
11-
once("init-c2pa", "html").forEach(async (element) => {
10+
async attach(context, settings) {
11+
once("init-c2pa", ".c2pa-wrapper", context).forEach(async (wrapper) => {
1212
const c2pa = await createC2pa({
1313
wasmSrc:
1414
"https://cdn.jsdelivr.net/npm/[email protected]/dist/assets/wasm/toolkit_bg.wasm",
1515
workerSrc:
1616
"https://cdn.jsdelivr.net/npm/[email protected]/dist/c2pa.worker.min.js",
1717
});
1818

19-
element.querySelectorAll(".c2pa-wrapper").forEach(async (wrapper) => {
20-
const image = wrapper.querySelector("img");
19+
wrapper.querySelectorAll("img").forEach(async (image) => {
2120
const result = await c2pa.read(image);
2221
const manifestStoreResult = await createL2ManifestStore(
2322
result.manifestStore
@@ -45,4 +44,4 @@ import "https://cdn.jsdelivr.net/npm/[email protected]/+esm";
4544
});
4645
},
4746
};
48-
})(Drupal, once);
47+
})(Drupal, once, drupalSettings);

0 commit comments

Comments
 (0)