Comparing version 1.0.0 to 1.0.1
@@ -328,3 +328,3 @@ ;(function(global) { | ||
if (this.config.activeDays.length) { | ||
this.config.activeDays.map(function(d) { | ||
this.config.activeDays = this.config.activeDays.map(function(d) { | ||
return [roundDate(new Date(d[0])).getTime(), d[1]]; | ||
@@ -336,3 +336,3 @@ }); | ||
if (this.config.omitDays.length) { | ||
this.config.omitDays.map(function(d) { | ||
this.config.omitDays = this.config.omitDays.map(function(d) { | ||
return [roundDate(new Date(d[0])).getTime(), d[1]]; | ||
@@ -339,0 +339,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
(function(global){var Datepickr=function(){var currentDate=new Date;var daysInMonth=[31,28,31,30,31,30,31,31,30,31,30,31];var buildCache=[];var date={current:{year:function(){return currentDate.getFullYear()},month:{integer:function(){return currentDate.getMonth()},string:function(months){var date=currentDate.getMonth();return monthToStr(date,months)}},day:function(){return currentDate.getDate()}},month:{string:function(month,months){var date=month;return monthToStr(date,months)},numDays:function(month,year){return month===1&&!(year&3)&&(year%100||!(year%400))?29:daysInMonth[month]}}};function calendarClick(e){switch(e.target.getAttribute("data-target")){case"month-prev":this.month--;if(this.month<0){this.year--;this.month=11}rebuildCalendar.call(this);break;case"month-next":this.month++;if(this.month>11){this.year++;this.month=0}rebuildCalendar.call(this);break;case"day":var today=(new Date).getTime();var d=new Date(this.year,this.month,e.target.textContent).getTime();var c=e.target.classList;if(this.config.halfDay){if(c.contains("halfday")){c.remove("halfday");this.config.activeDays=this.config.activeDays.map(function(date){if(date[0]===d)date[1]=1;return date})}else if(c.contains("active")){c.remove("active","halfday");this.config.activeDays=this.config.activeDays.filter(function(date){return date[0]!==d})}else{c.add("active","halfday");this.config.activeDays.push([d,.5])}}else{if(c.contains("active")){c.remove("active","halfday");this.config.activeDays=this.config.activeDays.filter(function(date){return date[0]!==d})}else{c.add("active");this.config.activeDays.push([d,1])}}this.config.activeDays.sort(function(a,b){return a[0]>b[0]});this.callback(this.config.activeDays);break}}function buildNode(nodeName,attributes,content){if(!(nodeName in buildCache)){buildCache[nodeName]=document.createElement(nodeName)}var element=buildCache[nodeName].cloneNode(false);if(attributes){for(var attribute in attributes){element.setAttribute(attribute,attributes[attribute])}}if(content){if(typeof content==="object"){element.appendChild(content)}else{element.textContent=content}}return element}function monthToStr(date,months){return months[date]}function roundDate(d){return new Date(d.getFullYear(),d.getMonth(),d.getDate())}function isToday(year,month,day){return day===date.current.day()&&month===date.current.month.integer()&&year===date.current.year()}function isPast(year,month,day){return new Date(year,month,day).getTime()<(new Date).getTime()}function isWeekend(year,month,day){var d=new Date(year,month,day).getDay();return d===0||d===6}function isOmitted(year,month,day){var d=new Date(year,month,day).getTime(),is;if(this.config.omitDays.length){this.config.omitDays.forEach(function(omitted){if(omitted===d)is=true})}return is}function buildWeekdays(weekdays){var weekdayHtml=document.createDocumentFragment();weekdays.forEach(function(weekday){weekdayHtml.appendChild(buildNode("th",{},weekday))});return weekdayHtml}function rebuildCalendar(){while(this.calendarBody.hasChildNodes()){this.calendarBody.removeChild(this.calendarBody.lastChild)}var firstOfMonth=new Date(this.year,this.month,1).getDay(),numDays=date.month.numDays(this.month,this.year);this.currentMonth.textContent=date.month.string(this.month,this.config.months)+" "+this.year;this.calendarBody.appendChild(buildDays.call(this,firstOfMonth,numDays,this.month,this.year))}function buildCurrentMonth(config,month,year,months){return buildNode("strong",{"class":"small"},date.month.string(month,months)+" "+year)}function buildMonths(config,month,year){var months=buildNode("div",{"class":"months"});var prevMonth=buildNode("a",{"class":"icon next button short quiet","data-target":"month-next",href:"#"});var nextMonth=buildNode("a",{"class":"icon prev button short quiet","data-target":"month-prev",href:"#"});months.appendChild(prevMonth);months.appendChild(nextMonth);return months}function buildDays(firstOfMonth,numDays,month,year){var calendarBody=document.createDocumentFragment(),row=buildNode("tr"),dayCount=0,klass,omit,i;for(i=1;i<=firstOfMonth;i++){row.appendChild(buildNode("td"));dayCount++}for(i=1;i<=numDays;i++){omit=false;if(dayCount===7){calendarBody.appendChild(row);row=buildNode("tr");dayCount=0}if(isToday(year,month,i)){if(this.config.omitWeekends&&isWeekend(year,month,i)){klass="today quiet";omit=true}else{klass="today"}}else if(this.config.omitPast&&isPast(year,month,i)||this.config.omitWeekends&&isWeekend(year,month,i)||this.config.omitDays&&this.config.omitDays.length&&isOmitted.call(this,year,month,i)){klass="fill-light quiet";omit=true}else{klass="fill-light"}if(this.config.activeDays.length){this.config.activeDays.forEach(function(d){if(roundDate(new Date(d[0])).getTime()===new Date(year,month,i).getTime()){klass+=d[1]===1?" active":" halfday active"}})}row.appendChild(buildNode("td",{},buildNode("a",{"class":klass,"data-target":!omit?"day":false,href:"#"},i)));dayCount++}for(i=1;i<=7-dayCount;i++){row.appendChild(buildNode("td"))}calendarBody.appendChild(row);return calendarBody}function buildCalendar(){var firstOfMonth=new Date(this.config.startYear,this.config.startMonth,1).getDay();var numDays=date.month.numDays(this.month,this.year);var calendarDiv=buildNode("div",{"class":"date-pickr"});this.currentMonth=buildCurrentMonth(this.config,this.month,this.year,this.config.months);var months=buildMonths(this.config,this.month,this.year);months.appendChild(this.currentMonth);var calendar=buildNode("table",{"class":"small"},buildNode("thead",{},buildNode("tr",{"class":"weekdays"},buildWeekdays(this.config.weekdays))));this.calendarBody=buildNode("tbody");this.calendarBody.appendChild(buildDays.call(this,firstOfMonth,numDays,this.month,this.year));calendar.appendChild(this.calendarBody);calendarDiv.appendChild(months);calendarDiv.appendChild(calendar);this.element.appendChild(calendarDiv);calendarDiv.addEventListener("click",function(e){e.preventDefault();calendarClick.call(this,e)}.bind(this));return calendarDiv}return function(el,cb,options){this.element=el;this.callback=cb;this.config={weekdays:["Sun","Mon","Tue","Wed","Thur","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],startYear:date.current.year(),startMonth:date.current.month.integer(),halfDay:false,omitPast:false,omitWeekends:false,omitDays:[],activeDays:[]};if(options){for(var key in options){if(this.config.hasOwnProperty(key)){this.config[key]=options[key]}}}if(this.config.activeDays.length){this.config.activeDays.map(function(d){return[roundDate(new Date(d[0])).getTime(),d[1]]})}if(this.config.omitDays.length){this.config.omitDays.map(function(d){return[roundDate(new Date(d[0])).getTime(),d[1]]})}this.year=this.config.startYear;this.month=this.config.startMonth;buildCalendar.call(this)}}();global.Datepickr=Datepickr;if(typeof module!=="undefined"&&module.exports)module.exports=Datepickr})(this); | ||
(function(global){var Datepickr=function(){var currentDate=new Date;var daysInMonth=[31,28,31,30,31,30,31,31,30,31,30,31];var buildCache=[];var date={current:{year:function(){return currentDate.getFullYear()},month:{integer:function(){return currentDate.getMonth()},string:function(months){var date=currentDate.getMonth();return monthToStr(date,months)}},day:function(){return currentDate.getDate()}},month:{string:function(month,months){var date=month;return monthToStr(date,months)},numDays:function(month,year){return month===1&&!(year&3)&&(year%100||!(year%400))?29:daysInMonth[month]}}};function calendarClick(e){switch(e.target.getAttribute("data-target")){case"month-prev":this.month--;if(this.month<0){this.year--;this.month=11}rebuildCalendar.call(this);break;case"month-next":this.month++;if(this.month>11){this.year++;this.month=0}rebuildCalendar.call(this);break;case"day":var today=(new Date).getTime();var d=new Date(this.year,this.month,e.target.textContent).getTime();var c=e.target.classList;if(this.config.halfDay){if(c.contains("halfday")){c.remove("halfday");this.config.activeDays=this.config.activeDays.map(function(date){if(date[0]===d)date[1]=1;return date})}else if(c.contains("active")){c.remove("active","halfday");this.config.activeDays=this.config.activeDays.filter(function(date){return date[0]!==d})}else{c.add("active","halfday");this.config.activeDays.push([d,.5])}}else{if(c.contains("active")){c.remove("active","halfday");this.config.activeDays=this.config.activeDays.filter(function(date){return date[0]!==d})}else{c.add("active");this.config.activeDays.push([d,1])}}this.config.activeDays.sort(function(a,b){return a[0]>b[0]});this.callback(this.config.activeDays);break}}function buildNode(nodeName,attributes,content){if(!(nodeName in buildCache)){buildCache[nodeName]=document.createElement(nodeName)}var element=buildCache[nodeName].cloneNode(false);if(attributes){for(var attribute in attributes){element.setAttribute(attribute,attributes[attribute])}}if(content){if(typeof content==="object"){element.appendChild(content)}else{element.textContent=content}}return element}function monthToStr(date,months){return months[date]}function roundDate(d){return new Date(d.getFullYear(),d.getMonth(),d.getDate())}function isToday(year,month,day){return day===date.current.day()&&month===date.current.month.integer()&&year===date.current.year()}function isPast(year,month,day){return new Date(year,month,day).getTime()<(new Date).getTime()}function isWeekend(year,month,day){var d=new Date(year,month,day).getDay();return d===0||d===6}function isOmitted(year,month,day){var d=new Date(year,month,day).getTime(),is;if(this.config.omitDays.length){this.config.omitDays.forEach(function(omitted){if(omitted===d)is=true})}return is}function buildWeekdays(weekdays){var weekdayHtml=document.createDocumentFragment();weekdays.forEach(function(weekday){weekdayHtml.appendChild(buildNode("th",{},weekday))});return weekdayHtml}function rebuildCalendar(){while(this.calendarBody.hasChildNodes()){this.calendarBody.removeChild(this.calendarBody.lastChild)}var firstOfMonth=new Date(this.year,this.month,1).getDay(),numDays=date.month.numDays(this.month,this.year);this.currentMonth.textContent=date.month.string(this.month,this.config.months)+" "+this.year;this.calendarBody.appendChild(buildDays.call(this,firstOfMonth,numDays,this.month,this.year))}function buildCurrentMonth(config,month,year,months){return buildNode("strong",{"class":"small"},date.month.string(month,months)+" "+year)}function buildMonths(config,month,year){var months=buildNode("div",{"class":"months"});var prevMonth=buildNode("a",{"class":"icon next button short quiet","data-target":"month-next",href:"#"});var nextMonth=buildNode("a",{"class":"icon prev button short quiet","data-target":"month-prev",href:"#"});months.appendChild(prevMonth);months.appendChild(nextMonth);return months}function buildDays(firstOfMonth,numDays,month,year){var calendarBody=document.createDocumentFragment(),row=buildNode("tr"),dayCount=0,klass,omit,i;for(i=1;i<=firstOfMonth;i++){row.appendChild(buildNode("td"));dayCount++}for(i=1;i<=numDays;i++){omit=false;if(dayCount===7){calendarBody.appendChild(row);row=buildNode("tr");dayCount=0}if(isToday(year,month,i)){if(this.config.omitWeekends&&isWeekend(year,month,i)){klass="today quiet";omit=true}else{klass="today"}}else if(this.config.omitPast&&isPast(year,month,i)||this.config.omitWeekends&&isWeekend(year,month,i)||this.config.omitDays&&this.config.omitDays.length&&isOmitted.call(this,year,month,i)){klass="fill-light quiet";omit=true}else{klass="fill-light"}if(this.config.activeDays.length){this.config.activeDays.forEach(function(d){if(roundDate(new Date(d[0])).getTime()===new Date(year,month,i).getTime()){klass+=d[1]===1?" active":" halfday active"}})}row.appendChild(buildNode("td",{},buildNode("a",{"class":klass,"data-target":!omit?"day":false,href:"#"},i)));dayCount++}for(i=1;i<=7-dayCount;i++){row.appendChild(buildNode("td"))}calendarBody.appendChild(row);return calendarBody}function buildCalendar(){var firstOfMonth=new Date(this.config.startYear,this.config.startMonth,1).getDay();var numDays=date.month.numDays(this.month,this.year);var calendarDiv=buildNode("div",{"class":"date-pickr"});this.currentMonth=buildCurrentMonth(this.config,this.month,this.year,this.config.months);var months=buildMonths(this.config,this.month,this.year);months.appendChild(this.currentMonth);var calendar=buildNode("table",{"class":"small"},buildNode("thead",{},buildNode("tr",{"class":"weekdays"},buildWeekdays(this.config.weekdays))));this.calendarBody=buildNode("tbody");this.calendarBody.appendChild(buildDays.call(this,firstOfMonth,numDays,this.month,this.year));calendar.appendChild(this.calendarBody);calendarDiv.appendChild(months);calendarDiv.appendChild(calendar);this.element.appendChild(calendarDiv);calendarDiv.addEventListener("click",function(e){e.preventDefault();calendarClick.call(this,e)}.bind(this));return calendarDiv}return function(el,cb,options){this.element=el;this.callback=cb;this.config={weekdays:["Sun","Mon","Tue","Wed","Thur","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],startYear:date.current.year(),startMonth:date.current.month.integer(),halfDay:false,omitPast:false,omitWeekends:false,omitDays:[],activeDays:[]};if(options){for(var key in options){if(this.config.hasOwnProperty(key)){this.config[key]=options[key]}}}if(this.config.activeDays.length){this.config.activeDays=this.config.activeDays.map(function(d){return[roundDate(new Date(d[0])).getTime(),d[1]]})}if(this.config.omitDays.length){this.config.omitDays=this.config.omitDays.map(function(d){return[roundDate(new Date(d[0])).getTime(),d[1]]})}this.year=this.config.startYear;this.month=this.config.startMonth;buildCalendar.call(this)}}();global.Datepickr=Datepickr;if(typeof module!=="undefined"&&module.exports)module.exports=Datepickr})(this); |
@@ -328,3 +328,3 @@ ;(function(global) { | ||
if (this.config.activeDays.length) { | ||
this.config.activeDays.map(function(d) { | ||
this.config.activeDays = this.config.activeDays.map(function(d) { | ||
return [roundDate(new Date(d[0])).getTime(), d[1]]; | ||
@@ -336,3 +336,3 @@ }); | ||
if (this.config.omitDays.length) { | ||
this.config.omitDays.map(function(d) { | ||
this.config.omitDays = this.config.omitDays.map(function(d) { | ||
return [roundDate(new Date(d[0])).getTime(), d[1]]; | ||
@@ -339,0 +339,0 @@ }); |
{ | ||
"name": "datepickr", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A do it yourself Date picker.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,3 @@ Datepickr - The do it yourself date picker. | ||
Datepickr is just a date picker. It makes as no assumptions how it's shown on | ||
the page. [__See demo__](http://tristen.ca/datepickr/). | ||
the page. [__See demo__](http://tristen.ca/datepickr/demo/). | ||
@@ -56,3 +56,3 @@ - Need to show/hide it on an input field? __Do it yourself__. | ||
To see examples of each option [see the demos](http://tristen.ca/datepickr/). | ||
To see examples of each option [see the demos](http://tristen.ca/datepickr/demo/). | ||
@@ -59,0 +59,0 @@ ### Use with node or browserify via `npm install datepickr`. |
Sorry, the diff of this file is not supported yet
107145
2197