diff --git a/wp-content/themes/brpfinanse/functions.php b/wp-content/themes/brpfinanse/functions.php index 02f94d7..6ec2871 100644 --- a/wp-content/themes/brpfinanse/functions.php +++ b/wp-content/themes/brpfinanse/functions.php @@ -257,3 +257,58 @@ function get_full_phone() { wp_send_json_success(['html' => $html]); } + +if (!function_exists('split_text_into_spans')) { + function split_text_into_spans($content, $wordClass = 'word', $charClass = 'char') { + if (empty($content)) return ''; + + $doc = new DOMDocument('1.0', 'UTF-8'); + libxml_use_internal_errors(true); + + $doc->loadHTML('
'.$content.'
', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); + libxml_clear_errors(); + + $xpath = new DOMXPath($doc); + + $textNodes = $xpath->query("//div[@id='wrapper']//text()[not(ancestor::script or ancestor::style or ancestor::svg or ancestor::code or ancestor::pre or ancestor::iframe)]"); + + foreach ($textNodes as $node) { + $text = $node->nodeValue; + if (!preg_match('/\S/u', $text)) continue; + + $fragment = $doc->createDocumentFragment(); + + $words = preg_split('/(\s+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE); + + foreach ($words as $word) { + if (trim($word) === '') { + $fragment->appendChild($doc->createTextNode($word)); + continue; + } + + $wordSpan = $doc->createElement('span'); + $wordSpan->setAttribute('class', $wordClass); + + $chars = preg_split('//u', $word, -1, PREG_SPLIT_NO_EMPTY); + foreach ($chars as $ch) { + $span = $doc->createElement('span'); + $span->setAttribute('class', $charClass); + $span->appendChild($doc->createTextNode($ch)); + $wordSpan->appendChild($span); + } + + $fragment->appendChild($wordSpan); + } + + $node->parentNode->replaceChild($fragment, $node); + } + + $wrapper = $doc->getElementById('wrapper'); + $html = ''; + foreach ($wrapper->childNodes as $child) { + $html .= $doc->saveHTML($child); + } + + return $html; + } +} \ No newline at end of file diff --git a/wp-content/themes/brpfinanse/page-132.php b/wp-content/themes/brpfinanse/page-132.php index 4f384bd..b56940a 100644 --- a/wp-content/themes/brpfinanse/page-132.php +++ b/wp-content/themes/brpfinanse/page-132.php @@ -22,7 +22,7 @@
-

+

@@ -77,9 +77,9 @@
-
+

- +
diff --git a/wp-content/themes/brpfinanse/page-72.php b/wp-content/themes/brpfinanse/page-72.php index afba613..d2afa9b 100644 --- a/wp-content/themes/brpfinanse/page-72.php +++ b/wp-content/themes/brpfinanse/page-72.php @@ -141,8 +141,8 @@
-
- +
+