← All changes
|
includes/page-form-builder/field-packs/static-text/_src/static-text.js
+34
-13
11.7
→
11.9
View file →
| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | // ================================================================================================= |
| 2 | 2 | // == Pack: Static Text (WP-template-less; schema-driven) |
| 3 | 3 | // == File: /includes/page-form-builder/field-packs/static-text/_out/static-text.js |
| 4 | 4 | // == Depends: WPBC_BFB_Field_Base, Field_Renderer_Registry, Core.Sanitize, Exporter API |
| 5 | -// == Version: 1.0.1 (09.11.2025) — add base CSS class "wpbc_static_text" to preview & export | |
| 5 | +// == Version: 1.1.0 (25.09.2026) — add sanitized link tokens to preview & export | |
| 6 | 6 | // ================================================================================================= |
| 7 | 7 | (function (w, d) { |
| 8 | 8 | 'use strict'; |
| 9 | 9 | |
| @@ -27,14 +27,15 @@ | ||
| 27 | 27 | class wpbc_bfb_field_static_text extends Base { |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Defaults (must mirror PHP schema). |
| 31 | - * @returns {{type:string,text:string,tag:string,align:string,bold:number,italic:number,html_allowed:number,nl2br:number,cssclass_extra:string,name:string,html_id:string,help:string,usage_key:string}} | |
| 31 | + * @returns {{type:string,text:string,links:Array,tag:string,align:string,bold:number,italic:number,html_allowed:number,nl2br:number,cssclass_extra:string,name:string,html_id:string,help:string,usage_key:string}} | |
| 32 | 32 | */ |
| 33 | 33 | static get_defaults() { |
| 34 | 34 | return { |
| 35 | 35 | type : 'static_text', |
| 36 | - text : 'Add your message here…', | |
| 36 | + text : 'Add your message here…', | |
| 37 | + links : [], | |
| 37 | 38 | tag : 'p', |
| 38 | 39 | align : 'left', |
| 39 | 40 | bold : 0, |
| 40 | 41 | italic : 0, |
| @@ -133,13 +134,23 @@ | ||
| 133 | 134 | var style_attr = style_bits.length ? ( ' style="' + style_bits.join(';') + '"' ) : ''; |
| 134 | 135 | |
| 135 | 136 | // Content |
| 136 | 137 | var content = ''; |
| 137 | - if ( d_norm.html_allowed ) { | |
| 138 | - content = String( d_norm.text || '' ); | |
| 139 | - } else { | |
| 140 | - content = this.escape_text( d_norm.text, !! d_norm.nl2br ); | |
| 141 | - } | |
| 138 | + if ( w.WPBC_BFB_Static_Text_Links && 'function' === typeof w.WPBC_BFB_Static_Text_Links.build_content_html ) { | |
| 139 | + content = w.WPBC_BFB_Static_Text_Links.build_content_html( | |
| 140 | + d_norm.text, | |
| 141 | + d_norm.links, | |
| 142 | + { | |
| 143 | + allow_html : !! d_norm.html_allowed, | |
| 144 | + nl2br : !! d_norm.nl2br, | |
| 145 | + preview_only: true | |
| 146 | + } | |
| 147 | + ); | |
| 148 | + } else if ( d_norm.html_allowed ) { | |
| 149 | + content = String( d_norm.text || '' ); | |
| 150 | + } else { | |
| 151 | + content = this.escape_text( d_norm.text, !! d_norm.nl2br ); | |
| 152 | + } | |
| 142 | 153 | |
| 143 | 154 | var help_html = d_norm.help ? '<div class="wpbc_bfb__help">' + esc_html( String( d_norm.help ) ) + '</div>' : ''; |
| 144 | 155 | |
| 145 | 156 | el.innerHTML = |
| @@ -239,13 +250,23 @@ | ||
| 239 | 250 | : ''; |
| 240 | 251 | |
| 241 | 252 | // Content: escape + nl2br when HTML is NOT allowed; raw when allowed. |
| 242 | 253 | var content; |
| 243 | - if ( d.html_allowed ) { | |
| 244 | - content = String( d.text || '' ); | |
| 245 | - } else { | |
| 246 | - content = wpbc_bfb_field_static_text.escape_text( d.text, !! d.nl2br ); | |
| 247 | - } | |
| 254 | + if ( w.WPBC_BFB_Static_Text_Links && 'function' === typeof w.WPBC_BFB_Static_Text_Links.build_content_html ) { | |
| 255 | + content = w.WPBC_BFB_Static_Text_Links.build_content_html( | |
| 256 | + d.text, | |
| 257 | + d.links, | |
| 258 | + { | |
| 259 | + allow_html : !! d.html_allowed, | |
| 260 | + nl2br : !! d.nl2br, | |
| 261 | + preview_only: false | |
| 262 | + } | |
| 263 | + ); | |
| 264 | + } else if ( d.html_allowed ) { | |
| 265 | + content = String( d.text || '' ); | |
| 266 | + } else { | |
| 267 | + content = wpbc_bfb_field_static_text.escape_text( d.text, !! d.nl2br ); | |
| 268 | + } | |
| 248 | 269 | |
| 249 | 270 | emit( |
| 250 | 271 | '<' + tag + id_attr + name_attr + cls_attr + style_attr + '>' + |
| 251 | 272 | content + |