Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/advanced.../admin/assets/js
File: dialog-advads-modal.js
// phpcs:disable Generic.WhiteSpace.ScopeIndent.IncorrectExact -- PHPCS can't handle es5 short functions
[0] Fix | Delete
const modal = element => {
[1] Fix | Delete
let termination;
[2] Fix | Delete
let targetForm;
[3] Fix | Delete
[4] Fix | Delete
/**
[5] Fix | Delete
* Remove the pound sign from the location hash.
[6] Fix | Delete
*
[7] Fix | Delete
* @return {string}
[8] Fix | Delete
*/
[9] Fix | Delete
const getId = () => window.location.hash.replace( '#', '' );
[10] Fix | Delete
[11] Fix | Delete
const showModal = () => {
[12] Fix | Delete
element.showModal();
[13] Fix | Delete
element.dispatchEvent( new CustomEvent( 'advads-modal-opened' ) );
[14] Fix | Delete
[15] Fix | Delete
termination = new Advads_Termination( element );
[16] Fix | Delete
[17] Fix | Delete
if ( targetForm ) {
[18] Fix | Delete
termination.collectValues();
[19] Fix | Delete
}
[20] Fix | Delete
};
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* If the current hash matches the modal id attribute, open it.
[24] Fix | Delete
*/
[25] Fix | Delete
const showIfHashMatches = () => {
[26] Fix | Delete
if ( getId() === element.id ) {
[27] Fix | Delete
showModal();
[28] Fix | Delete
}
[29] Fix | Delete
};
[30] Fix | Delete
[31] Fix | Delete
// Check whether to open modal on page load.
[32] Fix | Delete
showIfHashMatches();
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Listen to the hashchange event, to check if the current modal needs to be opened.
[36] Fix | Delete
*/
[37] Fix | Delete
window.addEventListener( 'hashchange', () => {
[38] Fix | Delete
showIfHashMatches();
[39] Fix | Delete
[40] Fix | Delete
if ( getId() !== 'close' ) {
[41] Fix | Delete
return;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
if ( ! targetForm || termination.terminationNotice( true ) ) {
[45] Fix | Delete
element.close();
[46] Fix | Delete
}
[47] Fix | Delete
} );
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Attach a click listener to all links referencing this modal and prevent their default action.
[51] Fix | Delete
* By changing the hash on every click, we also create a history entry.
[52] Fix | Delete
*/
[53] Fix | Delete
document.querySelectorAll( 'a[href$="#' + element.id + '"]' ).forEach( link => {
[54] Fix | Delete
link.addEventListener( 'click', e => {
[55] Fix | Delete
e.preventDefault();
[56] Fix | Delete
showModal();
[57] Fix | Delete
} );
[58] Fix | Delete
} );
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* On the cancel event, check for termination notice and fire a custom event.
[62] Fix | Delete
*/
[63] Fix | Delete
element.addEventListener( 'cancel', event => {
[64] Fix | Delete
event.preventDefault();
[65] Fix | Delete
if ( ! targetForm ) {
[66] Fix | Delete
element.close();
[67] Fix | Delete
return;
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
if ( termination.terminationNotice( true ) ) {
[71] Fix | Delete
element.close();
[72] Fix | Delete
[73] Fix | Delete
termination.observers.disconnect();
[74] Fix | Delete
[75] Fix | Delete
document.dispatchEvent( new CustomEvent( 'advads-modal-canceled', {
[76] Fix | Delete
detail: {
[77] Fix | Delete
modal_id: element.id
[78] Fix | Delete
}
[79] Fix | Delete
} ) );
[80] Fix | Delete
}
[81] Fix | Delete
} );
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* On the close event, i.e., a form got submit, empty the hash to prevent form from reopening.
[85] Fix | Delete
*/
[86] Fix | Delete
element.addEventListener( 'close', event => {
[87] Fix | Delete
if ( getId() === element.id ) {
[88] Fix | Delete
window.location.hash = '';
[89] Fix | Delete
}
[90] Fix | Delete
} );
[91] Fix | Delete
[92] Fix | Delete
// try if there is a form inside the modal, otherwise continue in catch.
[93] Fix | Delete
targetForm = element.querySelector( 'form' );
[94] Fix | Delete
if ( targetForm === null ) {
[95] Fix | Delete
try {
[96] Fix | Delete
targetForm = element.querySelector( 'button.advads-modal-close-action' ).form;
[97] Fix | Delete
} catch ( e ) {
[98] Fix | Delete
}
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
if ( targetForm ) {
[102] Fix | Delete
/**
[103] Fix | Delete
* Listen for the keydown event in all inputs.
[104] Fix | Delete
* If the enter key is pressed and the modal has a form, submit it, else do nothing.
[105] Fix | Delete
*/
[106] Fix | Delete
element.querySelectorAll( 'input' ).forEach( input => {
[107] Fix | Delete
input.addEventListener( 'keydown', e => {
[108] Fix | Delete
if ( e.key !== 'Enter' ) {
[109] Fix | Delete
return;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
if ( targetForm.reportValidity() ) {
[113] Fix | Delete
targetForm.submit();
[114] Fix | Delete
return;
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
// if there are inputs, but there is no form associated with them, do nothing.
[118] Fix | Delete
e.preventDefault();
[119] Fix | Delete
} );
[120] Fix | Delete
} );
[121] Fix | Delete
targetForm.addEventListener( 'submit', () => {
[122] Fix | Delete
window.location.hash = '';
[123] Fix | Delete
} );
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
/**
[127] Fix | Delete
* On the cancel buttons, check termination notice and close the modal.
[128] Fix | Delete
*/
[129] Fix | Delete
element.querySelectorAll( '.advads-modal-close, .advads-modal-close-background' ).forEach( button => {
[130] Fix | Delete
button.addEventListener( 'click', e => {
[131] Fix | Delete
e.preventDefault();
[132] Fix | Delete
element.dispatchEvent( new Event( 'cancel' ) );
[133] Fix | Delete
} );
[134] Fix | Delete
} );
[135] Fix | Delete
[136] Fix | Delete
try {
[137] Fix | Delete
/**
[138] Fix | Delete
* If the save button is not a `<button>` element. Close the form without changing the hash.
[139] Fix | Delete
*/
[140] Fix | Delete
element.querySelector( 'a.advads-modal-close-action' ).addEventListener( 'click', e => {
[141] Fix | Delete
e.preventDefault();
[142] Fix | Delete
element.close();
[143] Fix | Delete
} );
[144] Fix | Delete
} catch ( e ) {
[145] Fix | Delete
}
[146] Fix | Delete
};
[147] Fix | Delete
[148] Fix | Delete
window.addEventListener( 'DOMContentLoaded', () => {
[149] Fix | Delete
try {
[150] Fix | Delete
if ( typeof document.querySelector( '.advads-modal[id^=modal-]' ).showModal !== 'function' ) {
[151] Fix | Delete
return;
[152] Fix | Delete
}
[153] Fix | Delete
} catch ( e ) {
[154] Fix | Delete
return;
[155] Fix | Delete
}
[156] Fix | Delete
[...document.getElementsByClassName( 'advads-modal' )].forEach( modal );
[157] Fix | Delete
} );
[158] Fix | Delete
[159] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function