Teacher Calendar

v3.2

by Turner

HTML

<!DOCTYPE html>
<html>

  <head>
    <title>Mr. Turner's Calendar</title>
    <link type="text/css" rel="stylesheet" href="stylesheet.css">
    <script language="JavaScript">
<!--
function resize_iframe()
{

	var height=window.innerWidth;//Firefox
	if (document.body.clientHeight)
	{
		height=document.body.clientHeight;//IE
	}
	//resize the iframe according to the size of the
	//window (all these should be on the same line)
	document.getElementById("glu").style.height=parseInt(height-
	document.getElementById("glu").offsetTop-8)+"px";
}

// this will resize the iframe every
// time you change the size of the window.
window.onresize=resize_iframe; 

//Instead of using this you can use: 
//	<BODY onresize="resize_iframe()">


//-->
</script>
  </head>

  <body>
    <div class="leftPanel">
      <button id="updateButton">
      Update
      </button>
    </div>

    <div class="rightPanel">
    </div>
    
    <div class="tableHolder">
      <table id="calTable">
      </table>
    </div>


  </body>

</html>

CSS

#tableTitle{
  font-family:sans-serif;
  font-size:35pt;
}

#daysOfWeek {
  font-family:sans-serif;
  font-size:15pt;
}

.hoverCell{
    border: solid #FF9900;
    font-weight: bold;
}

.tableHolder{
  display: table;
  width: 100%;
  margin: auto;
}

.otherMonth{
  background-color: #ccccff;
}

.cell{
  display: table-cell;
  width: 100px;
  height: 100px;
}

#today{
  color: #ff0000;
  font-weight: bold;
}

#calTable {
  text-align: center;
  background-color: #cceeff;
  border-collapse: collapse;
  border: 5px solid black;
}

td{
    border: 2px solid black;
    text-align: left;
    vertical-align: top;
    font-size: 25px;
}

.leftPanel, .rightPanel {
  position: relative;
}

#dateRange{
  font-family:sans-serif;
  font-size:20pt;
  display: table-cell;
  position: relative;
}

JavaScript

//Runs from document load
$(document).ready(function(){
  //Create variables for the current month
  var toDate = new Date();
  var firstDate = new Date(toDate.getFullYear(), toDate.getMonth(), 1);
  var lastDate = new Date(toDate.getFullYear(), toDate.getMonth()+1, 0);
  
  //Build the date range
  $('.leftPanel').prepend("<input type='date' min='2016-08-01' max='2017-07-01' id='lastDate' value=''>");
  $('.leftPanel').prepend("<input type='date' min='2016-08-01' max='2017-07-01' id='firstDate' value=''>");
  
  //Create the first calendar
  makeCal(firstDate, lastDate);
  
  //Update calendar on button click
  $("#updateButton").click(function() {
    
    //Empty current table
    $(".tableHolder").empty(); //or $('#calTable tr').remove();?
    var sample1 = document.getElementById('firstDate').value;
    var testDate1 = new Date(sample1.substring(0,4), parseInt(sample1.substring(5,7))-1, sample1.substring(8));
    var sample2 = document.getElementById('lastDate').value;
    var testDate2 = new Date(sample2.substring(0,4), parseInt(sample2.substring(5,7))-1, sample2.substring(8));
    //$(".leftPanel").append(testDate1);
    //$(".leftPanel").append(testDate2);
    makeCal(testDate1, testDate2);
});
	//Highlight cell when mouse hoevers over it
  $('.cell').hover(
  		function(){
  			$(this).addClass('hoverCell');
    	},
    	function(){
        $(this).removeClass('hoverCell');
    	}
    );
});

//Build the calendar
function makeCal(startDate, endDate){
    //Create current date for reference
    var focusDate = new Date();
    
    //Change start or end date if not the beginning or end of the week, respectively
    if (startDate.getDay() != 0){
      startDate.setDate(startDate.getDate() - startDate.getDay(0))
    };
    if (endDate.getDay() != 6){
    	endDate.setDate(endDate.getDate()+(6-endDate.getDay()));
    };

	//Create the first start and end week dates so as not to replace/update the start/end dates
	var startWeek = new...