Skip to content

Commit a4180fa

Browse files
committed
v0.1.4
New directive : ClickOutside (removed dep v-click-outside)
1 parent 054e2f6 commit a4180fa

File tree

7 files changed

+312
-24
lines changed

7 files changed

+312
-24
lines changed

dist/vue-datepicker.esm.js

Lines changed: 114 additions & 5 deletions
Large diffs are not rendered by default.

dist/vue-datepicker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-datepicker.umd.js

Lines changed: 118 additions & 8 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@mathieustan/vue-datepicker",
33
"description": "A clean datepicker made with VueJs",
4-
"version": "0.1.3",
4+
"version": "0.1.4",
55
"author": "Mathieu Stanowski <[email protected]>",
66
"keywords": [
77
"vue",
@@ -45,8 +45,7 @@
4545
},
4646
"dependencies": {
4747
"body-scroll-lock": "^2.6.1",
48-
"dayjs": "^1.8.14",
49-
"v-click-outside": "^2.1.3"
48+
"dayjs": "^1.8.14"
5049
},
5150
"peerDependencies": {
5251
"core-js": "^2.6.5",

src/components/datepicker/DatePickerAgenda.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131

132132
<script>
133133
import { disableBodyScroll, enableBodyScroll, clearAllBodyScrollLocks } from 'body-scroll-lock';
134-
import { directive as clickOutside } from 'v-click-outside';
134+
import ClickOutside from '../../directives/click-outside';
135135
136136
import Dates, {
137137
getWeekDays,
@@ -156,7 +156,7 @@ import DatePickerYearMonth from './DatePickerYearMonth.vue';
156156
export default {
157157
name: 'DatepickerAgenda',
158158
mixins: [ detachable, dynamicPosition ],
159-
directives: { clickOutside },
159+
directives: { ClickOutside },
160160
components: { DatePickerHeader, DatePickerControls, DatePickerYearMonth },
161161
props: {
162162
name: { type: String },

src/directives/click-outside.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// https://github.com/simplesmiler/vue-clickaway
2+
// https://github.com/ndelvalle/v-click-outside/blob/master/lib/v-click-outside.js
3+
// Mixed both :)
4+
5+
const HAS_WINDOWS = typeof window !== 'undefined';
6+
const HAS_NAVIGATOR = typeof navigator !== 'undefined';
7+
const IS_TOUCH =
8+
HAS_WINDOWS && ('ontouchstart' in window || (HAS_NAVIGATOR && navigator.msMaxTouchPoints > 0));
9+
const EVENTS = IS_TOUCH ? ['touchstart', 'click'] : ['click'];
10+
11+
const instances = [];
12+
13+
const ClickOutside = {
14+
instances,
15+
bind: bind,
16+
update: (el, binding) => {
17+
if (binding.value === binding.oldValue) return;
18+
bind(el, binding);
19+
},
20+
unbind: unbind,
21+
};
22+
23+
function bind (el, { value }) {
24+
unbind(el);
25+
26+
const bindingValue = value;
27+
const isFunction = typeof bindingValue === 'function';
28+
const isObject = typeof bindingValue === 'object';
29+
30+
if (!isFunction && !isObject) return;
31+
32+
const isActive = !(bindingValue.isActive === false);
33+
if (!isActive) return;
34+
35+
const handler = isFunction ? bindingValue : bindingValue.handler;
36+
const instance = createInstance({ el, handler });
37+
38+
instance.eventHandlers.forEach(({ event, handler }) =>
39+
setTimeout(() => document.addEventListener(event, handler, false), 0),
40+
);
41+
instances.push(instance);
42+
}
43+
44+
function unbind (el) {
45+
const instanceIndex = instances.findIndex(instance => instance.el === el);
46+
if (instanceIndex === -1) return;
47+
48+
const instance = instances[instanceIndex];
49+
instance.eventHandlers.forEach(({ event, handler }) =>
50+
document.removeEventListener(event, handler, false),
51+
);
52+
instances.splice(instanceIndex, 1);
53+
}
54+
55+
// --------------------
56+
// Helpers
57+
// --------------------
58+
function createInstance ({ el, handler }) {
59+
return {
60+
el,
61+
eventHandlers: EVENTS.map(eventName => ({
62+
event: eventName,
63+
handler: event => onEvent({ event, el, handler }),
64+
})),
65+
};
66+
}
67+
68+
function onEvent ({ event, el, handler }) {
69+
const path = event.path || (event.composedPath ? event.composedPath() : undefined);
70+
if (path ? path.indexOf(el) < 0 : !el.contains(event.target)) {
71+
return handler(event, el);
72+
}
73+
};
74+
75+
export default ClickOutside;

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10081,11 +10081,6 @@ uuid@^3.0.1, uuid@^3.3.2:
1008110081
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
1008210082
integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==
1008310083

10084-
v-click-outside@^2.1.3:
10085-
version "2.1.3"
10086-
resolved "https://registry.yarnpkg.com/v-click-outside/-/v-click-outside-2.1.3.tgz#b7297abe833a439dc0895e6418a494381e64b5e7"
10087-
integrity sha512-8d11/fN+nkSPeor87K8OtGc/lDbRwbUiFwdzxQEGidlXt6eko3gIgRM7ghgi4p/zohF3Ja9hAaydAajV3gnlPQ==
10088-
1008910084
validate-npm-package-license@^3.0.1:
1009010085
version "3.0.4"
1009110086
resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a"

0 commit comments

Comments
 (0)