<input name="d1" id="d1" type="text" size="2" />
<input name="d2" id="d2" type="text" size="2" />
<input name="d3" id="d3" type="text" size="2" />
.row{width:2860px;}
.day{
width:90px;
height:70px;
float:left;
border-style:solid;
border-width:1px;
}
.day span{
display:block;
margin-left:2px;
margin-right:2px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>padas</title>
</head>
<body>
<div class="row">
<div class="day">1</div>
<div class="day">2<span>Something here</span></div>
<div class="day">3</div>
<div class="day">4</div>
<div class="day">5</div>
<div class="day">6</div>
<div class="day">7</div>
<div class="day">8</div>
<div class="day">9</div>
<div class="day">10</div>
<div class="day">11</div>
<div class="day">12</div>
<div class="day">13</div>
<div class="day">14</div>
<div class="day">15</div>
<div class="day">16</div>
<div class="day">17</div>
<div class="day">18</div>
<div class="day">19</div>
<div class="day">20</div>
<div class="day">21</div>
<div class="day">22</div>
<div class="day">23</div>
<div class="day">24</div>
<div class="day">25</div>
<div class="day">26</div>
<div class="day">27</div>
<div class="day">28</div>
<div class="day">29</div>
<div class="day">30</div>
<div class="day">31</div>
</div>
</body>
</html>
i need simple calendar can display only.Month,week,day no need another control.
yes, but data showing is not?
yes, you can change start from 1st and end is 30 and see, the width of events not large than 7?Seems to contradict this one:
only show is show with excelent. its not 1 2 3 ..31 status of day.(its not need edit,update or add event)
i need to show all days of month and events on that days(if got).
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Event Calendar in one row</title>
<style type="text/css">
.main {
width:1850px;
}
.month {
background-color:black;
font: bold 16px verdana;
padding: 5px;
color:white;
}
.daysofweek {
background-color:gray;
font:bold 12px verdana;
color:white;
float:left;
width:49px;
border-right:1px solid #EEEEEE;
text-align:center;
}
.days {
font-size: 12px;
font-family:verdana;
color:black;
background-color: lightyellow;
float:left;
width:49px;
border-right:1px solid #EEEEEE;
height:100px;
text-align:center;
overflow:visible;
}
.days #today{
font-weight: bold;
color: red;
}
.eventBar {
height:18px;
background-color:#069;
margin: 10px 0 0 2px;
position: absolute;
color:#fff;
text-align:left;
}
</style>
<script>
function buildCal(m, y, cM, cH, cDW, cD, brdr){
var mn = ['January','February','March','April','May','June','July','August','September','October','November','December'];
var dim = [31,0,31,30,31,30,31,31,30,31,30,31];
// calculate the offset from Sunday at the beginning of the month
var oD = new Date(y, m-1, 1); //DD replaced line to fix date bug when current day is 31st
oD.od = oD.getDay()+1; //DD replaced line to fix date bug when current day is 31st
var todaydate = new Date(); //DD added
var scanfortoday = (y == todaydate.getFullYear() && m == (todaydate.getMonth() + 1))? todaydate.getDate() : 0; //DD added
// check for leap year, set February number of days (28 or 29)
dim[1] = (((oD.getFullYear() % 100 !== 0) && (oD.getFullYear() % 4 === 0)) || (oD.getFullYear() % 400 === 0)) ? 29 : 28;
var t = '<div class="' + cM +'" >';
t += '<div class="' + cH + '">' + mn[m - 1] + ' - ' + y + '</div>'; // month and year header
for(w = 0; w < 5; w++) { //creates 35 repeating day names, 21 / 3 = 7, 7 x 5 = 35 total
for(s = 0; s < 21; s += 3) t += '<div class="' + cDW + '">' + "SunMonTueWedThuFriSat".substr(s,3) + '</div>';
}
t += '<div class="' + cDW + '">Sun</div><div class="' + cDW + '">Mon</div>'; //add two more day names to make 37 total
t += '<div style="clear:both"></div>'; //clear the float:left
//collect events for this month
var currentEvents = [], start, end, span;
for(e = 0; e < events.length; e++) {
var dStr = events[e].start.split(' ');
var da = dStr[0].split('-');
var ti = dStr[1].split(':');
start = new Date(parseInt(da[0],10),parseInt((da[1])-1,10),parseInt(da[2],10),parseInt(ti[0],10),parseInt(ti[1],10),parseInt(ti[2],10));
dStr = events[e].end.split(' ');
da = dStr[0].split('-');
ti = dStr[1].split(':');
end = new Date(parseInt(da[0],10),parseInt((da[1])-1,10),parseInt(da[2],10),parseInt(ti[0],10),parseInt(ti[1],10),parseInt(ti[2],10));
if((start.getMonth() + 1) == m && start.getFullYear() == y) {
span = Math.round((end.valueOf() - start.valueOf()) / (24 * 60 * 60 * 1000));
span = (events[e].allDay === "1" || events[e].allDay === "true") ? span : span + 1;
// add additional information to the array
events[e].span = span; //span of the event in days
events[e].day = start.getDate(); //date of the event
events[e].offset = oD.od - 1; //month start offset
events[e].startDate = start; //start date object
events[e].endDate = end; //end date object
events[e].used = false; //needed later for sorting
events[e].top = 0; //needed later for positioning
currentEvents.push(events[e]);
}
}
var sortedDates = [];
for (var key in currentEvents) {
sortedDates.push(currentEvents[key].startDate); //copy the startDates into a simple array
}
sortedDates.sort(date_sort_asc); //sort the start dates
var sortedEvents = currentEvents;
for (se = 0; se < sortedDates.length; se++) {
for (ce = 0; ce < sortedDates.length; ce++) { //match up the unsorted with the sorted startDates.
if(currentEvents[ce].startDate === sortedDates[se] && (!currentEvents[ce].used)) {
sortedEvents[ce].sortKey = se; // add a sort key to the sorted array of events
currentEvents[ce].used = true; //2 events may have exactly the same time stamp, "true" will prevent the same event from being added twice
}
}
}
//look for overlapping events
var monthDays = daysInMonth(m, y);//number of days in the current month
var overlaps = [];
for (de = 0; de < sortedEvents.length; de++) {
var id = sortedEvents[de].id;
var sDate = sortedEvents[de].startDate.getDate();
var sYear = sortedEvents[de].startDate.getFullYear();
var sd = sDate + '-' + sYear; //combine date-year
var sd1, span1 = sortedEvents[de].span;
for (re = 0; re < span1; re++) { //events can span days. Event days other than the start day can overlap another event's days
for (ee = 0; ee < sortedEvents.length; ee++) {
sd1 = sortedEvents[ee].startDate.getDate() + '-' + sortedEvents[de].startDate.getFullYear();//combine date-year
if (sd === sd1 && (sortedEvents[ee].id !== id)) overlaps.push(id + ',' + sortedEvents[ee].id);//compare
}
sDate = ((sDate + 1) > monthDays) ? 1 : sDate + 1;//advance date for multi-day events
sd = sDate + '-' + sYear;
}
}
var unique = overlaps.filter(onlyUnique); //save only unique overlaps
var unique1 = [];
//unique array may still include duplicate reverse order overlaps like "2,7" and "7,2"
//this loop eliminates reverse order duplicates
for (ge = 0; ge < unique.length; ge++) {
if (ge === 0) unique1.push(unique[ge]); //add the first item to unique1
for (he = 0; he < unique1.length; he++) {
var a = unique[ge].split(',');//split so we can reverse the order and compare
if ((a[1] + ',' + a[0]) === unique1[he] ||unique[ge] === unique1[he]) {
break; //break if both the forward or reverse of the pair exists in unique1...
} else { //...otherwise add unique[ge] to unique1
unique1.push(unique[ge]);
break;
}
}
}
//only unique pairs of overlaps remain in unique1 array
//now adjust the "top" property so later we can use it to stack events one above the other on calendar days
for (te = 0; te < unique1.length; te++) {
var ids = unique1[te].split(','), sortkeyA, sortKeyB;
for (be = 0; be < sortedEvents.length; be++) {
if (sortedEvents[be].id === ids[0]) sortkeyA = ids[0] + ',' + sortedEvents[be].sortKey;
if (sortedEvents[be].id === ids[1]) sortkeyB = ids[1] + ',' + sortedEvents[be].sortKey;
}
var sortA = sortkeyA.split(',');
var sortB = sortkeyB.split(',');
var first = (sortA[1] > sortB[1]) ? sortA[0] : sortB[0];
for (we = 0; we < sortedEvents.length; we++) {
if (sortedEvents[we].id === first) {
sortedEvents[we].top = sortedEvents[we].top + 1;
}
}
}
var daysPrevMonth = ((m - 1) === 0) ? dim[dim.length-1] : dim[m-2];//previous month number of days
for(i = 1; i <= 37; i++){ // create 37 boxes for days of the month
var x = '';
if ((i - oD.od) < 0) { //print out previous month's days
x = '<span style="color:#ccc">' + (daysPrevMonth + (i - (oD.od-1))) + '</span>';
} else if (((i - oD.od) >= 0) && ((i - oD.od) < dim[m-1])) { //print out this month's days
x = (i - oD.od) + 1;
} else { //print out next month's days
x = '<span style="color:#ccc">' + (i - (dim[m-1] + (oD.od-1))) + '</span>';
}
if (x == scanfortoday) {// find today
x = '<span id="today">' + x + '</span>'; // highlight today
}
for(me = 0; me < sortedEvents.length; me++) {
if ((sortedEvents[me].day + sortedEvents[me].offset) == i) { // add in the current events
x += '<div class="eventBar" style="margin-top:' + (sortedEvents[me].top * 20) + 'px;width:' + (((sortedEvents[me].span * 49) - 4) + sortedEvents[me].span) + 'px">' + sortedEvents[me].title + ', ' + sortedEvents[me].span + ' day event</div>';
}
}
t += '<div class="' + cD + '">' + x + '</div>';
}
return t += '</div>';
}
//date sorting function
var date_sort_asc = function (date1, date2) {
if (date1 > date2) return 1;
if (date1 < date2) return -1;
return 0;
};
//returns days in a given month and year
function daysInMonth(month,year) {
return new Date(year, month, 0).getDate();
}
//eliminates duplicates from an array
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
</script>
</head>
<body>
<button id="prev" onMouseUp="changeMonth(false)"> << </button>
<button id="next" onMouseUp="changeMonth(true)"> >> </button>
<div id="cal"></div>
<script>
var events = [
{"id":"1","title":"11-29-2013","start":"2013-11-29 10:25:28","end":"2013-11-30 10:25:34","url":"","allDay":"1"},
{"id":"2","title":"12-15-2013","start":"2013-12-15 10:25:47","end":"2013-12-16 10:25:39","url":"","allDay":"1"},
{"id":"3","title":"12-26-2013","start":"2013-12-26 10:25:50","end":"2013-12-27 10:25:42","url":"","allDay":"false"},
{"id":"4","title":"11-19-2013","start":"2013-11-19 00:00:00","end":"2013-11-23 00:00:00","url":"","allDay":"false"},
{"id":"5","title":"12-9-2013","start":"2013-12-09 00:00:00","end":"2013-12-11 00:00:00","url":"event","allDay":"false"},
{"id":"6","title":"12-8-2013","start":"2013-12-08 00:00:00","end":"2013-12-10 00:00:00","url":"event","allDay":"false"},
{"id":"7","title":"12-15-2013","start":"2013-12-15 10:25:47","end":"2013-12-18 10:25:39","url":"","allDay":"1"},
{"id":"8","title":"12-10-2013","start":"2013-12-10 10:25:47","end":"2013-12-12 10:26:39","url":"","allDay":"1"}
];
var todaydate = new Date();
var curmonth = todaydate.getMonth() + 1; //get current month (1-12)
var curyear = todaydate.getFullYear(); //get current year
var selectedmonth = curmonth;
var selectedyear = curyear;
document.getElementById('cal').innerHTML = buildCal(curmonth ,curyear, "main", "month", "daysofweek", "days", 1);
function changeMonth(direction) {
if (direction) {
selectedyear = ((selectedmonth+1) > 12) ? selectedyear+1 : selectedyear;
selectedmonth = ((selectedmonth+1) > 12) ? 1 : selectedmonth+1;
} else {
selectedyear = ((selectedmonth-1) == 0) ? selectedyear-1 : selectedyear;
selectedmonth = ((selectedmonth-1) == 0) ? 12 : selectedmonth-1;
}
document.getElementById('cal').innerHTML = buildCal(selectedmonth ,selectedyear, "main", "month", "daysofweek", "days", 1);
}
</script>
</body>
</html>