-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
1576 lines (1344 loc) · 46.1 KB
/
script.js
File metadata and controls
1576 lines (1344 loc) · 46.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Add or remove cards by editing this array.
// Each object below renders one card on the homepage.
const posts = [
{
id: 17,
title: "E&RSC Meeting Recap (March 3, 2026): Capacity to Pay and Non-Resident Special Education",
category: "journal",
date: "March 3, 2026",
excerpt:
"Recap of the March 3 E&RSC meeting topics on override size, taxpayer burden, and non-resident special education costs.",
resourcePage: "pages/ersc_meeting_capacity_to_pay_20260303.html"
},
{
id: 16,
title: "From Priorities to Proposal: Understanding How the PSB Budget is Built",
category: "journal",
date: "March 1, 2026",
excerpt:
"Superintendent Bella Wong explains how PSB builds its annual budget and navigates major trade-offs.",
resourcePage: "pages/from_priorities_to_proposal_psb_budget_20260301.html"
},
{
id: 13,
title: "DLS data for Property Tax Statistics",
category: "journal",
date: "February 25, 2026",
excerpt:
"This website has annual assessment and tax revenue data for Brookline (and all other MA communities).",
resourcePage: "pages/dls_data_property_tax_statistics_20260225.html"
},
{
id: 12,
title: "Town Administrator's Budget 101",
category: "journal",
date: "February 25, 2026",
excerpt:
"Town Administrator's virtual Budget 101 was held on February 26, 2026, and the recording is now available.",
resourcePage: "pages/town_administrator_budget_101_20260225.html"
},
{
id: 15,
title: "Brookline Assessor's Database",
category: "journal",
date: "February 25, 2026",
excerpt: "This database has detailed property tax data for every property in Brookline.",
resourcePage: "pages/brookline_assessors_database_20260225.html"
},
{
id: 10,
title: "E&RSC Futures Committee report (February 13, 2026)",
category: "journal",
date: "February 20, 2026",
excerpt: "The Futures Subcommittee report focuses on economic development strategy.",
resourcePage: "pages/esrc_futures_committee_report_20260220.html"
},
{
id: 9,
title: "E&RSC Schools Subcommittee report (February 9, 2026)",
category: "journal",
date: "February 20, 2026",
excerpt:
"Two major financial findings areas are discussed: unreimbursed special education for non-resident students and teacher salaries.",
resourcePage: "pages/esrc_schools_subcommittee_report_20260220.html"
},
{
id: 11,
title: "Good Government for Brookline: Selling Surplus Property Should Be On the Table",
category: "journal",
date: "February 20, 2026",
excerpt:
"\"I believe a case can be made that disposal of one or more town properties would be an improvement over resorting to layoffs and curtailment of services.\"",
resourcePage: "pages/good_government_surplus_property_20260220.html"
},
{
id: 6,
title: "Brookline News: Town's financial plan lays out high stakes for schools, fire department as override vote looms",
category: "journal",
date: "February 18, 2026",
excerpt:
"\"Town Administrator Charles Carey has released a $481 million budget proposal for fiscal year 2027 that offers the most detailed rationale to date for a tax override question likely to be on Brookline's ballot in the May election.\"",
resourcePage: "pages/brookline_news_override_20260218.html"
},
{
id: 5,
title: "FY2027 Financial Plan is now available",
category: "journal",
date: "February 16, 2026",
excerpt:
"\"This will be a pivotal year for Brookline: the community will likely be asked to decide if it wishes to accept higher taxes or significant reductions in services.\"",
resourcePage: "pages/fy2027_financial_plan_20260216.html"
},
{
id: 1,
title: "Draft Report from the Expenditures & Revenues Study Committee (E&RSC)",
category: "journal",
date: "February 12, 2026",
excerpt:
"Brookline's E&RSC released a draft of their report on Brookline's financial health, which will ultimately contain recommendations to the Select Board regarding a possible override ballot question for the May 2026 election.",
resourcePage: "pages/ersc_20260212.html"
},
{
id: 8,
title: "Tax Foundation Report: Massachusetts Proposition 2 1/2 Is Working",
category: "journal",
date: "February 12, 2026",
excerpt:
"The MMA has argued for Prop 2 1/2 reform. Here is an alternative view from Tax Foundation, a DC-based think tank.",
resourcePage: "pages/massachusetts_proposition_2_12_working_20260212.html"
},
{
id: 2,
title: "MMA report: Navigating the Storm",
category: "journal",
date: "February 12, 2026",
excerpt:
"The Massachusetts Municipal Association (MMA) followed up their October post about the fiscal crisis with a detailed plan to solve it.",
resourcePage: "pages/mma_navigate_20260212.html"
},
{
id: 3,
title: "MMA report: A Perfect Storm",
category: "journal",
date: "Feb 12, 2026",
excerpt:
"In October 2025, the Massachusetts Municipal Association (MMA) released a report that examines the key factors pressuring municipal budgets.",
resourcePage: "pages/mma_perfectstorm_20260212.html"
},
{
id: 7,
title: "What is Proposition 2 1/2",
category: "journal",
date: "February 12, 2026",
excerpt:
"Most everyone has heard of Proposition 2 1/2, but there are some common misunderstandings about it.",
resourcePage: "pages/proposition_2_1_2_20260212.html"
},
{
id: 4,
title: "Brookline's FY27-FY31 Long Range Financial Forecast",
category: "journal",
date: "February 12, 2026",
excerpt:
"The FY27-FY Long Range Financial Plan was presented to the Advisory Committee on January 13, 2026.",
resourcePage: "pages/LRF_20260113.html"
},
{
id: 14,
title: "Moderator's Brookline Fiscal Advisory Committee (2022)",
category: "journal",
date: "February 12, 2026",
excerpt: "Moderator's Brookline Fiscal Advisory Committee (2022)",
resourcePage: "pages/moderators_brookline_fiscal_advisory_committee_20260212.html"
}
];
const resourceLinks = [
{
label: "Budget Central",
url: "https://www.brooklinema.gov/851/Budget-Central"
},
{
label: "Brookline Assessor's Database",
url: "https://www.brooklinema.gov/DocumentCenter/Index/1562"
},
{
label: "Brookline Fiscal Advisory Committee",
url: "https://www.brooklinema.gov/3875/Arc-Moderators-Committee---Brookline-Fis"
},
{
label: "Brookline CivicClerk Portal",
url: "https://brooklinema.portal.civicclerk.com/"
},
{
label: "Brookline News",
url: "https://brookline.news/"
},
{
label: "DLS data for Property Tax Statistics",
url: "https://dls-gw.dor.state.ma.us/reports/rdPage.aspx?rdReport=Dashboard.Cat3PropTaxStat"
},
{
label: "FY2027 Financial Plan",
url: "https://stories.opengov.com/brooklinema/5cf061e0-65c6-428e-be0f-fee5a4848e8f/published/mpRiIYj5M"
},
{
label: "FY2027 Financial Plan (presentation)",
url: "https://www.brooklinema.gov/DocumentCenter/View/61071/FY2027-Financial-Plan?bidId="
},
{
label: "FY27-FY31 Long Range Financial Plan",
url: "https://www.brooklinema.gov/DocumentCenter/View/60730"
},
{
label: "Organization Chart",
url: "https://www.brooklinema.gov/DocumentCenter/View/3327/Town-of-Brookline-Organizational-Chart?bidId="
},
{
label: "Open Checkbook",
url: "https://stories.opengov.com/brooklinema/published/3gE577bjs"
},
{
label: "Brookline Public Schools Budget",
url: "https://brooklinema.portal.civicclerk.com/event/14954/files/attachment/10857"
}
];
const tickerTapeRows = [
{ label: "Property Tax", amount: 349452499 },
{ label: "Local Receipts", amount: 37633556 },
{ label: "State Aid", amount: 26693757 },
{ label: "Free Cash", amount: 20200000 },
{ label: "Other Available Funds", amount: 6267275 },
{ label: "Enterprises (net)", amount: 40896030 },
{ label: "TOTAL REVENUE", amount: 481143117, isTotal: true },
{ label: "Municipal Departments", amount: 101259557 },
{ label: "School Department", amount: 144533296 },
{ label: "Non-Departmental", amount: 161991096 },
{ label: "Special Appropriations", amount: 21671104 },
{ label: "Enterprises (net)", amount: 40896030 },
{ label: "Non-Appropriated", amount: 10792034 },
{ label: "TOTAL EXPENDITURES", amount: 481143117, isTotal: true }
];
const tickerConfig = {
enableSecondaryLoop: false,
showSecondaryTickerBar: false,
activeTickerContent: "override"
};
const overrideTickerMessage =
"The Town of Brookline will likely put a $5.31M override on the ballot for the May 5, 2026 election. The stated purpose is to stabilize the operating budget, fund contractual obligations, avoid deeper cuts in FY2028 and FY2029, and maintain expected service levels. This is a municipal operations override question only and would not include the schools. The schools may request their own override.";
const defaultBudgetRows = [
{
fiscalYear: "FY2027",
category: "Operating Budget (Town + Schools)",
amount: 481100000,
priorAmount: 464800000,
deltaAmount: 16300000,
deltaPercent: 3.5,
percentOfTotal: 100,
fundType: "operating",
isOneTime: false,
notes: "Reported in FY2027 Financial Plan overview.",
sourceDoc: "FY2027 Financial Plan",
sourcePage: "Overview",
sourceLabel: "FY2027 Financial Plan",
sourceUrl: "https://stories.opengov.com/brooklinema/5cf061e0-65c6-428e-be0f-fee5a4848e8f/published/mpRiIYj5M",
metricKey: "operating_total"
},
{
fiscalYear: "FY2027",
category: "Proposed Override",
amount: 5310000,
priorAmount: 0,
deltaAmount: 5310000,
deltaPercent: null,
percentOfTotal: 1.1,
fundType: "revenue",
isOneTime: false,
notes: "Proposed Proposition 2 1/2 override amount.",
sourceDoc: "FY2027 Financial Plan",
sourcePage: "Budget Message",
sourceLabel: "FY2027 Financial Plan",
sourceUrl: "https://stories.opengov.com/brooklinema/5cf061e0-65c6-428e-be0f-fee5a4848e8f/published/mpRiIYj5M",
metricKey: "override"
},
{
fiscalYear: "FY2027",
category: "Town Initial Structural Gap",
amount: 3000000,
priorAmount: 2100000,
deltaAmount: 900000,
deltaPercent: 42.9,
percentOfTotal: 0.6,
fundType: "operating",
isOneTime: false,
notes: "Initial gap before proposed efficiencies and revenue adjustments.",
sourceDoc: "FY2027 Financial Plan",
sourcePage: "Budget Message",
sourceLabel: "FY2027 Financial Plan",
sourceUrl: "https://stories.opengov.com/brooklinema/5cf061e0-65c6-428e-be0f-fee5a4848e8f/published/mpRiIYj5M",
metricKey: "town_gap"
},
{
fiscalYear: "FY2027",
category: "Public Schools Projected Gap",
amount: 6000000,
priorAmount: 4800000,
deltaAmount: 1200000,
deltaPercent: 25,
percentOfTotal: 1.2,
fundType: "operating",
isOneTime: false,
notes: "Plan cites a projected school budget gap exceeding this amount.",
sourceDoc: "FY2027 Financial Plan",
sourcePage: "Budget Message",
sourceLabel: "FY2027 Financial Plan",
sourceUrl: "https://stories.opengov.com/brooklinema/5cf061e0-65c6-428e-be0f-fee5a4848e8f/published/mpRiIYj5M",
metricKey: "school_gap"
},
{
fiscalYear: "FY2027",
category: "Anticipated Free Cash",
amount: 23000000,
priorAmount: 20100000,
deltaAmount: 2900000,
deltaPercent: 14.4,
percentOfTotal: 4.8,
fundType: "capital",
isOneTime: true,
notes: "Largely allocated to capital, reserves, and liabilities.",
sourceDoc: "FY2027 Financial Plan",
sourcePage: "Budget Message",
sourceLabel: "FY2027 Financial Plan",
sourceUrl: "https://stories.opengov.com/brooklinema/5cf061e0-65c6-428e-be0f-fee5a4848e8f/published/mpRiIYj5M",
metricKey: "free_cash"
}
];
const budgetCategoryMenu = [
{
key: "budget_summaries",
label: "1. Budget Summaries"
},
{
key: "revenue_funds",
label: "2. Revenue and Fund Accounting"
},
{
key: "department_budgets",
label: "3. Department Budget Tables"
},
{
key: "non_appropriated_balances",
label: "4. Non-Appropriated and Fund Balances"
},
{
key: "capital_plan",
label: "5. Capital Improvements Plan"
}
];
const views = {
journal: {
label: "Posts",
searchPlaceholder: "Search posts"
},
meetings: {
label: "Meetings",
searchPlaceholder: "Search meetings"
},
budget: {
label: "Budget Data",
searchPlaceholder: "Search budget categories"
},
links: {
label: "Links",
searchPlaceholder: "Search links"
}
};
const civicClerkSourceUrl =
"https://brooklinema.portal.civicclerk.com/?category_id=28,59,144,87,26";
const initialMeetingsData = Array.isArray(window.MEETINGS_DATA) ? window.MEETINGS_DATA : [];
const initialMeetingsMeta =
window.MEETINGS_META && typeof window.MEETINGS_META === "object" ? window.MEETINGS_META : null;
const initialBudgetData = Array.isArray(window.BUDGET_SUMMARY_DATA) ? window.BUDGET_SUMMARY_DATA : [];
function normalizeBudgetRows(rows) {
return (Array.isArray(rows) ? rows : []).map(normalizeBudgetRow).filter(Boolean);
}
const state = {
activeView: getViewFromHash(),
query: "",
meetings: initialMeetingsData,
meetingsMeta: {
sourceUrl: initialMeetingsMeta?.sourceUrl || civicClerkSourceUrl,
lastUpdated: initialMeetingsMeta?.lastUpdated || null,
count: initialMeetingsMeta?.count || initialMeetingsData.length
},
budgetRows: normalizeBudgetRows(initialBudgetData).length
? normalizeBudgetRows(initialBudgetData)
: normalizeBudgetRows(defaultBudgetRows),
budgetCategory: budgetCategoryMenu[0].key
};
const viewContent = document.querySelector("#view-content");
const postTemplate = document.querySelector("#post-template");
const searchInput = document.querySelector("#search-posts");
const searchWrap = document.querySelector(".search-wrap");
const viewMeta = document.querySelector("#view-meta");
const tabList = document.querySelector("#view-tablist");
const tabs = tabList ? Array.from(tabList.querySelectorAll(".view-tab[data-view]")) : [];
const siteHeader = document.querySelector(".site-header");
const tickerTrack = document.querySelector("#budget-ticker-track");
const secondaryTickerBar = document.querySelector("#secondary-ticker-bar");
const overrideTickerTrack = document.querySelector("#override-ticker-track");
function getViewFromHash() {
const hashView = window.location.hash.replace("#", "").trim().toLowerCase();
return views[hashView] ? hashView : "journal";
}
function formatDateTime(value) {
const date = new Date(value);
if (Number.isNaN(date.getTime())) {
return "Date TBD";
}
return new Intl.DateTimeFormat(undefined, {
month: "short",
day: "numeric",
year: "numeric",
hour: "numeric",
minute: "2-digit"
}).format(date);
}
function formatMeetingDateTime(value) {
const date = parseMeetingDateValue(value);
if (Number.isNaN(date.getTime())) {
return "Date TBD";
}
return new Intl.DateTimeFormat(undefined, {
month: "short",
day: "numeric",
year: "numeric",
hour: "numeric",
minute: "2-digit"
}).format(date);
}
function formatMeetingDate(value) {
const date = parseMeetingDateValue(value);
if (Number.isNaN(date.getTime())) {
return "Date TBD";
}
return new Intl.DateTimeFormat(undefined, {
month: "short",
day: "numeric",
year: "numeric"
}).format(date);
}
function formatMeetingTime(value) {
const date = parseMeetingDateValue(value);
if (Number.isNaN(date.getTime())) {
return "Time TBD";
}
return new Intl.DateTimeFormat(undefined, {
hour: "numeric",
minute: "2-digit"
}).format(date);
}
function formatDateOnly(value) {
const date = parseMeetingDateValue(value);
if (Number.isNaN(date.getTime())) {
return "Date TBD";
}
return new Intl.DateTimeFormat(undefined, {
month: "short",
day: "numeric",
year: "numeric"
}).format(date);
}
function parseMeetingDateValue(value) {
if (typeof value === "string") {
const trimmed = value.trim();
if (/^\d{4}-\d{2}-\d{2}t\d{2}:\d{2}(:\d{2})?(\.\d+)?z$/i.test(trimmed)) {
return new Date(trimmed.replace(/z$/i, ""));
}
}
return new Date(value);
}
function formatCurrency(value) {
if (typeof value !== "number" || Number.isNaN(value)) {
return "-";
}
return new Intl.NumberFormat(undefined, {
style: "currency",
currency: "USD",
maximumFractionDigits: 0
}).format(value);
}
function formatTickerAmount(value) {
if (typeof value !== "number" || Number.isNaN(value)) {
return "-";
}
return new Intl.NumberFormat(undefined, {
style: "currency",
currency: "USD",
maximumFractionDigits: 0
}).format(value);
}
function formatSignedCurrency(value) {
if (typeof value !== "number" || Number.isNaN(value)) {
return "-";
}
if (value === 0) {
return "$0";
}
return `${value > 0 ? "+" : "-"}${formatCurrency(Math.abs(value))}`;
}
function createTickerSegment(rows, options = {}) {
const { ariaHidden = false } = options;
const segment = document.createElement("div");
segment.className = "ticker-segment";
if (ariaHidden) {
segment.setAttribute("aria-hidden", "true");
}
rows.forEach((row, index) => {
const item = document.createElement("span");
item.className = row.isTotal ? "ticker-item ticker-item-total" : "ticker-item";
item.textContent = `${row.label}: ${formatTickerAmount(row.amount)}`;
segment.append(item);
if (index < rows.length - 1) {
const separator = document.createElement("span");
separator.className = "ticker-separator";
separator.textContent = "•";
separator.setAttribute("aria-hidden", "true");
segment.append(separator);
}
});
return segment;
}
function renderTickerTape() {
if (!tickerTrack) {
return;
}
tickerTrack.innerHTML = "";
tickerTrack.classList.remove("ticker-track--loop", "ticker-track--single");
if (tickerConfig.activeTickerContent === "override") {
tickerTrack.classList.add("ticker-track--loop");
tickerTrack.append(
createTickerTextSegment(overrideTickerMessage),
createTickerTextSegment(overrideTickerMessage, { ariaHidden: true })
);
return;
}
tickerTrack.append(createTickerSegment(tickerTapeRows));
if (tickerConfig.enableSecondaryLoop) {
tickerTrack.classList.add("ticker-track--loop");
tickerTrack.append(createTickerSegment(tickerTapeRows, { ariaHidden: true }));
return;
}
tickerTrack.classList.add("ticker-track--single");
}
function createTickerTextSegment(text, options = {}) {
const { ariaHidden = false } = options;
const segment = document.createElement("div");
segment.className = "ticker-segment";
if (ariaHidden) {
segment.setAttribute("aria-hidden", "true");
}
const item = document.createElement("span");
item.className = "ticker-item ticker-item-message";
item.textContent = text;
segment.append(item);
return segment;
}
function renderOverrideTickerTape() {
if (!overrideTickerTrack) {
return;
}
overrideTickerTrack.innerHTML = "";
overrideTickerTrack.classList.remove("ticker-track--loop", "ticker-track--single");
overrideTickerTrack.classList.add("ticker-track--loop");
overrideTickerTrack.append(
createTickerTextSegment(overrideTickerMessage),
createTickerTextSegment(overrideTickerMessage, { ariaHidden: true })
);
}
function formatPercent(value) {
if (typeof value !== "number" || Number.isNaN(value)) {
return "-";
}
return `${value.toFixed(1)}%`;
}
function formatSignedPercent(value) {
if (typeof value !== "number" || Number.isNaN(value)) {
return "-";
}
if (value === 0) {
return "0.0%";
}
return `${value > 0 ? "+" : ""}${value.toFixed(1)}%`;
}
function parseFiscalYearNumber(value) {
const match = `${value || ""}`.match(/(\d{2,4})/);
if (!match) {
return null;
}
const parsed = Number(match[1]);
if (!Number.isFinite(parsed)) {
return null;
}
return parsed < 100 ? parsed + 2000 : parsed;
}
function getLatestFiscalYear(rows) {
let latest = null;
rows.forEach((row) => {
const year = parseFiscalYearNumber(row.fiscalYear);
if (year && (!latest || year > latest)) {
latest = year;
}
});
return latest ? `FY${latest}` : null;
}
function formatFundType(value) {
const key = normalizeText(value);
if (key === "operating") {
return "Operating";
}
if (key === "capital") {
return "Capital";
}
if (key === "revenue") {
return "Revenue";
}
return "-";
}
function getBudgetCategoryByKey(key) {
return budgetCategoryMenu.find((category) => category.key === key) || null;
}
function formatBudgetCategory(value) {
return getBudgetCategoryByKey(value)?.label || "Unmapped";
}
function inferBudgetCategoryKey(row) {
const category = normalizeText(row.category);
const sourcePage = normalizeText(row.sourcePage);
const metricKey = normalizeText(row.metricKey);
const notes = normalizeText(row.notes);
if (category.includes("fund balance") || category.includes("non-appropriated") || sourcePage.includes("fund balance")) {
return "non_appropriated_balances";
}
if (
category.includes("free cash") ||
category.includes("available funds") ||
category.includes("reserve") ||
category.includes("contingency") ||
notes.includes("one-time funds") ||
notes.includes("stabilization")
) {
return "non_appropriated_balances";
}
if (
row.fundType === "revenue" ||
category.includes("property tax") ||
category.includes("local receipts") ||
category.includes("state aid") ||
category.includes("free cash") ||
category.includes("available funds") ||
notes.includes("revenue")
) {
return "revenue_funds";
}
if (
row.fundType === "capital" ||
sourcePage.includes("capital") ||
category.includes("capital") ||
category.includes("infrastructure") ||
category.includes("facilities") ||
category.includes("sidewalk")
) {
return "capital_plan";
}
if (
sourcePage.includes("operating summary") &&
!metricKey.includes("operating_total") &&
category !== "operating budget (town + schools)"
) {
return "department_budgets";
}
return "budget_summaries";
}
function getBudgetTrendClass(value) {
if (typeof value !== "number" || Number.isNaN(value) || value === 0) {
return "";
}
return value > 0 ? "budget-up" : "budget-down";
}
function setTabState() {
tabs.forEach((tab) => {
const tabView = tab.dataset.view;
const isActive = tabView === state.activeView;
tab.setAttribute("aria-selected", String(isActive));
tab.tabIndex = isActive ? 0 : -1;
});
}
function updateSearchUi() {
const hideSearch = state.activeView === "budget" || state.activeView === "links";
if (searchWrap) {
searchWrap.hidden = hideSearch;
}
if (hideSearch) {
return;
}
const config = views[state.activeView] || views.journal;
searchInput.placeholder = config.searchPlaceholder;
searchInput.setAttribute("aria-label", `Search ${config.label}`);
}
function updateViewMeta() {
if (state.activeView === "meetings") {
const lastUpdated = state.meetingsMeta.lastUpdated;
const meetingCount = Number.isFinite(state.meetingsMeta.count) ? state.meetingsMeta.count : state.meetings.length;
const updatedText = lastUpdated
? `Last updated ${formatDateTime(lastUpdated)}.`
: "No local meetings snapshot yet.";
viewMeta.hidden = false;
viewMeta.textContent = `${updatedText} ${meetingCount} meetings loaded.`;
return;
}
if (state.activeView === "budget") {
viewMeta.hidden = false;
viewMeta.textContent = "Choose one of the five FY2027 plan categories to view its budget rows.";
return;
}
if (state.activeView === "links") {
viewMeta.hidden = true;
viewMeta.textContent = "";
return;
}
viewMeta.hidden = true;
viewMeta.textContent = "";
}
function setActiveView(nextView, options = {}) {
const { fromHash = false } = options;
if (!views[nextView]) {
return;
}
state.activeView = nextView;
setTabState();
updateSearchUi();
updateViewMeta();
if (!fromHash && window.location.hash !== `#${nextView}`) {
history.replaceState(null, "", `#${nextView}`);
}
renderActiveView();
}
function updateStickyHeaderOffset() {
if (!siteHeader) {
return;
}
const headerHeight = Math.ceil(siteHeader.getBoundingClientRect().height);
document.documentElement.style.setProperty("--sticky-header-height", `${headerHeight}px`);
}
function addRevealAnimation(container) {
const cards = container.querySelectorAll(".post-card");
if (!cards.length) {
return;
}
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("visible");
observer.unobserve(entry.target);
}
});
},
{
threshold: 0.15
}
);
cards.forEach((card, index) => {
card.style.animationDelay = `${index * 55}ms`;
observer.observe(card);
});
}
function normalizeText(value) {
return `${value || ""}`.trim().toLowerCase();
}
function filterPosts() {
const normalizedQuery = normalizeText(state.query);
if (!normalizedQuery) {
return posts;
}
return posts.filter((post) => {
const content = `${post.title || ""} ${post.excerpt || ""} ${post.body || ""} ${post.category || ""}`.toLowerCase();
return content.includes(normalizedQuery);
});
}
function sortMeetingsByDate(meetings, direction = "asc") {
const sign = direction === "desc" ? -1 : 1;
return [...meetings].sort((a, b) => {
const left = parseMeetingDateValue(a.dateTime).getTime();
const right = parseMeetingDateValue(b.dateTime).getTime();
if (Number.isNaN(left) && Number.isNaN(right)) {
return 0;
}
if (Number.isNaN(left)) {
return 1;
}
if (Number.isNaN(right)) {
return -1;
}
return (left - right) * sign;
});
}
function splitMeetingsByTime(meetings) {
const now = Date.now();
const past = [];
const upcoming = [];
const undated = [];
meetings.forEach((meeting) => {
const timestamp = parseMeetingDateValue(meeting.dateTime).getTime();
if (Number.isNaN(timestamp)) {
undated.push(meeting);
return;
}
if (timestamp < now) {
past.push(meeting);
return;
}
upcoming.push(meeting);
});
return {
past: sortMeetingsByDate(past, "desc"),
upcoming: [...sortMeetingsByDate(upcoming, "asc"), ...undated]
};
}
function filterMeetingsByQuery() {
const normalizedQuery = normalizeText(state.query);
if (!normalizedQuery) {
return state.meetings;
}
return state.meetings.filter((meeting) => {
const content = `${meeting.body || ""} ${meeting.title || ""} ${meeting.location || ""} ${meeting.status || ""}`.toLowerCase();
return content.includes(normalizedQuery);
});
}
function filterResourceLinks() {
return resourceLinks;
}
function getBudgetRowsForActiveCategory() {
const filteredRows = state.budgetRows
.filter((row) => row.budgetCategory === state.budgetCategory);
return filteredRows.sort((a, b) => {
const leftYear = parseFiscalYearNumber(a.fiscalYear) || 0;
const rightYear = parseFiscalYearNumber(b.fiscalYear) || 0;
if (leftYear !== rightYear) {
return rightYear - leftYear;
}
const leftAmount = Number.isFinite(a.amount) ? a.amount : -Infinity;
const rightAmount = Number.isFinite(b.amount) ? b.amount : -Infinity;
if (leftAmount !== rightAmount) {
return rightAmount - leftAmount;
}
return `${a.category || ""}`.localeCompare(`${b.category || ""}`);
});
}
function onBudgetCategoryClick(nextCategoryKey) {
if (state.budgetCategory === nextCategoryKey) {
return;
}
if (!getBudgetCategoryByKey(nextCategoryKey)) {
return;
}
state.budgetCategory = nextCategoryKey;
renderBudget();
}
function renderEmptyState(text) {
const emptyState = document.createElement("p");
emptyState.className = "empty-state";
emptyState.textContent = text;
viewContent.append(emptyState);
}
function renderJournal() {
const filteredPosts = filterPosts();
viewContent.className = "view-content post-list";
viewContent.innerHTML = "";
if (!filteredPosts.length) {
renderEmptyState("No posts match your search.");
return;
}
filteredPosts.forEach((post) => {
const fragment = postTemplate.content.cloneNode(true);
const card = fragment.querySelector(".post-card");
fragment.querySelector(".post-date").textContent = post.date;
fragment.querySelector(".post-excerpt").textContent = post.excerpt;
fragment.querySelector(".post-title").textContent = post.title;
const body = fragment.querySelector(".post-body");
const button = fragment.querySelector(".read-more");
if (post.resourcePage) {
card.classList.add("clickable-card");
card.tabIndex = 0;
card.setAttribute("role", "link");
card.setAttribute("aria-label", `Open ${post.title}`);