forked from sebastianknopf/jQuery-Calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.calendar.min.js
8 lines (8 loc) · 3.42 KB
/
jquery.calendar.min.js
1
2
3
4
5
6
7
8
/*
* jQuery-Calendar Plugin v1.1.0
*
* 2018 (c) Sebastian Knopf
* This software is licensed under the MIT license!
* View LICENSE.md for more information
*/
!function(p){function l(e,t,n,a){var r=currentCalendar.find(".header-label").text().trim().split(" "),d=parseInt(r[1],10);currentMonth=n||(e?r[0]===t.months[t.months.length-1]?0:t.months.indexOf(r[0])+1:r[0]===t.months[0]?11:t.months.indexOf(r[0])-1),currentYear=a||(e&&0===currentMonth?d+1:e||11!==currentMonth?d:d-1);var o=function(e,t,n){var a=1,r=!0,d=new Date(t,e,a).getDay()-1,o=[31,t%4==0&&t%100!=0||t%400==0?29:28,31,30,31,30,31,31,30,31,30,31],c=[],l=0;for(;r;){c[l]=[];for(var s=0;s<7;s++)0==l?s==d&&(c[l][s]=a++,d++):a<=o[e]?c[l][s]=a++:(c[l][s]="",r=!1),o[e]<a&&(r=!1);l++}for(var u=p("<table>").addClass("current"),i=p("<tbody>").appendTo(u),h=0;h<c.length;h++){var f=p("<tr>").appendTo(i);p.each(c[h],function(e,t){var n=p("<td>").appendTo(f);n.text(t)})}p("td:empty",u).addClass("disabled"),currentMonth===(new Date).getMonth()&&p("td",u).filter(function(){return p(this).text()===(new Date).getDate().toString()}).addClass("today");return{frame:function(){return u.clone()},label:n.months[e]+" "+t}}(currentMonth,currentYear,t),c=o.frame();currentCalendar.find(".calendar-frame").empty().append(c),currentCalendar.find(".header-label").text(o.label),c.on("click","td",function(){p("td").removeClass("selected"),p(this).addClass("selected"),currentDay=p(this).text(),s(t.onSelect)})}function s(e){var t=new Date(currentYear,currentMonth,currentDay),n=[];n[0]=t.getDate()<10?"0"+t.getDate():t.getDate(),n[1]=t.getMonth()+1<10?"0"+(t.getMonth()+1):t.getMonth()+1,n[2]=t.getFullYear(),null!=e&&e({date:t,label:n.join(".")})}function u(e,t){var n=parseInt(e.slice(1),16),a=Math.round(2.55*t),r=(n>>16)+a,d=(n>>8&255)+a,o=(255&n)+a;return"#"+(16777216+65536*(r<255?r<1?0:r:255)+256*(d<255?d<1?0:d:255)+(o<255?o<1?0:o:255)).toString(16).slice(1)}p.fn.calendar=function(e){var t=p.extend({color:"#308B22",months:["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],days:["Mo","Di","Mi","Do","Fr","Sa","So"],onSelect:function(e){}},p.fn.calendar.defaults,e);return this.each(function(){!function(e,t){var n=t.color;e.addClass("calendar").empty();var a=p("<header>").appendTo(e);a.addClass("calendar-header"),a.css({background:n,color:function(e){e.length<5&&(e+=e.slice(1));return 16777215<e.replace("#","0x")?"#222":"#fff"}(n)});var r=p("<span>").appendTo(a);r.addClass("button").addClass("left"),r.html(" ⟨ "),r.bind("click",function(){currentCalendar=p(this).parents(".calendar"),l(!1,t)}),r.bind("mouseover",function(){p(this).css("background",u(n,-20))}),r.bind("mouseout",function(){p(this).css("background",n)});var d=p("<span>").appendTo(a);d.addClass("header-label"),d.html(" Month Year "),d.bind("click",function(){currentCalendar=p(this).parents(".calendar"),l(null,t,(new Date).getMonth(),(new Date).getFullYear()),currentDay=(new Date).getDate(),s(t.onSelect)});var o=p("<span>").appendTo(a);o.addClass("button").addClass("right"),o.html(" ⟩ "),o.bind("click",function(){currentCalendar=p(this).parents(".calendar"),l(!0,t)}),o.bind("mouseover",function(){p(this).css("background",u(n,-20))}),o.bind("mouseout",function(){p(this).css("background",n)});var c=p("<table>").appendTo(e);c.append("<thead><th>"+t.days.join("</th><th>")+"</th></thead>"),c.css({width:"100%"}),p("<div>").appendTo(e).addClass("calendar-frame"),d.click()}(p(this),t)})}}(jQuery);