Skip to content

Commit 1720a8a

Browse files
update: update field for concet contet from text area to WYSIWYG
1 parent c103557 commit 1720a8a

File tree

6 files changed

+191
-20
lines changed

6 files changed

+191
-20
lines changed

acf-json/group_663e1989e948a.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
"label": "Content",
88
"name": "content",
99
"aria-label": "",
10-
"type": "textarea",
10+
"type": "wysiwyg",
1111
"instructions": "",
12-
"required": 1,
12+
"required": 0,
1313
"conditional_logic": 0,
1414
"wrapper": {
1515
"width": "",
1616
"class": "",
1717
"id": ""
1818
},
1919
"default_value": "",
20-
"maxlength": "",
21-
"rows": 18,
22-
"placeholder": "",
23-
"new_lines": "br"
20+
"tabs": "all",
21+
"toolbar": "full",
22+
"media_upload": 1,
23+
"delay": 0
2424
},
2525
{
2626
"key": "field_663e198ac9269",
@@ -340,5 +340,5 @@
340340
"active": true,
341341
"description": "",
342342
"show_in_rest": 0,
343-
"modified": 1720011365
343+
"modified": 1729852651
344344
}

build/bundle.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array(), 'version' => '8094eff5ff0298e9140a');
1+
<?php return array('dependencies' => array(), 'version' => 'd0d7bf3f9001df5ec5e2');

build/css/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

functions.php

Lines changed: 163 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,21 +1140,173 @@ function utopia_get_page_title( $post = null ) {
11401140

11411141

11421142
function utopia_wrap_long_text( $text ) {
1143-
if ( strlen( $text ) > 685 ) {
1144-
$trimmed_text = substr( $text, 0, 685 );
1145-
$last_space_position = strrpos( $trimmed_text, ' ' );
1143+
// new
1144+
if ( ! $text ) {
1145+
return;
1146+
}
11461147

1147-
if ( false !== $last_space_position ) {
1148-
$trimmed_text = substr( $trimmed_text, 0, $last_space_position );
1148+
$max_length = 685;
1149+
1150+
// Используем DOMDocument для корректной работы с HTML
1151+
$dom = new DOMDocument();
1152+
libxml_use_internal_errors( true );
1153+
$dom->loadHTML( mb_convert_encoding( $text, 'HTML-ENTITIES', 'UTF-8' ) );
1154+
libxml_clear_errors();
1155+
1156+
$body = $dom->getElementsByTagName( 'body' )->item( 0 );
1157+
$truncated_content = '';
1158+
$remaining_content = '';
1159+
$current_length = 0;
1160+
$truncated = false;
1161+
$nodes_to_be_visible = array();
1162+
$nodes_to_be_invisible = array();
1163+
1164+
foreach ( $body->childNodes as $node ) {
1165+
if ( $node->nodeType !== XML_ELEMENT_NODE ) {
1166+
continue;
11491167
}
11501168

1151-
$remaining_text = substr( $text, $last_space_position );
1152-
$concert_more_text = '<span class="concert-more-text" hidden>' . $remaining_text . '</span>';
1153-
$concert_more_button = ' <button class="concert-more-button" onclick="this.previousElementSibling.hidden = false; this.hidden = true;">' . pll__( 'more' ) . '</button>';
1154-
return $trimmed_text . $concert_more_text . $concert_more_button;
1155-
} else {
1156-
return $text;
1169+
$node_content = $dom->saveHTML( $node );
1170+
$node_length = mb_strlen( strip_tags( $node_content ) );
1171+
1172+
if ( $current_length + $node_length < $max_length ) {
1173+
$nodes_to_be_visible[] = $node;
1174+
} else {
1175+
$truncated = true;
1176+
$nodes_to_be_invisible[] = $node;
1177+
}
1178+
1179+
$current_length += $node_length;
1180+
}
1181+
1182+
// $nodes_to_be_visible = array_filter(
1183+
// $nodes_to_be_visible,
1184+
// function ( $node ) {
1185+
// return $node->nodeType === XML_ELEMENT_NODE;
1186+
// }
1187+
// );
1188+
// $nodes_to_be_invisible = array_filter(
1189+
// $nodes_to_be_visible,
1190+
// function ( $node ) {
1191+
// return $node->nodeType === XML_ELEMENT_NODE;
1192+
// }
1193+
// );
1194+
1195+
// var_dump(
1196+
// array_map(
1197+
// function ( $node ) use ( $dom ) {
1198+
// return $dom->saveHTML( $node );
1199+
// },
1200+
// $nodes_to_be_visible
1201+
// ),
1202+
// array_map(
1203+
// function ( $node ) use ( $dom ) {
1204+
// return $dom->saveHTML( $node );
1205+
// },
1206+
// $nodes_to_be_invisible
1207+
// )
1208+
// );
1209+
// var_dump(
1210+
// $nodes_to_be_visible,
1211+
// $nodes_to_be_invisible
1212+
// );
1213+
1214+
if ( $truncated ) {
1215+
$last_visible_node = end( $nodes_to_be_visible );
1216+
1217+
$node_content = strip_tags( $dom->saveHTML( $last_visible_node ) );
1218+
$last_char = $node_content[ strlen( $node_content ) - 1 ];
1219+
1220+
if ( ! preg_match( '/\s/', $last_char ) ) {
1221+
$last_visible_node->appendChild( $dom->createTextNode( ' ' ) );
1222+
}
1223+
1224+
$button = $dom->createElement( 'button', pll__( 'more' ) );
1225+
$button->setAttribute( 'class', 'concert-more-button' );
1226+
$button->setAttribute( 'onclick', 'this.parentElement.nextElementSibling.hidden = false; this.hidden = true;' );
1227+
$last_visible_node->appendChild( $button );
1228+
}
1229+
1230+
foreach ( $nodes_to_be_visible as $node ) {
1231+
$truncated_content .= $dom->saveHTML( $node );
11571232
}
1233+
1234+
foreach ( $nodes_to_be_invisible as $node ) {
1235+
$remaining_content .= $dom->saveHTML( $node );
1236+
}
1237+
1238+
return $truncated_content . '<div hidden>' . $remaining_content . '</div>';
1239+
1240+
foreach ( $body->childNodes as $node ) {
1241+
if ( $truncated ) {
1242+
$remaining_content .= $dom->saveHTML( $node );
1243+
} else {
1244+
$node_content = $dom->saveHTML( $node );
1245+
$node_length = mb_strlen( strip_tags( $node_content ) );
1246+
1247+
if ( $current_length + $node_length > $max_length ) {
1248+
$truncated = true;
1249+
$button = $dom->createElement( 'button', pll__( 'more' ) );
1250+
$button->setAttribute( 'class', 'concert-more-button' );
1251+
$node->appendChild( $button );
1252+
1253+
$remaining_content .= $node_content;
1254+
} else {
1255+
$truncated_content .= $node_content;
1256+
$current_length += $node_length;
1257+
}
1258+
}
1259+
}
1260+
1261+
// var_dump( $truncated_content, $remaining_content );
1262+
1263+
echo '<div class="acf-content">';
1264+
echo $truncated_content;
1265+
1266+
if ( $remaining_content ) {
1267+
echo '<div class="remaining-content" style="display: none;">' . $remaining_content . '</div>';
1268+
}
1269+
1270+
echo '</div>';
1271+
1272+
// // JavaScript для обработки клика по кнопке
1273+
// echo "
1274+
// <script>
1275+
// document.addEventListener('DOMContentLoaded', function() {
1276+
// var button = document.querySelector('.show-more');
1277+
// var remainingContent = document.querySelector('.remaining-content');
1278+
1279+
// if (button && remainingContent) {
1280+
// button.addEventListener('click', function() {
1281+
// if (remainingContent.style.display === 'none') {
1282+
// remainingContent.style.display = 'block';
1283+
// button.textContent = 'Show less';
1284+
// } else {
1285+
// remainingContent.style.display = 'none';
1286+
// button.textContent = 'Show more';
1287+
// }
1288+
// });
1289+
// }
1290+
// });
1291+
// </script>
1292+
// ";
1293+
1294+
// old
1295+
// if ( strlen( $text ) > 685 ) {
1296+
// $trimmed_text = substr( $text, 0, 685 );
1297+
// $last_space_position = strrpos( $trimmed_text, ' ' );
1298+
1299+
// if ( false !== $last_space_position ) {
1300+
// $trimmed_text = substr( $trimmed_text, 0, $last_space_position );
1301+
// }
1302+
1303+
// $remaining_text = substr( $text, $last_space_position );
1304+
// $concert_more_text = '<span class="concert-more-text" hidden>' . $remaining_text . '</span>';
1305+
// $concert_more_button = ' <button class="concert-more-button" onclick="this.previousElementSibling.hidden = false; this.hidden = true;">' . pll__( 'more' ) . '</button>';
1306+
// return $trimmed_text . $concert_more_text . $concert_more_button;
1307+
// } else {
1308+
// return $text;
1309+
// }
11581310
}
11591311

11601312
function utopia_get_language_switcher() {

src/styles/pages/_concert.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444
font-weight: 400;
4545
line-height: 120%;
4646
text-indent: 2.5ch;
47+
48+
& p:not(:first-child) {
49+
margin-top: 40rem;
50+
}
51+
52+
& [hidden] {
53+
margin-top: 40rem;
54+
}
4755
}
4856

4957
&-more-button {

style.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ Description:
2020

2121
.rich-right-side p em {
2222
font-style: italic;
23+
24+
color: black;
25+
}
26+
27+
.rich-right-side p strong {
28+
font-weight: 400;
29+
color: #757575;
30+
}
31+
32+
.rich-right-side p strong em {
33+
color: #757575;
2334
}
2435

2536
.barba-container.inner-page[data-barba-namespace='single-concert']

0 commit comments

Comments
 (0)