| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * WPBC calendar loader bootstrap. |
| 3 | 3 | * ============================================================================================== |
| 4 | 4 | * - Finds every .calendar_loader_frame[data-wpbc-rid] on the page (now or later). |
| @@ -75,23 +75,32 @@ | ||
| 75 | 75 | function is_processed(el) { |
| 76 | 76 | return processed_set ? processed_set.has( el ) : (el && el.dataset && el.dataset.wpbcProcessed === '1'); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /* --------------------------------------------------------------------------- | |
| 80 | - * Messages (fixed English strings; no i18n) | |
| 81 | - * ------------------------------------------------------------------------ */ | |
| 82 | - | |
| 83 | - /** | |
| 84 | - * Build fixed English messages for a resource. | |
| 85 | - * @param {string|number} rid | |
| 86 | - * @return {{duplicate:string,support:string,lib_jq:string,lib_dp:string,lib_wpbc:string}} | |
| 87 | - */ | |
| 88 | - function get_messages(rid) { | |
| 89 | - var rid_int = parseInt( rid, 10 ); | |
| 90 | - return { | |
| 91 | - duplicate : | |
| 92 | - 'You have added the same calendar (ID = ' + rid_int + ') more than once on this page. ' + | |
| 93 | - 'Please keep only one calendar with the same ID on a page to avoid conflicts.', | |
| 79 | + /* --------------------------------------------------------------------------- | |
| 80 | + * Messages | |
| 81 | + * ------------------------------------------------------------------------ */ | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * Build visitor messages for a resource, using localized Form Messages when available. | |
| 85 | + * @param {string|number} rid | |
| 86 | + * @return {{duplicate:string,init_failed:string,support:string,lib_jq:string,lib_dp:string,lib_wpbc:string}} | |
| 87 | + */ | |
| 88 | + function get_messages(rid) { | |
| 89 | + var rid_int = parseInt( rid, 10 ); | |
| 90 | + var duplicate_message = | |
| 91 | + 'More than one calendar or booking form for Booking Resource ID {resource_id} is present on this page. ' + | |
| 92 | + 'A hidden copy still conflicts with the visible form and can prevent booking submission. ' + | |
| 93 | + 'The site administrator must keep only one calendar or form for this Booking Resource. ' + | |
| 94 | + 'After the page is corrected, reload it and try again.'; | |
| 95 | + | |
| 96 | + if ( w._wpbc && typeof w._wpbc.get_message === 'function' ) { | |
| 97 | + duplicate_message = w._wpbc.get_message( 'message_duplicate_booking_resource_on_page' ) || duplicate_message; | |
| 98 | + } | |
| 99 | + duplicate_message = String( duplicate_message ).replace( /\{resource_id\}/g, String( rid_int ) ); | |
| 100 | + | |
| 101 | + return { | |
| 102 | + duplicate : duplicate_message, | |
| 94 | 103 | init_failed: |
| 95 | 104 | 'The calendar could not be initialized on this page.' + '\n' + |
| 96 | 105 | 'Please check your browser console for JavaScript errors and conflicts with other scripts/plugins.', |
| 97 | 106 | support : '', /* 'Contact [email protected] if you have any questions.', */ |
| @@ -107,16 +116,31 @@ | ||
| 107 | 116 | 'For more information, please refer to this page: https://wpbookingcalendar.com/faq/' |
| 108 | 117 | }; |
| 109 | 118 | } |
| 110 | 119 | |
| 111 | - /** | |
| 112 | - * Wrap plain text (with newlines) in a small HTML container. | |
| 113 | - * @param {string} msg | |
| 114 | - * @return {string} | |
| 115 | - */ | |
| 116 | - function wrap_html(msg) { | |
| 117 | - return '<div style="font-size:13px;margin:10px;">' + String( msg || '' ).replace( /\n/g, '<br>' ) + '</div>'; | |
| 118 | - } | |
| 120 | + /** | |
| 121 | + * Escape a plain-text loader message before inserting its wrapper markup. | |
| 122 | + * | |
| 123 | + * @param {string} plain_text Visitor-facing plain text. | |
| 124 | + * @return {string} HTML-safe text. | |
| 125 | + */ | |
| 126 | + function escape_html(plain_text) { | |
| 127 | + return String( plain_text || '' ) | |
| 128 | + .replace( /&/g, '&' ) | |
| 129 | + .replace( /</g, '<' ) | |
| 130 | + .replace( />/g, '>' ) | |
| 131 | + .replace( /"/g, '"' ) | |
| 132 | + .replace( /'/g, ''' ); | |
| 133 | + } | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * Wrap plain text (with newlines) in a small HTML container. | |
| 137 | + * @param {string} msg | |
| 138 | + * @return {string} | |
| 139 | + */ | |
| 140 | + function wrap_html(msg) { | |
| 141 | + return '<div style="font-size:13px;margin:10px;">' + escape_html( msg ).replace( /\n/g, '<br>' ) + '</div>'; | |
| 142 | + } | |
| 119 | 143 | |
| 120 | 144 | /** Library presence checks (fast & cheap). */ |
| 121 | 145 | function has_jq() { |
| 122 | 146 | return !!(w.jQuery && jQuery.fn && typeof jQuery.fn.on === 'function'); |