| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Options; |
| 3 |
|
| 4 |
|
| 5 |
use Averta\WordPress\File\FileSystem; |
| 6 |
use Depicter\Document\CSS\Selector; |
| 7 |
use Depicter\Html\Html; |
| 8 |
|
| 9 |
class Loading |
| 10 |
{ |
| 11 |
/** |
| 12 |
* @var object |
| 13 |
*/ |
| 14 |
public $lazyload; |
| 15 |
|
| 16 |
/** |
| 17 |
* @var string |
| 18 |
*/ |
| 19 |
public $loadingSymbol = 'dotFlashing-dark'; |
| 20 |
|
| 21 |
/** |
| 22 |
* @var bool |
| 23 |
*/ |
| 24 |
public $initAfterAppear; |
| 25 |
|
| 26 |
/** |
| 27 |
* get html of loading symbol |
| 28 |
* @return \TypeRocket\Html\Html |
| 29 |
*/ |
| 30 |
public function render() { |
| 31 |
|
| 32 |
// loadingSymbol consist of two part , the symbolID and dark or light mode |
| 33 |
$loadingSymbol = explode( '-', $this->loadingSymbol ); |
| 34 |
$loadingMarkup = ''; |
| 35 |
$loadingPath = DEPICTER_PLUGIN_PATH . '/resources/scripts/loadings/snippets/'.$loadingSymbol[0].'/'.$loadingSymbol[1].'.html'; |
| 36 |
|
| 37 |
if ( in_array( $loadingSymbol[0], $this->loadingsList() ) && is_file( $loadingPath ) ) { |
| 38 |
$loadingMarkup = \Depicter::storage()->filesystem()->read( $loadingPath ); |
| 39 |
} |
| 40 |
|
| 41 |
return Html::div( |
| 42 |
[ |
| 43 |
'class' => Selector::prefixify('loading-container') . ' ' . Selector::prefixify('loading ' . $this->loadingSymbol ), |
| 44 |
], |
| 45 |
$loadingMarkup |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Get preload value |
| 51 |
* |
| 52 |
* @return false|string |
| 53 |
*/ |
| 54 |
public function getValue() { |
| 55 |
$type = $this->lazyload->type ?? 'sequential'; |
| 56 |
|
| 57 |
switch ( $type ): |
| 58 |
case 'nearby': |
| 59 |
return $this->lazyload->nearbyNum ?? 1; |
| 60 |
break; |
| 61 |
case 'sequential': |
| 62 |
return 0; |
| 63 |
break; |
| 64 |
case 'all': |
| 65 |
return 'all'; |
| 66 |
break; |
| 67 |
default: |
| 68 |
return false; |
| 69 |
break; |
| 70 |
endswitch; |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* The list of valid loading symbol names |
| 76 |
* |
| 77 |
* @return array |
| 78 |
*/ |
| 79 |
public function loadingsList() { |
| 80 |
return [ |
| 81 |
'audio', |
| 82 |
'ballTriangle', |
| 83 |
'bars', |
| 84 |
'circles', |
| 85 |
'dotFlashing', |
| 86 |
'dotReplacing', |
| 87 |
'dotStraightSwing', |
| 88 |
'dotSwing', |
| 89 |
'grid', |
| 90 |
'hearts', |
| 91 |
'oval', |
| 92 |
'puff', |
| 93 |
'rings', |
| 94 |
'spinningCircles', |
| 95 |
'tailSpin', |
| 96 |
'threeDots' |
| 97 |
]; |
| 98 |
} |
| 99 |
} |
| 100 |
|