| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class HC3_Ui_Element_CollapseCheckbox extends HC3_Ui_Abstract_Collection |
| 3 |
{ |
| 4 |
protected $html = NULL; |
| 5 |
protected $name = NULL; |
| 6 |
protected $label = NULL; |
| 7 |
protected $content = NULL; |
| 8 |
protected $expand = FALSE; |
| 9 |
|
| 10 |
protected $border = FALSE; |
| 11 |
protected $arrow = '↓'; |
| 12 |
|
| 13 |
public function __construct( HC3_Ui $html, $name, $label, $content, $expand = FALSE ) |
| 14 |
{ |
| 15 |
$this->html = $html; |
| 16 |
$this->name = $name; |
| 17 |
$this->label = $label; |
| 18 |
$this->content = $content; |
| 19 |
|
| 20 |
$this->add( $this->label ); |
| 21 |
$this->add( $this->content ); |
| 22 |
|
| 23 |
$checked = $this->expand ? TRUE : FALSE; |
| 24 |
$value = NULL; |
| 25 |
$label = NULL; |
| 26 |
$name = $this->name; |
| 27 |
$checkbox = $this->html->makeInputCheckbox( $name, $label, $value, $checked ); |
| 28 |
|
| 29 |
$this->add( $checkbox ); |
| 30 |
|
| 31 |
if( $expand ){ |
| 32 |
$this->expand(); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
public function border( $border = TRUE ) |
| 37 |
{ |
| 38 |
$this->border = $border; |
| 39 |
return $this; |
| 40 |
} |
| 41 |
|
| 42 |
public function arrow( $arrow ) |
| 43 |
{ |
| 44 |
$this->arrow = $arrow; |
| 45 |
return $this; |
| 46 |
} |
| 47 |
|
| 48 |
public function expand( $expand = true ) |
| 49 |
{ |
| 50 |
$this->expand = $expand; |
| 51 |
|
| 52 |
$checkbox = $this->children[2]; |
| 53 |
$checkbox->setChecked( $expand ); |
| 54 |
|
| 55 |
return $this; |
| 56 |
} |
| 57 |
|
| 58 |
public function render() |
| 59 |
{ |
| 60 |
$thisLabel = $this->children[0]; |
| 61 |
$thisContent = $this->children[1]; |
| 62 |
$checkbox = $this->children[2]; |
| 63 |
|
| 64 |
$this_id = 'hc3_' . mt_rand( 100000, 999999 ); |
| 65 |
|
| 66 |
$checkbox |
| 67 |
->addAttr('id', $this_id) |
| 68 |
->addAttr('class', 'hc-collapse-toggler') |
| 69 |
->addAttr('style', 'display: inline-block;') |
| 70 |
->addAttr('class', 'hc-valign-middle') |
| 71 |
; |
| 72 |
|
| 73 |
$trigger = $this->html->makeElement('label', $thisLabel) |
| 74 |
->addAttr('for', $this_id) |
| 75 |
->addAttr('class', 'hc-inline-block') |
| 76 |
// ->addAttr('class', 'hc-py1') |
| 77 |
->addAttr('class', 'hc-collapse-burger') |
| 78 |
->addAttr('class', 'hc-regular') |
| 79 |
->addAttr('class', 'hc-ml1') |
| 80 |
; |
| 81 |
|
| 82 |
if( ! is_object($thisLabel) ){ |
| 83 |
$trigger |
| 84 |
->addAttr('title', strip_tags($thisLabel) ) |
| 85 |
; |
| 86 |
} |
| 87 |
|
| 88 |
if( $this->border ){ |
| 89 |
$trigger |
| 90 |
->addAttr('title', strip_tags($thisLabel) ) |
| 91 |
->addAttr('class', 'hc-border-bottom-dotted') |
| 92 |
->addAttr('class', 'hc-border-gray') |
| 93 |
; |
| 94 |
} |
| 95 |
|
| 96 |
// $trigger = $this->html->makeBlock( $trigger ) |
| 97 |
// ->addAttr('class', 'hc-collapse-burger') |
| 98 |
// ; |
| 99 |
|
| 100 |
$content = $this->html->makeBlock( $thisContent ) |
| 101 |
->addAttr('class', 'hc-collapse-content') |
| 102 |
->addAttr('class', 'hc-mt1') |
| 103 |
// ->addAttr('class', 'hc-ml2') |
| 104 |
; |
| 105 |
|
| 106 |
$trigger = $this->html->makeCollection( array($checkbox, $trigger) ); |
| 107 |
$out = $this->html->makeCollection( array($trigger, $content) ); |
| 108 |
|
| 109 |
$out = $this->html->makeBlock( $out ) |
| 110 |
->addAttr('class', 'hc-collapse-container') |
| 111 |
; |
| 112 |
|
| 113 |
return $out; |
| 114 |
} |
| 115 |
} |