52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
/**
|
|
* Admin UI behavior for Robotstxt SMTP settings.
|
|
*
|
|
* @package RobotstxtSMTP
|
|
*/
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
var initializeAdmin = function () {
|
|
var security = document.getElementById( 'robotstxt_smtp_security' );
|
|
var port = document.getElementById( 'robotstxt_smtp_port' );
|
|
|
|
if ( ! security || ! port) {
|
|
return;
|
|
}
|
|
|
|
var defaultPorts = {
|
|
none: 25,
|
|
ssl: 465,
|
|
tls: 587
|
|
};
|
|
|
|
var previousValue = security.value || 'none';
|
|
|
|
security.addEventListener(
|
|
'change',
|
|
function () {
|
|
var newValue = security.value || 'none';
|
|
var previousDefault = Object.prototype.hasOwnProperty.call( defaultPorts, previousValue )
|
|
? defaultPorts[previousValue]
|
|
: null;
|
|
var newDefault = Object.prototype.hasOwnProperty.call( defaultPorts, newValue )
|
|
? defaultPorts[newValue]
|
|
: null;
|
|
var currentPort = parseInt( port.value, 10 );
|
|
|
|
if ( ! Number.isNaN( currentPort ) && null !== previousDefault && currentPort === previousDefault && null !== newDefault) {
|
|
port.value = newDefault;
|
|
}
|
|
|
|
previousValue = newValue;
|
|
}
|
|
);
|
|
};
|
|
|
|
if ('loading' !== document.readyState) {
|
|
initializeAdmin();
|
|
} else {
|
|
document.addEventListener( 'DOMContentLoaded', initializeAdmin );
|
|
}
|
|
})();
|