MCPcopy Create free account
hub / github.com/TomDoesTech/GOTTH / getRespCodeTarget

Function getRespCodeTarget

static/script/response-targets.js:17–62  ·  view source on GitHub ↗

* @param {HTMLElement} elt * @param {number} respCode * @returns {HTMLElement | null}

(elt, respCodeNumber)

Source from the content-addressed store, hash-verified

15 * @returns {HTMLElement | null}
16 */
17 function getRespCodeTarget(elt, respCodeNumber) {
18 if (!elt || !respCodeNumber) return null;
19
20 var respCode = respCodeNumber.toString();
21
22 // '*' is the original syntax, as the obvious character for a wildcard.
23 // The 'x' alternative was added for maximum compatibility with HTML
24 // templating engines, due to ambiguity around which characters are
25 // supported in HTML attributes.
26 //
27 // Start with the most specific possible attribute and generalize from
28 // there.
29 var attrPossibilities = [
30 respCode,
31
32 respCode.substr(0, 2) + '*',
33 respCode.substr(0, 2) + 'x',
34
35 respCode.substr(0, 1) + '*',
36 respCode.substr(0, 1) + 'x',
37 respCode.substr(0, 1) + '**',
38 respCode.substr(0, 1) + 'xx',
39
40 '*',
41 'x',
42 '***',
43 'xxx',
44 ];
45 if (startsWith(respCode, '4') || startsWith(respCode, '5')) {
46 attrPossibilities.push('error');
47 }
48
49 for (var i = 0; i < attrPossibilities.length; i++) {
50 var attr = attrPrefix + attrPossibilities[i];
51 var attrValue = api.getClosestAttributeValue(elt, attr);
52 if (attrValue) {
53 if (attrValue === "this") {
54 return api.findThisElement(elt, attr);
55 } else {
56 return api.querySelectorExt(elt, attrValue);
57 }
58 }
59 }
60
61 return null;
62 }
63
64 /** @param {Event} evt */
65 function handleErrorFlag(evt) {

Callers 1

Calls 1

startsWithFunction · 0.85

Tested by

no test coverage detected