Skip to content

Commit 3bc3f76

Browse files
authored
Merge branch 'master' into patch-2
2 parents 5123f39 + 56c50a4 commit 3bc3f76

File tree

8 files changed

+1877
-28
lines changed

8 files changed

+1877
-28
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [2.2.0] - 2018-04-08
2+
3+
### Changed
4+
- Refer to `event.path` instead of `element.contains(event.target)` for more reliable containment check (fixes #23), kudos to @jonobr1
5+
16
## [2.1.0] - 2016-11-24
27

38
### Changed
@@ -17,7 +22,7 @@ Reworked for Vue 2.0
1722

1823
## [1.1.5] - 2016-09-30
1924

20-
Skipped 1.1.4 due to publising mistake
25+
Skipped 1.1.4 due to publishing mistake
2126

2227
### Changed
2328
- Exposed version

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
> Reusable clickaway directive for reusable [Vue.js](https://github.com/vuejs/vue) components
44
55
[![npm version](https://img.shields.io/npm/v/vue-clickaway.svg)](https://www.npmjs.com/package/vue-clickaway)
6+
[![CDNJS](https://img.shields.io/cdnjs/v/vue-clickaway.svg)](https://cdnjs.com/libraries/vue-clickaway)
67

78
## Overview
89

910
Sometimes you need to detect clicks **outside** of the element (to close a modal
1011
window or hide a dropdown select). There is no native event for that, and Vue.js
1112
does not cover you either. This is why `vue-clickaway` exists. Please check out
12-
the [demo](https://jsfiddle.net/simplesmiler/4w1cs8u3/) before reading further.
13+
the [demo](https://jsfiddle.net/simplesmiler/4w1cs8u3/150/) before reading further.
1314

1415
## Requirements
1516

@@ -25,18 +26,10 @@ From npm:
2526
$ npm install vue-clickaway --save
2627
```
2728

28-
From CDN:
29+
From CDN (minified):
2930
``` html
30-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue-clickaway.js"></script>
31-
<!-- OR -->
32-
<script src="https://cdn.rawgit.com/simplesmiler/vue-clickaway/2.1.0/dist/vue-clickaway.js"></script>
33-
```
34-
35-
For minified version include one of these
36-
```html
37-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue-clickaway.min.js"></script>
38-
<!-- OR -->
39-
<script src="https://cdn.rawgit.com/simplesmiler/vue-clickaway/2.1.0/dist/vue-clickaway.min.js"></script>
31+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue-clickaway.min.js"></script>
32+
<script src="https://cdn.rawgit.com/simplesmiler/vue-clickaway/2.2.0/dist/vue-clickaway.min.js"></script>
4033
```
4134

4235
## Usage
@@ -84,7 +77,14 @@ export default {
8477
1. Pay attention to the letter case. `onClickaway` turns into `v-on-clickaway`,
8578
while `onClickAway` turns into `v-on-click-away`.
8679
2. Prior to `vue@^2.0`, directive were able to accept statements.
87-
This is no longer the case.
80+
This is no longer the case. If you need to pass arguments, just do
81+
`v-on-clickaway="() => away(arg1)"`.
82+
3. There is a common issue with dropdowns (and modals) inside an element with
83+
`v-on-clickaway`. Some UI libraries chose to implement these UI elements
84+
by attaching the DOM element directly to the body. This makes clicks on
85+
a dropped element trigger away handler. To combat that, you have to add
86+
an extra check in the handler, for where the event originated from.
87+
See #9 for an example.
8888

8989
## License
9090

dist/vue-clickaway.common.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var Vue = require('vue');
44
Vue = 'default' in Vue ? Vue['default'] : Vue;
55

6-
var version = '2.1.0';
6+
var version = '2.2.0';
77

88
var compatible = (/^2\./).test(Vue.version);
99
if (!compatible) {
@@ -44,9 +44,11 @@ function bind(el, binding) {
4444
}, 0);
4545

4646
el[HANDLER] = function(ev) {
47-
// @NOTE: IE 5.0+
48-
// @REFERENCE: https://developer.mozilla.org/en/docs/Web/API/Node/contains
49-
if (initialMacrotaskEnded && !el.contains(ev.target)) {
47+
// @NOTE: this test used to be `el.containts`, but `ev.path` is better,
48+
// because it tests whether the element was there at the time of
49+
// the click, not whether it is there now, that the event has arrived
50+
// to the top.
51+
if (initialMacrotaskEnded && ev.path.indexOf(el) < 0) {
5052
return callback(ev);
5153
}
5254
};

dist/vue-clickaway.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Vue = 'default' in Vue ? Vue['default'] : Vue;
44

5-
var version = '2.1.0';
5+
var version = '2.2.0';
66

77
var compatible = (/^2\./).test(Vue.version);
88
if (!compatible) {
@@ -43,9 +43,11 @@
4343
}, 0);
4444

4545
el[HANDLER] = function(ev) {
46-
// @NOTE: IE 5.0+
47-
// @REFERENCE: https://developer.mozilla.org/en/docs/Web/API/Node/contains
48-
if (initialMacrotaskEnded && !el.contains(ev.target)) {
46+
// @NOTE: this test used to be `el.containts`, but `ev.path` is better,
47+
// because it tests whether the element was there at the time of
48+
// the click, not whether it is there now, that the event has arrived
49+
// to the top.
50+
if (initialMacrotaskEnded && ev.path.indexOf(el) < 0) {
4951
return callback(ev);
5052
}
5153
};

dist/vue-clickaway.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.

index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Vue from 'vue';
22

3-
export var version = '2.1.0';
3+
export var version = '2.2.0';
44

55
var compatible = (/^2\./).test(Vue.version);
66
if (!compatible) {
@@ -41,9 +41,11 @@ function bind(el, binding) {
4141
}, 0);
4242

4343
el[HANDLER] = function(ev) {
44-
// @NOTE: IE 5.0+
45-
// @REFERENCE: https://developer.mozilla.org/en/docs/Web/API/Node/contains
46-
if (initialMacrotaskEnded && !el.contains(ev.target)) {
44+
// @NOTE: this test used to be `el.containts`, but `ev.path` is better,
45+
// because it tests whether the element was there at the time of
46+
// the click, not whether it is there now, that the event has arrived
47+
// to the top.
48+
if (initialMacrotaskEnded && ev.path.indexOf(el) < 0) {
4749
return callback(ev);
4850
}
4951
};

0 commit comments

Comments
 (0)