Skip to content

Commit

Permalink
Make functions reusable and actually use them when they already are
Browse files Browse the repository at this point in the history
  • Loading branch information
NightScript370 committed May 2, 2024
1 parent 51e1709 commit fe1e97e
Show file tree
Hide file tree
Showing 7 changed files with 4,765 additions and 4,753 deletions.
16 changes: 5 additions & 11 deletions assets/js/WebsiteCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class WebsiteCalendar extends KosherZmanim.JewishCalendar {
}
}

/** @returns {{en: string; he: string}} */
formatJewishMonth() {
// @ts-ignore
return ['en', 'he']
.map(locale => [locale, this.getDate().toLocaleString(locale + '-u-ca-hebrew', { month: 'long' })])
.reduce(function (obj, [key, val]) {
Expand Down Expand Up @@ -480,8 +482,8 @@ class WebsiteCalendar extends KosherZmanim.JewishCalendar {
const yomTovIndex = this.getYomTovIndex();

const mashivHarush = {
start: new KosherZmanim.JewishDate(this.getJewishYear(), KosherZmanim.JewishDate.TISHREI, 22),
end: new KosherZmanim.JewishDate(this.getJewishYear(), KosherZmanim.JewishDate.NISSAN, 15)
start: new KosherZmanim.JewishDate(this.getJewishYear(), KosherZmanim.JewishDate.TISHREI, 22).getDate(),
end: new KosherZmanim.JewishDate(this.getJewishYear(), KosherZmanim.JewishDate.NISSAN, 15).getDate()
}

const normalAmidah = !(this.getDayOfWeek() == 7 || [
Expand Down Expand Up @@ -566,7 +568,7 @@ class WebsiteCalendar extends KosherZmanim.JewishCalendar {
hallel: hallel,
tachanun: todaysTachanun ? 2 : 0,
amidah: {
"mechayehHametim": (this.isInBetween(mashivHarush.start, mashivHarush.end) ? "משיב הרוח" : "מוריד הטל"),
"mechayehHametim": (KosherZmanim.temporalExtended.rangeDates(mashivHarush.start, this.getDate(), mashivHarush.end) ? "משיב הרוח" : "מוריד הטל"),
"mevarechHashanim": (!normalAmidah ? null :
(this.isBarechAleinu() ? "ברך עלינו" : "ברכנו")),
"ulChaparatPesha": (!this.isRoshChodesh() ? null : ulChaparatPesha)
Expand Down Expand Up @@ -639,14 +641,6 @@ class WebsiteCalendar extends KosherZmanim.JewishCalendar {
return validAv || validTamuz || validSefira
}

/**
* @param {KosherZmanim.JewishDate} startDate
* @param {KosherZmanim.JewishDate} endDate
*/
isInBetween(startDate, endDate) {
return (this.compareTo(startDate) > 0 && this.compareTo(endDate) < 0);
}

/*
* If an attribute returns true, that means the mourning customs are in effect
*/
Expand Down
1 change: 0 additions & 1 deletion assets/js/icsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export default function icsExport (amudehHoraahZman, plainDateParams, geoLocatio
events.push({
start: calc.getShkiya().epochMilliseconds,
end: calc.chainDate(jCal.getDate().withCalendar("hebrew").with({ day: 15 })).getAlotHashachar().epochMilliseconds,
// @ts-ignore
title: funcSettings.language == "he" ? "ברכת הלבנה - חדש " + jMonth.he : "Birkat Halevana - Month of " + jMonth.en,
description: "End-time of the Rama (Stringent): " + birkLev.data.end.toLocaleString()
})
Expand Down
55 changes: 35 additions & 20 deletions assets/js/zmanimListUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,24 +381,44 @@ class zmanimListUpdater {
}
fastContainer.style.removeProperty("display");

/**
* @param {Element} contElem
*/
function hideErev(contElem, inverse=false) {
const cond = (inverse ? !todayFast : todayFast)
contElem.querySelectorAll('[data-zfFind="erevTzom"]')
.forEach(elem => {
if (!(elem instanceof HTMLElement))
return;

if (cond)
elem.style.display = "none";
else
elem.style.removeProperty("display");
});
}

const fastJCal = this.jCal.isTaanis() || this.jCal.isTaanisBechoros() ? this.jCal : this.jCal.tomorrow();
const fastCalc = this.zmanFuncs.chainDate(fastJCal.getDate());
const nameElements = [...fastContainer.getElementsByTagName("h5")];
nameElements.forEach(element => element.style.display = "none");

const ourFast = nameElements.find(element => element.getAttribute("data-zfFind") == fastJCal.getYomTovIndex().toString());
hideErev(ourFast);
ourFast.style.removeProperty("display");
if (todayFast) {
ourFast.querySelectorAll('[data-zfFind="erevTzom"]').forEach(element => element.style.display = "none")
} else {
ourFast.querySelectorAll('[data-zfFind="erevTzom"]').forEach(element => element.style.removeProperty("display"))
}

/** @type {Record<'multiDay' | 'oneDay', HTMLElement>} */
const timeList = {
multiDay: fastContainer.querySelector('[data-zfFind="twoDayTimes"]'),
oneDay: fastContainer.querySelector('[data-zfFind="oneDayTimes"]')
};

if ([KosherZmanim.JewishCalendar.TISHA_BEAV, KosherZmanim.JewishCalendar.YOM_KIPPUR].includes(fastJCal.getYomTovIndex())) {
fastContainer.querySelector('[data-zfFind="oneDayTimes"]').style.display = "none";
timeList.oneDay.style.display = "none";
timeList.multiDay.style.removeProperty("display");

const multiDayTimesList = fastContainer.querySelector('[data-zfFind="twoDayTimes"]');
const erevTzom = multiDayTimesList.firstElementChild;
const erevTzom = timeList.multiDay.firstElementChild;
hideErev(erevTzom);
if (erevTzom.lastChild.nodeType == Node.TEXT_NODE) {
erevTzom.lastChild.remove();
}
Expand All @@ -408,13 +428,8 @@ class zmanimListUpdater {
(fastJCal.getYomTovIndex() == KosherZmanim.JewishCalendar.YOM_KIPPUR ? erevCalc.getCandleLighting() : erevCalc.getShkiya())
erevTzom.appendChild(document.createTextNode(timeOnErev.toLocaleString(...this.dtF)));

if (this.jCal.isTaanis()) {
erevTzom.querySelectorAll('[data-zfFind="erevTzom"]').forEach(element => element.style.display = "none")
} else {
erevTzom.querySelectorAll('[data-zfFind="erevTzom"]').forEach(element => element.style.removeProperty("display"))
}

const yomTzom = multiDayTimesList.lastElementChild;
const yomTzom = timeList.multiDay.lastElementChild;
hideErev(yomTzom, true);
if (yomTzom.lastChild.nodeType == Node.TEXT_NODE)
yomTzom.lastChild.remove();

Expand All @@ -426,13 +441,13 @@ class zmanimListUpdater {
yomTzom.appendChild(document.createTextNode(fastCalc.getTzaitLechumra().toLocaleString(...this.dtF)))
}
} else {
fastContainer.querySelector('[data-zfFind="twoDayTimes"]').style.display = "none";
const timeBox = fastContainer.querySelector('[data-zfFind="oneDayTimes"]');
if (timeBox.lastChild.nodeType == Node.TEXT_NODE) {
timeBox.lastChild.remove();
timeList.multiDay.style.display = "none";
timeList.oneDay.style.removeProperty("display")
if (timeList.oneDay.lastChild.nodeType == Node.TEXT_NODE) {
timeList.oneDay.lastChild.remove();
}

timeBox.appendChild(document.createTextNode(
timeList.oneDay.appendChild(document.createTextNode(
fastCalc.getAlotHashachar().toLocaleString(...this.dtF) + ' - ' + fastCalc.getTzaitLechumra().toLocaleString(...this.dtF)
))
}
Expand Down
Loading

0 comments on commit fe1e97e

Please sign in to comment.