| 1 |
( function() { |
| 2 |
let thisFormId = 0; |
| 3 |
|
| 4 |
jQuery( document ).ready( function() { |
| 5 |
const thisForm = document.getElementById( 'form_id' ); |
| 6 |
if ( thisForm ) { |
| 7 |
thisFormId = thisForm.value; |
| 8 |
} |
| 9 |
|
| 10 |
// Only load on views settings page. |
| 11 |
if ( document.getElementById( 'frm_dyncontent' ) !== null ) { |
| 12 |
viewInit(); |
| 13 |
} |
| 14 |
|
| 15 |
document.addEventListener( 'frm_legacy_views_handle_field_focus', function( event ) { |
| 16 |
const { idAttrValue } = event.frmData; |
| 17 |
toggleAllowedShortcodes( idAttrValue ); |
| 18 |
} ); |
| 19 |
} ); |
| 20 |
|
| 21 |
function viewInit() { |
| 22 |
const $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) ); |
| 23 |
$advInfo.before( '<div id="frm_position_ele"></div>' ); |
| 24 |
setupMenuOffset(); |
| 25 |
|
| 26 |
jQuery( document ).on( 'blur', '#param', checkDetailPageSlug ); |
| 27 |
jQuery( document ).on( 'blur', 'input[name^="options[where_val]"]', checkFilterParamNames ); |
| 28 |
|
| 29 |
// Show loading indicator. |
| 30 |
jQuery( '#publish' ).on( 'mousedown', function() { |
| 31 |
this.classList.add( 'frm_loading_button' ); |
| 32 |
} ); |
| 33 |
|
| 34 |
// move content tabs |
| 35 |
jQuery( '#frm_dyncontent .handlediv' ).before( jQuery( '#frm_dyncontent .nav-menus-php' ) ); |
| 36 |
|
| 37 |
// click content tabs |
| 38 |
jQuery( '.nav-tab-wrapper a' ).on( 'click', clickContentTab ); |
| 39 |
|
| 40 |
// click tabs after panel is replaced with ajax |
| 41 |
jQuery( '#side-sortables' ).on( 'click', '.frm_doing_ajax.categorydiv .category-tabs a', clickTabsAfterAjax ); |
| 42 |
|
| 43 |
initToggleShortcodes(); |
| 44 |
jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ); |
| 45 |
|
| 46 |
jQuery( 'input[name="show_count"]' ).on( 'change', showCount ); |
| 47 |
|
| 48 |
jQuery( document.getElementById( 'form_id' ) ).on( 'change', displayFormSelected ); |
| 49 |
|
| 50 |
const $addRemove = jQuery( '.frm_repeat_rows' ); |
| 51 |
$addRemove.on( 'click', '.frm_add_order_row', addOrderRow ); |
| 52 |
$addRemove.on( 'click', '.frm_add_where_row', addWhereRow ); |
| 53 |
$addRemove.on( 'change', '.frm_insert_where_options', insertWhereOptions ); |
| 54 |
$addRemove.on( 'change', '.frm_where_is_options', hideWhereOptions ); |
| 55 |
|
| 56 |
setDefaultPostStatus(); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Checks the Detail Page slug to see if it's a reserved word and displays a message if it is. |
| 61 |
*/ |
| 62 |
function checkDetailPageSlug() { |
| 63 |
let slug = jQuery( '#param' ).val(); |
| 64 |
let msg; |
| 65 |
slug = slug.trim().toLowerCase(); |
| 66 |
if ( Array.isArray( frmAdminJs.unsafe_params ) && frmAdminJs.unsafe_params.includes( slug ) ) { |
| 67 |
msg = frmAdminJs.slug_is_reserved; |
| 68 |
msg = msg.replace( '****', addHtmlTags( slug, 'strong' ) ); |
| 69 |
msg += '<br /><br />'; |
| 70 |
msg += addHtmlTags( `<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">${ frmAdminJs.reserved_words }</a>`, 'div' ); |
| 71 |
infoModal( msg ); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Checks View filter value for params named with reserved words and displays a message if any are found. |
| 77 |
*/ |
| 78 |
function checkFilterParamNames() { |
| 79 |
const regEx = /\[\s*get\s*param\s*=\s*['"]?([a-zA-Z-_]+)['"]?/ig; |
| 80 |
const filterValue = jQuery( this ).val(); |
| 81 |
let match = regEx.exec( filterValue ); |
| 82 |
let unsafeParams = ''; |
| 83 |
|
| 84 |
while ( match !== null ) { |
| 85 |
if ( Array.isArray( frmAdminJs.unsafe_params ) && frmAdminJs.unsafe_params.includes( match[ 1 ] ) ) { |
| 86 |
if ( unsafeParams !== '' ) { |
| 87 |
unsafeParams += `", "${ match[ 1 ] }`; |
| 88 |
} else { |
| 89 |
unsafeParams = match[ 1 ]; |
| 90 |
} |
| 91 |
} |
| 92 |
match = regEx.exec( filterValue ); |
| 93 |
} |
| 94 |
|
| 95 |
if ( unsafeParams !== '' ) { |
| 96 |
let msg = frmAdminJs.param_is_reserved; |
| 97 |
msg = msg.replace( '****', addHtmlTags( unsafeParams, 'strong' ) ); |
| 98 |
msg += '<br /><br />'; |
| 99 |
msg += ` <a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">${ frmAdminJs.reserved_words }</a>`; |
| 100 |
|
| 101 |
infoModal( msg ); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
function addHtmlTags( text, tag ) { |
| 106 |
tag = tag ? tag : 'p'; |
| 107 |
return `<${ tag }>${ text }</${ tag }>`; |
| 108 |
} |
| 109 |
|
| 110 |
function initToggleShortcodes() { |
| 111 |
if ( typeof tinymce !== 'object' ) { |
| 112 |
return; |
| 113 |
} |
| 114 |
|
| 115 |
DOM = tinymce.DOM; |
| 116 |
if ( DOM.events !== undefined && DOM.events.add !== undefined ) { |
| 117 |
DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseover', function() { |
| 118 |
if ( jQuery( '*:focus' ).length > 0 ) { |
| 119 |
return; |
| 120 |
} |
| 121 |
if ( this.id ) { |
| 122 |
toggleAllowedShortcodes( this.id.slice( 3, -5 ) ); |
| 123 |
} |
| 124 |
} ); |
| 125 |
DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseout', function() { |
| 126 |
if ( jQuery( '*:focus' ).length > 0 ) { |
| 127 |
return; |
| 128 |
} |
| 129 |
if ( this.id ) { |
| 130 |
toggleAllowedShortcodes( this.id.slice( 3, -5 ) ); |
| 131 |
} |
| 132 |
} ); |
| 133 |
} else { |
| 134 |
jQuery( '#frm_dyncontent' ).on( 'mouseover mouseout', '.wp-editor-wrap', function() { |
| 135 |
if ( jQuery( '*:focus' ).length > 0 ) { |
| 136 |
return; |
| 137 |
} |
| 138 |
if ( this.id ) { |
| 139 |
toggleAllowedShortcodes( this.id.slice( 3, -5 ) ); |
| 140 |
} |
| 141 |
} ); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
function setDefaultPostStatus() { |
| 146 |
const urlQuery = window.location.search.substring( 1 ); |
| 147 |
if ( ! urlQuery.includes( 'action=edit' ) ) { |
| 148 |
document.getElementById( 'post-visibility-display' ).textContent = frmAdminJs.private_label; |
| 149 |
document.getElementById( 'hidden-post-visibility' ).value = 'private'; |
| 150 |
document.getElementById( 'visibility-radio-private' ).checked = true; |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
function setupMenuOffset() { |
| 155 |
window.onscroll = document.documentElement.onscroll = setMenuOffset; |
| 156 |
setMenuOffset(); |
| 157 |
} |
| 158 |
|
| 159 |
function setMenuOffset() { |
| 160 |
const fields = document.getElementById( 'frm_adv_info' ); |
| 161 |
if ( ! fields ) { |
| 162 |
return; |
| 163 |
} |
| 164 |
|
| 165 |
const currentOffset = document.documentElement.scrollTop || document.body.scrollTop; // body for Safari |
| 166 |
if ( currentOffset === 0 ) { |
| 167 |
fields.classList.remove( 'frm_fixed' ); |
| 168 |
return; |
| 169 |
} |
| 170 |
|
| 171 |
const posEle = document.getElementById( 'frm_position_ele' ); |
| 172 |
if ( ! posEle ) { |
| 173 |
return; |
| 174 |
} |
| 175 |
|
| 176 |
const eleOffset = jQuery( posEle ).offset(); |
| 177 |
const offset = eleOffset.top; |
| 178 |
let desiredOffset = offset - currentOffset; |
| 179 |
let menuHeight = 0; |
| 180 |
|
| 181 |
const menu = document.getElementById( 'wpadminbar' ); |
| 182 |
if ( menu ) { |
| 183 |
menuHeight = menu.offsetHeight; |
| 184 |
} |
| 185 |
|
| 186 |
if ( desiredOffset < menuHeight ) { |
| 187 |
desiredOffset = menuHeight; |
| 188 |
} |
| 189 |
|
| 190 |
if ( desiredOffset > menuHeight ) { |
| 191 |
fields.classList.remove( 'frm_fixed' ); |
| 192 |
} else { |
| 193 |
fields.classList.add( 'frm_fixed' ); |
| 194 |
if ( desiredOffset !== 32 ) { |
| 195 |
fields.style.top = `${ desiredOffset }px`; |
| 196 |
} |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
function showCount() { |
| 201 |
/*jshint validthis:true */ |
| 202 |
const value = jQuery( this ).val(); |
| 203 |
|
| 204 |
const $cont = document.getElementById( 'date_select_container' ); |
| 205 |
const tab = document.getElementById( 'frm_listing_tab' ); |
| 206 |
let label = tab.getAttribute( 'data-label' ); |
| 207 |
if ( value === 'calendar' ) { |
| 208 |
jQuery( '.hide_dyncontent, .hide_single_content' ).removeClass( 'frm_hidden' ); |
| 209 |
jQuery( '.limit_container' ).addClass( 'frm_hidden' ); |
| 210 |
$cont.style.display = 'block'; |
| 211 |
} else if ( value === 'dynamic' ) { |
| 212 |
jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).removeClass( 'frm_hidden' ); |
| 213 |
} else if ( value === 'one' ) { |
| 214 |
label = tab.getAttribute( 'data-one' ); |
| 215 |
jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).addClass( 'frm_hidden' ); |
| 216 |
} else { |
| 217 |
jQuery( '.hide_dyncontent' ).addClass( 'frm_hidden' ); |
| 218 |
jQuery( '.limit_container, .hide_single_content' ).removeClass( 'frm_hidden' ); |
| 219 |
} |
| 220 |
|
| 221 |
if ( value !== 'calendar' ) { |
| 222 |
$cont.style.display = 'none'; |
| 223 |
} |
| 224 |
tab.innerHTML = label; |
| 225 |
} |
| 226 |
|
| 227 |
function displayFormSelected() { |
| 228 |
/*jshint validthis:true */ |
| 229 |
const formId = jQuery( this ).val(); |
| 230 |
thisFormId = formId; // set the global form id |
| 231 |
if ( formId === '' ) { |
| 232 |
return; |
| 233 |
} |
| 234 |
|
| 235 |
jQuery.ajax( { |
| 236 |
type: 'POST', |
| 237 |
url: ajaxurl, |
| 238 |
data: { |
| 239 |
action: 'frm_get_cd_tags_box', |
| 240 |
form_id: formId, |
| 241 |
nonce: frmGlobal.nonce |
| 242 |
}, |
| 243 |
success( html ) { |
| 244 |
jQuery( '#frm_adv_info .categorydiv' ).html( html ); |
| 245 |
} |
| 246 |
} ); |
| 247 |
|
| 248 |
jQuery.ajax( { |
| 249 |
type: 'POST', |
| 250 |
url: ajaxurl, |
| 251 |
data: { |
| 252 |
action: 'frm_get_date_field_select', |
| 253 |
form_id: formId, |
| 254 |
nonce: frmGlobal.nonce |
| 255 |
}, |
| 256 |
success( html ) { |
| 257 |
jQuery( document.getElementById( 'date_select_container' ) ).html( html ); |
| 258 |
} |
| 259 |
} ); |
| 260 |
} |
| 261 |
|
| 262 |
function clickTabsAfterAjax() { |
| 263 |
/*jshint validthis:true */ |
| 264 |
const t = jQuery( this ).attr( 'href' ); |
| 265 |
jQuery( this ).parent().addClass( 'tabs' ).siblings( 'li' ).removeClass( 'tabs' ); |
| 266 |
jQuery( t ).show().siblings( '.tabs-panel' ).hide(); |
| 267 |
return false; |
| 268 |
} |
| 269 |
|
| 270 |
function clickContentTab() { |
| 271 |
/*jshint validthis:true */ |
| 272 |
const link = jQuery( this ); |
| 273 |
const t = link.attr( 'href' ); |
| 274 |
if ( t === undefined ) { |
| 275 |
return false; |
| 276 |
} |
| 277 |
|
| 278 |
const c = t.replace( '#', '.' ); |
| 279 |
link.closest( '.nav-tab-wrapper' ).find( 'a' ).removeClass( 'nav-tab-active' ); |
| 280 |
link.addClass( 'nav-tab-active' ); |
| 281 |
jQuery( '.nav-menu-content' ).not( t ).not( c ).hide(); |
| 282 |
jQuery( `${ t },${ c }` ).show(); |
| 283 |
|
| 284 |
return false; |
| 285 |
} |
| 286 |
|
| 287 |
function addOrderRow() { |
| 288 |
const logicRows = document.getElementById( 'frm_order_options' ).querySelectorAll( '.frm_logic_rows div' ); |
| 289 |
jQuery.ajax( { |
| 290 |
type: 'POST', |
| 291 |
url: ajaxurl, |
| 292 |
data: { |
| 293 |
action: 'frm_add_order_row', |
| 294 |
form_id: thisFormId, |
| 295 |
order_key: getNewRowId( logicRows, 'frm_order_field_', 1 ), |
| 296 |
nonce: frmGlobal.nonce |
| 297 |
}, |
| 298 |
success( html ) { |
| 299 |
jQuery( '#frm_order_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_order_row' ).hide(); |
| 300 |
} |
| 301 |
} ); |
| 302 |
} |
| 303 |
|
| 304 |
function addWhereRow() { |
| 305 |
const rowDivs = document.getElementById( 'frm_where_options' ).querySelectorAll( '.frm_logic_rows div' ); |
| 306 |
jQuery.ajax( { |
| 307 |
type: 'POST', |
| 308 |
url: ajaxurl, |
| 309 |
data: { |
| 310 |
action: 'frm_add_where_row', |
| 311 |
form_id: thisFormId, |
| 312 |
where_key: getNewRowId( rowDivs, 'frm_where_field_', 1 ), |
| 313 |
nonce: frmGlobal.nonce |
| 314 |
}, |
| 315 |
success( html ) { |
| 316 |
jQuery( '#frm_where_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_where_row' ).hide(); |
| 317 |
} |
| 318 |
} ); |
| 319 |
} |
| 320 |
|
| 321 |
function insertWhereOptions() { |
| 322 |
/*jshint validthis:true */ |
| 323 |
const { value } = this; |
| 324 |
const whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' ); |
| 325 |
|
| 326 |
jQuery.ajax( { |
| 327 |
type: 'POST', |
| 328 |
url: ajaxurl, |
| 329 |
data: { |
| 330 |
action: 'frm_add_where_options', |
| 331 |
where_key: whereKey, |
| 332 |
field_id: value, |
| 333 |
nonce: frmGlobal.nonce |
| 334 |
}, |
| 335 |
success( html ) { |
| 336 |
jQuery( document.getElementById( `where_field_options_${ whereKey }` ) ).html( html ); |
| 337 |
} |
| 338 |
} ); |
| 339 |
} |
| 340 |
|
| 341 |
function hideWhereOptions() { |
| 342 |
/*jshint validthis:true */ |
| 343 |
const { value } = this; |
| 344 |
const whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' ); |
| 345 |
|
| 346 |
if ( value === 'group_by' || value === 'group_by_newest' ) { |
| 347 |
document.getElementById( `where_field_options_${ whereKey }` ).style.display = 'none'; |
| 348 |
} else { |
| 349 |
document.getElementById( `where_field_options_${ whereKey }` ).style.display = 'inline-block'; |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
function getNewRowId( rows, replace, defaultValue ) { |
| 354 |
if ( ! rows.length ) { |
| 355 |
return defaultValue !== undefined ? defaultValue : 0; |
| 356 |
} |
| 357 |
return parseInt( rows[ rows.length - 1 ].id.replace( replace, '' ), 10 ) + 1; |
| 358 |
} |
| 359 |
|
| 360 |
function toggleAllowedShortcodes( id ) { |
| 361 |
let c; |
| 362 |
let clickedID; |
| 363 |
|
| 364 |
if ( id === undefined ) { |
| 365 |
id = ''; |
| 366 |
} |
| 367 |
c = id; |
| 368 |
|
| 369 |
if ( id.includes( '-search-input' ) ) { |
| 370 |
return; |
| 371 |
} |
| 372 |
|
| 373 |
if ( id !== '' ) { |
| 374 |
const $ele = jQuery( document.getElementById( id ) ); |
| 375 |
if ( $ele.attr( 'class' ) && id !== 'wpbody-content' && id !== 'content' && id !== 'dyncontent' && id !== 'success_msg' ) { |
| 376 |
let d = $ele.attr( 'class' ).split( ' ' )[ 0 ]; |
| 377 |
if ( d === 'frm_long_input' || d === 'frm_98_width' || d === undefined ) { |
| 378 |
d = ''; |
| 379 |
} else { |
| 380 |
id = d.trim(); |
| 381 |
} |
| 382 |
c = `${ c } ${ d }`; |
| 383 |
c = c.replace( 'widefat', '' ).replace( 'frm_with_left_label', '' ); |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
jQuery( '#frm-insert-fields-box,#frm-conditionals,#frm-adv-info-tab,#frm-dynamic-values' ).attr( 'data-fills', c.trim() ); |
| 388 |
const a = [ |
| 389 |
'content', 'wpbody-content', 'dyncontent', 'success_url', |
| 390 |
'success_msg', 'edit_msg', 'frm_dyncontent', 'frm_not_email_message', |
| 391 |
'frm_not_email_subject' |
| 392 |
]; |
| 393 |
const b = [ |
| 394 |
'before_content', 'after_content', 'frm_not_email_to', |
| 395 |
'dyn_default_value' |
| 396 |
]; |
| 397 |
|
| 398 |
if ( jQuery.inArray( id, a ) >= 0 ) { |
| 399 |
jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' ); |
| 400 |
jQuery( `.frm_code_list a.hide_${ id }` ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); |
| 401 |
} else if ( jQuery.inArray( id, b ) >= 0 ) { |
| 402 |
jQuery( `.frm_code_list:not(.frm-dropdown-menu) a:not(.show_${ id })` ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); |
| 403 |
jQuery( `.frm_code_list a.show_${ id }` ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' ); |
| 404 |
} else { |
| 405 |
jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); |
| 406 |
} |
| 407 |
|
| 408 |
// Automatically select a tab. |
| 409 |
if ( id === 'dyn_default_value' ) { |
| 410 |
clickedID = 'frm_dynamic_values'; |
| 411 |
document.getElementById( `${ clickedID }_tab` ).click(); |
| 412 |
jQuery( `#${ clickedID.replace( /_/g, '-' ) } .frm_show_inactive` ).addClass( 'frm_hidden' ); |
| 413 |
jQuery( `#${ clickedID.replace( /_/g, '-' ) } .frm_show_active` ).removeClass( 'frm_hidden' ); |
| 414 |
} |
| 415 |
} |
| 416 |
}() ); |
| 417 |
|