From 9ddfd764ed79e1d776e515a2cd5d4676bf673523 Mon Sep 17 00:00:00 2001
From: Johannes Raggam
Date: Thu, 26 Nov 2026 00:02:49 +0100
Subject: [PATCH 1/2] pat-inject: Autoformat.
---
src/pat/inject/documentation.md | 6 +-
src/pat/inject/index.html | 949 +++++++++++++++-----------------
src/pat/inject/inject.js | 34 +-
src/pat/inject/inject.test.js | 144 ++---
4 files changed, 530 insertions(+), 603 deletions(-)
diff --git a/src/pat/inject/documentation.md b/src/pat/inject/documentation.md
index d439ac896..2eb10504d 100644
--- a/src/pat/inject/documentation.md
+++ b/src/pat/inject/documentation.md
@@ -302,9 +302,9 @@ after:
Next month
- …
+ …
- …
+ …
### Modals
@@ -332,7 +332,7 @@ After injection was triggered:
-### Configurable error pages.
+### Configurable error pages
In cases of AJAX errors, you can provide custom error pages by providing custom meta tags.
For example, if you add this meta tag to the html ``:
diff --git a/src/pat/inject/index.html b/src/pat/inject/index.html
index 179b64565..0c70c464e 100644
--- a/src/pat/inject/index.html
+++ b/src/pat/inject/index.html
@@ -1,580 +1,505 @@
-
- Injection pattern
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+ Injection pattern
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
In this example, a
- Single HTML source
+ Single HTML source
is used for various injections.
-
-
+
-
-
-
-
- ?
-
-
-
-
- ?
-
-
-
-
- ?
-
-
-
+
+
+ I am visible now
+
+
+
+
+
+
+
+ ?
+
-
-
- Inject and scroll demos
-
+
+
+
+ Inject and scroll demos
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+
-
-
-
-
- Like
-
-
-
- Dislike
-
-
-
-
+
+
+
+
+
+ Like
+
+
+
+ Dislike
+
+
+
+ Like
-
+ data-pat-inject="target: self::element"
+ >Like
+
-
-
+ Dislike
-
-
-
- Can replace itself
- Like
-
-
-
- Can replace itself when a button in a form
-
-
-
-
-
- Inject history example
-
- Inject some text and record the history
-
-
- here goes the injection
-
-
-
-
-
- Inject autosubmit with form using GET and POST
-
-
-
-
- here goes the injection
-
-
-
-
- Call something without injecting anything
-
+ data-pat-inject="target: self::element"
+ >Like
+
+
+
+
+ Inject history example
+
+ Inject some text and record the history
+
+
+ here goes the injection
+
+
+
+
+
+ Inject autosubmit with form using GET and POST
+
+
+
+
+ here goes the injection
+
+
+
+
+ Call something without injecting anything
+
You need to open your network inspector to actually validate
that the request is sent. It works if you see a call to
demo/backend-action.html in the list of requested items.
-
-
- Trigger something, but don't inject results
-
-
-
+
+
-
-
-
-
-
+
+
diff --git a/src/pat/inject/inject.js b/src/pat/inject/inject.js
index 0e75b6873..424d7a339 100644
--- a/src/pat/inject/inject.js
+++ b/src/pat/inject/inject.js
@@ -78,12 +78,12 @@ const inject = {
if (el.nodeName === "A" && $(cfgs[0].nextHref).length > 0) {
log.debug(
"Skipping as next href is anchor, which already exists",
- cfgs[0].nextHref
+ cfgs[0].nextHref,
);
// TODO: reconsider how the injection enters exhausted state
el.setAttribute(
"href",
- (window.location.href.split("#")[0] || "") + cfgs[0].nextHref
+ (window.location.href.split("#")[0] || "") + cfgs[0].nextHref,
);
return $el;
}
@@ -117,7 +117,7 @@ const inject = {
(e) => {
if (
e.submitter?.matches(
- "[type=submit], button:not([type=button]), [type=image]"
+ "[type=submit], button:not([type=button]), [type=image]",
)
) {
// make sure the submitting button is sent
@@ -125,7 +125,7 @@ const inject = {
ajax.onClickSubmit(e);
}
this.onTrigger(e);
- }
+ },
);
} else if (el?.matches(".pat-subform")) {
log.debug("Initializing subform with injection");
@@ -145,7 +145,7 @@ const inject = {
const delayed_trigger = (uuid_) => {
// Check if the element has been removed from the dom
const still_there = document.querySelector(
- `[data-pat-inject-uuid="${uuid_}"]`
+ `[data-pat-inject-uuid="${uuid_}"]`,
);
if (!still_there) {
return false;
@@ -159,7 +159,7 @@ const inject = {
};
window.setTimeout(
delayed_trigger.bind(null, uuid),
- cfgs[0].delay
+ cfgs[0].delay,
);
}
break;
@@ -472,7 +472,9 @@ const inject = {
const method = cfg.sourceMod === "content" ? "innerHTML" : "outerHTML";
// There might be multiple sources, so we need to loop over them.
// Access them with "innerHTML" or "outerHTML" depending on the sourceMod.
- const sources_string = [...$sources].map(source => source[method]).join("\n");
+ const sources_string = [...$sources]
+ .map((source) => source[method])
+ .join("\n");
wrapper.innerHTML = sources_string;
for (const img of wrapper.content.querySelectorAll("img")) {
@@ -483,7 +485,7 @@ const inject = {
(e) => {
$(e.currentTarget).trigger("pat-inject-content-loaded");
},
- { once: true }
+ { once: true },
);
}
}
@@ -562,7 +564,7 @@ const inject = {
const scroll_container = dom.find_scroll_container(
scroll_target,
null,
- window
+ window,
);
if (cfg.scroll === "top") {
@@ -573,7 +575,7 @@ const inject = {
}
el.dispatchEvent(
- new Event("pat-inject-success", { bubbles: true, cancelable: true })
+ new Event("pat-inject-success", { bubbles: true, cancelable: true }),
);
},
@@ -614,7 +616,7 @@ const inject = {
sources$[idx1],
cfg,
ev.target,
- $title
+ $title,
);
}
}
@@ -754,13 +756,13 @@ const inject = {
do_close_panel = false;
// Re-trigger close-panel event if it was caught while injection was in progress.
el.dispatchEvent(
- new Event("close-panel", { bubbles: true, cancelable: true })
+ new Event("close-panel", { bubbles: true, cancelable: true }),
);
}
});
$el.on("pat-ajax-error.pat-inject", this._onInjectError.bind(this, $el, cfgs));
$el.on("pat-ajax-success.pat-inject pat-ajax-error.pat-inject", () =>
- $el.removeData("pat-inject-triggered")
+ $el.removeData("pat-inject-triggered"),
);
// Prevent closing the panel while injection is in progress.
@@ -935,7 +937,7 @@ const inject = {
for (const [pattern_name, opts] of Object.entries(this._rebaseOptions)) {
for (const el_ of dom.querySelectorAllAndMe(
page,
- `[data-pat-${pattern_name}]`
+ `[data-pat-${pattern_name}]`,
)) {
const pattern = registry.patterns?.[pattern_name];
const pattern_parser = pattern?.parser;
@@ -962,7 +964,7 @@ const inject = {
if (changed) {
el_.setAttribute(
`data-pat-${pattern_name}`,
- JSON.stringify(options.length === 1 ? options[0] : options)
+ JSON.stringify(options.length === 1 ? options[0] : options),
);
}
}
@@ -1157,7 +1159,7 @@ $(document).on("patterns-injected.inject", async (ev, cfg, trigger, injected) =>
detail: {
injected: injected,
},
- })
+ }),
);
}
});
diff --git a/src/pat/inject/inject.test.js b/src/pat/inject/inject.test.js
index 9850a8821..9a0fa9d49 100644
--- a/src/pat/inject/inject.test.js
+++ b/src/pat/inject/inject.test.js
@@ -47,7 +47,7 @@ describe("pat-inject", function () {
describe("1 - The next-href argument", function () {
it("1.1 - allows you to specify the href to be applied to the clicked element after injection", async function () {
var $a = $(
- 'link '
+ 'link ',
);
var $div = $('
');
$("#lab").append($a).append($div);
@@ -98,7 +98,7 @@ describe("pat-inject", function () {
it("2.2 - can be set to another string value which then gets added to the target while content is still loading'", async function () {
const spy_ajax = jest.spyOn($, "ajax").mockImplementation(() => deferred);
var $a = $(
- 'link '
+ 'link ',
);
var $div = $('
');
$("#lab").empty().append($a).append($div);
@@ -123,7 +123,7 @@ describe("pat-inject", function () {
it("2.3 - can be set to an empty string value so that nothing gets added to the target while content is still loading'", async function () {
const spy_ajax = jest.spyOn($, "ajax");
var $a = $(
- 'link '
+ 'link ',
);
var $div = $('
');
$("#lab").empty().append($a).append($div);
@@ -173,7 +173,7 @@ describe("pat-inject", function () {
it("3.2 - can be set to 'never' to never ask for confirmation", async function () {
var $a = $(
- 'link '
+ 'link ',
);
var $div = $('
');
$("#lab").empty().append($a).append($div);
@@ -200,7 +200,7 @@ describe("pat-inject", function () {
it("3.3 - can be set to 'always' to always ask for confirmation before injecting", async function () {
var $a = $(
- 'link '
+ 'link ',
);
var $div = $('
');
$("#lab").empty().append($a).append($div);
@@ -227,7 +227,7 @@ describe("pat-inject", function () {
it("3.4 - can be set to 'form-data' to ask for confirmation before injecting over form fields changed by the user", async function () {
var $a = $(
- 'link '
+ 'link ',
);
var $div = $('');
$("#lab").empty().append($a).append($div);
@@ -261,7 +261,7 @@ describe("pat-inject", function () {
describe("3.5 - The confirm-message argument", function () {
it("3.5.1 - can be used to provide a custom confirmation prompt message", async function () {
var $a = $(
- 'link '
+ 'link ',
);
var $div = $('
');
$("#lab").empty().append($a).append($div);
@@ -291,7 +291,7 @@ describe("pat-inject", function () {
describe("4 - rebaseURL", function () {
it("4.1 - Keep URL with scheme", function () {
expect(
- pattern._rebaseURL("http://example.com/foo/", "http://other.com/me")
+ pattern._rebaseURL("http://example.com/foo/", "http://other.com/me"),
).toBe("http://other.com/me");
});
@@ -301,13 +301,13 @@ describe("pat-inject", function () {
it("4.3 - Rebase to base with filename", function () {
expect(
- pattern._rebaseURL("http://example.com/foo/index.html", "me/page.html")
+ pattern._rebaseURL("http://example.com/foo/index.html", "me/page.html"),
).toBe("http://example.com/foo/me/page.html");
});
it("4.4 - Rebase to base with directory path", function () {
expect(pattern._rebaseURL("http://example.com/foo/", "me/page.html")).toBe(
- "http://example.com/foo/me/page.html"
+ "http://example.com/foo/me/page.html",
);
});
@@ -315,7 +315,7 @@ describe("pat-inject", function () {
expect(
pattern
._rebaseURL("/foo/", "me/page.html")
- .indexOf("/foo/me/page.html") > 0
+ .indexOf("/foo/me/page.html") > 0,
).toBe(true);
});
@@ -323,7 +323,7 @@ describe("pat-inject", function () {
expect(
pattern
._rebaseURL("example.com/foo/", "me/page.html")
- .indexOf("example.com/foo/me/page.html") > 0
+ .indexOf("example.com/foo/me/page.html") > 0,
).toBe(true);
});
@@ -331,8 +331,8 @@ describe("pat-inject", function () {
expect(
pattern._rebaseURL(
"http://example.com/foo/",
- "data:image-base64gibberish"
- )
+ "data:image-base64gibberish",
+ ),
).toBe("data:image-base64gibberish");
});
});
@@ -342,27 +342,27 @@ describe("pat-inject", function () {
expect(
pattern._rebaseHTML(
"base",
- "\nThis is a simple test
"
- )
+ "\nThis is a simple test
",
+ ),
).toBe("This is a simple test
");
});
it("5.2 - Basic markup", function () {
expect(
- pattern._rebaseHTML("base", "This is a simple test
")
+ pattern._rebaseHTML("base", "This is a simple test
"),
).toBe("This is a simple test
");
});
it("5.3 - Recover from unclosed tags", function () {
expect(pattern._rebaseHTML("base", "This is a simple test
")).toBe(
- "This is a simple test
"
+ "This is a simple test
",
);
});
it("5.4 - Anchor element without href attribute", function () {
var spy_rebaseURL = jest.spyOn(pattern, "_rebaseURL");
expect(pattern._rebaseHTML("base", "This is a test ")).toBe(
- "This is a test "
+ "This is a test ",
);
expect(spy_rebaseURL).not.toHaveBeenCalled();
@@ -373,10 +373,10 @@ describe("pat-inject", function () {
expect(
pattern._rebaseHTML(
"http://example.com/test/",
- 'This is a test '
- )
+ 'This is a test ',
+ ),
).toBe(
- 'This is a test '
+ 'This is a test ',
);
});
@@ -384,16 +384,16 @@ describe("pat-inject", function () {
expect(
pattern._rebaseHTML(
"http://example.com/test/",
- 'This is a test '
- )
+ 'This is a test ',
+ ),
).toBe(
- 'This is a test '
+ 'This is a test ',
);
});
it("5.7 - Check if image is rebased correctly", function () {
expect(
- pattern._rebaseHTML("http://example.com/test/", ' ')
+ pattern._rebaseHTML("http://example.com/test/", ' '),
).toBe(' ');
});
@@ -401,8 +401,8 @@ describe("pat-inject", function () {
expect(
pattern._rebaseHTML(
"base",
- "This string has src = \"foo\" , src= bar , and SrC='foo'
"
- )
+ "This string has src = \"foo\" , src= bar , and SrC='foo'
",
+ ),
).toBe("This string has src = \"foo\" , src= bar , and SrC='foo'
");
});
@@ -420,7 +420,7 @@ describe("pat-inject", function () {
data-pat-date-picker="i18n:./i18n"
data-pat-datetime-picker="i18n:./path/to/i18n"
data-pat-collapsible="load-content:../load/content/from/here"
- />`
+ />`,
);
const el = document.createElement("div");
@@ -466,7 +466,7 @@ describe("pat-inject", function () {
"/>
- `
+ `,
);
const el = document.createElement("div");
@@ -482,7 +482,7 @@ describe("pat-inject", function () {
expect(test1_config[0].source).toEqual("#one");
expect(test1_config[0].target).toEqual(".two");
expect(test1_config[1].url).toEqual(
- "https://example.com/test/./index2.html"
+ "https://example.com/test/./index2.html",
);
expect(test1_config[1].source).toEqual("#okay");
expect(test1_config[2]["loading-class"]).toEqual("some");
@@ -493,7 +493,7 @@ describe("pat-inject", function () {
const res = pattern._rebaseHTML(
"https://example.com/test/",
- '
'
+ '
',
);
const el = document.createElement("div");
@@ -839,7 +839,7 @@ describe("pat-inject", function () {
$a.trigger("click");
answer(
- 'new replacement
'
+ 'new replacement
',
);
await utils.timeout(1); // wait a tick for async to settle.
expect($div.html()).toBe("new replacement");
@@ -861,7 +861,7 @@ describe("pat-inject", function () {
"" +
'repl1
' +
'repl2
' +
- ""
+ "