Skip to content

Commit

Permalink
moved inline styles to file and load it
Browse files Browse the repository at this point in the history
  • Loading branch information
geckod22 committed Nov 18, 2024
1 parent 5f18dca commit af2d843
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 22 deletions.
4 changes: 2 additions & 2 deletions components/linkPrefetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const LinkPrefetch = ({methods, constants}) => {
description={constants.text.linkPrefetchDescription}
>
{/* Desktop Settings */}
<div className="nfd-toggle-field nfd-mb-6" style={{display: 'flex', flexDirection:'row'}}>
<div className="nfd-toggle-field nfd-mb-6">
<div >
<label className="nfd-label" htmlFor="link-prefetch-active-desktop">{constants.text.linkPrefetchActivateOnDesktopLabel}</label>
<div className="nfd-select-field__description">
Expand Down Expand Up @@ -80,7 +80,7 @@ const LinkPrefetch = ({methods, constants}) => {
)
}
{/* Mobile Settings */}
<div className="nfd-toggle-field nfd-mb-6" style={{display: 'flex', flexDirection:'row'}}>
<div className="nfd-toggle-field nfd-mb-6">
<div >
<label className="nfd-label" htmlFor="link-prefetch-active-mobile">{constants.text.linkPrefetchActivateOnMobileLabel}</label>
<div className="nfd-select-field__description">
Expand Down
12 changes: 1 addition & 11 deletions includes/LinkPrefetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function add_to_runtime( $sdk ) {
* return void
*/
public function enqueueScripts() {
$plugin_url = $this->container->plugin()->url . $this->getScriptPath();
$plugin_url = $this->container->plugin()->url . get_scripts_path( 'linkPrefetch' );
$settings = get_option( 'nfd_link_prefetch_settings', static::getDefaultSettings() );

if ( ! $settings['activeOnDesktop'] && ! $settings['activeOnMobile'] ) {
Expand All @@ -60,16 +60,6 @@ public function enqueueScripts() {
wp_add_inline_script( 'linkprefetcher', 'window.LP_CONFIG = ' . wp_json_encode( $settings ), 'before' );
}

/**
* Get js script path.
*
* return string
*/
public function getScriptPath() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
return 'vendor/newfold-labs/wp-module-performance/scripts/linkPrefetch' . $suffix . '.js';
}

/**
* Get link prefetch default settings.
*
Expand Down
11 changes: 11 additions & 0 deletions includes/Performance.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public function __construct( Container $container ) {
$container->set( 'cachePurger', $cachePurger );

$container->set( 'hasMustUsePlugin', file_exists( WPMU_PLUGIN_DIR . '/endurance-page-cache.php' ) );

add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}

/**
Expand Down Expand Up @@ -293,4 +295,13 @@ public function adminBarMenu( \WP_Admin_Bar $wp_admin_bar ) {
);
}
}

/**
* Enqueue scripts and styles in admin
*/
public function enqueue_scripts() {
$plugin_url = $this->container->plugin()->url . get_styles_path();
wp_register_style( 'wp-module-performance-styles', $plugin_url );
wp_enqueue_style( 'wp-module-performance-styles' );
}
}
42 changes: 33 additions & 9 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ function getCacheLevel() {
* @return string[]
*/
function getCacheLevels() {
return [
return array(
0 => 'Off', // Disable caching
1 => 'Assets Only', // Cache assets only
2 => 'Normal', // Cache pages and assets for a shorter time range
3 => 'Advanced', // Cache pages and assets for a longer time range
];
);
}

/**
Expand All @@ -36,10 +36,10 @@ function getCacheLevelDropdown() {
$name = Performance::OPTION_CACHE_LEVEL;
$label = __( 'Cache Level', 'newfold-performance-module' );
?>
<select name="<?= esc_attr( $name ) ?>" aria-label="<?= esc_attr( $label ) ?>">
<?php foreach ( $cacheLevels as $cacheLevel => $optionLabel ): ?>
<option value="<?= absint( $cacheLevel ) ?>"<?php selected( $cacheLevel, $currentCacheLevel ) ?>>
<?= esc_html( $optionLabel ); ?>
<select name="<?php echo esc_attr( $name ); ?>" aria-label="<?php echo esc_attr( $label ); ?>">
<?php foreach ( $cacheLevels as $cacheLevel => $optionLabel ) : ?>
<option value="<?php echo absint( $cacheLevel ); ?>"<?php selected( $cacheLevel, $currentCacheLevel ); ?>>
<?php echo esc_html( $optionLabel ); ?>
</option>
<?php endforeach; ?>
</select>
Expand All @@ -65,10 +65,10 @@ function getSkip404InputField() {
?>
<input
type="checkbox"
name="<?= esc_attr( $name ) ?>"
name="<?php echo esc_attr( $name ); ?>"
value="1"
aria-label="<?= esc_attr( $label ) ?>"
<?php checked( $value, true ) ?>
aria-label="<?php echo esc_attr( $label ); ?>"
<?php checked( $value, true ); ?>
/>
<?php
}
Expand Down Expand Up @@ -134,3 +134,27 @@ function toSnakeCase( string $value, string $delimiter = '_' ) {
function toStudlyCase( $value ) {
return str_replace( ' ', '', ucwords( str_replace( array( '-', '_' ), ' ', $value ) ) );
}

/**
* Get styles path.
*
* return string
*/
function get_styles_path() {
return 'vendor/newfold-labs/wp-module-performance/styles/styles.css';
}

/**
* Get js script path.
*
* @param $string script name.
* return string
*/
function get_scripts_path( $script_name = '' ) {
$basePath = 'vendor/newfold-labs/wp-module-performance/scripts/';
if ( empty( $script_name ) ) {
return $basePath;
}
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
return "vendor/newfold-labs/wp-module-performance/scripts/$script_name$suffix.js";
}
4 changes: 4 additions & 0 deletions styles/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.nfd-container__block.newfold-link-prefetch .nfd-toggle-field.nfd-mb-6 {
display: flex;
flex-direction: row;
}

0 comments on commit af2d843

Please sign in to comment.