Skip to content

Commit 493e1be

Browse files
committed
pat calendar: Support on events with a URL via set to .
1 parent 5bd0ccb commit 493e1be

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
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.
4142
- pat tooltip: Use tippy v6 based implementation.
4243
- pat tooltip: Introduce new option ``arrowPadding`` to define the padding of the box arrow from the corners of the tooltip.

src/pat/calendar/calendar.js

Lines changed: 11 additions & 0 deletions
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);
@@ -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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,44 @@ describe("Calendar tests", () => {
303303
done();
304304
});
305305

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