| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class HC3_Ui_Element_ListInline extends HC3_Ui_Abstract_Collection |
| 3 |
{ |
| 4 |
protected $htmlFactory = NULL; |
| 5 |
protected $valign = 'middle'; |
| 6 |
|
| 7 |
public function __construct( HC3_Ui $htmlFactory, array $items = array() ) |
| 8 |
{ |
| 9 |
$this->htmlFactory = $htmlFactory; |
| 10 |
parent::__construct( $items ); |
| 11 |
} |
| 12 |
|
| 13 |
public function valign( $set ) |
| 14 |
{ |
| 15 |
$this->valign = $set; |
| 16 |
return $this; |
| 17 |
} |
| 18 |
|
| 19 |
public function render() |
| 20 |
{ |
| 21 |
$out = NULL; |
| 22 |
|
| 23 |
// content |
| 24 |
$out = ''; |
| 25 |
|
| 26 |
if( $this->separated ){ |
| 27 |
$separator = ($this->separated === TRUE) ? '|' : $this->separated; // | |
| 28 |
$separator = $this->htmlFactory->makeBlock($separator) |
| 29 |
->addAttr('class', 'hc-gray') |
| 30 |
->render() |
| 31 |
; |
| 32 |
|
| 33 |
$children = array(); |
| 34 |
$ii = 0; |
| 35 |
foreach( $this->children as $child ){ |
| 36 |
$child = '' . $child; |
| 37 |
if( ! strlen($child) ){ |
| 38 |
continue; |
| 39 |
} |
| 40 |
|
| 41 |
if( $ii ){ |
| 42 |
$children[] = $separator; |
| 43 |
// $children[] = '•'; |
| 44 |
} |
| 45 |
|
| 46 |
$children[] = $child; |
| 47 |
$ii++; |
| 48 |
} |
| 49 |
} |
| 50 |
else { |
| 51 |
$children = $this->children; |
| 52 |
} |
| 53 |
|
| 54 |
$ii = 0; |
| 55 |
$count = count($children); |
| 56 |
foreach( $children as $child ){ |
| 57 |
$dataPw = ''; |
| 58 |
if( is_object($child) && method_exists($child, 'getAttr') ){ |
| 59 |
$dataPw = $child->getAttr( 'data-pw' ); |
| 60 |
if( is_array($dataPw) ) $dataPw = current( $dataPw ); |
| 61 |
} |
| 62 |
|
| 63 |
$child = '' . $child; |
| 64 |
if( ! strlen($child) ){ |
| 65 |
continue; |
| 66 |
} |
| 67 |
|
| 68 |
$child = $this->htmlFactory->makeBlock( $child ) |
| 69 |
// ->addAttr('class', 'hc-inline-block') |
| 70 |
->addAttr('class', 'hc-valign-' . $this->valign) |
| 71 |
; |
| 72 |
|
| 73 |
if( $dataPw ){ |
| 74 |
$child->addAttr( 'data-pw', $dataPw ); |
| 75 |
} |
| 76 |
|
| 77 |
if( $this->gutter && ($ii < ($count-1)) ){ |
| 78 |
// $child->addAttr('class', 'hc-mr' . $this->gutter); |
| 79 |
// $child->addAttr('class', 'hc-me' . $this->gutter); |
| 80 |
} |
| 81 |
$out .= '' . $child; |
| 82 |
|
| 83 |
$ii++; |
| 84 |
} |
| 85 |
|
| 86 |
if( strlen($out) ){ |
| 87 |
$out = $this->htmlFactory->makeBlock( $out ) |
| 88 |
->addAttr( 'class', 'pw-flex' ) |
| 89 |
->addAttr( 'class', 'pw-gap' . $this->gutter ) |
| 90 |
// ->addAttr('class', 'hc-nowrap') |
| 91 |
; |
| 92 |
} |
| 93 |
|
| 94 |
return $out; |
| 95 |
} |
| 96 |
} |