Skip to content

Commit

Permalink
fixed issue when exclude keywords is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
geckod22 committed Dec 16, 2024
1 parent f94146f commit dc9112c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion includes/LinkPrefetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function getDefaultSettings() {
'instantClick' => false,
'activeOnMobile' => false,
'mobileBehavior' => 'touchstart',
'ignoreKeywords' => 'wp-admin,#,?',
'ignoreKeywords' => '#,?',
);
}

Expand Down
12 changes: 9 additions & 3 deletions scripts/linkPrefetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ document.addEventListener( 'DOMContentLoaded', () => {
activeOnDesktop: config.activeOnDesktop,
behavior: config.behavior,
hoverDelay: parseInt( config.hoverDelay ) || 60,
ignoreKeywords: config.ignoreKeywords.split( ',' ),
ignoreKeywords: config.ignoreKeywords ? config.ignoreKeywords.split( ',' ) : '',
instantClick: config.instantClick,
mobileActive: config.activeOnMobile,
isMobile: config.isMobile,
Expand Down Expand Up @@ -138,13 +138,19 @@ document.addEventListener( 'DOMContentLoaded', () => {
if ( ! url || this.prefetchedUrls.has( url ) ) {
return false;
}

if (
url.replace( /\/$/, '' ) ===
location.href.replace( /\/$/, '' ) ||
this.ignoreKeywords.some( ( k ) => url.includes( k ) )
(
this.ignoreKeywords !== '' &&
this.ignoreKeywords.some( ( k ) => url.includes( k ) )
)

) {
return false;
}

return true;
}

Expand All @@ -164,7 +170,7 @@ document.addEventListener( 'DOMContentLoaded', () => {
instantClick: true,
activeOnMobile: true,
mobileBehavior: 'viewport',
ignoreKeywords: 'wp-admin,#,?',
ignoreKeywords: '#,?',
};

new LinkPrefetcher( config ).init();
Expand Down

0 comments on commit dc9112c

Please sign in to comment.