| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Elements; |
| 3 |
|
| 4 |
use Depicter\Document\Models; |
| 5 |
use Depicter\Html\Html; |
| 6 |
|
| 7 |
class Symbol extends Models\Element |
| 8 |
{ |
| 9 |
|
| 10 |
public function render() { |
| 11 |
$symbolContent = ''; |
| 12 |
|
| 13 |
if( ! empty( $this->options->content ) ){ |
| 14 |
$symbolContent = $this->options->content; |
| 15 |
} |
| 16 |
|
| 17 |
$args = $this->getDefaultAttributes(); |
| 18 |
|
| 19 |
if ( ! empty( $this->options->disableOnFirst ) ) { |
| 20 |
$args['data-disable-on-first'] = 'true'; |
| 21 |
} |
| 22 |
|
| 23 |
if ( ! empty( $this->options->disableOnLast ) ) { |
| 24 |
$args['data-disable-on-last'] = 'true'; |
| 25 |
} |
| 26 |
|
| 27 |
$div = Html::div( $args, "\n\t" . $symbolContent . "\n" ); |
| 28 |
|
| 29 |
if ( false !== $a = $this->getLinkTag() ) { |
| 30 |
return $a->nest( "\n" .$div ) . "\n"; |
| 31 |
} |
| 32 |
|
| 33 |
return $div . "\n"; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Get styles of svg |
| 38 |
* |
| 39 |
* @return array|array[] |
| 40 |
*/ |
| 41 |
protected function getSymbolCss( $state = 'normal' ) { |
| 42 |
// Get styles list from styles property |
| 43 |
$symbolIconStyles = ! empty( $this->styles ) ? $this->styles->generateCssForModulesOfState( ['svg'], $state ) : []; |
| 44 |
|
| 45 |
if( !empty( $this->options->iconScale->default ) ){ |
| 46 |
$symbolIconStyles['default']['transform'] = "scale( {$this->options->iconScale->default} )"; |
| 47 |
} |
| 48 |
if( !empty( $this->options->iconScale->tablet ) ){ |
| 49 |
$symbolIconStyles['tablet']['transform'] = "scale( {$this->options->iconScale->tablet} )"; |
| 50 |
} |
| 51 |
if( !empty( $this->options->iconScale->mobile ) ){ |
| 52 |
$symbolIconStyles['mobile']['transform'] = "scale( {$this->options->iconScale->mobile} )"; |
| 53 |
} |
| 54 |
|
| 55 |
return $symbolIconStyles; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Get list of selector and CSS for element |
| 60 |
* |
| 61 |
* @return array |
| 62 |
* @throws \JsonMapper_Exception |
| 63 |
*/ |
| 64 |
public function getSelectorAndCssList(){ |
| 65 |
parent::getSelectorAndCssList(); |
| 66 |
|
| 67 |
$this->selectorCssList[ '.'. $this->getSelector() .' .depicter-symbol-container' ] = $this->getSymbolCss( 'normal' ); |
| 68 |
$this->selectorCssList[ '.'. $this->getSelector() .':hover .depicter-symbol-container' ] = $this->getSymbolCss( 'hover' ); |
| 69 |
|
| 70 |
$transition = $this->prepare()->styles->getTransitionCss(); |
| 71 |
if ( !empty( $transition ) ) { |
| 72 |
$this->selectorCssList[ '.'. $this->getSelector() .' .depicter-symbol-container' ] = array_merge_recursive( $this->selectorCssList[ '.'. $this->getSelector() .' .depicter-symbol-container' ], $transition ); |
| 73 |
} |
| 74 |
|
| 75 |
return $this->selectorCssList; |
| 76 |
} |
| 77 |
} |
| 78 |
|