Skip to content

Commit 2ddd459

Browse files
authored
Merge pull request #810 from Patternslib/calendar-tooltip
pat calendar: Support pat-tooltip
2 parents 5bd0ccb + d94bd94 commit 2ddd459

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
- pat calendar: Allow filtering/hiding events based in comparing the checkbox id with the classes of the displayed events.
3838
- pat calendar: Support `pat-inject` on events with a URL via `pat-inject-source` and `pat-inject-target` configuration options.
3939
- pat calendar: Support `pat-switch` for rendered events via some configuration options.
40+
- pat calendar: Support `pat-tooltip` on events with a URL via `pat-tooltip-source` set to `ajax`.
4041
- pat calendar: Store view, date and active categories per URL, allowing to individually customize the calendar per page.
42+
- pat calendar: Support `url` in the event JSON model additionally to `@id`.
43+
The unique identifier is often not semantically correct for a URL to the item, especially when we want to call a specific view.
4144
- pat tooltip: Use tippy v6 based implementation.
4245
- pat tooltip: Introduce new option ``arrowPadding`` to define the padding of the box arrow from the corners of the tooltip.
4346
- pat tooltip: set content when mounting to avoid positioning problems.

src/pat/calendar/calendar.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ parser.addArgument("event-sources", [], undefined, true);
6363
parser.addArgument("pat-inject-source", null);
6464
parser.addArgument("pat-inject-target", null);
6565

66+
// pat-tooltip support for individual events
67+
parser.addArgument("pat-tooltip-source", null, ["ajax", null]);
68+
6669
// pat-switch support for individual events
6770
parser.addArgument("pat-switch-selector", null);
6871
parser.addArgument("pat-switch-remove", null);
@@ -240,7 +243,7 @@ export default Base.extend({
240243
start: new Date(event.start),
241244
end: new Date(event.end),
242245
allDay: event.whole_day,
243-
url: event["@id"],
246+
url: event.url || event["@id"],
244247

245248
backgroundColor: event.color,
246249
borderColor: event.color,
@@ -339,6 +342,14 @@ export default Base.extend({
339342
do_scan = true;
340343
}
341344

345+
// pat-tooltip support
346+
if (args.event.url && this.options.pat["tooltip-source"] === "ajax") {
347+
// Only set pat-tooltip if event has a url
348+
args.el.classList.add("pat-tooltip");
349+
args.el.setAttribute("data-pat-tooltip", "source: ajax");
350+
do_scan = true;
351+
}
352+
342353
// pat-switch support
343354
const switch_sel = this.options.pat["switch-selector"];
344355
if (switch_sel) {

src/pat/calendar/calendar.test.js

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ const mockFetch = () =>
1919
"@id": "./test_event.html",
2020
},
2121
{
22-
title: "Event 3",
23-
start: "2020-10-14",
24-
end: "2020-10-16",
22+
"title": "Event 3",
23+
"start": "2020-10-14",
24+
"end": "2020-10-16",
25+
"@id": "./test_event.html",
26+
"url": "./@@test-event",
2527
},
2628
],
2729
}),
@@ -249,7 +251,7 @@ describe("Calendar tests", () => {
249251

250252
expect(event1.href).toBeFalsy();
251253
expect(event2.href).toBe("http://localhost/test_event.html");
252-
expect(event3.href).toBeFalsy();
254+
expect(event3.href).toBe("http://localhost/@@test-event");
253255

254256
global.fetch.mockClear();
255257
delete global.fetch;
@@ -293,16 +295,54 @@ describe("Calendar tests", () => {
293295
expect(event2.getAttribute("data-pat-inject")).toBe("target: #event-info; source: #document-body"); // prettier-ignore
294296
expect(event2.getAttribute("data-pat-switch")).toBe("selector: #event-info; add: event-info--active; remove: event-info--inactive"); // prettier-ignore
295297

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

301303
global.fetch.mockClear();
302304
delete global.fetch;
303305
done();
304306
});
305307

308+
it("Loads events and initializes them with pat-tooltip", async (done) => {
309+
// pat-inject is only set if event has a url.
310+
const el = document.querySelector(".pat-calendar");
311+
el.setAttribute(
312+
"data-pat-calendar",
313+
`initial-date: 2020-10-10;
314+
url: ./test.json;
315+
pat-tooltip-source: ajax;
316+
`
317+
);
318+
319+
global.fetch = jest.fn().mockImplementation(mockFetch);
320+
321+
registry.scan(document.body);
322+
await utils.timeout(1); // wait a tick for async to settle.
323+
324+
const events = [...document.querySelectorAll(".fc-event-title")];
325+
326+
const event1 = events.filter((it) => it.textContent === "Event 1")[0].closest(".fc-event"); // prettier-ignore
327+
const event2 = events.filter((it) => it.textContent === "Event 2")[0].closest(".fc-event"); // prettier-ignore
328+
const event3 = events.filter((it) => it.textContent === "Event 3")[0].closest(".fc-event"); // prettier-ignore
329+
330+
console.log(event3.outerHTML);
331+
332+
expect(event1.classList.contains("pat-tooltip")).toBe(false);
333+
expect(event1.hasAttribute("data-pat-tooltip")).toBe(false);
334+
335+
expect(event2.classList.contains("pat-tooltip")).toBe(true);
336+
expect(event2.getAttribute("data-pat-tooltip")).toBe("source: ajax"); // prettier-ignore
337+
338+
expect(event3.classList.contains("pat-tooltip")).toBe(true);
339+
expect(event3.getAttribute("data-pat-tooltip")).toBe("source: ajax"); // prettier-ignore
340+
341+
global.fetch.mockClear();
342+
delete global.fetch;
343+
done();
344+
});
345+
306346
it("Loads correct date if set in query string", async (done) => {
307347
const el = document.querySelector(".pat-calendar");
308348
el.setAttribute("data-pat-calendar", "timezone: Europe/Berlin");

src/pat/calendar/documentation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ The calendar can be configured through a `data-pat-calendar` attribute. The avai
6666
| `pat-switch-selector` | | CSS selector | Defines the element on which pat-select should operate on. | string |
6767
| `pat-switch-add` | | CSS class name | Defines the class name to be added. | string |
6868
| `pat-switch-remove` | | CSS class name | Defines the class name to be removed. | string |
69+
| `pat-tooltip-source` | null | null, "ajax" | If set to "ajax" and a URL is configured for an displayed event, it will open the url in a tooltip. | string |
6970

src/pat/calendar/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
55
<title>Demo page</title>
66
<link rel="stylesheet" href="/style/common.css" type="text/css">
7+
<link
8+
rel="stylesheet"
9+
href="../../../node_modules/tippy.js/dist/tippy.css"
10+
type="text/css"
11+
/>
712
<script
813
src="/dist/bundle.js"
914
type="text/javascript"
@@ -22,6 +27,7 @@
2227
event-color: fuchsia;
2328
pat-inject-target: #event-info;
2429
pat-inject-source: #document-body;
30+
pat-tooltip-source: ajax;
2531
pat-switch-selector: #event-info;
2632
pat-switch-remove: event-info--inactive;
2733
pat-switch-add: event-info--active;

0 commit comments

Comments
 (0)