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
|
|
|
|
39
|
|
|
$this->struct['id'] = 'grid'; |
40
|
|
|
if ( ! empty( $this->struct['size'] ) ) { |
41
|
|
|
$this->struct['size'] = explode( ' ', $this->struct['size'] ); |
42
|
|
|
} else { |
43
|
|
|
$this->struct['size'][] = 1; |
44
|
|
|
} |
45
|
|
|
parent::setup(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get Data from all controls of this section |
50
|
|
|
* |
51
|
|
|
* @since 1.0.0 |
52
|
|
|
* @see \uix\load |
53
|
|
|
* @return array|null Array of sections data structured by the controls |
54
|
|
|
*/ |
55
|
|
|
public function get_data() { |
56
|
|
|
|
57
|
|
|
$data = $this->get_child_data(); |
58
|
|
|
if ( empty( $data ) ) { |
59
|
|
|
$data = null; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $data; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Sets the data for all children |
67
|
|
|
* |
68
|
|
|
* @since 1.0.0 |
69
|
|
|
* @access public |
70
|
|
|
*/ |
71
|
|
|
public function set_data( $data ) { |
72
|
|
|
|
73
|
|
|
foreach ( $this->child as $child ) { |
74
|
|
|
if ( method_exists( $child, 'set_data' ) ) { |
75
|
|
|
$child->set_data( $data ); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
$this->data = $data; |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Sets the wrappers attributes |
85
|
|
|
* |
86
|
|
|
* @since 1.0.0 |
87
|
|
|
* @access public |
88
|
|
|
*/ |
89
|
|
|
public function set_attributes() { |
90
|
|
|
|
91
|
|
|
if ( ! empty( $this->struct['size'] ) ) { |
92
|
|
|
$this->attributes['class'][] = 'uix-grid'; |
93
|
|
|
$this->attributes['class'][] = 'col-' . implode( '-', $this->struct['size'] ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
parent::set_attributes(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Render the complete section |
101
|
|
|
* |
102
|
|
|
* @since 1.0.0 |
103
|
|
|
* @access public |
104
|
|
|
* @return string|null HTML of rendered notice |
105
|
|
|
*/ |
106
|
|
|
public function render() { |
107
|
|
|
|
108
|
|
|
$output = '<div ' . $this->build_attributes() . '>'; |
109
|
|
|
$output .= $this->render_children(); |
110
|
|
|
$output .= '</div>'; |
111
|
|
|
|
112
|
|
|
return $output; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Enqueues specific tabs assets for the active pages |
117
|
|
|
* |
118
|
|
|
* @since 1.0.0 |
119
|
|
|
* @access public |
120
|
|
|
*/ |
121
|
|
|
public function set_assets() { |
122
|
|
|
|
123
|
|
|
$this->assets['style']['grid'] = $this->url . 'assets/css/grid' . UIX_ASSET_DEBUG . '.css'; |
124
|
|
|
|
125
|
|
|
parent::set_assets(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Enqueues specific tabs assets for the active pages |
130
|
|
|
* |
131
|
|
|
* @since 1.0.0 |
132
|
|
|
* @access protected |
133
|
|
|
*/ |
134
|
|
|
protected function set_active_styles() { |
135
|
|
|
|
136
|
|
|
if ( ! empty( $this->struct['size'] ) ) { |
137
|
|
|
$str = ''; |
138
|
|
|
foreach ( $this->struct['size'] as $fr ) { |
139
|
|
|
$str .= $fr . 'fr '; |
140
|
|
|
} |
141
|
|
|
$style = '.uix-grid.col-' . implode( '-', $this->struct['size'] ) . '{grid-template-columns:' . $str . ';}'; |
142
|
|
|
$style .= '@media screen and (max-width: 600px){'; |
143
|
|
|
$style .= '.uix-grid.col-' . implode( '-', $this->struct['size'] ) . '{grid-template-columns:1fr;}'; |
144
|
|
|
$style .= '}'; |
145
|
|
|
uix_share()->set_active_styles( $style ); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
} |
150
|
|
|
|