PluginProbe
Booking Calendar / 10.15.6
Booking Calendar v10.15.6
11.9 11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 All 205 releases
booking / includes / page-form-builder / field-packs / _shared / _src / hint-shortcode-wptpl.js

hint-shortcode-wptpl.js in Booking Calendar 10.15.6, at includes/page-form-builder/field-packs/_shared/_src/hint-shortcode-wptpl.js

168 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // == WPBC BFB Shared Pack Helper: Generic Hint Shortcode
2 (function ( w, d ) {
3 'use strict';
4
5 w.WPBC_BFB_RegisterShortcodeHintPack = function ( cfg ) {
6 cfg = cfg || {};
7
8 var T = String( cfg.token || '' );
9 var S = String( cfg.shortcode || T );
10 var P = String( cfg.prefix || '' );
11 var L = String( cfg.label || T );
12 var B = String( cfg.boot || '' );
13 var F = String( cfg.fallback || '' );
14 var Core = w.WPBC_BFB_Core || {};
15 var Registry = Core.WPBC_BFB_Field_Renderer_Registry;
16 var Base = Core.WPBC_BFB_Field_Base;
17
18 if ( ! T ) {
19 return;
20 }
21
22 if ( ! Registry || typeof Registry.register !== 'function' || ! Base ) {
23 w._wpbc?.dev?.error?.( 'wpbc_bfb_field_' + T, 'Core registry/base missing' );
24 return;
25 }
26
27 class ShortcodeHintField extends Base {
28 static template_id = 'wpbc-bfb-field-' + T;
29
30 static get_defaults() {
31 return { type: T, prefix_text: P, html_id: '', cssclass: '', help: '' };
32 }
33
34 static get_boot() {
35 return B ? ( w[ B ] || {} ) : {};
36 }
37
38 static render( el, data, ctx ) {
39 if ( ! el ) {
40 return;
41 }
42
43 var d_normalized = this.normalize_data( data );
44 var s = Core.WPBC_BFB_Sanitize || {};
45 var boot = this.get_boot();
46 var html_id = d_normalized.html_id ? ( s.sanitize_html_id ? s.sanitize_html_id( String( d_normalized.html_id ) ) : String( d_normalized.html_id ) ) : '';
47 var cssclass = d_normalized.cssclass ? ( s.sanitize_css_classlist ? s.sanitize_css_classlist( String( d_normalized.cssclass ) ) : String( d_normalized.cssclass ) ) : '';
48 var tpl = this.get_template( this.template_id );
49 var is_supported = String( boot.is_supported || '0' ) === '1';
50
51 if ( typeof tpl !== 'function' ) {
52 el.innerHTML = '<div class="wpbc_bfb__error" role="alert">Template not found: ' + this.template_id + '.</div>';
53 return;
54 }
55
56 try {
57 el.innerHTML = tpl( Object.assign( {}, d_normalized, {
58 html_id: html_id,
59 cssclass: cssclass,
60 is_supported: is_supported,
61 upgrade_text: String( boot.upgrade_text || '' ),
62 preview_value: String( boot.preview_value || F )
63 } ) );
64 } catch ( er ) {
65 w._wpbc?.dev?.error?.( T + '_wptpl.tpl.render', er );
66 el.innerHTML = '<div class="wpbc_bfb__error" role="alert">Error rendering ' + L + ' preview.</div>';
67 return;
68 }
69
70 el.dataset.type = T;
71 el.dataset.prefix_text = d_normalized.prefix_text != null ? String( d_normalized.prefix_text ) : '';
72 el.dataset.html_id = html_id;
73 el.dataset.cssclass = cssclass;
74 el.dataset.help = d_normalized.help != null ? String( d_normalized.help ) : '';
75 el.setAttribute( 'data-label', d_normalized.prefix_text != null ? String( d_normalized.prefix_text ) : '' );
76 Core.UI?.WPBC_BFB_Overlay?.ensure?.( ctx?.builder, el );
77 }
78
79 static on_field_drop( data, el, ctx ) {
80 super.on_field_drop?.( data, el, ctx );
81 }
82 }
83
84 try {
85 Registry.register( T, ShortcodeHintField );
86 } catch ( er ) {
87 w._wpbc?.dev?.error?.( 'wpbc_bfb_field_' + T + '.register', er );
88 }
89
90 function register_booking_form_exporter() {
91 var exporter = w.WPBC_BFB_Exporter;
92 if ( ! exporter || typeof exporter.register !== 'function' ) {
93 return;
94 }
95 if ( typeof exporter.has_exporter === 'function' && exporter.has_exporter( T ) ) {
96 return;
97 }
98
99 var s = Core.WPBC_BFB_Sanitize || {};
100 var esc_html = s.escape_html || function ( value ) {
101 return String( value ).replace( /&/g, '&amp;' ).replace( /</g, '&lt;' ).replace( />/g, '&gt;' ).replace( /"/g, '&quot;' ).replace( /'/g, '&#039;' );
102 };
103 var sanitize_html_id = s.sanitize_html_id || function ( value ) { return String( value || '' ); };
104 var sanitize_css_classlist = s.sanitize_css_classlist || function ( value ) { return String( value || '' ); };
105
106 exporter.register( T, function ( field, emit ) {
107 var prefix_text = ( field && typeof field.prefix_text === 'string' ) ? field.prefix_text.trim() : P;
108 var html_id = field && field.html_id ? sanitize_html_id( field.html_id ) : '';
109 var cssclass = field && field.cssclass ? sanitize_css_classlist( field.cssclass ) : '';
110 var body_html = '';
111 var attrs = '';
112
113 if ( prefix_text ) {
114 body_html += esc_html( prefix_text ) + '&nbsp;';
115 }
116 body_html += '<strong>[' + S + ']</strong>';
117 if ( html_id ) {
118 attrs += ' id="' + esc_html( html_id ) + '"';
119 }
120 if ( cssclass ) {
121 attrs += ' class="' + esc_html( cssclass ) + '"';
122 }
123 if ( attrs ) {
124 body_html = '<span' + attrs + '>' + body_html + '</span>';
125 }
126 emit( body_html );
127 } );
128 }
129
130 if ( w.WPBC_BFB_Exporter && typeof w.WPBC_BFB_Exporter.register === 'function' ) {
131 register_booking_form_exporter();
132 } else {
133 d.addEventListener( 'wpbc:bfb:exporter-ready', register_booking_form_exporter, { once: true } );
134 }
135
136 function register_booking_data_exporter() {
137 var content_exporter = w.WPBC_BFB_ContentExporter;
138 if ( ! content_exporter || typeof content_exporter.register !== 'function' ) {
139 return;
140 }
141 if ( typeof content_exporter.has_exporter === 'function' && content_exporter.has_exporter( T ) ) {
142 return;
143 }
144
145 content_exporter.register( T, function ( field, emit, extras ) {
146 extras = extras || {};
147 var cfg_export = extras.cfg || {};
148 var raw_label = ( field && typeof field.prefix_text === 'string' ) ? field.prefix_text.trim() : '';
149 var label = raw_label.replace( /\s*:\s*$/, '' ) || L;
150
151 if ( typeof content_exporter.emit_line_bold_field === 'function' ) {
152 // Intentionally stop exporting hints into the "Content of booking fields data" form!
153 // content_exporter.emit_line_bold_field( emit, label, S, cfg_export );
154 return;
155 }
156 // Intentionally stop exporting hints into the "Content of booking fields data" form!
157 // emit( '<b>' + label + '</b>: <f>[' + S + ']</f><br>' );
158 } );
159 }
160
161 if ( w.WPBC_BFB_ContentExporter && typeof w.WPBC_BFB_ContentExporter.register === 'function' ) {
162 register_booking_data_exporter();
163 } else {
164 d.addEventListener( 'wpbc:bfb:content-exporter-ready', register_booking_data_exporter, { once: true } );
165 }
166 };
167 })( window, document );
168