← All changes
|
includes/widgets/Woo_Archive_Description/Woo_Archive_Description.php
+41
-5
51.1.76
→
51.1.83
View file →
| @@ -30,9 +30,9 @@ | ||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function get_icon(): string |
| 33 | 33 | { |
| 34 | - return 'eicon-editor-paragraph'; | |
| 34 | + return 'king-addons-icon king-addons-woo-archive-description'; | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public function get_categories(): array |
| 38 | 38 | { |
| @@ -38,8 +38,22 @@ | ||
| 38 | 38 | { |
| 39 | 39 | return ['king-addons-woo-builder']; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | + /** | |
| 43 | + * Script handles. | |
| 44 | + * | |
| 45 | + * ModulesMap registers this file, but without declaring the dependency here | |
| 46 | + * Elementor never enqueues it - the "Read more" toggle had no script behind | |
| 47 | + * it on the page. | |
| 48 | + * | |
| 49 | + * @return array<int,string> | |
| 50 | + */ | |
| 51 | + public function get_script_depends(): array | |
| 52 | + { | |
| 53 | + return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-archive-description-script']; | |
| 54 | + } | |
| 55 | + | |
| 42 | 56 | public function get_style_depends(): array |
| 43 | 57 | { |
| 44 | 58 | return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-archive-description-style']; |
| 45 | 59 | } |
| @@ -67,8 +81,9 @@ | ||
| 67 | 81 | 'read_more_text', |
| 68 | 82 | [ |
| 69 | 83 | 'label' => esc_html__('Read more text (Pro)', 'king-addons'), |
| 70 | 84 | 'type' => Controls_Manager::TEXT, |
| 85 | + 'dynamic' => ['active' => true], | |
| 71 | 86 | 'default' => esc_html__('Read more', 'king-addons'), |
| 72 | 87 | ] |
| 73 | 88 | ); |
| 74 | 89 | |
| @@ -99,8 +114,9 @@ | ||
| 99 | 114 | 'custom_text', |
| 100 | 115 | [ |
| 101 | 116 | 'label' => esc_html__('Custom text', 'king-addons'), |
| 102 | 117 | 'type' => Controls_Manager::TEXTAREA, |
| 118 | + 'dynamic' => ['active' => true], | |
| 103 | 119 | 'rows' => 4, |
| 104 | 120 | 'condition' => [ |
| 105 | 121 | 'source' => 'custom', |
| 106 | 122 | ], |
| @@ -177,11 +193,20 @@ | ||
| 177 | 193 | } |
| 178 | 194 | } |
| 179 | 195 | |
| 180 | 196 | if (empty($desc)) { |
| 197 | + // Nothing to show is a legitimate state, but a blank widget in the | |
| 198 | + // editor reads as a fault. | |
| 199 | + if (\Elementor\Plugin::$instance->editor->is_edit_mode()) { | |
| 200 | + echo '<div class="king-addons-woo-builder-notice">' | |
| 201 | + . esc_html__('The description comes from the shop page or the category being viewed.', 'king-addons') | |
| 202 | + . '</div>'; | |
| 203 | + } | |
| 181 | 204 | return; |
| 182 | 205 | } |
| 183 | 206 | |
| 207 | + $full_desc = $desc; | |
| 208 | + | |
| 184 | 209 | $trim = !empty($settings['trim_words']) && $can_pro ? (int) $settings['trim_words'] : 0; |
| 185 | 210 | $trimmed = false; |
| 186 | 211 | if ($trim > 0) { |
| 187 | 212 | $trimmed = true; |
| @@ -198,13 +223,24 @@ | ||
| 198 | 223 | $settings['format'] |
| 199 | 224 | ); |
| 200 | 225 | } |
| 201 | 226 | |
| 202 | - echo '<div class="ka-woo-archive-description">'; | |
| 203 | - echo wp_kses_post($desc); | |
| 204 | - if ($trimmed && !empty($settings['read_more_text']) && $can_pro) { | |
| 205 | - echo '<a class="ka-woo-archive-description__readmore" href="#">' . esc_html($settings['read_more_text']) . '</a>'; | |
| 227 | + $has_more = $trimmed && !empty($settings['read_more_text']) && $can_pro; | |
| 228 | + | |
| 229 | + echo '<div class="ka-woo-archive-description"' . ($has_more ? ' data-ka-expandable="1"' : '') . '>'; | |
| 230 | + echo '<div class="ka-woo-archive-description__short">' . wp_kses_post($desc) . '</div>'; | |
| 231 | + | |
| 232 | + if ($has_more) { | |
| 233 | + // The link was an href="#" with no behaviour behind it: clicking | |
| 234 | + // "Read more" jumped to the top of the page and never revealed | |
| 235 | + // anything. The full text ships alongside, hidden until asked for - | |
| 236 | + // and only when the toggle exists, so the page never carries the | |
| 237 | + // same paragraph twice for nothing. | |
| 238 | + echo '<div class="ka-woo-archive-description__full" hidden>' . wp_kses_post($full_desc) . '</div>'; | |
| 239 | + echo '<button type="button" class="ka-woo-archive-description__readmore" aria-expanded="false">' | |
| 240 | + . esc_html($settings['read_more_text']) . '</button>'; | |
| 206 | 241 | } |
| 242 | + | |
| 207 | 243 | echo '</div>'; |
| 208 | 244 | } |
| 209 | 245 | } |
| 210 | 246 | |