| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Common; |
| 3 |
|
| 4 |
use Averta\Core\Utility\Data; |
| 5 |
use Averta\WordPress\Utility\JSON; |
| 6 |
use Depicter\Document\CSS\Breakpoints; |
| 7 |
|
| 8 |
class Parallax extends States{ |
| 9 |
|
| 10 |
/** |
| 11 |
* Get all parallax attributes |
| 12 |
* |
| 13 |
* @return array |
| 14 |
*/ |
| 15 |
public function getParallaxAttrs() { |
| 16 |
$attrs = []; |
| 17 |
|
| 18 |
// Collect animation attributes |
| 19 |
foreach ( Breakpoints::names() as $breakpoint ){ |
| 20 |
$breakpoint_prefix = $breakpoint ? $breakpoint . '-' : $breakpoint; |
| 21 |
$breakpoint_prefix = $breakpoint == 'default' ? '' : $breakpoint_prefix; |
| 22 |
|
| 23 |
if( isset( $this->{$breakpoint}->enabled ) ){ |
| 24 |
$attrs[ 'data-'. $breakpoint_prefix .'parallax' ] = !empty($this->{$breakpoint}->enabled) ? $this->getParallaxOption( $this->{$breakpoint} ) : 'false'; |
| 25 |
} |
| 26 |
|
| 27 |
} |
| 28 |
|
| 29 |
return $attrs; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Get parallax option |
| 34 |
* |
| 35 |
* @param object $parallaxOptions |
| 36 |
* @return string |
| 37 |
*/ |
| 38 |
public function getParallaxOption( $parallaxOptions ) { |
| 39 |
$options['type'] = $parallaxOptions->type = $parallaxOptions->type ?? '2d'; |
| 40 |
|
| 41 |
if ( $parallaxOptions->type === '2d' ) { |
| 42 |
isset( $parallaxOptions->x ) && $options['x'] = $parallaxOptions->x; |
| 43 |
isset( $parallaxOptions->y ) && $options['y'] = $parallaxOptions->y; |
| 44 |
} elseif ( $parallaxOptions->type === '3d' ) { |
| 45 |
isset( $parallaxOptions->x ) && $options['x'] = $parallaxOptions->x; |
| 46 |
isset( $parallaxOptions->y ) && $options['y'] = $parallaxOptions->y; |
| 47 |
isset( $parallaxOptions->rx ) && $options['rx'] = $parallaxOptions->rx; |
| 48 |
isset( $parallaxOptions->ry ) && $options['ry'] = $parallaxOptions->ry; |
| 49 |
isset( $parallaxOptions->zOrigin ) && $options['zOrigin'] = $parallaxOptions->zOrigin; |
| 50 |
} elseif ( $parallaxOptions->type == 'scroll' || $parallaxOptions->type == 'viewScroll' ) { |
| 51 |
isset( $parallaxOptions->dir ) && $options['dir'] = $parallaxOptions->dir; |
| 52 |
isset( $parallaxOptions->movement ) && $options['movement'] = $parallaxOptions->movement; |
| 53 |
isset( $parallaxOptions->scale ) && $options['scale'] = $parallaxOptions->scale; |
| 54 |
isset( $parallaxOptions->rotate ) && $options['rotate'] = $parallaxOptions->rotate; |
| 55 |
// Add value for following params even if params are not set |
| 56 |
$options['fade'] = isset( $parallaxOptions->fade ) ? Data::isTrue( $parallaxOptions->fade ) : true; |
| 57 |
$options['twoWay'] = isset( $parallaxOptions->twoWay ) ? Data::isTrue( $parallaxOptions->twoWay ) : true; |
| 58 |
} |
| 59 |
|
| 60 |
$options['smooth'] = isset( $parallaxOptions->smooth ) ? Data::isTrue( $parallaxOptions->smooth ) : true; |
| 61 |
|
| 62 |
return JSON::encode( $options ); |
| 63 |
} |
| 64 |
} |
| 65 |
|