Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add admin bar site status toggle helper method #23

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading