Skip to content

Commit

Permalink
fix: Make multi character instance work too
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-st committed Apr 22, 2021
1 parent 368adcc commit 132e463
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ $( document ).ready( function() {

const $this = $( this );
const url = $this.attr( 'href' );
const params = new URL( url ).searchParams;

let instance, instanceSelector;

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

// Add the instance class to the wrapper.
this.classList.forEach( ( cssClass ) => {
if ( cssClass.startsWith( 'lcpax-instance-' ) ) {
$wrapper.addClass( cssClass );
}
} );

// Remove the title attr, should be removed from LCP anyway.
$nextlink.removeAttr( 'title' );

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

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

let instance, instanceSelector;

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

// Get LCP instance selector.
params.forEach( ( value, key ) => {
if ( 'lcp_page' === key.substring( 0, 8 ) ) {
instance = key[ 8 ];
// Get LCP instance info from the class that was added in PHP.
e.delegateTarget.classList.forEach( ( cssClass ) => {
if ( cssClass.startsWith( 'lcpax-instance-' ) ) {
instance = cssClass.slice( 15 );
instanceSelector = `#lcp_instance_${ instance }`;
}
} );
Expand Down

0 comments on commit 132e463

Please sign in to comment.