1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* UIX Grid |
4
|
|
|
* |
5
|
|
|
* @package ui |
6
|
|
|
* @author David Cramer |
7
|
|
|
* @license GPL-2.0+ |
8
|
|
|
* @link |
9
|
|
|
* @copyright 2016 David Cramer |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace uix\ui; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* A Grid system for layout control |
16
|
|
|
* |
17
|
|
|
* @since 1.0.0 |
18
|
|
|
* @see \uix\uix |
19
|
|
|
*/ |
20
|
|
|
class grid extends section { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The type of object |
24
|
|
|
* |
25
|
|
|
* @since 1.0.0 |
26
|
|
|
* @access public |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
public $type = 'grid'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* All objects loaded - application method for finishing off loading objects |
33
|
|
|
* |
34
|
|
|
* @since 1.0.0 |
35
|
|
|
* @access public |
36
|
|
|
*/ |
37
|
|
|
public function setup() { |
38
|
|
|
if ( ! empty( $this->struct['size'] ) ) { |
39
|
|
|
$this->struct['size'] = explode( ' ', $this->struct['size'] ); |
40
|
|
|
} else { |
41
|
|
|
$this->struct['size'][] = 1; |
42
|
|
|
} |
43
|
|
|
parent::setup(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get Data from all controls of this section |
48
|
|
|
* |
49
|
|
|
* @since 1.0.0 |
50
|
|
|
* @see \uix\load |
51
|
|
|
* @return array|null Array of sections data structured by the controls |
52
|
|
|
*/ |
53
|
|
|
public function get_data() { |
54
|
|
|
|
55
|
|
|
$data = $this->get_child_data(); |
56
|
|
|
if ( empty( $data ) ) { |
57
|
|
|
$data = null; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $data; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Sets the data for all children |
65
|
|
|
* |
66
|
|
|
* @since 1.0.0 |
67
|
|
|
* @access public |
68
|
|
|
*/ |
69
|
|
|
public function set_data( $data ) { |
70
|
|
|
|
71
|
|
|
foreach ( $this->child as $child ) { |
72
|
|
|
if ( method_exists( $child, 'set_data' ) ) { |
73
|
|
|
$child->set_data( $data ); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
$this->data = $data; |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Sets the wrappers attributes |
83
|
|
|
* |
84
|
|
|
* @since 1.0.0 |
85
|
|
|
* @access public |
86
|
|
|
*/ |
87
|
|
|
public function set_attributes() { |
88
|
|
|
|
89
|
|
|
if ( ! empty( $this->struct['size'] ) ) { |
90
|
|
|
$this->attributes['class'][] = 'uix-grid'; |
91
|
|
|
$this->attributes['class'][] = 'col-' . implode( '-', $this->struct['size'] ); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
parent::set_attributes(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Render the complete section |
99
|
|
|
* |
100
|
|
|
* @since 1.0.0 |
101
|
|
|
* @access public |
102
|
|
|
* @return string|null HTML of rendered notice |
103
|
|
|
*/ |
104
|
|
|
public function render() { |
105
|
|
|
|
106
|
|
|
$output = '<div ' . $this->build_attributes() . '>'; |
107
|
|
|
$output .= $this->render_children(); |
108
|
|
|
$output .= '</div>'; |
109
|
|
|
|
110
|
|
|
return $output; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Enqueues specific tabs assets for the active pages |
115
|
|
|
* |
116
|
|
|
* @since 1.0.0 |
117
|
|
|
* @access public |
118
|
|
|
*/ |
119
|
|
|
public function set_assets() { |
120
|
|
|
|
121
|
|
|
$this->assets['style']['grid'] = $this->url . 'assets/css/grid' . UIX_ASSET_DEBUG . '.css'; |
122
|
|
|
|
123
|
|
|
parent::set_assets(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Enqueues specific tabs assets for the active pages |
128
|
|
|
* |
129
|
|
|
* @since 1.0.0 |
130
|
|
|
* @access protected |
131
|
|
|
*/ |
132
|
|
|
protected function set_active_styles() { |
133
|
|
|
|
134
|
|
|
if ( ! empty( $this->struct['size'] ) ) { |
135
|
|
|
$str = ''; |
136
|
|
|
foreach ( $this->struct['size'] as $fr ) { |
137
|
|
|
$str .= $fr . 'fr '; |
138
|
|
|
} |
139
|
|
|
$style = '.uix-grid.col-' . implode( '-', $this->struct['size'] ) . '{grid-template-columns:' . $str . ';}'; |
140
|
|
|
$style .= '@media screen and (max-width: 600px){'; |
141
|
|
|
$style .= '.uix-grid.col-' . implode( '-', $this->struct['size'] ) . '{grid-template-columns:1fr;}'; |
142
|
|
|
$style .= '}'; |
143
|
|
|
uix_share()->set_active_styles( $style ); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
} |
148
|
|
|
|