| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Elements; |
| 3 |
|
| 4 |
use Depicter\Document\CSS\Selector; |
| 5 |
use Depicter\Document\Helper\Helper; |
| 6 |
use Depicter\Document\Models\Common\Styles; |
| 7 |
use Depicter\Document\Models\Element; |
| 8 |
use Depicter\GuzzleHttp\Exception\GuzzleException; |
| 9 |
use Depicter\Html\Html; |
| 10 |
|
| 11 |
class HoverSwitchImage extends Element |
| 12 |
{ |
| 13 |
/** |
| 14 |
* @throws GuzzleException |
| 15 |
* @throws \JsonMapper_Exception |
| 16 |
*/ |
| 17 |
public function render() |
| 18 |
{ |
| 19 |
$args = $this->getDefaultAttributes(); |
| 20 |
$args[ 'data-type' ] = "hoverSwitch"; |
| 21 |
|
| 22 |
if ( ! empty( $this->options->switchDuration ) ) { |
| 23 |
$args[ 'data-switch-duration' ] = $this->options->switchDuration; |
| 24 |
} |
| 25 |
|
| 26 |
$output = Html::div( $args ); |
| 27 |
if ( ! empty( $this->options->primarySource->src ) ) { |
| 28 |
$primarySrcset = \Depicter::media()->getSrcSet( $this->maybeReplaceDataSheetTags( $this->options->primarySource->src ) ); |
| 29 |
$source = ! empty( $primarySrcset ) ? Html::source( [ |
| 30 |
'data-depicter-srcset' => $primarySrcset, |
| 31 |
'srcset' => \Depicter::media()::IMAGE_PLACEHOLDER_SRC, |
| 32 |
] ) : ""; |
| 33 |
|
| 34 |
$img = Html::img( '', [ |
| 35 |
'src' => \Depicter::media()::IMAGE_PLACEHOLDER_SRC, |
| 36 |
'data-depicter-src' => \Depicter::media()->getSourceUrl( $this->maybeReplaceDataSheetTags( $this->options->primarySource->src ) ), |
| 37 |
'alt' => \Depicter::media()->getAltText( $this->maybeReplaceDataSheetTags( $this->options->primarySource->src ) ) |
| 38 |
] ); |
| 39 |
|
| 40 |
$primaryImage = Html::picture( [ |
| 41 |
'class' => Selector::prefixify( 'primary' ) |
| 42 |
], $source . $img ); |
| 43 |
|
| 44 |
$output->nest( "\n" . $primaryImage ); |
| 45 |
} |
| 46 |
|
| 47 |
if ( ! empty( $this->options->secondarySource->src ) ) { |
| 48 |
|
| 49 |
$secondarySrcset = \Depicter::media()->getSrcSet( $this->maybeReplaceDataSheetTags( $this->options->secondarySource->src ) ); |
| 50 |
$source = ! empty( $secondarySrcset ) ? Html::source( [ |
| 51 |
'data-depicter-srcset' => $secondarySrcset, |
| 52 |
'srcset' => \Depicter::media()::IMAGE_PLACEHOLDER_SRC, |
| 53 |
] ) : ""; |
| 54 |
|
| 55 |
$img = Html::img( '', [ |
| 56 |
'src' => \Depicter::media()::IMAGE_PLACEHOLDER_SRC, |
| 57 |
'data-depicter-src' => \Depicter::media()->getSourceUrl( $this->maybeReplaceDataSheetTags( $this->options->secondarySource->src ) ), |
| 58 |
'alt' => \Depicter::media()->getAltText( $this->maybeReplaceDataSheetTags( $this->options->secondarySource->src ) ) |
| 59 |
] ); |
| 60 |
|
| 61 |
$secondaryImage = Html::picture( [ |
| 62 |
'class' => Selector::prefixify( 'secondary' ) |
| 63 |
], $source . $img ); |
| 64 |
|
| 65 |
$output->nest( "\n" . $secondaryImage ); |
| 66 |
} |
| 67 |
|
| 68 |
return $output; |
| 69 |
} |
| 70 |
} |
| 71 |
|