| 1 |
<?php |
| 2 |
|
| 3 |
namespace Booktics\Assets; |
| 4 |
|
| 5 |
/** |
| 6 |
* Manage all admin scripts and styles |
| 7 |
*/ |
| 8 |
class Admin_Assets extends Base_Assets { |
| 9 |
/** |
| 10 |
* Register single service |
| 11 |
* |
| 12 |
* @return void |
| 13 |
*/ |
| 14 |
public function register() { |
| 15 |
add_action( 'admin_enqueue_scripts', [ |
| 16 |
$this, |
| 17 |
'register_styles_scripts' |
| 18 |
] ); |
| 19 |
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Enqueue scripts and styles |
| 24 |
* |
| 25 |
* @return void |
| 26 |
*/ |
| 27 |
public function enqueue() { |
| 28 |
$screen = get_current_screen(); |
| 29 |
if ( $screen->base !== 'toplevel_page_booktics') { |
| 30 |
return; |
| 31 |
} |
| 32 |
wp_enqueue_style( 'wp-color-picker' ); |
| 33 |
wp_enqueue_style( 'booktics-admin-style' ); |
| 34 |
wp_enqueue_style( 'booktics-vendor' ); |
| 35 |
|
| 36 |
wp_enqueue_media(); |
| 37 |
wp_enqueue_script( 'booktics-flatpickr-scripts' ); |
| 38 |
wp_enqueue_script( 'booktics-packages' ); |
| 39 |
wp_enqueue_script( 'booktics-dashboard-scripts' ); |
| 40 |
|
| 41 |
wp_localize_script( 'booktics-packages', 'booktics', Localize::get_admin() ); |
| 42 |
wp_localize_script( 'booktics-packages', 'booktics_enabled_modules', booktics_get_enabled_modules() ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Get all scripts |
| 47 |
* |
| 48 |
* @return array List register scripts |
| 49 |
*/ |
| 50 |
public function get_scripts(): array { |
| 51 |
$scripts = [ |
| 52 |
'booktics-dashboard-scripts' => [ |
| 53 |
'src' => booktics()->assets_url . '/build/js/dashboard.js', |
| 54 |
'deps' => [ 'booktics-packages' ], |
| 55 |
'in_footer' => true, |
| 56 |
], |
| 57 |
'booktics-flatpickr-scripts' => [ |
| 58 |
'src' => booktics()->assets_url . '/js/vendors/flatpickr.js', |
| 59 |
'deps' => [], |
| 60 |
'in_footer' => true, |
| 61 |
], |
| 62 |
'booktics-packages' => [ |
| 63 |
'src' => booktics()->assets_url . '/build/js/packages.js', |
| 64 |
'deps' => [ |
| 65 |
'wp-api-fetch', |
| 66 |
'wp-components', |
| 67 |
'wp-compose', |
| 68 |
'wp-i18n' |
| 69 |
], |
| 70 |
'in_footer' => true, |
| 71 |
], |
| 72 |
]; |
| 73 |
|
| 74 |
return apply_filters( 'booktics_admin_assets', $scripts ); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* List of register styles |
| 79 |
* |
| 80 |
* @return array |
| 81 |
*/ |
| 82 |
public function get_styles(): array { |
| 83 |
$styles = [ |
| 84 |
'booktics-admin-style' => [ |
| 85 |
'src' => booktics()->assets_url . '/build/css/admin.css', |
| 86 |
], |
| 87 |
'booktics-vendor' => [ |
| 88 |
'src' => booktics()->assets_url . '/build/css/vendor.css', |
| 89 |
], |
| 90 |
]; |
| 91 |
|
| 92 |
return apply_filters( 'booktics_admin_styles', $styles ); |
| 93 |
} |
| 94 |
} |