Skip to content

Commit 6c1b25d

Browse files
authored
Merge pull request #268 from newfold-labs/fix/link-prefetch
Fix Link Prefetch Not Respecting Capabilities
2 parents 7c10411 + 887cbad commit 6c1b25d

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

includes/LinkPrefetch/LinkPrefetch.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,31 @@ public function __construct( Container $container ) {
100100
* @return array Modified runtime object.
101101
*/
102102
public function add_to_runtime( $sdk ) {
103+
$current_settings = get_option( self::$option_name, false );
103104

104-
self::$default_settings['behavior'] = $this::$has_link_prefetch_click && $this::$has_link_prefetch_hover ? 'mouseHover' : 'mouseDown';
105+
if ( false === $current_settings ) {
106+
if ( $this::$has_link_prefetch_click || $this::$has_link_prefetch_hover ) {
107+
self::$default_settings['activeOnDesktop'] = true;
108+
self::$default_settings['activeOnMobile'] = true;
109+
}
105110

106-
$values = array(
107-
'settings' => get_option( self::$option_name, self::$default_settings ),
111+
if ( $this::$has_link_prefetch_click ) {
112+
self::$default_settings['behavior'] = 'mouseDown';
113+
self::$default_settings['mobileBehavior'] = 'touchstart';
114+
}
115+
116+
if ( $this::$has_link_prefetch_hover ) {
117+
self::$default_settings['behavior'] = 'mouseHover';
118+
self::$default_settings['mobileBehavior'] = 'viewport';
119+
}
120+
121+
$current_settings = self::$default_settings;
122+
}
123+
124+
return array_merge(
125+
$sdk,
126+
array( 'linkPrefetch' => array( 'settings' => $current_settings ) )
108127
);
109-
return array_merge( $sdk, array( 'linkPrefetch' => $values ) );
110128
}
111129

112130
/**

0 commit comments

Comments
 (0)