Skip to content

Commit

Permalink
Next (flatpickr#881)
Browse files Browse the repository at this point in the history
* documentClick - dont preventDefault()

* v3

* Expose util methods for plugins

* Create ignoredFocusElements option to circumvent documentClick

* open() - allow specifying positionElement()

* updateValue() - enforce triggerChange opt when updating value

* Create rangePlugin
resolves flatpickr#584

* v3

* build

* rangePlugin - ensure clear() works

* Create onDestroy() hook for plugins

* rangePlugin - handle destroy()

* build

* rangePlugin - force-set allowInput

* Move rangePlugin to a file vs folder

* mv rangePlugin

* rangePlugin - fix defaultDate behavior
resolves flatpickr#872

* build

* build

* rangePlugin - focus on corresponding date on open

* build

* Add .npmignore

* Slightly decrease day size
flatpickr#874

* v3.0.1

* build

* fix failing timestamp test due to timezone

* Add check for onDestroy()

* build

* update .npmignore

* v3.0.2

* Update license

* Add eslintrc

* cleanup spec

* eslint-plugin-jest

* 3.0.3

* v3.0.3

* build
  • Loading branch information
chmln authored Jun 10, 2017
1 parent 8f49e61 commit 6683f08
Show file tree
Hide file tree
Showing 25 changed files with 508 additions and 259 deletions.
71 changes: 71 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"rules": {
"brace-style": [
"error",
"stroustrup"
],
"space-in-parens": 1,
"max-len": [
"error",
95,
{
"ignoreRegExpLiterals": true,
"ignoreComments": true,
"ignoreStrings": true
}
],
"no-extra-bind": 2,
"no-eq-null": 1,
"no-unreachable": 2,
"comma-dangle": [
"error",
"only-multiline"
],
"quotes": [
"error",
"double"
],
"space-infix-ops": "warn",
"no-prototype-builtins": "warn",
"no-invalid-regexp": 1,
"no-duplicate-case": 2,
"no-redeclare": 2,
"no-constant-condition": 2,
"no-undef": "warn",
"no-extra-semi": 2,
"no-dupe-keys": 2,
"indent": [
"error",
"tab",
{
"SwitchCase": 1
}
],
"no-caller": 2,
"curly": [
"warn",
"multi-or-nest"
],
"no-global-assign": "warn",
"no-extra-boolean-cast": 1,
"no-ex-assign": 2,
"no-unused-expressions": "warn",
"no-mixed-spaces-and-tabs": 2,
"no-unsafe-negation": "warn",
"valid-typeof": 2,
"no-sparse-arrays": 2,
"no-fallthrough": 2
},
"parser": "babel-eslint",
"env": {
"jquery": true,
"es6": true,
"commonjs": true,
"browser": true,
"jest": true
},
"plugins": [
"flowtype",
"jest"
]
}
74 changes: 0 additions & 74 deletions .eslintrc.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .flowconfig

This file was deleted.

6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!LICENSE.md
!dist
!dist/**/*
!src
!src/**/*
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016
Copyright (c) 2017 Gregory Petrosyan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 9 additions & 9 deletions dist/flatpickr.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
line-height: 24px;
border-radius: 5px;
position: absolute;
width: 315px;
width: 307.875px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
-ms-touch-action: manipulation;
Expand Down Expand Up @@ -360,7 +360,7 @@
background: transparent;
text-align: center;
overflow: hidden;
width: 315px;
width: 307.875px;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
Expand Down Expand Up @@ -397,7 +397,7 @@ span.flatpickr-weekday {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 315px;
width: 307.875px;
}
.flatpickr-days:focus {
outline: 0;
Expand All @@ -406,9 +406,9 @@ span.flatpickr-weekday {
padding: 0;
outline: 0;
text-align: left;
width: 315px;
min-width: 315px;
max-width: 315px;
width: 307.875px;
min-width: 307.875px;
max-width: 307.875px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
display: inline-block;
Expand Down Expand Up @@ -462,9 +462,9 @@ span.flatpickr-weekday {
-webkit-flex-basis: 14.2857143%;
-ms-flex-preferred-size: 14.2857143%;
flex-basis: 14.2857143%;
max-width: 40px;
height: 40px;
line-height: 40px;
max-width: 39px;
height: 39px;
line-height: 39px;
margin: 0;
display: inline-block;
position: relative;
Expand Down
35 changes: 23 additions & 12 deletions dist/flatpickr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

/*! flatpickr v2.6.3, @license MIT */
/*! flatpickr v3.0.3, @license MIT */
function FlatpickrInstance(element, config) {
var self = this;

self._ = {};
self._.afterDayAnim = afterDayAnim;
self._bind = bind;
self._compareDates = compareDates;
self._setHoursFromDate = setHoursFromDate;
self.changeMonth = changeMonth;
self.changeYear = changeYear;
self.clear = clear;
Expand Down Expand Up @@ -843,6 +846,8 @@ function FlatpickrInstance(element, config) {
}

function destroy() {
if (self.config !== undefined) triggerEvent("Destroy");

for (var i = self._handlers.length; i--;) {
var h = self._handlers[i];
h.element.removeEventListener(h.event, h.handler);
Expand Down Expand Up @@ -888,8 +893,7 @@ function FlatpickrInstance(element, config) {

var lostFocus = e.type === "blur" ? isInput && e.relatedTarget && !isCalendarElem(e.relatedTarget) : !isInput && !isCalendarElement;

if (lostFocus) {
e.preventDefault();
if (lostFocus && self.config.ignoredFocusElements.indexOf(e.target) === -1) {
self.close();

if (self.config.mode === "range" && self.selectedDates.length === 1) {
Expand Down Expand Up @@ -1092,7 +1096,7 @@ function FlatpickrInstance(element, config) {
if (self.isOpen && !self.config.static && !self.config.inline) positionCalendar();
}

function open(e) {
function open(e, positionElement) {
if (self.isMobile) {
if (e) {
e.preventDefault();
Expand All @@ -1111,7 +1115,7 @@ function FlatpickrInstance(element, config) {

self.isOpen = true;
self.calendarContainer.classList.add("open");
positionCalendar();
positionCalendar(positionElement);
self._input.classList.add("active");

triggerEvent("Open");
Expand Down Expand Up @@ -1149,7 +1153,7 @@ function FlatpickrInstance(element, config) {
function parseConfig() {
var boolOpts = ["wrap", "weekNumbers", "allowInput", "clickOpens", "time_24hr", "enableTime", "noCalendar", "altInput", "shorthandCurrentMonth", "inline", "static", "enableSeconds", "disableMobile"];

var hooks = ["onChange", "onClose", "onDayCreate", "onKeyDown", "onMonthChange", "onOpen", "onParseConfig", "onReady", "onValueUpdate", "onYearChange"];
var hooks = ["onChange", "onClose", "onDayCreate", "onDestroy", "onKeyDown", "onMonthChange", "onOpen", "onParseConfig", "onReady", "onValueUpdate", "onYearChange"];

self.config = Object.create(flatpickr.defaultConfig);

Expand Down Expand Up @@ -1213,16 +1217,18 @@ function FlatpickrInstance(element, config) {
}

function positionCalendar() {
var positionElement = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : self._positionElement;

if (self.calendarContainer === undefined) return;

var calendarHeight = self.calendarContainer.offsetHeight,
calendarWidth = self.calendarContainer.offsetWidth,
configPos = self.config.position,
inputBounds = self._positionElement.getBoundingClientRect(),
inputBounds = positionElement.getBoundingClientRect(),
distanceFromBottom = window.innerHeight - inputBounds.bottom,
showOnTop = configPos === "above" || configPos !== "below" && distanceFromBottom < calendarHeight && inputBounds.top > calendarHeight;

var top = window.pageYOffset + inputBounds.top + (!showOnTop ? self._positionElement.offsetHeight + 2 : -calendarHeight - 2);
var top = window.pageYOffset + inputBounds.top + (!showOnTop ? positionElement.offsetHeight + 2 : -calendarHeight - 2);

toggleClass(self.calendarContainer, "arrowTop", !showOnTop);
toggleClass(self.calendarContainer, "arrowBottom", showOnTop);
Expand Down Expand Up @@ -1376,7 +1382,7 @@ function FlatpickrInstance(element, config) {
}

function setDate(date, triggerChange, format) {
if (!date) return self.clear(triggerChange);
if (date !== 0 && !date) return self.clear(triggerChange);

setSelectedDate(date, format);

Expand Down Expand Up @@ -1630,7 +1636,8 @@ function FlatpickrInstance(element, config) {
return self.formatDate(dObj, self.config.altFormat);
}).join(joinChar);
}
triggerEvent("ValueUpdate");

if (triggerChange !== false) triggerEvent("ValueUpdate");
}

function mouseDelta(e) {
Expand Down Expand Up @@ -1999,7 +2006,7 @@ FlatpickrInstance.prototype = {
* @return {Date} the parsed Date object
*/
parseDate: function parseDate(date, givenFormat, timeless) {
if (!date) return null;
if (date !== 0 && !date) return null;

var date_orig = date;

Expand Down Expand Up @@ -2212,6 +2219,8 @@ flatpickr.defaultConfig = FlatpickrInstance.defaultConfig = {

plugins: [],

ignoredFocusElements: [],

// called every time calendar is closed
onClose: undefined, // function (dateObj, dateStr) {}

Expand Down Expand Up @@ -2239,7 +2248,9 @@ flatpickr.defaultConfig = FlatpickrInstance.defaultConfig = {
// called every time the year is changed
onYearChange: undefined,

onKeyDown: undefined
onKeyDown: undefined,

onDestroy: undefined
};

/* istanbul ignore next */
Expand Down
4 changes: 2 additions & 2 deletions dist/flatpickr.min.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/flatpickr.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ie.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ span.flatpickr-current-month {
}
span.flatpickr-day {
width: 14.2857143%;
margin: 0 2.5px;
margin: 0 2.491071428571428px;
}
Loading

0 comments on commit 6683f08

Please sign in to comment.