Skip to content
This repository has been archived by the owner on Aug 20, 2022. It is now read-only.

Commit

Permalink
build: release 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyuanchen committed Dec 15, 2018
1 parent b1f5d60 commit bc2e58a
Show file tree
Hide file tree
Showing 14 changed files with 3,088 additions and 5,376 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## next
## 1.0.2 (Dec 15, 2018)

- Convert 2-digit year to 2000+ (#186).

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Datepicker

[![Build Status](https://travis-ci.org/fengyuanchen/datepicker.svg)](https://travis-ci.org/fengyuanchen/datepicker) [![Downloads](https://img.shields.io/npm/dm/@chenfengyuan/datepicker.svg)](https://www.npmjs.com/package/@chenfengyuan/datepicker) [![Version](https://img.shields.io/npm/v/@chenfengyuan/datepicker.svg)](https://www.npmjs.com/package/@chenfengyuan/datepicker)
[![Build Status](https://img.shields.io/travis/fengyuanchen/datepicker.svg)](https://travis-ci.org/fengyuanchen/datepicker) [![Downloads](https://img.shields.io/npm/dm/@chenfengyuan/datepicker.svg)](https://www.npmjs.com/package/@chenfengyuan/datepicker) [![Version](https://img.shields.io/npm/v/@chenfengyuan/datepicker.svg)](https://www.npmjs.com/package/@chenfengyuan/datepicker)

> A simple jQuery datepicker plugin.
- [Website](https://fengyuanchen.github.io/datepicker)
- [Website](https://fengyuanchen.github.io/datepicker/)

## Table of contents

Expand Down
96 changes: 67 additions & 29 deletions dist/datepicker.common.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*!
* Datepicker v1.0.1
* Datepicker v1.0.2
* https://fengyuanchen.github.io/datepicker
*
* Copyright 2014-present Chen Fengyuan
* Released under the MIT license
*
* Date: 2018-11-14T13:59:48.051Z
* Date: 2018-12-15T03:52:10.525Z
*/

'use strict';
Expand Down Expand Up @@ -137,7 +137,7 @@ function isUndefined(value) {
return typeof value === 'undefined';
}
function isDate(value) {
return typeOf(value) === 'date';
return typeOf(value) === 'date' && !isNaN(value.getTime());
}
function proxy(fn, context) {
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
Expand Down Expand Up @@ -216,6 +216,30 @@ function getScrollParent(element) {
}).eq(0);
return position === 'fixed' || !scrollParent.length ? $(element.ownerDocument || document) : scrollParent;
}
/**
* Add leading zeroes to the given value
* @param {number} value - The value to add.
* @param {number} [length=1] - The expected value length.
* @returns {string} Returns converted value.
*/

function addLeadingZero(value) {
var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var str = String(Math.abs(value));
var i = str.length;
var result = '';

if (value < 0) {
result += '-';
}

while (i < length) {
i += 1;
result += '0';
}

return result + str;
}

var REGEXP_DIGITS = /\d+/g;
var methods = {
Expand Down Expand Up @@ -468,41 +492,42 @@ var methods = {
parts = date.match(REGEXP_DIGITS) || [];
}

date = new Date();
var length = format.parts.length;
var year = date.getFullYear();
var day = date.getDate();
var month = date.getMonth();
var parsedDate = date ? new Date(date) : new Date();

if (!isDate(parsedDate)) {
parsedDate = new Date();
}

if (parts.length === length) {
if (parts.length === format.parts.length) {
$.each(parts, function (i, part) {
var value = parseInt(part, 10);

switch (format.parts[i]) {
case 'dd':
case 'd':
day = value;
parsedDate.setDate(value);
break;

case 'mm':
case 'm':
month = value - 1;
parsedDate.setMonth(value - 1);
break;

case 'yy':
year = 2000 + value;
parsedDate.setFullYear(2000 + value);
break;

case 'yyyy':
year = value;
// Converts 2-digit year to 2000+
parsedDate.setFullYear(part.length === 2 ? 2000 + value : value);
break;

default:
}
});
}

return new Date(year, month, day);
return parsedDate;
},

/**
Expand All @@ -517,14 +542,16 @@ var methods = {

if (isDate(date)) {
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();
var values = {
d: date.getDate(),
m: date.getMonth() + 1,
yy: year.toString().substring(2),
yyyy: year
d: day,
dd: addLeadingZero(day, 2),
m: month + 1,
mm: addLeadingZero(month + 1, 2),
yy: String(year).substring(2),
yyyy: addLeadingZero(year, 4)
};
values.dd = (values.d < 10 ? '0' : '') + values.d;
values.mm = (values.m < 10 ? '0' : '') + values.m;
formatted = format.source;
$.each(format.parts, function (i, part) {
formatted = formatted.replace(part, values[part]);
Expand All @@ -545,6 +572,7 @@ var handlers = {
click: function click(e) {
var $target = $(e.target);
var options = this.options,
date = this.date,
viewDate = this.viewDate,
format = this.format;
e.stopPropagation();
Expand All @@ -564,15 +592,17 @@ var handlers = {
case 'years next':
{
viewYear = view === 'years prev' ? viewYear - 10 : viewYear + 10;
this.viewDate = new Date(viewYear, viewMonth, getMinDay(viewYear, viewMonth, viewDay));
viewDate.setFullYear(viewYear);
viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));
this.renderYears();
break;
}

case 'year prev':
case 'year next':
viewYear = view === 'year prev' ? viewYear - 1 : viewYear + 1;
this.viewDate = new Date(viewYear, viewMonth, getMinDay(viewYear, viewMonth, viewDay));
viewDate.setFullYear(viewYear);
viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));
this.renderMonths();
break;

Expand All @@ -596,10 +626,12 @@ var handlers = {

case 'year':
viewYear = parseInt($target.text(), 10);
this.date = new Date(viewYear, viewMonth, getMinDay(viewYear, viewMonth, viewDay));
date.setFullYear(viewYear);
date.setDate(getMinDay(viewYear, viewMonth, viewDay));
viewDate.setFullYear(viewYear);
viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));

if (format.hasMonth) {
this.viewDate = new Date(this.date);
this.showView(VIEWS.MONTHS);
} else {
$target.addClass(options.pickedClass).siblings().removeClass(options.pickedClass);
Expand All @@ -622,7 +654,9 @@ var handlers = {
viewMonth -= 12;
}

this.viewDate = new Date(viewYear, viewMonth, getMinDay(viewYear, viewMonth, viewDay));
viewDate.setFullYear(viewYear);
viewDate.setMonth(viewMonth);
viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));
this.renderDays();
break;

Expand All @@ -646,10 +680,12 @@ var handlers = {

case 'month':
viewMonth = $.inArray($target.text(), options.monthsShort);
this.date = new Date(viewYear, viewMonth, getMinDay(viewYear, viewMonth, viewDay));
date.setMonth(viewMonth);
date.setDate(getMinDay(viewYear, viewMonth, viewDay));
viewDate.setMonth(viewMonth);
viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));

if (format.hasDay) {
this.viewDate = new Date(viewYear, viewMonth, getMinDay(viewYear, viewMonth, viewDay));
this.showView(VIEWS.DAYS);
} else {
$target.addClass(options.pickedClass).siblings().removeClass(options.pickedClass);
Expand All @@ -670,8 +706,10 @@ var handlers = {
}

viewDay = parseInt($target.text(), 10);
this.date = new Date(viewYear, viewMonth, viewDay);
this.viewDate = new Date(viewYear, viewMonth, viewDay);
date.setMonth(viewMonth);
date.setDate(viewDay);
viewDate.setMonth(viewMonth);
viewDate.setDate(viewDay);
this.renderDays();

if (view === 'day') {
Expand Down
8 changes: 4 additions & 4 deletions dist/datepicker.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*!
* Datepicker v1.0.1
* Datepicker v1.0.2
* https://fengyuanchen.github.io/datepicker
*
* Copyright 2014-present Chen Fengyuan
* Released under the MIT license
*
* Date: 2018-11-14T13:59:44.094Z
* Date: 2018-12-15T03:52:06.949Z
*/

.datepicker-container {
Expand All @@ -15,17 +15,17 @@
left: 0;
line-height: 30px;
position: fixed;
-webkit-tap-highlight-color: transparent;
top: 0;
-ms-touch-action: none;
touch-action: none;
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
width: 210px;
z-index: -1;
-webkit-tap-highlight-color: transparent;
-webkit-touch-callout: none;
}

.datepicker-container::before,
Expand Down
Loading

0 comments on commit bc2e58a

Please sign in to comment.