Skip to content

Commit

Permalink
Merge pull request #23 from newfold-labs/update/admin-bar-site-status
Browse files Browse the repository at this point in the history
Add admin bar site status toggle helper method
  • Loading branch information
circlecube authored Jan 16, 2024
2 parents 98f13af + 041c64e commit 09e5a9b
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions static/js/coming-soon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

const buildObject = () => {
return {
isEnabled: checkComingSoonStatus,
enable: enableComingSoon,
disable: disableComingSoon,
lastChanged: getLastChanged,
isEnabled,
enable,
disable,
lastChanged,
toggleAdminBarSiteStatus,
};
};

const checkComingSoonStatus = async () => {
const isEnabled = async () => {
let status;

await window.wp
Expand All @@ -36,7 +37,7 @@
return status;
};

const enableComingSoon = async () => {
const enable = async () => {
const result = {};

await window.wp
Expand All @@ -48,6 +49,7 @@
if ( response.hasOwnProperty( 'comingSoon' ) ) {
result.success = true;
result.comingSoon = response.comingSoon;
toggleAdminBarSiteStatus( true );
} else {
result.success = false;
}
Expand All @@ -59,7 +61,7 @@
return result;
};

const disableComingSoon = async () => {
const disable = async () => {
const result = {};

await window.wp
Expand All @@ -71,6 +73,7 @@
if ( response.hasOwnProperty( 'comingSoon' ) ) {
result.success = true;
result.comingSoon = response.comingSoon;
toggleAdminBarSiteStatus( false );
} else {
result.success = false;
}
Expand All @@ -82,7 +85,7 @@
return result;
};

const getLastChanged = async () => {
const lastChanged = async () => {
let value;

await window.wp
Expand All @@ -104,6 +107,18 @@
return value;
};

const toggleAdminBarSiteStatus = ( newState ) => {
const siteStatus = document.querySelector(
'#wp-toolbar #nfd-site-status'
);

if ( ! siteStatus ) {
return;
}

siteStatus.setAttribute( 'data-coming-soon', newState );
};

window.addEventListener( 'DOMContentLoaded', () => {
attachToRuntime();
} );
Expand Down

0 comments on commit 09e5a9b

Please sign in to comment.