-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4e01f57
Showing
3 changed files
with
494 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
/** code by webdevtrick ( https://webdevtrick.com ) **/ | ||
var month = [ | ||
"January", | ||
"February", | ||
"March", | ||
"April", | ||
"May", | ||
"June", | ||
"July", | ||
"August", | ||
"September", | ||
"October", | ||
"November", | ||
"December", | ||
]; | ||
var weekday = [ | ||
"Sunday", | ||
"Monday", | ||
"Tuesday", | ||
"Wednesday", | ||
"Thursday", | ||
"Friday", | ||
"Saturday", | ||
]; | ||
var weekdayShort = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"]; | ||
var monthDirection = 0; | ||
|
||
function getNextMonth() { | ||
monthDirection++; | ||
var current; | ||
var now = new Date(); | ||
if (now.getMonth() == 11) { | ||
current = new Date(now.getFullYear() + monthDirection, 0, 1); | ||
} else { | ||
current = new Date(now.getFullYear(), now.getMonth() + monthDirection, 1); | ||
} | ||
initCalender(getMonth(current)); | ||
} | ||
|
||
function getPrevMonth() { | ||
monthDirection--; | ||
var current; | ||
var now = new Date(); | ||
if (now.getMonth() == 11) { | ||
current = new Date(now.getFullYear() + monthDirection, 0, 1); | ||
} else { | ||
current = new Date(now.getFullYear(), now.getMonth() + monthDirection, 1); | ||
} | ||
initCalender(getMonth(current)); | ||
} | ||
Date.prototype.isSameDateAs = function (pDate) { | ||
return ( | ||
this.getFullYear() === pDate.getFullYear() && | ||
this.getMonth() === pDate.getMonth() && | ||
this.getDate() === pDate.getDate() | ||
); | ||
}; | ||
|
||
function getMonth(currentDay) { | ||
var now = new Date(); | ||
var currentMonth = month[currentDay.getMonth()]; | ||
var monthArr = []; | ||
for (i = 1 - currentDay.getDate(); i < 31; i++) { | ||
var tomorrow = new Date(currentDay); | ||
tomorrow.setDate(currentDay.getDate() + i); | ||
if (currentMonth !== month[tomorrow.getMonth()]) { | ||
break; | ||
} else { | ||
monthArr.push({ | ||
date: { | ||
weekday: weekday[tomorrow.getDay()], | ||
weekday_short: weekdayShort[tomorrow.getDay()], | ||
day: tomorrow.getDate(), | ||
month: month[tomorrow.getMonth()], | ||
year: tomorrow.getFullYear(), | ||
current_day: now.isSameDateAs(tomorrow) ? true : false, | ||
date_info: tomorrow, | ||
}, | ||
}); | ||
} | ||
} | ||
return monthArr; | ||
} | ||
|
||
function clearCalender() { | ||
$("table tbody tr").each(function () { | ||
$(this) | ||
.find("td") | ||
.removeClass("active selectable currentDay between hover") | ||
.html(""); | ||
}); | ||
$("td").each(function () { | ||
$(this).unbind("mouseenter").unbind("mouseleave"); | ||
}); | ||
$("td").each(function () { | ||
$(this).unbind("click"); | ||
}); | ||
clickCounter = 0; | ||
} | ||
|
||
function initCalender(monthData) { | ||
var row = 0; | ||
var classToAdd = ""; | ||
var currentDay = ""; | ||
var today = new Date(); | ||
|
||
clearCalender(); | ||
$.each(monthData, function (i, value) { | ||
var weekday = value.date.weekday_short; | ||
var day = value.date.day; | ||
var column = 0; | ||
var index = i + 1; | ||
|
||
$(".sideb .header .month").html(value.date.month); | ||
$(".sideb .header .year").html(value.date.year); | ||
if (value.date.current_day) { | ||
currentDay = "currentDay"; | ||
classToAdd = "selectable"; | ||
$(".right-wrapper .header span").html(value.date.weekday); | ||
$(".right-wrapper .day").html(value.date.day); | ||
$(".right-wrapper .month").html(value.date.month); | ||
} | ||
if (today.getTime() < value.date.date_info.getTime()) { | ||
classToAdd = "selectable"; | ||
} | ||
$("tr.weedays th").each(function () { | ||
var row = $(this); | ||
if (row.data("weekday") === weekday) { | ||
column = row.data("column"); | ||
return; | ||
} | ||
}); | ||
$( | ||
$($($("tr.days").get(row)).find("td").get(column)) | ||
.addClass(classToAdd + " " + currentDay) | ||
.html(day) | ||
); | ||
currentDay = ""; | ||
if (column == 6) { | ||
row++; | ||
} | ||
}); | ||
$("td.selectable").click(function () { | ||
dateClickHandler($(this)); | ||
}); | ||
} | ||
initCalender(getMonth(new Date())); | ||
|
||
var clickCounter = 0; | ||
$(".fa-angle-double-right").click(function () { | ||
$(".right-wrapper").toggleClass("is-active"); | ||
$(this).toggleClass("is-active"); | ||
}); | ||
|
||
function dateClickHandler(elem) { | ||
var day1 = parseInt($(elem).html()); | ||
if (clickCounter === 0) { | ||
$("td.selectable").each(function () { | ||
$(this).removeClass("active between hover"); | ||
}); | ||
} | ||
clickCounter++; | ||
if (clickCounter === 2) { | ||
$("td.selectable").each(function () { | ||
$(this).unbind("mouseenter").unbind("mouseleave"); | ||
}); | ||
clickCounter = 0; | ||
return; | ||
} | ||
$(elem).toggleClass("active"); | ||
$("td.selectable").hover( | ||
function () { | ||
var day2 = parseInt($(this).html()); | ||
$(this).addClass("hover"); | ||
$("td.selectable").each(function () { | ||
$(this).removeClass("between"); | ||
}); | ||
if (day1 > day2 + 1) { | ||
$("td.selectable").each(function () { | ||
var dayBetween = parseInt($(this).html()); | ||
if (dayBetween > day2 && dayBetween < day1) { | ||
$(this).addClass("between"); | ||
} | ||
}); | ||
} else if (day1 < day2 + 1) { | ||
$("td.selectable").each(function () { | ||
var dayBetween = parseInt($(this).html()); | ||
if (dayBetween > day1 && dayBetween < day2) { | ||
$(this).addClass("between"); | ||
} | ||
}); | ||
} | ||
}, | ||
function () { | ||
$(this).removeClass("hover"); | ||
} | ||
); | ||
} | ||
$(".fa-angle-left").click(function () { | ||
getPrevMonth(); | ||
$(".main").addClass("is-rotated-left"); | ||
setTimeout(function () { | ||
$(".main").removeClass("is-rotated-left"); | ||
}, 195); | ||
}); | ||
|
||
$(".fa-angle-right").click(function () { | ||
getNextMonth(); | ||
$(".main").addClass("is-rotated-right"); | ||
setTimeout(function () { | ||
$(".main").removeClass("is-rotated-right"); | ||
}, 195); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<!DOCTYPE html> | ||
<!-- code by webdevtrick ( https://webdevtrick.com ) --> | ||
<html> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>HTML CSS JavaScript Calender | Webdevtrick.com</title> | ||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
|
||
<body> | ||
|
||
<div class="main"> | ||
<div class="sideb"> | ||
<div class="header"><i class="fa fa-angle-left" aria-hidden="true"></i><span><span class="month"> | ||
</span><span class="year"></span></span><i class="fa fa-angle-right" aria-hidden="true"></i></div> | ||
<div class="calender"> | ||
<table> | ||
<thead> | ||
<tr class="weedays"> | ||
<th data-weekday="sun" data-column="0">Sun</th> | ||
<th data-weekday="mon" data-column="1">Mon</th> | ||
<th data-weekday="tue" data-column="2">Tue</th> | ||
<th data-weekday="wed" data-column="3">Wed</th> | ||
<th data-weekday="thu" data-column="4">Thu</th> | ||
<th data-weekday="fri" data-column="5">Fri</th> | ||
<th data-weekday="sat" data-column="6">Sat</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr class="days" data-row="0"> | ||
<td data-column="0"></td> | ||
<td data-column="1"></td> | ||
<td data-column="2"></td> | ||
<td data-column="3"></td> | ||
<td data-column="4"></td> | ||
<td data-column="5"></td> | ||
<td data-column="6"></td> | ||
</tr> | ||
<tr class="days" data-row="1"> | ||
<td data-column="0"></td> | ||
<td data-column="1"></td> | ||
<td data-column="2"></td> | ||
<td data-column="3"></td> | ||
<td data-column="4"></td> | ||
<td data-column="5"></td> | ||
<td data-column="6"></td> | ||
</tr> | ||
<tr class="days" data-row="2"> | ||
<td data-column="0"></td> | ||
<td data-column="1"></td> | ||
<td data-column="2"></td> | ||
<td data-column="3"></td> | ||
<td data-column="4"></td> | ||
<td data-column="5"></td> | ||
<td data-column="6"></td> | ||
</tr> | ||
<tr class="days" data-row="3"> | ||
<td data-column="0"></td> | ||
<td data-column="1"></td> | ||
<td data-column="2"></td> | ||
<td data-column="3"></td> | ||
<td data-column="4"></td> | ||
<td data-column="5"></td> | ||
<td data-column="6"></td> | ||
</tr> | ||
<tr class="days" data-row="4"> | ||
<td data-column="0"></td> | ||
<td data-column="1"></td> | ||
<td data-column="2"></td> | ||
<td data-column="3"></td> | ||
<td data-column="4"></td> | ||
<td data-column="5"></td> | ||
<td data-column="6"></td> | ||
</tr> | ||
<tr class="days" data-row="5"> | ||
<td data-column="0"></td> | ||
<td data-column="1"></td> | ||
<td data-column="2"></td> | ||
<td data-column="3"></td> | ||
<td data-column="4"></td> | ||
<td data-column="5"></td> | ||
<td data-column="6"></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
<div class="showDate"><i class="fa fa-angle-double-right" aria-hidden="true"></i></div> | ||
</div> | ||
<div class="right-wrapper"> | ||
<div class="header"><span></span></div><span class="day"></span><span class="month"></span> | ||
</div> | ||
</div> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | ||
|
||
<script src="function.js"></script> | ||
|
||
</body> | ||
|
||
</html> |
Oops, something went wrong.