| 1 |
/** |
| 2 |
* SureDonation Elementor editor behaviours. |
| 3 |
* |
| 4 |
* Backs the Donation Form widget's "Edit Form" button, which opens the selected |
| 5 |
* form's own editor in a new tab. |
| 6 |
* |
| 7 |
* @package SureDonation |
| 8 |
* @since x.x.x |
| 9 |
*/ |
| 10 |
|
| 11 |
/* global elementor, suredonationElementorData */ |
| 12 |
document.addEventListener( 'DOMContentLoaded', function () { |
| 13 |
if ( typeof elementor === 'undefined' ) { |
| 14 |
return; |
| 15 |
} |
| 16 |
|
| 17 |
elementor.channels.editor.on( 'suredonation:form:edit', function ( view ) { |
| 18 |
const settings = view && view.elementSettingsModel; |
| 19 |
|
| 20 |
if ( ! settings ) { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
// The form selector is split into one control per campaign |
| 25 |
// (`form_id_{id}`) plus a campaign-less fallback (`form_id`); only the |
| 26 |
// control matching the current campaign holds the chosen value. Mirrors |
| 27 |
// Donation_Form_Widget::resolve_form_id(). |
| 28 |
const campaignId = parseInt( settings.get( 'campaign_id' ), 10 ) || 0; |
| 29 |
const controlKey = campaignId ? 'form_id_' + campaignId : 'form_id'; |
| 30 |
const formId = parseInt( settings.get( controlKey ), 10 ) || 0; |
| 31 |
|
| 32 |
if ( ! formId ) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
const editWindow = window.open( |
| 37 |
suredonationElementorData.adminUrl + |
| 38 |
'post.php?post=' + |
| 39 |
formId + |
| 40 |
'&action=edit', |
| 41 |
'_blank' |
| 42 |
); |
| 43 |
|
| 44 |
if ( editWindow ) { |
| 45 |
editWindow.focus(); |
| 46 |
} |
| 47 |
} ); |
| 48 |
} ); |
| 49 |
|