| 1 |
<?php |
| 2 |
|
| 3 |
namespace JFB_Modules\Blocks_V2\Text_Field; |
| 4 |
|
| 5 |
use Jet_Form_Builder\Exceptions\Repository_Exception; |
| 6 |
use JFB_Components\Module\Base_Module_Handle_It; |
| 7 |
use JFB_Modules\Blocks_V2\Interfaces\Block_Asset_Interface; |
| 8 |
use JFB_Modules\Blocks_V2\Module; |
| 9 |
use Jet_Form_Builder\Blocks\Module as LegacyBlocksModule; |
| 10 |
|
| 11 |
class Block_Asset implements Block_Asset_Interface { |
| 12 |
|
| 13 |
public function init_hooks() { |
| 14 |
add_action( |
| 15 |
'jet-form-builder/editor-assets/before', |
| 16 |
array( $this, 'register_editor_styles' ) |
| 17 |
); |
| 18 |
add_action( |
| 19 |
'jet-form-builder/editor-assets/before', |
| 20 |
array( $this, 'enqueue_editor_assets' ) |
| 21 |
); |
| 22 |
add_action( |
| 23 |
'wp_enqueue_scripts', |
| 24 |
array( $this, 'register_frontend_assets' ) |
| 25 |
); |
| 26 |
add_action( |
| 27 |
'jet_plugins/frontend/register_scripts', |
| 28 |
array( $this, 'register_frontend_assets' ) |
| 29 |
); |
| 30 |
add_filter( |
| 31 |
'jet-form-builder/before-end-form', |
| 32 |
array( $this, 'enqueue_required_assets' ) |
| 33 |
); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
|
| 38 |
* @throws Repository_Exception |
| 39 |
*/ |
| 40 |
public function register_editor_styles() { |
| 41 |
/** @var Module $blocks_v2 */ |
| 42 |
$blocks_v2 = jet_form_builder()->module( 'blocks-v2' ); |
| 43 |
$asset = require $blocks_v2->get_dir( 'text-field/assets/build/editor.asset.php' ); |
| 44 |
wp_register_style( |
| 45 |
$blocks_v2->get_handle( 'text-field-editor-style' ), |
| 46 |
$blocks_v2->get_url( 'text-field/assets/build/editor.css' ), |
| 47 |
array(), |
| 48 |
$asset['version'] . 'afd' |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* @throws Repository_Exception |
| 54 |
*/ |
| 55 |
public function register_frontend_assets() { |
| 56 |
/** @var Module $blocks_v2 */ |
| 57 |
$blocks_v2 = jet_form_builder()->module( 'blocks-v2' ); |
| 58 |
$asset = require $blocks_v2->get_dir( 'text-field/assets/build/frontend/field.asset.php' ); |
| 59 |
|
| 60 |
if ( true === $asset ) { |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
$asset['dependencies'][] = LegacyBlocksModule::MAIN_SCRIPT_HANDLE; |
| 65 |
|
| 66 |
wp_register_script( |
| 67 |
$blocks_v2->get_handle( 'text-field' ), |
| 68 |
$blocks_v2->get_url( 'text-field/assets/build/frontend/field.js' ), |
| 69 |
$asset['dependencies'], |
| 70 |
$asset['version'], |
| 71 |
true |
| 72 |
); |
| 73 |
|
| 74 |
wp_register_style( |
| 75 |
$blocks_v2->get_handle( 'text-field' ), |
| 76 |
$blocks_v2->get_url( 'text-field/assets/build/frontend/field.css' ), |
| 77 |
array(), |
| 78 |
$asset['version'] |
| 79 |
); |
| 80 |
|
| 81 |
$asset_mask = require $blocks_v2->get_dir( 'text-field/assets/build/frontend/field.mask.asset.php' ); |
| 82 |
|
| 83 |
$asset_mask['dependencies'][] = LegacyBlocksModule::MAIN_SCRIPT_HANDLE; |
| 84 |
$asset_mask['dependencies'][] = 'jet-form-builder-inputmask'; |
| 85 |
|
| 86 |
wp_register_script( |
| 87 |
'jet-form-builder-inputmask', |
| 88 |
$blocks_v2->get_url( 'text-field/assets/lib/jquery.inputmask.min.js' ), |
| 89 |
array( 'jquery' ), |
| 90 |
$asset_mask['version'], |
| 91 |
true |
| 92 |
); |
| 93 |
|
| 94 |
wp_register_script( |
| 95 |
$blocks_v2->get_handle( 'text-field-mask' ), |
| 96 |
$blocks_v2->get_url( 'text-field/assets/build/frontend/field.mask.js' ), |
| 97 |
$asset_mask['dependencies'], |
| 98 |
$asset_mask['version'], |
| 99 |
true |
| 100 |
); |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* @return void |
| 105 |
* @throws Repository_Exception |
| 106 |
*/ |
| 107 |
public function enqueue_editor_assets() { |
| 108 |
/** @var Module $blocks_v2 */ |
| 109 |
$blocks_v2 = jet_form_builder()->module( 'blocks-v2' ); |
| 110 |
$asset = require $blocks_v2->get_dir( 'text-field/assets/build/editor.asset.php' ); |
| 111 |
|
| 112 |
if ( true === $asset ) { |
| 113 |
return; |
| 114 |
} |
| 115 |
|
| 116 |
wp_enqueue_script( |
| 117 |
$blocks_v2->get_handle( 'text-field-editor' ), |
| 118 |
$blocks_v2->get_url( 'text-field/assets/build/editor.js' ), |
| 119 |
$asset['dependencies'], |
| 120 |
$asset['version'], |
| 121 |
true |
| 122 |
); |
| 123 |
|
| 124 |
$block_render = new Block_Render( new Block_Type() ); |
| 125 |
|
| 126 |
wp_localize_script( |
| 127 |
$blocks_v2->get_handle( 'text-field-editor' ), |
| 128 |
'JFBTextFieldConfig', |
| 129 |
array( |
| 130 |
'seenIcon' => $block_render->get_seen_icon(), |
| 131 |
'unSeenIcon' => $block_render->get_unseen_icon(), |
| 132 |
) |
| 133 |
); |
| 134 |
} |
| 135 |
|
| 136 |
public function enqueue_required_assets() { |
| 137 |
wp_enqueue_script( Base_Module_Handle_It::HANDLE_PREFIX . 'blocks-v2-text-field' ); |
| 138 |
} |
| 139 |
} |
| 140 |
|