PlacementNormal.php
3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Nextend\SmartSlider3\Renderable\Placement;
use Nextend\SmartSlider3\Renderable\Component\AbstractComponent;
class PlacementNormal extends AbstractPlacement {
public function attributes(&$attributes) {
$data = $this->component->data;
$attributes['data-pm'] = 'normal';
$devices = $this->component->getOwner()
->getAvailableDevices();
$desktopPortraitSelfAlign = $data->get('desktopportraitselfalign', 'inherit');
$desktopPortraitMaxWidth = intval($data->get('desktopportraitmaxwidth', 0));
$desktopPortraitHeight = $data->get('desktopportraitheight', 0);
$desktopPortraitMargin = $data->get('desktopportraitmargin');
if (!empty($desktopPortraitMargin)) {
$desktopPortraitMargin = $this->component->spacingToPxValue($desktopPortraitMargin);
} else {
$desktopPortraitMargin = array(
0,
0,
0,
0
);
}
foreach ($devices as $device) {
$margin = $data->get($device . 'margin');
if (!empty($margin)) {
$marginValues = $this->component->spacingToPxValue($margin);
$cssText = array();
if (($marginValues[0] == 0 && $desktopPortraitMargin[0] != 0) || $marginValues[0] != 0) {
$cssText[] = '--margin-top:' . $marginValues[0] . 'px';
}
if (($marginValues[1] == 0 && $desktopPortraitMargin[1] != 0) || $marginValues[1] != 0) {
$cssText[] = '--margin-right:' . $marginValues[1] . 'px';
}
if (($marginValues[2] == 0 && $desktopPortraitMargin[2] != 0) || $marginValues[2] != 0) {
$cssText[] = '--margin-bottom:' . $marginValues[2] . 'px';
}
if (($marginValues[3] == 0 && $desktopPortraitMargin[3] != 0) || $marginValues[3] != 0) {
$cssText[] = '--margin-left:' . $marginValues[3] . 'px';
}
$this->component->style->add($device, '', implode(';', $cssText));
}
$height = $data->get($device . 'height');
if ($height === 0 || !empty($height)) {
if ($height == 0) {
if ($desktopPortraitHeight > 0) {
$this->component->style->add($device, '', 'height:auto');
}
} else {
$this->component->style->add($device, '', 'height:' . $height . 'px');
}
}
$maxWidth = intval($data->get($device . 'maxwidth', -1));
if ($maxWidth > 0) {
$this->component->style->add($device, '', 'max-width:' . $maxWidth . 'px');
} else if ($maxWidth === 0 && $device != 'desktopportrait' && $maxWidth != $desktopPortraitMaxWidth) {
$this->component->style->add($device, '', 'max-width:none');
}
$selfAlign = $data->get($device . 'selfalign', '');
if ($device == 'desktopportrait') {
if ($desktopPortraitSelfAlign != 'inherit') {
$this->component->style->add($device, '', AbstractComponent::selfAlignToStyle($selfAlign));
}
} else if ($desktopPortraitSelfAlign != $selfAlign) {
$this->component->style->add($device, '', AbstractComponent::selfAlignToStyle($selfAlign));
}
}
}
public function adminAttributes(&$attributes) {
$this->component->createDeviceProperty('maxwidth', 0);
$this->component->createDeviceProperty('margin', '0|*|0|*|0|*|0');
$this->component->createDeviceProperty('height', 0);
$this->component->createDeviceProperty('selfalign', 'inherit');
}
}