Skip to content

Commit 132e463

Browse files
committed
fix: Make multi character instance work too
1 parent 368adcc commit 132e463

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

public/js/main.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ $( document ).ready( function() {
88

99
const $this = $( this );
1010
const url = $this.attr( 'href' );
11-
const params = new URL( url ).searchParams;
1211

1312
let instance, instanceSelector;
1413

15-
// Get LCP instance selector.
16-
params.forEach( ( value, key ) => {
17-
if ( 'lcp_page' === key.substring( 0, 8 ) ) {
18-
instance = key[ 8 ];
14+
// Get LCP instance info from the class that was added in PHP.
15+
e.delegateTarget.classList.forEach( ( cssClass ) => {
16+
if ( cssClass.startsWith( 'lcpax-instance-' ) ) {
17+
instance = cssClass.slice( 15 );
1918
instanceSelector = `#lcp_instance_${ instance }`;
2019
}
2120
} );
@@ -43,6 +42,13 @@ $( document ).ready( function() {
4342
const $wrapper = $( '<div class="lcpax-nextlink-wrapper"></div>' );
4443
const $spinner = $paginator.find( '.lcpax-spinner' );
4544

45+
// Add the instance class to the wrapper.
46+
this.classList.forEach( ( cssClass ) => {
47+
if ( cssClass.startsWith( 'lcpax-instance-' ) ) {
48+
$wrapper.addClass( cssClass );
49+
}
50+
} );
51+
4652
// Remove the title attr, should be removed from LCP anyway.
4753
$nextlink.removeAttr( 'title' );
4854

@@ -57,18 +63,17 @@ $( document ).ready( function() {
5763

5864
const $this = $( this );
5965
const url = $this.attr( 'href' );
60-
const params = new URL( url ).searchParams;
6166
const $spinner = $( e.delegateTarget ).find( '.lcpax-spinner' );
6267

6368
let instance, instanceSelector;
6469

6570
// Show the spinner.
6671
$spinner.css( 'display', 'inline' );
6772

68-
// Get LCP instance selector.
69-
params.forEach( ( value, key ) => {
70-
if ( 'lcp_page' === key.substring( 0, 8 ) ) {
71-
instance = key[ 8 ];
73+
// Get LCP instance info from the class that was added in PHP.
74+
e.delegateTarget.classList.forEach( ( cssClass ) => {
75+
if ( cssClass.startsWith( 'lcpax-instance-' ) ) {
76+
instance = cssClass.slice( 15 );
7277
instanceSelector = `#lcp_instance_${ instance }`;
7378
}
7479
} );

0 commit comments

Comments
 (0)