1
1
import $ from "jquery" ;
2
- import Base from "../../core/base " ;
2
+ import { BasePattern } from "../../core/basepattern " ;
3
3
import logging from "../../core/logging" ;
4
4
import Parser from "../../core/parser" ;
5
5
import events from "../../core/events" ;
@@ -54,14 +54,15 @@ parser.addArgument("url", null);
54
54
// onAfterUpdate
55
55
// onDestroy
56
56
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 ;
60
61
61
- tippy : null ,
62
+ tippy = null ;
62
63
63
- active_class : "tooltip-active-hover" ,
64
- inactive_class : "tooltip-inactive" ,
64
+ active_class = "tooltip-active-hover" ;
65
+ inactive_class = "tooltip-inactive" ;
65
66
66
67
async init ( ) {
67
68
const el = this . el ;
@@ -70,8 +71,6 @@ export default Base.extend({
70
71
import ( "tippy.js/dist/tippy.css" ) ;
71
72
}
72
73
const Tippy = ( await import ( "tippy.js" ) ) . default ;
73
-
74
- this . options = parser . parse ( el , this . options ) ;
75
74
this . tippy_options = this . parseOptionsForTippy ( this . options ) ;
76
75
77
76
const defaultProps = {
@@ -116,25 +115,25 @@ export default Base.extend({
116
115
// Initially mark as inactive
117
116
el . classList . add ( this . inactive_class ) ;
118
117
}
119
- } ,
118
+ }
120
119
121
120
show ( ) {
122
121
// Show this tooltip
123
122
// API method.
124
123
this . tippy . show ( ) ;
125
- } ,
124
+ }
126
125
127
126
async hide ( ) {
128
127
// Hide this tooltip
129
128
await utils . timeout ( 1 ) ; // wait a tick for event being processed by other handlers.
130
129
this . tippy . hide ( ) ;
131
- } ,
130
+ }
132
131
133
132
destroy ( ) {
134
133
// Remove this tooltip
135
134
// API method.
136
135
this . tippy . destroy ( ) ;
137
- } ,
136
+ }
138
137
139
138
parseOptionsForTippy ( opts ) {
140
139
const placement = ( pos ) => {
@@ -253,12 +252,12 @@ export default Base.extend({
253
252
}
254
253
255
254
return tippy_options ;
256
- } ,
255
+ }
257
256
258
257
_initialize_content ( ) {
259
258
// Initialize any other patterns.
260
259
registry . scan ( this . tippy . popper ) ;
261
- } ,
260
+ }
262
261
263
262
async _onShow ( ) {
264
263
const tippy_classes = [ ] ;
@@ -322,7 +321,7 @@ export default Base.extend({
322
321
] ) ;
323
322
324
323
this . _initialize_content ( ) ;
325
- } ,
324
+ }
326
325
327
326
_onHide ( ) {
328
327
if ( this . options . markInactive ) {
@@ -338,7 +337,7 @@ export default Base.extend({
338
337
if ( this . options . source === "ajax" ) {
339
338
this . tippy . setContent ( document . createElement ( "progress" ) ) ;
340
339
}
341
- } ,
340
+ }
342
341
343
342
async _get_content ( url = this . options . url ) {
344
343
let selector ;
@@ -369,13 +368,13 @@ export default Base.extend({
369
368
await utils . timeout ( 1 ) ; // Wait a tick before forceUpdate. Might fail due to unset popperInstance.
370
369
this . tippy . popperInstance . forceUpdate ( ) ; // re-position tippy after content is known.
371
370
}
372
- } ,
371
+ }
373
372
374
373
async get_content ( url = this . options . url ) {
375
374
// API method: _get_content + _initialize_content
376
375
await this . _get_content ( url ) ;
377
376
this . _initialize_content ( ) ;
378
- } ,
377
+ }
379
378
380
379
get_url_parts ( href ) {
381
380
// Return the URL and a CSS ID selector.
@@ -392,9 +391,9 @@ export default Base.extend({
392
391
url = `${ url } ?${ query } ` ;
393
392
}
394
393
return { url, selector } ;
395
- } ,
394
+ }
396
395
397
- _ajaxDataTypeHandlers : {
396
+ _ajaxDataTypeHandlers = {
398
397
html ( text , url , selector ) {
399
398
let tmp = document . createElement ( "div" ) ;
400
399
tmp . innerHTML = text ;
@@ -414,5 +413,9 @@ export default Base.extend({
414
413
const ret = await pat . renderForInjection ( cfg , text ) ;
415
414
return ret [ 0 ] ;
416
415
} ,
417
- } ,
418
- } ) ;
416
+ } ;
417
+ }
418
+
419
+ registry . register ( Pattern ) ;
420
+ export default Pattern ;
421
+ export { Pattern } ;
0 commit comments