← All changes
|
includes/page-form-builder/_src/export/builder-exporter.js
+25
-22
11.0
→
11.8.4
View file →
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * @file: ../includes/page-form-builder/_out/export/builder-exporter.js |
| 3 | 3 | */ |
| 4 | 4 | (function () { |
| @@ -216,11 +216,13 @@ | ||
| 216 | 216 | // ================================================================================================= |
| 217 | 217 | const walk_section = (sec) => { |
| 218 | 218 | const section_col_styles = parse_col_styles_json( sec && sec.col_styles ); |
| 219 | 219 | |
| 220 | - return { | |
| 221 | - id : sec?.id, | |
| 222 | - columns: (sec?.columns || []).map( (col, col_index) => { | |
| 220 | + return { | |
| 221 | + id : sec?.id, | |
| 222 | + html_id : sec?.html_id || '', | |
| 223 | + cssclass : sec?.cssclass || '', | |
| 224 | + columns : (sec?.columns || []).map( (col, col_index) => { | |
| 223 | 225 | const items = Array.isArray( col?.items ) |
| 224 | 226 | ? col.items |
| 225 | 227 | : [ |
| 226 | 228 | ...(col?.fields || []).map( (f) => ({ type: 'field', data: f }) ), |
| @@ -460,13 +462,14 @@ | ||
| 460 | 462 | ? section.columns |
| 461 | 463 | : [ { width: '100%', fields: [], sections: [] } ]; |
| 462 | 464 | |
| 463 | 465 | // Row is active if ANY column carries styles. |
| 464 | - var row_is_active = cols.some( function (col) { return has_non_default_col_styles( col && col.col_styles ); } ); | |
| 465 | - var row_attr_active = row_is_active ? ' data-colstyles-active="1"' : ''; | |
| 466 | + var row_is_active = cols.some( function (col) { return has_non_default_col_styles( col && col.col_styles ); } ); | |
| 467 | + var row_attr_active = row_is_active ? ' data-colstyles-active="1"' : ''; | |
| 468 | + var row_custom_attrs = WPBC_BFB_Exporter.item_wrapper_attrs( section, ctx ); | |
| 469 | + | |
| 470 | + open( `<r${row_custom_attrs}${row_attr_active}>` ); | |
| 466 | 471 | |
| 467 | - open( `<r${row_attr_active}>` ); | |
| 468 | - | |
| 469 | 472 | const bases = compute_effective_bases( cols, cfg.gapPercent ); |
| 470 | 473 | const esc_attr = core.WPBC_BFB_Sanitize.escape_html; |
| 471 | 474 | |
| 472 | 475 | cols.forEach( (col, idx) => { |
| @@ -511,20 +514,20 @@ | ||
| 511 | 514 | } |
| 512 | 515 | |
| 513 | 516 | |
| 514 | 517 | /** |
| 515 | - * Build attribute string for the <item> wrapper. | |
| 516 | - * Currently only used for CAPTCHA: pushes css classes and html_id to the wrapper. | |
| 517 | - * Also ensures uniqueness of the html_id across the export (uses ctx.usedIds). | |
| 518 | - * | |
| 519 | - * @param {Object} field | |
| 520 | - * @param {{usedIds:Set<string>}} ctx | |
| 521 | - * @returns {string} e.g. ' class="x y" id="myId"' | |
| 522 | - */ | |
| 523 | - static item_wrapper_attrs(field, ctx) { | |
| 524 | - if ( ! field ) { | |
| 525 | - return ''; | |
| 526 | - } | |
| 518 | + * Build a sanitized custom CSS class and HTML ID attribute string for an exported wrapper. | |
| 519 | + * Used by section row wrappers and fields whose attributes belong on the <item> wrapper. | |
| 520 | + * Also ensures uniqueness of the html_id across the export (uses ctx.usedIds). | |
| 521 | + * | |
| 522 | + * @param {Object} wrapper_data Object containing optional cssclass and html_id properties. | |
| 523 | + * @param {{usedIds:Set<string>}} ctx | |
| 524 | + * @returns {string} e.g. ' class="x y" id="myId"' | |
| 525 | + */ | |
| 526 | + static item_wrapper_attrs(wrapper_data, ctx) { | |
| 527 | + if ( ! wrapper_data ) { | |
| 528 | + return ''; | |
| 529 | + } | |
| 527 | 530 | const esc_html = core.WPBC_BFB_Sanitize.escape_html; |
| 528 | 531 | const cls_sanit = core.WPBC_BFB_Sanitize.sanitize_css_classlist; |
| 529 | 532 | const sid = core.WPBC_BFB_Sanitize.sanitize_html_id; |
| 530 | 533 | |
| @@ -529,11 +532,11 @@ | ||
| 529 | 532 | const sid = core.WPBC_BFB_Sanitize.sanitize_html_id; |
| 530 | 533 | |
| 531 | 534 | let out = ''; |
| 532 | 535 | |
| 533 | - const cls_raw = String( field.cssclass_extra || field.cssclass || field.class || '' ); | |
| 534 | - const cls = cls_sanit( cls_raw ); | |
| 535 | - let html_id = field.html_id ? sid( String( field.html_id ) ) : ''; | |
| 536 | + const cls_raw = String( wrapper_data.cssclass_extra || wrapper_data.cssclass || wrapper_data.class || '' ); | |
| 537 | + const cls = cls_sanit( cls_raw ); | |
| 538 | + let html_id = wrapper_data.html_id ? sid( String( wrapper_data.html_id ) ) : ''; | |
| 536 | 539 | if ( html_id && ctx?.usedIds ) { |
| 537 | 540 | let unique = html_id, i = 2; |
| 538 | 541 | while ( ctx.usedIds.has( unique ) ) { |
| 539 | 542 | unique = `${html_id}_${i++}`; |