Skip to content

Commit

Permalink
feat: Loading of assets in admin area.
Browse files Browse the repository at this point in the history
  • Loading branch information
danimalweb committed Jan 9, 2024
1 parent 4c7a074 commit bc34b74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 32 deletions.
26 changes: 3 additions & 23 deletions inc/lib/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,11 @@

namespace Tofino\Assets;

/**
* Load admin styles
*
* Register and enqueue the stylesheet used in the admin area.
* Filemtime added as a querystring to ensure correct version is sent to the client.
* Function added to both the login_head (Login page) and admin_head (Admin pages)
*
* @since 1.0.0
* @return void
*/
function admin_styles()
{
wp_register_style('tofino/css/admin', get_stylesheet_directory_uri() . '/dist/admin.css', [], false);
wp_enqueue_style('tofino/css/admin');
}
add_action('login_head', __NAMESPACE__ . '\\admin_styles');
add_action('admin_head', __NAMESPACE__ . '\\admin_styles');


/**
* Main JS script
*
* Register and enqueue the mains js used in front end.
* Filemtime added as a querystring to ensure correct version is sent to the client.
*
* @since 1.1.0
* @return void
Expand Down Expand Up @@ -93,18 +74,17 @@ function localize_scripts()
/**
* Load admin scripts
*
* Register and enqueue the scripts used in the admin area.
* Filemtime added as a querystring to ensure correct version is sent to the client.
* Register and enqueue the scripts and css used in the admin area.
*
* @since 1.0.0
* @return void
*/
function admin_scripts()
{
wp_register_script('tofino/js/admin', get_stylesheet_directory_uri() . '/dist/admin.js', [], null);
wp_enqueue_script('tofino/js/admin');
\Tofino\Vite::useVite('js/admin.ts');
}
add_action('admin_enqueue_scripts', __NAMESPACE__ . '\\admin_scripts');
add_action('login_head', __NAMESPACE__ . '\\admin_scripts');


/**
Expand Down
18 changes: 9 additions & 9 deletions inc/lib/clean.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,17 @@ function remove_extra_markup()


// Defer scripts
if (!is_admin() && $GLOBALS['pagenow'] != 'wp-login.php') {
function add_defer_attribute($tag, $handle)
{
if ($handle === 'tofino' || $handle === 'form-builder') {
return str_replace('script src', 'script type="module" src', $tag);
} else {
return str_replace(' src', ' defer src', $tag);
}
function add_defer_attribute($tag, $handle)
{
if (str_starts_with($handle, 'tofino') || $handle === 'form-builder') {
return str_replace('script src', 'script type="module" src', $tag);
} else if (!is_admin() && $GLOBALS['pagenow'] != 'wp-login.php') {
return str_replace(' src', ' defer src', $tag);
} else {
return $tag;
}
add_filter('script_loader_tag', __NAMESPACE__ . '\\add_defer_attribute', 10, 2);
}
add_filter('script_loader_tag', __NAMESPACE__ . '\\add_defer_attribute', 10, 2);


// Clean nav classes
Expand Down

0 comments on commit bc34b74

Please sign in to comment.