| 1 |
<?php |
| 2 |
/** |
| 3 |
* The file contains the class of Tab Control Holder. |
| 4 |
* |
| 5 |
* @author Alex Kovalev <alex.kovalevv@gmail.com> |
| 6 |
* @copyright (c) 2018, Webcraftic Ltd |
| 7 |
* |
| 8 |
* @package factory-forms |
| 9 |
* @since 1.0.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly |
| 13 |
if( !defined('ABSPATH') ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
if( !class_exists('Wbcr_FactoryForms420_TabHolder') ) { |
| 18 |
|
| 19 |
/** |
| 20 |
* Tab Control Holder |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
*/ |
| 24 |
class Wbcr_FactoryForms420_TabHolder extends Wbcr_FactoryForms420_Holder { |
| 25 |
|
| 26 |
/** |
| 27 |
* A holder type. |
| 28 |
* |
| 29 |
* @since 1.0.0 |
| 30 |
* @var string |
| 31 |
*/ |
| 32 |
public $type = 'tab'; |
| 33 |
|
| 34 |
/** |
| 35 |
* An align of a tab (horizontal or vertical). |
| 36 |
* |
| 37 |
* @since 1.0.0 |
| 38 |
* @var string |
| 39 |
*/ |
| 40 |
public $align = 'horizontal'; |
| 41 |
|
| 42 |
/** |
| 43 |
* Creates a new instance of control holder. |
| 44 |
* |
| 45 |
* @since 1.0.0 |
| 46 |
* @param mixed[] $options A holder options. |
| 47 |
* @param FactoryForms420_Form $form A parent form. |
| 48 |
*/ |
| 49 |
public function __construct($options, $form) |
| 50 |
{ |
| 51 |
parent::__construct($options, $form); |
| 52 |
$this->align = isset($options['align']) |
| 53 |
? $options['align'] |
| 54 |
: 'horizontal'; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Here we should render a beginning html of the tab. |
| 59 |
* |
| 60 |
* @since 1.0.0 |
| 61 |
* @return void |
| 62 |
*/ |
| 63 |
public function beforeRendering() |
| 64 |
{ |
| 65 |
|
| 66 |
$is_first_tab = true; |
| 67 |
$tab_class = $this->getOption('class'); |
| 68 |
|
| 69 |
if( !empty($tab_class) ) { |
| 70 |
$this->addCssClass($tab_class); |
| 71 |
} |
| 72 |
|
| 73 |
$this->addCssClass('factory-align-' . $this->align); |
| 74 |
|
| 75 |
?> |
| 76 |
<div <?php $this->attrs() ?>> |
| 77 |
<div class="factory-headers"> |
| 78 |
<ul class="nav nav-tabs"> |
| 79 |
<?php foreach($this->elements as $element) { |
| 80 |
if( $element->options['type'] !== 'tab-item' ) { |
| 81 |
continue; |
| 82 |
} |
| 83 |
|
| 84 |
$tab_icon = ''; |
| 85 |
$has_icon = isset($element->options['icon']); |
| 86 |
|
| 87 |
if( $has_icon ) { |
| 88 |
$tab_icon = $element->options['icon']; |
| 89 |
} |
| 90 |
|
| 91 |
$builder = new Wbcr_FactoryForms420_HtmlAttributeBuilder(); |
| 92 |
|
| 93 |
$builder->addCssClass('factory-tab-item-header'); |
| 94 |
$builder->addCssClass('factory-tab-item-header-' . $element->getName()); |
| 95 |
|
| 96 |
if( $has_icon ) { |
| 97 |
$builder->addCssClass('factory-tab-item-header-with-icon'); |
| 98 |
} |
| 99 |
if( $is_first_tab ) { |
| 100 |
$builder->addCssClass('active'); |
| 101 |
} |
| 102 |
|
| 103 |
$builder->addHtmlData('tab-id', $element->getName()); |
| 104 |
$is_first_tab = false; |
| 105 |
|
| 106 |
if( $has_icon ) { ?> |
| 107 |
<style> |
| 108 |
.factory-form-tab-item-header-<?php $element->name() ?> a { |
| 109 |
background-image: url("<?php echo $tab_icon ?>"); |
| 110 |
} |
| 111 |
</style> |
| 112 |
<?php } ?> |
| 113 |
<li <?php $builder->printAttrs() ?>> |
| 114 |
<a href="#<?php $element->name() ?>" data-toggle="tab"> |
| 115 |
<?php $element->title() ?> |
| 116 |
</a> |
| 117 |
</li> |
| 118 |
<?php } ?> |
| 119 |
</ul> |
| 120 |
</div> |
| 121 |
<div class='tab-content factory-bodies'> |
| 122 |
<?php |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Here we should render an end html of the tab. |
| 127 |
* |
| 128 |
* @since 1.0.0 |
| 129 |
* @return void |
| 130 |
*/ |
| 131 |
public function afterRendering() |
| 132 |
{ |
| 133 |
?> |
| 134 |
</div> |
| 135 |
</div> |
| 136 |
<?php |
| 137 |
} |
| 138 |
} |
| 139 |
} |