@@ -17,8 +17,9 @@ class Pattern extends BasePattern {
17
17
static trigger = ".pat-navigation" ;
18
18
static parser = parser ;
19
19
20
+ parser_group_options = false ;
21
+
20
22
init ( ) {
21
- this . options = parser . parse ( this . el , this . options ) ;
22
23
this . $el = $ ( this . el ) ;
23
24
24
25
this . init_listeners ( ) ;
@@ -29,7 +30,7 @@ class Pattern extends BasePattern {
29
30
* Initialize listeners for the navigation.
30
31
*/
31
32
init_listeners ( ) {
32
- const current = this . options . currentClass ;
33
+ const current = this . options [ "current-class" ] ;
33
34
34
35
events . add_event_listener (
35
36
this . el ,
@@ -74,7 +75,7 @@ class Pattern extends BasePattern {
74
75
* Initial run to mark the current item and its parents.
75
76
*/
76
77
init_markings ( ) {
77
- if ( this . el . querySelector ( `.${ this . options . currentClass } ` ) ) {
78
+ if ( this . el . querySelector ( `.${ this . options [ "current-class" ] } ` ) ) {
78
79
log . debug ( "Mark navigation items based on existing current class" ) ;
79
80
this . mark_current ( ) ;
80
81
} else {
@@ -118,9 +119,9 @@ class Pattern extends BasePattern {
118
119
: this . el . querySelectorAll ( `.current > a, a.current` ) ;
119
120
120
121
for ( const item of current_els ) {
121
- item . classList . add ( this . options . currentClass ) ;
122
- const wrapper = item . closest ( this . options . itemWrapper ) ;
123
- wrapper ?. classList . add ( this . options . currentClass ) ;
122
+ item . classList . add ( this . options [ "current-class" ] ) ;
123
+ const wrapper = item . closest ( this . options [ "item-wrapper" ] ) ;
124
+ wrapper ?. classList . add ( this . options [ "current-class" ] ) ;
124
125
this . mark_in_path ( wrapper || item ) ;
125
126
log . debug ( "Statically set current item marked as current" , item ) ;
126
127
}
@@ -133,16 +134,16 @@ class Pattern extends BasePattern {
133
134
*
134
135
*/
135
136
mark_in_path ( start_el ) {
136
- let path_el = this . get_parent ( start_el , this . options . itemWrapper , this . el ) ;
137
+ let path_el = this . get_parent ( start_el , this . options [ "item-wrapper" ] , this . el ) ;
137
138
while ( path_el ) {
138
- if ( ! path_el . matches ( `.${ this . options . currentClass } ` ) ) {
139
- path_el . classList . add ( this . options . inPathClass ) ;
139
+ if ( ! path_el . matches ( `.${ this . options [ "current-class" ] } ` ) ) {
140
+ path_el . classList . add ( this . options [ "in-path-class" ] ) ;
140
141
for ( const it of [ ...path_el . children ] . filter ( ( it ) => it . matches ( "a" ) ) ) {
141
- it . classList . add ( this . options . inPathClass ) ;
142
+ it . classList . add ( this . options [ "in-path-class" ] ) ;
142
143
}
143
144
log . debug ( "Marked item as in-path" , path_el ) ;
144
145
}
145
- path_el = this . get_parent ( path_el , this . options . itemWrapper , this . el ) ;
146
+ path_el = this . get_parent ( path_el , this . options [ "item-wrapper" ] , this . el ) ;
146
147
}
147
148
}
148
149
@@ -166,11 +167,11 @@ class Pattern extends BasePattern {
166
167
new URL ( nav_item . getAttribute ( "href" , "" ) , current_url ) ?. href
167
168
) ;
168
169
169
- const wrapper = nav_item . closest ( this . options . itemWrapper ) ;
170
+ const wrapper = nav_item . closest ( this . options [ "item-wrapper" ] ) ;
170
171
171
172
if ( nav_url === current_url_prepared ) {
172
- nav_item . classList . add ( this . options . currentClass ) ;
173
- wrapper ?. classList . add ( this . options . currentClass ) ;
173
+ nav_item . classList . add ( this . options [ "current-class" ] ) ;
174
+ wrapper ?. classList . add ( this . options [ "current-class" ] ) ;
174
175
this . mark_in_path ( nav_item ) ;
175
176
} else if (
176
177
// Compare the current navigation item url with a slash at the
@@ -180,8 +181,8 @@ class Pattern extends BasePattern {
180
181
// be in the path.
181
182
nav_url !== portal_url
182
183
) {
183
- nav_item . classList . add ( this . options . inPathClass ) ;
184
- wrapper ?. classList . add ( this . options . inPathClass ) ;
184
+ nav_item . classList . add ( this . options [ "in-path-class" ] ) ;
185
+ wrapper ?. classList . add ( this . options [ "in-path-class" ] ) ;
185
186
} else {
186
187
// Not even in path.
187
188
continue ;
@@ -194,11 +195,11 @@ class Pattern extends BasePattern {
194
195
*/
195
196
clear_items ( ) {
196
197
const items = this . el . querySelectorAll (
197
- `.${ this . options . inPathClass } , .${ this . options . currentClass } `
198
+ `.${ this . options [ "in-path-class" ] } , .${ this . options [ "current-class" ] } `
198
199
) ;
199
200
for ( const item of items ) {
200
- item . classList . remove ( this . options . inPathClass ) ;
201
- item . classList . remove ( this . options . currentClass ) ;
201
+ item . classList . remove ( this . options [ "in-path-class" ] ) ;
202
+ item . classList . remove ( this . options [ "current-class" ] ) ;
202
203
}
203
204
}
204
205
0 commit comments