Skip to content

Commit 7241dec

Browse files
authored
Merge pull request #806 from Patternslib/thet-cal-injectonlyifurl
pat-calendar: pat-inject is only set event has a url.
2 parents 8613b70 + 23198b4 commit 7241dec

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

CHANGES.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
- pat calendar: Store the current date and view in query parameters.
3636
- pat calendar: Fetch events from the backend.
3737
- pat calendar: Allow filtering/hiding events based in comparing the checkbox id with the classes of the displayed events.
38-
- pat calendar: Support injection of events when clicking on and event rather than redirecting to them.
39-
Done by adding `pat-inject` to rendered events via some configuration options.
38+
- pat calendar: Support `pat-inject` on events with a URL via `pat-inject-source` and `pat-inject-target` configuration options.
4039
- pat calendar: Support `pat-switch` for rendered events via some configuration options.
4140
- pat calendar: Store view, date and active categories per URL, allowing to individually customize the calendar per page.
4241
- pat tooltip: Use tippy v6 based implementation.

src/pat/calendar/calendar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ export default Base.extend({
329329
// pat-inject support
330330
const source = this.options.pat["inject-source"];
331331
const target = this.options.pat["inject-target"];
332-
if (source || target) {
332+
if (args.event.url && (source || target)) {
333+
// Only set pat-inject if event has a url
333334
args.el.classList.add("pat-inject");
334335
args.el.setAttribute(
335336
"data-pat-inject",

src/pat/calendar/calendar.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ describe("Calendar tests", () => {
257257
});
258258

259259
it("Loads events and initializes them with pat-inject and pat-switch", async (done) => {
260+
// pat-inject is only set if event has a url.
260261
const el = document.querySelector(".pat-calendar");
261262
el.setAttribute(
262263
"data-pat-calendar",
@@ -282,19 +283,19 @@ describe("Calendar tests", () => {
282283

283284
console.log(event3.outerHTML);
284285

285-
expect(event1.classList.contains("pat-inject")).toBe(true);
286+
expect(event1.classList.contains("pat-inject")).toBe(false);
286287
expect(event1.classList.contains("pat-switch")).toBe(true);
287-
expect(event1.getAttribute("data-pat-inject")).toBe("target: #event-info; source: #document-body"); // prettier-ignore
288+
expect(event1.hasAttribute("data-pat-inject")).toBe(false);
288289
expect(event1.getAttribute("data-pat-switch")).toBe("selector: #event-info; add: event-info--active; remove: event-info--inactive"); // prettier-ignore
289290

290291
expect(event2.classList.contains("pat-inject")).toBe(true);
291292
expect(event2.classList.contains("pat-switch")).toBe(true);
292293
expect(event2.getAttribute("data-pat-inject")).toBe("target: #event-info; source: #document-body"); // prettier-ignore
293294
expect(event2.getAttribute("data-pat-switch")).toBe("selector: #event-info; add: event-info--active; remove: event-info--inactive"); // prettier-ignore
294295

295-
expect(event3.classList.contains("pat-inject")).toBe(true);
296+
expect(event3.classList.contains("pat-inject")).toBe(false);
296297
expect(event3.classList.contains("pat-switch")).toBe(true);
297-
expect(event3.getAttribute("data-pat-inject")).toBe("target: #event-info; source: #document-body"); // prettier-ignore
298+
expect(event3.hasAttribute("data-pat-inject")).toBe(false);
298299
expect(event3.getAttribute("data-pat-switch")).toBe("selector: #event-info; add: event-info--active; remove: event-info--inactive"); // prettier-ignore
299300

300301
global.fetch.mockClear();

0 commit comments

Comments
 (0)