| Server IP : 170.10.161.225 / Your IP : 216.73.216.78 Web Server : Apache System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64 User : calvet ( 273824) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : ON Directory : /home/www/calvetrealty.com/wp-content/plugins/readabler/src/Merkulove/Unity/assets/js/ |
Upload File : |
/**
* Unity Dashboard
*
* @param window.mdpDashboard
*/
( function () {
document.readyState === 'loading' ?
document.addEventListener( 'DOMContentLoaded', initUnityDashboard ) :
initUnityDashboard();
const { restBase, nonce, translation } = window.mdpDashboard;
/**
* Get async data about plugin for dashboard
* @param pluginName
* @param ask
*/
function getAsyncValue( pluginName, ask ) {
const xHttp = new XMLHttpRequest();
xHttp.open( 'POST', `${ restBase }readabler/v2/dashboard/?nonce=${ nonce }&plugin=${ pluginName }`, true);
xHttp.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded');
xHttp.onload = () => {
if ( xHttp.status !== 200 ) {
renderLicenseStatus( pluginName );
return;
}
switch ( ask ) {
case 'license':
renderLicenseStatus( pluginName, JSON.parse( xHttp.response ) );
break;
case 'update':
renderUpdateStatus( pluginName, JSON.parse( xHttp.response ) );
break;
}
};
xHttp.send(`ask=${ ask }` );
}
/**
* Async plugin activation
* @param target
*/
function activatePlugin( target ) {
const buttonText = target.innerHTML;
// Make button disabled
target.classList.add( 'button-disabled' );
// Add Waiting...
target.innerHTML = translation.wait;
let dots = 0;
const waiting = setInterval( () => {
target.innerHTML += '.';
dots++;
if ( dots === 3 ) {
dots = 0;
target.innerHTML = translation.wait;
}
}, 200 );
// Work only once
if ( target.href === '' ) { return; }
const url = target.href;
target.href = '';
const xHttp = new XMLHttpRequest();
xHttp.open( 'POST', url, true);
xHttp.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded');
xHttp.onload = () => {
// Remove Waiting...
clearInterval( waiting );
target.innerHTML = buttonText;
// Make button disabled
target.classList.remove( 'button-disabled' );
if ( xHttp.status === 200 ) {
target.closest( '.mdp-dashboard__buttons' ).querySelectorAll( '.button' ).forEach( ( button ) => {
button.removeAttribute( 'style' );
} );
target.remove();
} else {
location.href = url;
}
};
xHttp.send('' );
}
/**
* Render license activation status
* @param pluginName
* @param isLicenseValid
* @param translation.licenseActive
* @param translation.licenseInactive
* @param translation.licenseUnknown
* @param translation.latestVersion
* @param translation.update
*/
function renderLicenseStatus( pluginName, isLicenseValid = '' ) {
const $status = document.querySelector( `div[data-plugin="${ pluginName }"] .mdp-dashboard__status__license a` );
if ( isLicenseValid === true ) {
$status.closest( '.mdp-dashboard__status__license' ).className += `--valid`;
$status.innerHTML += translation.licenseActive;
} else if ( false === isLicenseValid ) {
$status.closest( '.mdp-dashboard__status__license' ).className += `--invalid`;
$status.innerHTML += translation.licenseInactive;
} else {
$status.closest( '.mdp-dashboard__status__license' ).className += `--unknown`;
$status.innerHTML += translation.licenseUnknown;
}
}
/**
* Render update status
* @param pluginName
* @param lastVersion
*/
function renderUpdateStatus( pluginName, lastVersion ) {
const $update = document.querySelector( `div[data-plugin="${ pluginName }"] .mdp-dashboard__status__update` );
const currentVersion = $update.dataset.version;
if ( lastVersion === '' ) {
$update.remove();
return;
}
$update.className += `-version`;
if ( currentVersion === lastVersion ) {
$update.querySelector( '.mdp-dashboard__status__update-needed' ).remove();
$update.querySelector( '.mdp-dashboard__status__update-no-needed .mdp-dashboard__status__version' ).innerHTML = lastVersion;
$update.querySelector( '.mdp-dashboard__status__update-no-needed' ).removeAttribute( 'style' );
} else {
$update.querySelector( '.mdp-dashboard__status__update-no-needed' ).remove();
$update.querySelector( '.mdp-dashboard__status__update-needed .mdp-dashboard__status__version' ).innerHTML = lastVersion;
$update.querySelector( '.mdp-dashboard__status__update-needed' ).removeAttribute( 'style' );
}
}
/**
* Get plugins data
*/
function getPlugins() {
document.querySelectorAll( '.mdp-dashboard__plugin' ).forEach( ( plugin ) => {
const pluginName = plugin.dataset.plugin;
getAsyncValue( pluginName, 'license' );
getAsyncValue( pluginName, 'update' )
} );
}
/**
* Init dashboard widget
*/
function initUnityDashboard() {
getPlugins();
document.querySelectorAll( '.button-activate' ).forEach( ( plugin ) => {
plugin.addEventListener( 'click', ( e ) => {
e.preventDefault( e );
activatePlugin( e.target );
} );
} );
}
} () );