Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

datepickr

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datepickr - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

4

CHANGELOG.md

@@ -0,1 +1,5 @@

### v1.4.1
- [bug] Fix for Safari https://github.com/tristen/datepickr/pull/11
### v1.4.0

@@ -2,0 +6,0 @@

386

dist/datepickr.js

@@ -1,385 +0,1 @@

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Datepickr=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"/Users/tristen/dev/github/datepickr/index.js":[function(require,module,exports){
;(function(global) {
Date.prototype.getPickrDate = function(opts) { return (opts && opts.utc) ? this.getUTCDate() : this.getDate(); };
Date.prototype.getPickrFullYear = function(opts) { return (opts && opts.utc) ? this.getUTCFullYear() : this.getFullYear(); };
Date.prototype.getPickrMonth = function(opts) { return (opts && opts.utc) ? this.getUTCMonth() : this.getMonth(); };
Date.prototype.getPickrDay = function(opts) { return (opts && opts.utc) ? this.getUTCDay() : this.getDay(); };
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(opts) { return currentDate.getPickrFullYear(opts); },
month: function(opts) { return currentDate.getPickrMonth(opts); },
day: function(opts) { return currentDate.getPickrDate(opts); }
},
month: {
string: function(month, months) {
var date = month;
return monthToStr(date, months);
},
numDays: function(month, year) {
// Check to see if february is a leap year.
// Otherwise, return the respective # of days.
return (month === 1 && !(year & 3) &&
(year % 1e2 || !(year % 4e2))) ?
29 : daysInMonth[month];
}
}
};
function calendarClick(e) {
var time = new Date(this.year, this.month).getTime();
switch (e.target.getAttribute('data-target')) {
case 'month-prev':
if (this.config.minDate && time <= this.config.minDate) return;
this.month--;
if (this.month < 0) {
this.year--;
this.month = 11;
}
rebuildCalendar.call(this);
break;
case 'month-next':
if (this.config.maxDate && time >= this.config.maxDate) return;
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, 0.5]);
}
} else {
if (c.contains('active')) {
c.remove('active', 'halfday');
this.config.activeDays = this.config.activeDays.filter(function(date) {
return date[0] !== d;
});
} else {
if ( this.config.singleSelection ) {
var daylinks = this.element.querySelectorAll('a');
Object.keys(daylinks).forEach(function (akey) {
daylinks[akey].classList.remove('active', 'halfday');
});
this.config.activeDays = [[d, 1]];
} else {
this.config.activeDays.push([d, 1]);
}
c.add('active');
}
}
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.getPickrFullYear(this.config), d.getPickrMonth(this.config), d.getPickrDate(this.config));
}
function isToday(year, month, day) {
return day === date.current.day(this.config) &&
month === date.current.month(this.config) &&
year === date.current.year(this.config);
}
function isPast(year, month, day) {
return new Date(year, month, day).getTime() < new Date().getTime();
}
function isFuture(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).getPickrDay(this.config);
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).getPickrDay(this.config),
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;
// Print out previous month's 'days'
for (i = 1; i <= firstOfMonth; i++) {
row.appendChild(buildNode('td'));
dayCount++;
}
for (i = 1; i <= numDays; i++) {
omit = false;
// If we have reached the end of a week,
// wrap to the next line.
if (dayCount === 7) {
calendarBody.appendChild(row);
row = buildNode('tr');
dayCount = 0;
}
if (isToday.call(this, year, month, i)) {
if (this.config.omitWeekends && isWeekend.call(this, year, month, i)) {
klass = 'today quiet';
omit = true;
} else {
klass = 'today';
}
} else if (this.config.omitPast && isPast(year, month, i) ||
this.config.omitFuture && isFuture(year, month, i) ||
this.config.omitWeekends && isWeekend.call(this, 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';
}
var self = this;
// If any dates were passed set day as active.
if (this.config.activeDays.length) {
this.config.activeDays.forEach(function(d) {
if (roundDate.call(self, 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++;
}
// If we haven't finished at the end of the week,
// start writing out the 'days' for the next month.
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).getPickrDay(this.config);
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, opts) {
var datepickr = {};
this.element = el;
this.callback = cb;
this.config = {
utc: false,
weekdays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat'],
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
minDate: null,
maxDate: null,
halfDay: false,
omitPast: false,
omitFuture: false,
omitWeekends: false,
omitDays: [],
activeDays: [],
singleSelection: false
};
this.config.startYear = date.current.year(this.config);
this.config.startMonth = date.current.month(this.config);
if (opts) {
for (var key in opts) {
if (this.config.hasOwnProperty(key)) {
this.config[key] = opts[key];
}
}
}
var self = this;
// Normalize any active days by rounding them.
if (this.config.activeDays.length) {
this.config.activeDays = this.config.activeDays.map(function(d) {
return [roundDate.call(self, new Date(d[0])).getTime(), d[1]];
});
}
// Normalize any omitted days by rounding them.
if (this.config.omitDays.length) {
this.config.omitDays = this.config.omitDays.map(function(d) {
return roundDate.call(self, new Date(d)).getTime();
});
}
datepickr.options = function(opts) {
if (opts) {
for (var key in opts) {
if (this.config.hasOwnProperty(key)) {
this.config[key] = opts[key];
}
}
}
}.bind(this);
this.year = this.config.startYear;
this.month = this.config.startMonth;
buildCalendar.call(this);
return datepickr;
};
})();
global.Datepickr = Datepickr;
if (typeof module !== 'undefined' && module.exports) module.exports = Datepickr;
})(this);
},{}]},{},["/Users/tristen/dev/github/datepickr/index.js"])("/Users/tristen/dev/github/datepickr/index.js")
});
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.Datepickr=t()}}(function(){return function t(e,i,n){function a(o,s){if(!i[o]){if(!e[o]){var c="function"==typeof require&&require;if(!s&&c)return c(o,!0);if(r)return r(o,!0);var h=new Error("Cannot find module '"+o+"'");throw h.code="MODULE_NOT_FOUND",h}var f=i[o]={exports:{}};e[o][0].call(f.exports,function(t){var i=e[o][1][t];return a(i?i:t)},f,f.exports,t,e,i,n)}return i[o].exports}for(var r="function"==typeof require&&require,o=0;o<n.length;o++)a(n[o]);return a}({1:[function(t,e,i){!function(t){Date.prototype.getPickrDate=function(t){return t&&t.utc?this.getUTCDate():this.getDate()},Date.prototype.getPickrFullYear=function(t){return t&&t.utc?this.getUTCFullYear():this.getFullYear()},Date.prototype.getPickrMonth=function(t){return t&&t.utc?this.getUTCMonth():this.getMonth()},Date.prototype.getPickrDay=function(t){return t&&t.utc?this.getUTCDay():this.getDay()};var i=function(){function t(t){var e=new Date(this.year,this.month).getTime();switch(t.target.getAttribute("data-target")){case"month-prev":if(this.config.minDate&&e<=this.config.minDate)return;this.month--,this.month<0&&(this.year--,this.month=11),f.call(this);break;case"month-next":if(this.config.maxDate&&e>=this.config.maxDate)return;this.month++,this.month>11&&(this.year++,this.month=0),f.call(this);break;case"day":var i=new Date(this.year,this.month,t.target.textContent).getTime(),n=t.target.classList;if(this.config.halfDay)n.contains("halfday")?(n.remove("halfday"),this.config.activeDays=this.config.activeDays.map(function(t){return t[0]===i&&(t[1]=1),t})):n.contains("active")?(n.remove("active","halfday"),this.config.activeDays=this.config.activeDays.filter(function(t){return t[0]!==i})):(n.add("active","halfday"),this.config.activeDays.push([i,.5]));else if(n.contains("active"))n.remove("active","halfday"),this.config.activeDays=this.config.activeDays.filter(function(t){return t[0]!==i});else{if(this.config.singleSelection){for(var a=this.element.querySelectorAll("a"),r=0;r<a.length;r++)a[r].classList.remove("active","halfday");this.config.activeDays=[[i,1]]}else this.config.activeDays.push([i,1]);n.add("active")}this.config.activeDays.sort(function(t,e){return t[0]-e[0]}),this.callback(this.config.activeDays)}}function e(t,e,i){t in p||(p[t]=document.createElement(t));var n=p[t].cloneNode(!1);if(e)for(var a in e)n.setAttribute(a,e[a]);return i&&("object"==typeof i?n.appendChild(i):n.textContent=i),n}function i(t,e){return e[t]}function n(t){return new Date(t.getPickrFullYear(this.config),t.getPickrMonth(this.config),t.getPickrDate(this.config))}function a(t,e,i){return i===D.current.day(this.config)&&e===D.current.month(this.config)&&t===D.current.year(this.config)}function r(t,e,i){return new Date(t,e,i).getTime()<(new Date).getTime()}function o(t,e,i){return new Date(t,e,i).getTime()>(new Date).getTime()}function s(t,e,i){var n=new Date(t,e,i).getPickrDay(this.config);return 0===n||6===n}function c(t,e,i){var n,a=new Date(t,e,i).getTime();return this.config.omitDays.length&&this.config.omitDays.forEach(function(t){t===a&&(n=!0)}),n}function h(t){var i=document.createDocumentFragment();return t.forEach(function(t){i.appendChild(e("th",{},t))}),i}function f(){for(;this.calendarBody.hasChildNodes();)this.calendarBody.removeChild(this.calendarBody.lastChild);var t=new Date(this.year,this.month,1).getPickrDay(this.config),e=D.month.numDays(this.month,this.year);this.currentMonth.textContent=D.month.string(this.month,this.config.months)+" "+this.year,this.calendarBody.appendChild(g.call(this,t,e,this.month,this.year))}function u(t,i,n,a){return e("strong",{"class":"small"},D.month.string(i,a)+" "+n)}function l(){var t=e("div",{"class":"months"}),i=e("a",{"class":"icon next button short quiet","data-target":"month-next",href:"#"}),n=e("a",{"class":"icon prev button short quiet","data-target":"month-prev",href:"#"});return t.appendChild(i),t.appendChild(n),t}function g(t,i,h,f){var u,l,g,d=document.createDocumentFragment(),y=e("tr"),m=0;for(g=1;t>=g;g++)y.appendChild(e("td")),m++;for(g=1;i>=g;g++){l=!1,7===m&&(d.appendChild(y),y=e("tr"),m=0),a.call(this,f,h,g)?this.config.omitWeekends&&s.call(this,f,h,g)?(u="today quiet",l=!0):u="today":this.config.omitPast&&r(f,h,g)||this.config.omitFuture&&o(f,h,g)||this.config.omitWeekends&&s.call(this,f,h,g)||this.config.omitDays&&this.config.omitDays.length&&c.call(this,f,h,g)?(u="fill-light quiet",l=!0):u="fill-light";var p=this;this.config.activeDays.length&&this.config.activeDays.forEach(function(t){n.call(p,new Date(t[0])).getTime()===new Date(f,h,g).getTime()&&(u+=1===t[1]?" active":" halfday active")}),y.appendChild(e("td",{},e("a",{"class":u,"data-target":l?!1:"day",href:"#"},g))),m++}for(g=1;7-m>=g;g++)y.appendChild(e("td"));return d.appendChild(y),d}function d(){var i=new Date(this.config.startYear,this.config.startMonth,1).getPickrDay(this.config),n=D.month.numDays(this.month,this.year),a=e("div",{"class":"date-pickr"});this.currentMonth=u(this.config,this.month,this.year,this.config.months);var r=l(this.config,this.month,this.year);r.appendChild(this.currentMonth);var o=e("table",{"class":"small"},e("thead",{},e("tr",{"class":"weekdays"},h(this.config.weekdays))));return this.calendarBody=e("tbody"),this.calendarBody.appendChild(g.call(this,i,n,this.month,this.year)),o.appendChild(this.calendarBody),a.appendChild(r),a.appendChild(o),this.element.appendChild(a),a.addEventListener("click",function(e){e.preventDefault(),t.call(this,e)}.bind(this)),a}var y=new Date,m=[31,28,31,30,31,30,31,31,30,31,30,31],p=[],D={current:{year:function(t){return y.getPickrFullYear(t)},month:function(t){return y.getPickrMonth(t)},day:function(t){return y.getPickrDate(t)}},month:{string:function(t,e){var n=t;return i(n,e)},numDays:function(t,e){return 1!==t||3&e||!(e%100)&&e%400?m[t]:29}}};return function(t,e,i){var a={};if(this.element=t,this.callback=e,this.config={utc:!1,weekdays:["Sun","Mon","Tue","Wed","Thur","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],minDate:null,maxDate:null,halfDay:!1,omitPast:!1,omitFuture:!1,omitWeekends:!1,omitDays:[],activeDays:[],singleSelection:!1},this.config.startYear=D.current.year(this.config),this.config.startMonth=D.current.month(this.config),i)for(var r in i)this.config.hasOwnProperty(r)&&(this.config[r]=i[r]);var o=this;return this.config.activeDays.length&&(this.config.activeDays=this.config.activeDays.map(function(t){return[n.call(o,new Date(t[0])).getTime(),t[1]]})),this.config.omitDays.length&&(this.config.omitDays=this.config.omitDays.map(function(t){return n.call(o,new Date(t)).getTime()})),a.options=function(t){if(t)for(var e in t)this.config.hasOwnProperty(e)&&(this.config[e]=t[e])}.bind(this),this.year=this.config.startYear,this.month=this.config.startMonth,d.call(this),a}}();t.Datepickr=i,"undefined"!=typeof e&&e.exports&&(e.exports=i)}(this)},{}]},{},[1])(1)});

@@ -14,5 +14,11 @@ ;(function(global) {

current: {
year: function(opts) { return currentDate.getPickrFullYear(opts); },
month: function(opts) { return currentDate.getPickrMonth(opts); },
day: function(opts) { return currentDate.getPickrDate(opts); }
year: function(opts) {
return currentDate.getPickrFullYear(opts);
},
month: function(opts) {
return currentDate.getPickrMonth(opts);
},
day: function(opts) {
return currentDate.getPickrDate(opts);
}
},

@@ -56,3 +62,2 @@ month: {

case 'day':
var today = new Date().getTime();
var d = new Date(this.year, this.month, e.target.textContent).getTime();

@@ -84,9 +89,9 @@ var c = e.target.classList;

if ( this.config.singleSelection ) {
var daylinks = this.element.querySelectorAll('a');
Object.keys(daylinks).forEach(function (akey) {
daylinks[akey].classList.remove('active', 'halfday');
});
this.config.activeDays = [[d, 1]];
var daylinks = this.element.querySelectorAll('a');
for (var i = 0; i < daylinks.length; i++) {
daylinks[i].classList.remove('active', 'halfday');
}
this.config.activeDays = [[d, 1]];
} else {
this.config.activeDays.push([d, 1]);
this.config.activeDays.push([d, 1]);
}

@@ -120,3 +125,3 @@ c.add('active');

if (content) {
if (typeof(content) === 'object') {
if (typeof content === 'object') {
element.appendChild(content);

@@ -195,3 +200,3 @@ } else {

function buildMonths(config, month, year) {
function buildMonths() {
var months = buildNode('div', {

@@ -198,0 +203,0 @@ 'class': 'months'

{
"name": "datepickr",
"version": "1.4.0",
"version": "1.4.1",
"description": "A do it yourself Date picker.",

@@ -8,2 +8,3 @@ "main": "index.js",

"start": "watchify index.js -s Datepickr -o dist/datepickr.js & serve",
"build": "browserify index.js -s Datepickr | uglifyjs -c -m > dist/datepickr.js",
"test": "echo \"Error: no test specified\" && exit 1"

@@ -27,4 +28,7 @@ },

"devDependencies": {
"uglify-js": "^2.4.15"
"browserify": "^13.0.0",
"serve": "^1.4.0",
"uglify-js": "^2.6.1",
"watchify": "^3.7.0"
}
}

@@ -84,4 +84,12 @@ Datepickr

### Developing
npm install && npm start
### Building
npm run build
### Credits
Code originally based off of [datepickr](https://code.google.com/p/datepickr/).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc