Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
style.php
1<?php
2
3namespace Bitrix\Landing\Node;
4
8
9class Style
10{
11 public static function getStyle(Block $block, string $selector): array
12 {
13 $data = [];
14 $resultList = self::getNodesBySelector($block, $selector);
15
16 foreach ($resultList as $pos => $res)
17 {
18 if ($res->getNodeType() === $res::ELEMENT_NODE)
19 {
20 $classList = trim($res->getAttribute('class'));
21 if ($classList)
22 {
23 $data['classList'][$pos] = $classList;
24 }
25
26 $styles = StyleInliner::getStyle($res);
27 $stylesPrepared = [];
28 foreach ($styles as $key => $style)
29 {
30 if ($style && $key !== 'background-image')
31 {
32 $stylesPrepared[$key] = $style;
33 }
34 if ($key === 'background-image' && $style === '')
35 {
36 $stylesPrepared[$key] = $style;
37 }
38 }
39 if (!empty($stylesPrepared))
40 {
41 $data['style'][$pos] = $stylesPrepared;
42
43 }
44 }
45 }
46
47 return $data;
48 }
49
55 public static function getNodesBySelector(Block $block, string $selector): array
56 {
57 $doc = $block->getDom();
58
59 // prepare wrapper
60 $wrapper = '#' . $block->getAnchor($block->getId());
61 if ($selector === '#wrapper')
62 {
63 $selector = '#block' . $block->getId();
64 }
65
66 // nodes for get
67 if ($selector === $wrapper)
68 {
69 $wrapperNode = [];
70 foreach ($doc->getChildNodesArray() as $node)
71 {
72 if ($node->getNodeType() === Node::ELEMENT_NODE)
73 {
74 $wrapperNode[] = $node;
75 break;
76 }
77 }
78
79 return $wrapperNode;
80 }
81
82 return $doc->querySelectorAll($selector);
83 }
84}
getDom($clear=false)
Definition block.php:3962
static getAnchor($id)
Definition block.php:1717
static getStyle(Block $block, string $selector)
Definition style.php:11
static getNodesBySelector(Block $block, string $selector)
Definition style.php:55