| 1 |
<?php |
| 2 |
|
| 3 |
namespace Getwid\Blocks; |
| 4 |
|
| 5 |
class ProgressBar extends \Getwid\Blocks\AbstractBlock { |
| 6 |
|
| 7 |
protected static $blockName = 'getwid/progress-bar'; |
| 8 |
|
| 9 |
public function __construct() { |
| 10 |
|
| 11 |
parent::__construct( self::$blockName ); |
| 12 |
|
| 13 |
register_block_type( |
| 14 |
'getwid/progress-bar', |
| 15 |
array( |
| 16 |
'render_callback' => [ $this, 'render_callback' ] |
| 17 |
) |
| 18 |
); |
| 19 |
|
| 20 |
//Register JS/CSS assets |
| 21 |
wp_register_script( |
| 22 |
'waypoints', |
| 23 |
getwid_get_plugin_url( 'vendors/waypoints/lib/jquery.waypoints.min.js' ), |
| 24 |
[ 'jquery' ], |
| 25 |
'4.0.1', |
| 26 |
true |
| 27 |
); |
| 28 |
} |
| 29 |
|
| 30 |
public function getLabel() { |
| 31 |
return __('Progress Bar', 'getwid'); |
| 32 |
} |
| 33 |
|
| 34 |
public function block_frontend_assets() { |
| 35 |
|
| 36 |
if ( is_admin() ) { |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
if ( ! wp_script_is( 'waypoints', 'enqueued' ) ) { |
| 41 |
wp_enqueue_script('waypoints'); |
| 42 |
} |
| 43 |
|
| 44 |
if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
$rtl = is_rtl() ? '.rtl' : ''; |
| 49 |
|
| 50 |
wp_enqueue_style( |
| 51 |
self::$blockName, |
| 52 |
getwid_get_plugin_url( 'assets/blocks/progress-bar/style' . $rtl . '.css' ), |
| 53 |
[], |
| 54 |
getwid()->settings()->getVersion() |
| 55 |
); |
| 56 |
|
| 57 |
wp_enqueue_script( |
| 58 |
self::$blockName, |
| 59 |
getwid_get_plugin_url( 'assets/blocks/progress-bar/frontend.js' ), |
| 60 |
[ 'jquery', 'waypoints' ], |
| 61 |
getwid()->settings()->getVersion(), |
| 62 |
true |
| 63 |
); |
| 64 |
} |
| 65 |
|
| 66 |
public function render_callback( $attributes, $content ) { |
| 67 |
|
| 68 |
$this->block_frontend_assets(); |
| 69 |
|
| 70 |
return $content; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
getwid()->blocksManager()->addBlock( |
| 75 |
new \Getwid\Blocks\ProgressBar() |
| 76 |
); |
| 77 |
|