Skip to content

Commit 4fdb12a

Browse files
committed
maint(pat-tooltip): Switch to class based pattern.
1 parent 554e32e commit 4fdb12a

File tree

2 files changed

+146
-138
lines changed

2 files changed

+146
-138
lines changed

src/pat/tooltip/tooltip.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import $ from "jquery";
2-
import Base from "../../core/base";
2+
import { BasePattern } from "../../core/basepattern";
33
import logging from "../../core/logging";
44
import Parser from "../../core/parser";
55
import events from "../../core/events";
@@ -54,14 +54,15 @@ parser.addArgument("url", null);
5454
// onAfterUpdate
5555
// onDestroy
5656

57-
export default Base.extend({
58-
name: "tooltip",
59-
trigger: ".pat-tooltip, .pat-tooltip-ng",
57+
class Pattern extends BasePattern {
58+
static name = "tooltip";
59+
static trigger = ".pat-tooltip, .pat-tooltip-ng";
60+
static parser = parser;
6061

61-
tippy: null,
62+
tippy = null;
6263

63-
active_class: "tooltip-active-hover",
64-
inactive_class: "tooltip-inactive",
64+
active_class = "tooltip-active-hover";
65+
inactive_class = "tooltip-inactive";
6566

6667
async init() {
6768
const el = this.el;
@@ -70,8 +71,6 @@ export default Base.extend({
7071
import("tippy.js/dist/tippy.css");
7172
}
7273
const Tippy = (await import("tippy.js")).default;
73-
74-
this.options = parser.parse(el, this.options);
7574
this.tippy_options = this.parseOptionsForTippy(this.options);
7675

7776
const defaultProps = {
@@ -116,25 +115,25 @@ export default Base.extend({
116115
// Initially mark as inactive
117116
el.classList.add(this.inactive_class);
118117
}
119-
},
118+
}
120119

121120
show() {
122121
// Show this tooltip
123122
// API method.
124123
this.tippy.show();
125-
},
124+
}
126125

127126
async hide() {
128127
// Hide this tooltip
129128
await utils.timeout(1); // wait a tick for event being processed by other handlers.
130129
this.tippy.hide();
131-
},
130+
}
132131

133132
destroy() {
134133
// Remove this tooltip
135134
// API method.
136135
this.tippy.destroy();
137-
},
136+
}
138137

139138
parseOptionsForTippy(opts) {
140139
const placement = (pos) => {
@@ -253,12 +252,12 @@ export default Base.extend({
253252
}
254253

255254
return tippy_options;
256-
},
255+
}
257256

258257
_initialize_content() {
259258
// Initialize any other patterns.
260259
registry.scan(this.tippy.popper);
261-
},
260+
}
262261

263262
async _onShow() {
264263
const tippy_classes = [];
@@ -322,7 +321,7 @@ export default Base.extend({
322321
]);
323322

324323
this._initialize_content();
325-
},
324+
}
326325

327326
_onHide() {
328327
if (this.options.markInactive) {
@@ -338,7 +337,7 @@ export default Base.extend({
338337
if (this.options.source === "ajax") {
339338
this.tippy.setContent(document.createElement("progress"));
340339
}
341-
},
340+
}
342341

343342
async _get_content(url = this.options.url) {
344343
let selector;
@@ -369,13 +368,13 @@ export default Base.extend({
369368
await utils.timeout(1); // Wait a tick before forceUpdate. Might fail due to unset popperInstance.
370369
this.tippy.popperInstance.forceUpdate(); // re-position tippy after content is known.
371370
}
372-
},
371+
}
373372

374373
async get_content(url = this.options.url) {
375374
// API method: _get_content + _initialize_content
376375
await this._get_content(url);
377376
this._initialize_content();
378-
},
377+
}
379378

380379
get_url_parts(href) {
381380
// Return the URL and a CSS ID selector.
@@ -392,9 +391,9 @@ export default Base.extend({
392391
url = `${url}?${query}`;
393392
}
394393
return { url, selector };
395-
},
394+
}
396395

397-
_ajaxDataTypeHandlers: {
396+
_ajaxDataTypeHandlers = {
398397
html(text, url, selector) {
399398
let tmp = document.createElement("div");
400399
tmp.innerHTML = text;
@@ -414,5 +413,9 @@ export default Base.extend({
414413
const ret = await pat.renderForInjection(cfg, text);
415414
return ret[0];
416415
},
417-
},
418-
});
416+
};
417+
}
418+
419+
registry.register(Pattern);
420+
export default Pattern;
421+
export { Pattern };

0 commit comments

Comments
 (0)