assets
1 year ago
interfaces
1 year ago
block-asset.php
1 year ago
block-attributes.php
1 year ago
block-render.php
1 year ago
block-template.php
1 year ago
block.json
1 year ago
block-asset.php
119 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JFB_Compatibility\Jet_Engine\Blocks\Check_Mark; |
| 4 | |
| 5 | use Jet_Form_Builder\Blocks\Module; |
| 6 | use Jet_Form_Builder\Exceptions\Repository_Exception; |
| 7 | use JFB_Compatibility\Jet_Engine\Jet_Engine; |
| 8 | use JFB_Modules\Blocks_V2\Interfaces\Block_Asset_Interface; |
| 9 | |
| 10 | class Block_Asset implements Block_Asset_Interface { |
| 11 | |
| 12 | public function init_hooks() { |
| 13 | add_action( |
| 14 | 'enqueue_block_editor_assets', |
| 15 | array( $this, 'enqueue_editor_assets' ) |
| 16 | ); |
| 17 | add_action( |
| 18 | 'wp_enqueue_scripts', |
| 19 | array( $this, 'register_frontend_assets' ) |
| 20 | ); |
| 21 | add_action( |
| 22 | 'jet_plugins/frontend/register_scripts', |
| 23 | array( $this, 'register_frontend_assets' ) |
| 24 | ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @return void |
| 29 | * @throws Repository_Exception |
| 30 | */ |
| 31 | public function register_frontend_assets() { |
| 32 | $script_asset = require_once $this->get_dir( '/assets/build/frontend/radio.asset.php' ); |
| 33 | |
| 34 | if ( true === $script_asset ) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | array_push( |
| 39 | $script_asset['dependencies'], |
| 40 | 'jet-fb-radio-field' |
| 41 | ); |
| 42 | |
| 43 | wp_register_style( |
| 44 | $this->get_handle( 'check-mark' ), |
| 45 | $this->get_url( '/assets/build/frontend/main.css' ), |
| 46 | array(), |
| 47 | $script_asset['version'] |
| 48 | ); |
| 49 | |
| 50 | wp_register_script( |
| 51 | $this->get_handle( 'check-mark-radio' ), |
| 52 | $this->get_url( '/assets/build/frontend/radio.js' ), |
| 53 | $script_asset['dependencies'], |
| 54 | $script_asset['version'], |
| 55 | true |
| 56 | ); |
| 57 | |
| 58 | $script_asset = require_once $this->get_dir( '/assets/build/frontend/checkbox.asset.php' ); |
| 59 | |
| 60 | array_push( |
| 61 | $script_asset['dependencies'], |
| 62 | 'jet-fb-checkbox-field' |
| 63 | ); |
| 64 | |
| 65 | wp_register_script( |
| 66 | $this->get_handle( 'check-mark-checkbox' ), |
| 67 | $this->get_url( '/assets/build/frontend/checkbox.js' ), |
| 68 | $script_asset['dependencies'], |
| 69 | $script_asset['version'], |
| 70 | true |
| 71 | ); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @return void |
| 76 | */ |
| 77 | public function enqueue_editor_assets() { |
| 78 | $screen = get_current_screen(); |
| 79 | |
| 80 | if ( ! $screen || 'jet-engine' !== $screen->post_type ) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | $script_asset = require_once $this->get_dir( '/assets/build/editor.asset.php' ); |
| 85 | |
| 86 | wp_enqueue_script( |
| 87 | $this->get_handle( 'check-mark-editor' ), |
| 88 | $this->get_url( '/assets/build/editor.js' ), |
| 89 | $script_asset['dependencies'], |
| 90 | $script_asset['version'], |
| 91 | true |
| 92 | ); |
| 93 | } |
| 94 | |
| 95 | /** @noinspection PhpUnhandledExceptionInspection */ |
| 96 | private function get_dir( string $path = '' ): string { |
| 97 | /** @var Jet_Engine $compat */ |
| 98 | $compat = jet_form_builder()->compat( Jet_Engine::class ); |
| 99 | |
| 100 | return $compat->get_dir( 'blocks/check-mark' . $path ); |
| 101 | } |
| 102 | |
| 103 | /** @noinspection PhpUnhandledExceptionInspection */ |
| 104 | private function get_url( string $path ): string { |
| 105 | /** @var Jet_Engine $compat */ |
| 106 | $compat = jet_form_builder()->compat( Jet_Engine::class ); |
| 107 | |
| 108 | return $compat->get_url( 'blocks/check-mark' . $path ); |
| 109 | } |
| 110 | |
| 111 | /** @noinspection PhpUnhandledExceptionInspection */ |
| 112 | private function get_handle( string $prefix ): string { |
| 113 | /** @var Jet_Engine $compat */ |
| 114 | $compat = jet_form_builder()->compat( Jet_Engine::class ); |
| 115 | |
| 116 | return $compat->get_handle( $prefix ); |
| 117 | } |
| 118 | } |
| 119 |