window.cal = {}; cal.hilightNow = function() { $(".calendarSubWrapper").each(function() { if ($(this).children("h4").text() == moment().format("MMMM")) { console.log($(this).children("h4").text()); $(this).children(".calendar").each(function() { $(this).children("tbody").each(function() { $(this).children("tr").each(function() { $(this).children("td").each(function() { console.log($(this).html()); if ($(this).text() == moment().format("D")) { $(this).addClass("working"); console.log($(this).text()); } }) }) }) }) } }) } cal.genYear = function(y) { var ret = ""; for (var i = 1; i <= 12; i++) { ret += cal.genPage(y, i); } return ret; } cal.switchMode = function() { switch(options.calendarSelector) { case "monthly": $("#wholeYearSelect").css("display", "none"); $("#yearSelect, #monthSelect").css("display", "inline-block"); $("#calendarWrapper").html(cal.genPage($("#yearSelect").val(), $("#monthSelect").val())); if ($("#yearSelect").val() == moment().format("Y")) cal.hilightNow(); break; case "yearly": $("#wholeYearSelect").css("display", "inline-block"); $("#yearSelect, #monthSelect").css("display", "none"); $("#calendarWrapper").html(cal.genYear($("#wholeYearSelect").val())); if ($("#wholeYearSelect").val() == moment().format("Y")) cal.hilightNow(); break; } } cal.genPage = function(y, m) { var ret = ""; var t = moment([y, m-1]); var offset = t.format("d"); ret += `
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
` } for (var j = offset; j < 7; j++) { ret += ` | ${t.format("D")} | ` t.add(1, "day"); if (t.format("M") != m) break; } } else { for (var j = 0; j < 7; j++) { ret += `${t.format("D")} | ` t.add(1, "day"); if (t.format("M") != m) break; } } ret += `