Skip to content

Commit

Permalink
Formatting – 2 space tab
Browse files Browse the repository at this point in the history
  • Loading branch information
marclucraft authored Jul 26, 2023
1 parent bdcfe97 commit 748755a
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions notice.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
jQuery(document).ready(notice);

var state = {
post_id : ajax_object.post_id, // post id sent from php backend
first_modified : undefined, // when the post was first modified
started : false, // post notification requests started
interval: undefined, // global interval for reattempting requests
interval_count : 0, // how many times has the request been attempted
status : undefined // whether the post is scheduled or published
}
post_id: ajax_object.post_id, // post id sent from php backend
first_modified: undefined, // when the post was first modified
started: false, // post notification requests started
interval: undefined, // global interval for reattempting requests
interval_count: 0, // how many times has the request been attempted
status: undefined // whether the post is scheduled or published
}

function notice() {
if (!isWpCoreEditorDefined()) {
Expand All @@ -26,7 +26,7 @@ function notice() {
const post = editor.getCurrentPost();

// runs until post data loads
if(!post || post === {}){
if (!post || post === {}) {
return;
}

Expand All @@ -45,7 +45,7 @@ function notice() {
const htmlElement = jQuery("#send_onesignal_notification")[0];

if (!!htmlElement) {
send_os_notif = htmlElement.checked;
send_os_notif = htmlElement.checked;
}

// if last modified differs from first modified times, post_modified = true
Expand All @@ -54,7 +54,7 @@ function notice() {
const is_published = status === "publish";

// if hasn't started, change detected, box checked, and the status is 'publish'
if (!state.started && post_modified && send_os_notif && is_published ) {
if (!state.started && post_modified && send_os_notif && is_published) {
state.interval = setInterval(get_metadata, 3000); // starts requests
state.started = true;
}
Expand All @@ -70,22 +70,22 @@ function notice() {
post_id: state.post_id
};

jQuery.get(ajax_object.ajax_url, data, function(response) {
jQuery.get(ajax_object.ajax_url, data, function (response) {
response = JSON.parse(response);
let { status_code, response_body } = response;

if(window.DEBUG_MODE){
if (window.DEBUG_MODE) {
console.log(response);
}

const is_status_empty = status_code.length == 0;

if(!is_status_empty){
if (!is_status_empty) {
status_code = parseInt(status_code);

// status 0: HTTP request failed
if (status_code === 0) {
error_notice("OneSignal Push: request failed with status code 0. "+response_body);
error_notice("OneSignal Push: request failed with status code 0. " + response_body);
reset_state();
return;
}
Expand All @@ -95,8 +95,8 @@ function notice() {
if (!response_body) {
error_notice(
"OneSignal Push: there was a " +
status_code +
" error sending your notification"
status_code +
" error sending your notification"
);
} else {
error_notice("OneSignal Push: there was a " + status_code + " error sending your notification: " + response_body);
Expand Down Expand Up @@ -131,7 +131,7 @@ function notice() {
if (state.status === "publish") {
var notice_text = "OneSignal Push: Successfully sent a notification.";
delivery_link_text = " Go to your app's Delivery tab to check sent messages: https://dashboard.onesignal.com/apps/";
} else if (state.status === "future"){
} else if (state.status === "future") {
var notice_text = "OneSignal Push: Successfully scheduled a notification.";
}

Expand All @@ -141,16 +141,16 @@ function notice() {
"info",
notice_text + delivery_link_text,
{
id:'onesignal-notice',
isDismissible: true
id: 'onesignal-notice',
isDismissible: true
}
);
};

const error_notice = error => {
wp.data.dispatch("core/notices").createNotice("error", error, {
isDismissible: true,
id:'onesignal-error'
isDismissible: true,
id: 'onesignal-error'
});
};

Expand Down Expand Up @@ -194,8 +194,8 @@ const isWpCoreEditorDefined = () => {
* }
*/
window.OneSignal = {
debug : () => {
window.DEBUG_MODE = window.DEBUG_MODE ? !window.DEBUG_MODE : true;
notice();
}
debug: () => {
window.DEBUG_MODE = window.DEBUG_MODE ? !window.DEBUG_MODE : true;
notice();
}
};

0 comments on commit 748755a

Please sign in to comment.