PageSourceSearch

https://www.dcbib.dk/modules/custom/dpl_react/js/handler.js?tm868m

js dcbib.dk collected 2026-10-02 18:44:16 UTC 1,838 bytes, 60 lines download raw bytes

1(function dplReact(Drupal) {
2  // Behaviors might be called with a DOM element (document on page
3  // load) or a jQuery object (on AJAX load). DPL React expects a DOM
4  // element with querySelectorAll, so this tries to do the right
5  // thing.
6  const getElement = function getElement(element) {
7    if (typeof element.querySelectorAll !== 'function') {
8      element = element[0] || element;
9    }
10
11    if (typeof element.querySelectorAll !== 'function') {
12      return null;
13    }
14
15    return element;
16  };
17
18  // Simplified port of jQuery DOMEval to vanilla JS.
19  // https://github.com/jquery/jquery/blob/3.6.0/src/core/DOMEval.js
20  const DOMEval = function DOMEval(code) {
21    const doc = document;
22    const script = doc.createElement('script');
23    script.text = code;
24    doc.head.appendChild(script).parentNode.removeChild(script);
25  };
26
27  Drupal.behaviors.dplReactHandler = {
28    attach(context) {
29      const element = getElement(context);
30      if (element) {
31        // Port jQuery.ajax with dataType script to vanilla JS with Fetch API.
32        fetch('/dpl-react/user-tokens', {
33          headers: {
34            Accept:
35              'text/javascript, application/javascript, ' +
36              'application/ecmascript, application/x-ecmascript',
37          },
38        })
39          .then((response) => {
40            if (!response.ok) {
41              throw new Error(
42                `HTTP error response: ${response.status} - ${response.statusText}`,
43              );
44            }
45            return response.text();
46          })
47          .then((response) => {
48            DOMEval(response);
49            window.dplReact.mount(element);
50          });
51      }
52    },
53    detach(context) {
54      const element = getElement(context);
55      if (element) {
56        window.dplReact.unmount(element);
57      }
58    },
59  };
60})(Drupal);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.