Skip to content

Commit

Permalink
Finish Unnamed Infant feature
Browse files Browse the repository at this point in the history
  • Loading branch information
shogenapps committed Jun 1, 2024
1 parent d98d8bc commit 93e67e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
51 changes: 30 additions & 21 deletions src/features/unnamed_infant/unnamed_infant.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ shouldInitializeFeature("unnamedInfant").then((result) => {
}
});

function doUnnamedInfant() {
async function doUnnamedInfant() {
const options = await getFeatureOptions("unnamedInfant");
const firstName = $("#mFirstName").val();
const birthDate = $("#mBirthDate").val();
const deathDate = $("#mDeathDate").val();
Expand All @@ -39,27 +40,35 @@ function doUnnamedInfant() {
}
});

let enhanced = false;
const enhancedEditorButton = $("#toggleMarkupColor");
if (enhancedEditorButton.attr("value") == "Turn Off Enhanced Editor") {
enhancedEditorButton.trigger("click");
enhanced = true;
}
const bioBox = $("#wpTextbox1");
const bio = bioBox.val();
// Search Biography for Died Young sticker
if (!bio.includes(diedYoungWithoutEnd)) {
// Find /== ?Biography ?==/ and insert Died Young sticker after it.
const bioIndex = bio.search(/== ?Biography ?==/);
if (bioIndex != -1) {
const bioStart = bio.slice(0, bioIndex + 15);
const bioEnd = bio.slice(bioIndex + 15);
bioBox.val(bioStart + "\n" + diedYoung + "\n" + bioEnd);
message += "<br>Died Young sticker added to Biography";
if (options.diedYoung) {
let enhanced = false;
const enhancedEditorButton = $("#toggleMarkupColor");
if (enhancedEditorButton.attr("value") == "Turn Off Enhanced Editor") {
enhancedEditorButton.trigger("click");
enhanced = true;
}
const bioBox = $("#wpTextbox1");
const bio = bioBox.val();
// Search Biography for Died Young sticker
if (!bio.includes(diedYoungWithoutEnd)) {
// Find /== ?Biography ?==/ and insert Died Young sticker after it.
const bioIndex = bio.search(/== ?Biography ?==/);
if (bioIndex != -1) {
let diedYoungTemplate = diedYoung;

if (options.diedYoungImage && options.diedYoungImage != "Default") {
diedYoungTemplate = `{{Died Young|${options.diedYoungImage}}}`;
}

const bioStart = bio.slice(0, bioIndex + 15);
const bioEnd = bio.slice(bioIndex + 15);
bioBox.val(bioStart + "\n" + diedYoungTemplate + "\n" + bioEnd);
message += "<br>Died Young sticker added to Biography";
}
}
if (enhanced) {
enhancedEditorButton.trigger("click");
}
}
if (enhanced) {
enhancedEditorButton.trigger("click");
}
}
// Show message
Expand Down
3 changes: 1 addition & 2 deletions src/features/unnamed_infant/unnamed_infant_options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { options } from "yargs";
import { registerFeature, OptionType } from "../../core/options/options_registry";
import { isProfileEdit, isProfileAddRelative, isAddUnrelatedPerson } from "../../core/pageType";

Expand All @@ -15,7 +14,7 @@ registerFeature({
{
id: "diedYoung",
type: OptionType.CHECKBOX,
label: "Add Died Young sticker for people who died aged 16 or younger",
label: "Add Died Young sticker",
defaultValue: false,
},
{
Expand Down

0 comments on commit 93e67e0

Please sign in to comment.