summaryrefslogtreecommitdiff
path: root/index.html
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-06-16 20:21:51 -0400
committerJules Laplace <jules@okfoc.us>2016-06-16 20:21:51 -0400
commitfcfe603abdb124a318c42f958ce7db456bdb278c (patch)
treeae615cf9a50b6098fe7e5a800ff3336ba2ef985a /index.html
first commit
Diffstat (limited to 'index.html')
-rwxr-xr-xindex.html655
1 files changed, 655 insertions, 0 deletions
diff --git a/index.html b/index.html
new file mode 100755
index 0000000..ceeff4d
--- /dev/null
+++ b/index.html
@@ -0,0 +1,655 @@
+<!doctype html>
+<html>
+<head>
+<title>Lodges by Date</title>
+<link rel="stylesheet" type="text/css" href="pickadate.css">
+<style type="text/css">
+html,body { overflow-x: hidden; }
+#data, #summer { margin-left: 400px; }
+#summer { display: none; }
+.bold { font-weight: bold; background: #eee; color: black; }
+a { text-decoration: underline; color: blue; cursor: pointer; }
+#district { text-transform: capitalize; }
+</style>
+</head>
+<body>
+
+<input type="text" class="datepicker">
+<button id="next">Next day</button>
+<select id="districts"></select>
+<select id="lodges"></select>
+
+<div id="summer">
+<img src="palmtree.gif"><br>
+<i>no meetings july and august!</i>
+</div>
+
+<div id="data">
+
+<p>
+Today is <span id="today"></span>, better known as <span id="todayindex"></span>.<br>
+</p>
+
+<p>
+These lodges meet today: <span id="todaylodges"></span><br>
+These lodges meet tomorrow: <span id="tomorrowlodges"></span>
+</p>
+
+<p>
+<span class="lodgename"></span> meets this month: <span id="estuarymeetings"></span><br>
+<span class="lodgename"></span> next meets: <span id="estuarynext"></span>
+</p>
+
+<p>
+The next full moon is <span id="nextfullmoon"></span>.<br>
+</p>
+
+<div id="lodgeinfo">
+</div>
+
+<script id="lodgeinfo-template" type="text/html">
+<div class="info">
+ <p>
+ <b id="name"></b> <b>#</b><b id="id"></b><br>
+ <span id="dates"></span><br>
+ <span id="district"></span>
+ </p>
+</div>
+</script>
+
+</body>
+<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
+<script type="text/javascript" src="pickadate.js"></script>
+<script type="text/javascript" src="nylodges-grand-lodge.js"></script>
+<script type="text/javascript">
+
+var days = "Su Mo Tu We Th Fr Sa".split(" ");
+var longdays = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" ");
+var months = "January February March April May June July August September October November December".split(" ");
+var monthsLookup = lookup(months);
+var shortMonths = wrap(map(function(x){ return [ x.slice(0,3), monthsLookup[x] ] }, months));
+var daysLookup = lookup(days);
+var Ordinals = "all first second third fourth fifth sixth seventh eighth ninth tenth".split(" ")
+var ShortOrdinals = "1st 2nd 3rd 4th".split(" ")
+
+var today = new Date();
+var DatesByIndex = {};
+var LodgeListByDate = {};
+
+var Lodges = {}
+var LodgesByIndex = {}
+var LodgesWithMonth = {}
+var LodgesByDistrict = {}
+var AllLodgesByIndex = LodgesByIndex
+LodgeList.forEach(function(l){
+ var id = l.title.match(/\d+/)[0]
+ l.id = id
+ var tpartz = l.title.split("No")
+ l.name = tpartz[0]
+ l.address = l.address.split(",")
+ l.district = l.district.toLowerCase()
+ delete l.title
+ Lodges[id] = l
+
+ var day
+ longdays.some(function(d){
+ if (l.dates.toLowerCase().match(d.toLowerCase())) {
+ day = d.substr(0,2)
+ return true
+ }
+ return false
+ })
+
+ ShortOrdinals.forEach(function(oo, i){
+ if (l.dates.match(oo)) {
+ var ok = oo[0] + day
+ LodgesByIndex[ok] = LodgesByIndex[ok] || []
+ LodgesByIndex[ok].push(id)
+ LodgesByDistrict[ l.district ] = LodgesByDistrict[ l.district ] || {}
+ LodgesByDistrict[ l.district ][ok] = LodgesByDistrict[ l.district ][ok] || []
+ LodgesByDistrict[ l.district ][ok].push(id)
+ }
+ })
+
+})
+
+/*
+var LodgesByIndex = {
+ '1Mo': [2, 4, 9, 17, 33, 36, 49, 76, 77, 88, 116, 131],
+ '1Tu': [8, 12, 21, 38, 40, 55, 57, 63, 67, 108, 113, 148],
+ '1We': [5, 7, 11, 18, 25, 30, 34, 43, 64, 66, 103, 125],
+ '1Th': [3, 6, 16, 22, 31, 42, 51, 60, 121, 140, 145],
+ '1Fr': [10, 89],
+ '1Sa': [120, 149],
+ '2Mo': [19, 70, 95, 101, 112, 115, 144, 147, 332],
+ '2Tu': [14, 28, 29, 69, 73, 78, 85, 87, 102, 104, 110, 146],
+ '2We': [15, 39, 44, 79, 97, 107, 119, 142],
+ '2Th': [1, 61, 65, 81],
+ '2Fr': [122],
+ '2Sa': [24],
+ '3Mo': [2, 4, 9, 17, 33, 49, 76, 77, 88, 116, 131],
+ '3Tu': [8, 12, 21, 38, 40, 51, 57, 63, 67, 143],
+ '3We': [5, 7, 11, 13, 18, 25, 30, 34, 43, 64, 66, 103, 125],
+ '3Th': [3, 6, 16, 22, 31, 42, 47, 51, 121, 140, 145],
+ '3Fr': [10, 89, "PLR"],
+ '3Sa': [120, 149],
+ '4Mo': [70, 95, 101, 112, 115],
+ '4Tu': [14, 28, 29, 73, 78, 85, 102, 104],
+ '4We': [39, 44, 97, 119, "MLR"],
+ '4Th': [1, 61, 65, 81],
+ 'MSa': [46], // on or before full moon
+ 'MTh': [48]
+};
+var LodgesWithMonth = {
+ 'PLR': shortMonthLookup("Feb Apr Sep Oct Dec".split(" ")),
+ 'MLR': shortMonthLookup("Feb Mar May Sep Oct Dec".split(" "))
+};
+*/
+/*
+S on or before full moon 46
+T on or before full moon 48
+3rd F, Feb/Apr/Sep/Oct/Dec PLR
+4th W, Feb/Mar/May/Sep/Oct/Dec MLR
+*/
+
+var daysInMonth = [31,28,31,30, 31,30,31,31, 30,31,30,31];
+var daysInMonthSum = [0,31,59,90, 120,151,181,212, 243,273,304,334];
+var daysInMonthLeap = [0,31,60,91, 121,152,182,213, 244,274,305,335];
+
+var DatesByLodge = reverseLookup(LodgesByIndex);
+
+Date.prototype.getFirstOfMonth = function(){
+ var firstofmonth = new Date();
+ firstofmonth.setMonth(this.getMonth());
+ firstofmonth.setFullYear(this.getFullYear());
+ firstofmonth.setDate(1);
+ return firstofmonth;
+}
+Date.prototype.getWeekOfMonth = function() {
+ var firstofmonth = this.getFirstOfMonth();
+ var week = this.getWeekOfYear() - firstofmonth.getWeekOfYear();
+ if (this.getDay() >= firstofmonth.getDay()) {
+ week += 1;
+ }
+ return week;
+}
+Date.prototype.getWeekOfYear = function(){
+ return Math.floor( (this.getYearDay() - this.getDay() + 10) / 7 );
+}
+Date.prototype.getYearDay = function(){
+ var ord = this.getDate();
+ if (this.isLeapYear()) {
+ return ord + daysInMonthLeap[ this.getMonth() ];
+ } else {
+ return ord + daysInMonthSum[ this.getMonth() ];
+ }
+}
+Date.prototype.isLeapYear = function(){
+ var year = this.getFullYear();
+ if (year % 400 == 0) {
+ return true;
+ }
+ else if (year % 100 == 0) {
+ return false;
+ }
+ else if (year % 4 == 0) {
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+Date.prototype.getDaysInMonth = function(){
+ var month = this.getMonth();
+ if (month == 1 && this.isLeapYear()) {
+ return 29;
+ } else {
+ return daysInMonth[month];
+ }
+}
+Date.prototype.copy = function(){
+ return new Date( this.getTime() );
+}
+Date.prototype.getWeekDayIndex = function(){
+ return this.getWeekOfMonth() + days[this.getDay()];
+}
+Date.prototype.tomorrow = function(){
+ var tomorrow = this.copy();
+ tomorrow.setDate(this.getDate() + 1);
+ return tomorrow;
+}
+Date.prototype.nextMonth = function(){
+ var nextmonth = this.copy();
+ nextmonth.setMonth(this.getMonth() + 1);
+ var another = nextmonth.copy();
+ another.setMonth(this.getMonth() + 2);
+ nextmonth.cache();
+ another.cache();
+ return nextmonth;
+}
+Date.prototype.display = function(){
+ return longdays[this.getDay()] + " " + months[this.getMonth()] + " " + this.getDate() + ", " + this.getFullYear();
+}
+Date.prototype.dateFromIndex = function(index) {
+ return DatesByIndex[this.getFullYear()][this.getMonth()][index];
+}
+function shortMonth(s) {
+ return s.slice(0,3);
+}
+function shortMonthLookup(a) {
+ return lookup(map(function(x){ return shortMonths[x] }, a));
+}
+
+function map (f,a) {
+ var aa = [];
+ for (var i = 0; i < a.length; i++) {
+ // console.log(a[i], f(a[i]));
+ aa[i] = f(a[i]);
+ }
+ return aa;
+}
+function wrap(a) {
+ var lookup = {};
+ for (var i = 0; i < a.length; i++) {
+ lookup[a[i][0]] = a[i][1];
+ }
+ return lookup;
+}
+
+// date.setTime( date.getTime() + date.getTimezoneOffset() * 60000 );
+var bluemoon = new Date( 96, 1, 3, 16, 15, 0 );
+var lunarperiod = 29 * ( 24 * 3600 * 1000 ) + 12 * ( 3600 * 1000 ) + 44.05 * ( 60 * 1000 );
+Date.prototype.moonPhase = function(){
+ var phasetime = ( this.getTime() - bluemoon.getTime() ) % lunarperiod;
+ return fraction = phasetime / lunarperiod;
+}
+Date.prototype.nextFullMoon = function(){
+ var phasetime = ( this.getTime() - bluemoon.getTime() ) % lunarperiod;
+ var fullmoonDaysFromNow = Math.round( ( lunarperiod - phasetime ) / ( 24 * 3600 * 1000 ) )
+ var fullmoon = this.copy();
+
+ fullmoonDaysFromNow %= 29;
+
+ fullmoon.setDate( this.getDate() + fullmoonDaysFromNow );
+ return fullmoon;
+}
+
+Date.prototype.isCached = function() {
+ var year = this.getFullYear();
+ var month = this.getMonth()
+ return (year in DatesByIndex) && (month in DatesByIndex[year]);
+}
+Date.prototype.cache = function () {
+ if (this.isCached()) {
+ return;
+ }
+ var year = this.getFullYear();
+ var month = this.getMonth();
+
+ if (!DatesByIndex[year]) DatesByIndex[year] = {};
+ if (!DatesByIndex[year][month]) DatesByIndex[year][month] = {};
+ if (!LodgeListByDate[year]) LodgeListByDate[year] = {};
+ if (!LodgeListByDate[year][month]) LodgeListByDate[year][month] = {};
+
+ var llbd = LodgeListByDate[year][month];
+
+ var fullmoon = this.nextFullMoon();
+
+ // console.log([ this.getDaysInMonth() ]);
+ for (var i = 1; i <= this.getDaysInMonth(); i++) {
+ var date = this.copy();
+ date.setDate(i);
+ var week = date.getWeekOfMonth();
+ var index = date.getWeekDayIndex();
+
+ DatesByIndex[date.getFullYear()][date.getMonth()][index] = date;
+ var lodgelist = date.getLodges();
+
+ for (var j = 0; j < lodgelist.length; j++) {
+ var lodge_id = lodgelist[j] + "";
+ if (!llbd[lodge_id]) llbd[lodge_id] = [];
+ llbd[lodge_id].push(date);
+ }
+
+ console.log([
+ index,
+ date.getWeekOfYear(),
+ week,
+ days[date.getDay()],
+ date.getDate(),
+ months[date.getMonth()],
+ lodgelist
+ ]);
+ }
+}
+
+function append(car, cdr){
+ for (var i in cdr) {
+ car.push(cdr[i]);
+ }
+}
+Date.prototype.isSameDay = function(date) {
+ return this.getFullYear() == date.getFullYear() && this.getMonth() == date.getMonth() && this.getDate() == date.getDate();
+}
+Date.prototype.isSummer = function(){
+ switch (this.getMonth()) {
+ case 6:
+ case 7:
+ return true;
+ }
+ return false;
+}
+function filter(f,a) {
+ var l = [];
+ if (a) {
+ for (var i = 0; i < a.length; i++) {
+ f(a[i]) && l.push(a[i])
+ }
+ }
+ return l;
+}
+Date.prototype.getLodges = function (date) {
+
+ var weekIndex = this.getWeekDayIndex();
+ var lodges = [];
+
+ if (weekIndex in LodgesByIndex) {
+ append( lodges, LodgesByIndex[weekIndex] );
+ }
+
+ var fullmoon = this.nextFullMoon();
+
+ if ( this.isSameDay(fullmoon) ) {
+ var index = "M" + days[this.getDay()]
+ if ( index in LodgesByIndex ) {
+ append( lodges, LodgesByIndex[index] );
+ }
+ } else if ((fullmoon.getTime() - this.getTime()) < 86400000 * 6) {
+ var index = "M" + days[this.getDay()]
+ if ( index in LodgesByIndex) {
+ append( lodges, LodgesByIndex[index] );
+ }
+ }
+
+ var month = this.getMonth();
+
+ // filter if a lodge does not meet in the current month
+ return filter(function(x){
+ return ( !( x in LodgesWithMonth ) || month in LodgesWithMonth[x] );
+ }, lodges);
+
+}
+function reverseLookup(hash) {
+ var rev = {};
+ for (var d in hash) {
+ var arr = hash[d];
+ for (var j = 0; j < arr.length; j++) {
+ var num = arr[j];
+ rev[num] = rev[num] || [];
+ rev[num].push(d);
+ }
+ }
+ return rev;
+}
+function lookup(arr){
+ var lookup = {};
+ for (var i = 0; i < arr.length; i++) {
+ lookup[arr[i]] = i;
+ }
+ return lookup;
+}
+
+
+function keys(h) {
+ var a = [];
+ for (var i in h) {
+ if (h.hasOwnProperty(i)) {
+ a.push(i);
+ }
+ }
+ return a;
+}
+
+function lodge_name(id) {
+ if (id+"" in Lodges) {
+ var lodge = Lodges[id+""];
+ if (parseInt(id)) {
+ return lodge.name + " #" + lodge.id;
+ } else {
+ return lodge.name;
+ }
+ } else {
+ return id;
+ }
+}
+
+var lodge_id = 23;
+
+var $select = $("select#lodges");
+function build_lodge_selector(){
+ $select.empty()
+ map(function(tup){
+ var $option = $("<option>").attr({
+ 'value': tup[1]
+ });
+ $option.html( tup[0] );
+ $select.append($option);
+ },
+ map(function(id){ return [lodge_name(id), id] },
+ keys(DatesByLodge)
+ ).sort(function(a,b){
+ if (a[0] < b[0])
+ return -1;
+ if (a[0] > b[0])
+ return 1;
+ return 0;
+ })
+ );
+ $select.val(lodge_id);
+}
+build_lodge_selector()
+
+$select.change(function(){
+ lodge_id = $(this).val();
+ render();
+});
+function selectLodge(id) {
+ if (isNaN(parseInt(id))) {
+ lodge_id = id;
+ } else {
+ lodge_id = parseInt(id);
+ }
+ $select.val(lodge_id);
+ render();
+}
+
+
+var $districtSelect = $("select#districts")
+Ordinals.forEach(function(o,i){
+ var $option = $("<option>").attr({
+ 'value': o
+ })
+ if (i == 0) {
+ $option.html("All Lodges")
+ }
+ else {
+ $option.html(o[0].toUpperCase() + o.substr(1) + " " + "Manhattan")
+ }
+ $districtSelect.append($option)
+})
+$districtSelect.val("all")
+$districtSelect.change(function(){
+ var district = $(this).val()
+ if (district == "all") {
+ LodgesByIndex = AllLodgesByIndex
+ }
+ else {
+ LodgesByIndex = LodgesByDistrict[ district.toLowerCase() + " manhattan district" ]
+ }
+ DatesByLodge = reverseLookup(LodgesByIndex)
+ build_lodge_selector()
+ var todays_lodges = today.getLodges()
+ if (todays_lodges[lodge_id] === -1) {
+ lodge_id = Object.keys(DatesByLodge)[0]
+ }
+ render()
+})
+
+
+var LodgeInfoView = $("#lodgeinfo-template").html();
+function renderView(view, lodge) {
+ var $view = $(view);
+ var lodge_keys = keys(lodge);
+ for (var i in lodge_keys) {
+ $view.find("#"+lodge_keys[i]).html(lodge[lodge_keys[i]]);
+ }
+ $view.find("#image").attr("src", lodge["image"]);
+ $view.find("a").each(function(){
+ $(this).attr("href", lodge[this.className]);
+ });
+ $view.find("#address").html(lodge.address.join("<br>"));
+ return $view;
+};
+
+var today = new Date ();
+var pickadate;
+
+function init(){
+ bind();
+ render();
+}
+
+function linkLodge(id){
+ return "<a onclick=\"selectLodge(\'" + id + "')\">" + id + "</a>";
+}
+function linkLodges(lodges) {
+ if (lodges && lodges.length) {
+ return map(linkLodge, lodges).join(", ")
+ }
+}
+function renderLodges(lodges) {
+ if (lodges && lodges.length) {
+ return map(function(id){ return renderView(LodgeInfoView, Lodges[id+""]).html() }, lodges).join("")
+ }
+}
+
+
+function render(){
+ if (today.isSummer()) {
+ $("#data").hide();
+ $("#summer").show();
+ return;
+ }
+ today.cache();
+ $("#data").show();
+ $("#summer").hide();
+
+ $("#today").html( today.display() );
+ $("#todayindex").html( today.getWeekDayIndex() );
+
+ $("#todaylodges").html( linkLodges( today.getLodges() ) || "None!" );
+ $("#tomorrowlodges").html( linkLodges( today.tomorrow().getLodges() ) || "None!" );
+
+ $(".lodgename").html( lodge_name(lodge_id) );
+
+ var today_lodges = today.getLodges()
+ // if (lodge_id+"" in Lodges) {
+ // var lodge = Lodges[lodge_id+""];
+ // $("#lodgeinfo").html( renderView(LodgeInfoView, lodge) ).show();
+ // }
+ if (today_lodges.length) {
+ $("#lodgeinfo").html( renderLodges( today_lodges ) ).show();
+ } else {
+ $("#lodgeinfo").hide();
+ }
+
+ var lodgeDates = LodgeListByDate[today.getFullYear()][today.getMonth()][lodge_id+""];
+ nextMonth = today.nextMonth();
+
+ console.log(lodgeDates, lodge_id);
+
+ $("#estuarymeetings").html( (function(){
+ var dd = [];
+ for (var i in lodgeDates) {
+ dd.push( lodgeDates[i].display() );
+ }
+ return dd;
+ })().join(", "));
+
+ $("#estuarynext").html( (function(){
+ for (var i in lodgeDates) {
+ var date = lodgeDates[i];
+ if ( date > today ) {
+ return date.display();
+ }
+ }
+ var dates = LodgeListByDate[ nextMonth.getFullYear() ][ nextMonth.getMonth() ][ lodge_id+"" ];
+ if (dates && dates.length) {
+ return dates[0].display();
+ } else {
+ return "";
+ }
+ })() );
+
+ $("#nextfullmoon").html( today.nextFullMoon().display() );
+
+ boldenLodgeDates();
+
+}
+
+function bind(){
+ var input = $( '.datepicker' ).pickadate({
+ format: 'ddd, dd mmm yyyy',
+ onSelect: function() {
+ this.open();
+ var dp = this.getDate("yyyy-m-d").split("-");
+ var year = parseInt( dp[0] );
+ var month = parseInt( dp[1] ) - 1;
+ var day = parseInt( dp[2] );
+ today = new Date( year, month, day );
+ render();
+ },
+ onChangeMonth: function(){
+ boldenLodgeDates();
+ }
+ });
+ var picker = input.data( 'pickadate' )
+ picker.open();
+ $("#next").click(function(){
+ today = today.tomorrow();
+ today.nextMonth().cache();
+ picker.setDate(1900+today.getYear(), today.getMonth()+1, today.getDate())
+ });
+}
+
+function boldenLodgeDates(){
+ $(".bold").removeClass("bold");
+
+ var pickadate = $( '.datepicker').data( 'pickadate' );
+ var dis = pickadate.getMonth();
+
+ switch (dis.MONTH) {
+ case 6:
+ case 7:
+ return;
+ }
+
+ (new Date(dis.YEAR, dis.MONTH, 1)).cache();
+ var lodgeDates = LodgeListByDate[dis.YEAR][dis.MONTH][lodge_id+""];
+
+ for (var i in lodgeDates) {
+ var date = lodgeDates[i];
+ $(".pickadate__day[data-date='" + dis.YEAR + "/" + dis.MONTH + "/" + date.getDate() + "']").addClass("bold");
+ }
+}
+
+
+init();
+
+</script>
+</html>
+
+
+
+
+