Skip to content

Commit a675d44

Browse files
committed
Release 2.0.0-rc.1
1 parent 3679c80 commit a675d44

7 files changed

+136
-138
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## [2.0.0-rc.1] - 2016-09-30
2+
3+
Reworked for Vue 2.0
4+
5+
### Breaking changes
6+
- `v-on-clickaway` used to be able to accept statements, like `v-on-clickaway="a = a + 1"` or `v-on-clickaway="doSomething(context)"`. This is no longer supported.
7+
18
## [1.1.5] - 2016-09-30
29

310
Skipped 1.1.4 due to publising mistake
@@ -64,3 +71,5 @@ Initial release
6471
[1.1.2]: https://github.com/simplesmiler/vue-clickaway/compare/1.1.1...1.1.2
6572
[1.1.3]: https://github.com/simplesmiler/vue-clickaway/compare/1.1.2...1.1.3
6673
[1.1.5]: https://github.com/simplesmiler/vue-clickaway/compare/1.1.3...1.1.5
74+
75+
[2.0.0]: https://github.com/simplesmiler/vue-clickaway/compare/1.1.5...2.0.0

README.md

+8-19
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
Sometimes you need to detect clicks **outside** of the element (to close a modal
1010
window or hide a dropdown select). There is no native event for that, and Vue.js
1111
does not cover you either. This is why `vue-clickaway` exists. Please check out
12-
the [demo](https://jsfiddle.net/simplesmiler/bbbh5bt6/) before reading further.
12+
the [demo](https://jsfiddle.net/simplesmiler/4w1cs8u3/) before reading further.
1313

1414
## Requirements
1515

16-
- vue: ^1.0.0
16+
- vue: ^2.0.0-rc.1
17+
18+
If you need a version for Vue 1, try `[email protected]`.
1719

1820
## Install
1921

@@ -26,9 +28,9 @@ $ npm install vue-clickaway --save
2628
From CDN:
2729

2830
``` html
29-
<script src="https://cdn.rawgit.com/simplesmiler/vue-clickaway/1.1.5/dist/vue-clickaway.js"></script>
31+
<script src="https://cdn.rawgit.com/simplesmiler/vue-clickaway/2.0.0-rc.1/dist/vue-clickaway.js"></script>
3032
<!-- OR -->
31-
<script src="https://cdn.rawgit.com/simplesmiler/vue-clickaway/1.1.5/dist/vue-clickaway.min.js"></script>
33+
<script src="https://cdn.rawgit.com/simplesmiler/vue-clickaway/2.0.0-rc.1/dist/vue-clickaway.min.js"></script>
3234
```
3335

3436
## Usage
@@ -71,25 +73,12 @@ export default {
7173
};
7274
```
7375

74-
## Notes
75-
76-
1. `require('vue-clickaway/mixin')` was the recommended syntax prior to `1.1.0`.
77-
Although this syntax is still supported, it is recommended to use `import`
78-
syntax for es6 and `require('vue-clickaway').mixin` for common-js.
79-
2. A version for `vue@^0.12.9` is not supported, but is availabale as
80-
81-
8276
## Caveats
8377

8478
1. Pay attention to the letter case. `onClickaway` turns into `v-on-clickaway`,
8579
while `onClickAway` turns into `v-on-click-away`.
86-
2. Prior to `[email protected]` views were able to inherit assets from the parent views,
87-
which made it possible to define the directive on the root view
88-
and have it available across the whole view hierarchy.
89-
Since `[email protected]` this is not possible. If you still want to define the directive
90-
application-wide, you should `Vue.directive('on-clickaway', onClickaway);`
91-
in your application entry point. But bear in mind that this introduces
92-
implicit dependency for your components, making them less reusable.
80+
2. Prior to `vue@^2.0`, directive were able to accept statements.
81+
This is no longer the case.
9382

9483
## License
9584

dist/vue-clickaway.common.js

+38-38
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,57 @@
33
var Vue = require('vue');
44
Vue = 'default' in Vue ? Vue['default'] : Vue;
55

6-
var version = '1.1.5';
6+
var version = '2.0.0-rc.1';
77

8-
var compatible = (/^1\./).test(Vue.version);
8+
var compatible = (/^2\./).test(Vue.version);
99
if (!compatible) {
10-
Vue.util.warn('VueClickaway ' + version + ' only supports Vue 1.x, and does not support Vue ' + Vue.version);
10+
Vue.util.warn('VueClickaway ' + version + ' only supports Vue 2.x, and does not support Vue ' + Vue.version);
1111
}
1212

13-
var directive = {
1413

15-
acceptStatement: true,
16-
priority: 700,
1714

18-
update: function(handler) {
19-
if (typeof handler !== 'function') {
20-
if (process.env.NODE_ENV !== 'production') {
21-
Vue.util.warn(
22-
this.name + '="' +
23-
this.expression + '" expects a function value, ' +
24-
'got ' + handler
25-
);
26-
}
27-
return;
28-
}
15+
// @SECTION: implementation
2916

30-
this.reset();
17+
var HANDLER = '_vue_clickaway_handler';
3118

32-
var el = this.el;
33-
var scope = this._scope || this.vm;
19+
function bind(el, binding) {
20+
unbind(el);
3421

35-
this.handler = function(ev) {
36-
// @NOTE: IE 5.0+
37-
// @REFERENCE: https://developer.mozilla.org/en/docs/Web/API/Node/contains
38-
if (!el.contains(ev.target)) {
39-
scope.$event = ev;
40-
var res = handler(ev);
41-
scope.$event = null;
42-
return res;
43-
}
44-
};
22+
var callback = binding.value;
23+
if (typeof callback !== 'function') {
24+
if (process.env.NODE_ENV !== 'production') {
25+
Vue.util.warn(
26+
'v-' + binding.name + '="' +
27+
binding.expression + '" expects a function value, ' +
28+
'got ' + callback
29+
);
30+
}
31+
return;
32+
}
4533

46-
Vue.util.on(document.documentElement, 'click', this.handler);
47-
},
34+
el[HANDLER] = function(ev) {
35+
// @NOTE: IE 5.0+
36+
// @REFERENCE: https://developer.mozilla.org/en/docs/Web/API/Node/contains
37+
if (!el.contains(ev.target)) {
38+
return callback(ev);
39+
}
40+
};
4841

49-
reset: function() {
50-
Vue.util.off(document.documentElement, 'click', this.handler);
51-
},
42+
document.documentElement.addEventListener('click', el[HANDLER], false);
43+
}
5244

53-
unbind: function() {
54-
this.reset();
55-
},
45+
function unbind(el) {
46+
document.documentElement.removeEventListener('click', el[HANDLER], false);
47+
delete el[HANDLER];
48+
}
5649

50+
var directive = {
51+
bind: bind,
52+
update: function(el, binding) {
53+
if (binding.value === binding.oldValue) return;
54+
bind(el, binding);
55+
},
56+
unbind: unbind,
5757
};
5858

5959
var mixin = {

dist/vue-clickaway.js

+39-39
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,57 @@
22

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

5-
var version = '1.1.5';
5+
var version = '2.0.0-rc.1';
66

7-
var compatible = (/^1\./).test(Vue.version);
7+
var compatible = (/^2\./).test(Vue.version);
88
if (!compatible) {
9-
Vue.util.warn('VueClickaway ' + version + ' only supports Vue 1.x, and does not support Vue ' + Vue.version);
9+
Vue.util.warn('VueClickaway ' + version + ' only supports Vue 2.x, and does not support Vue ' + Vue.version);
1010
}
1111

12-
var directive = {
1312

14-
acceptStatement: true,
15-
priority: 700,
16-
17-
update: function(handler) {
18-
if (typeof handler !== 'function') {
19-
if ('development' !== 'production') {
20-
Vue.util.warn(
21-
this.name + '="' +
22-
this.expression + '" expects a function value, ' +
23-
'got ' + handler
24-
);
25-
}
26-
return;
27-
}
2813

29-
this.reset();
14+
// @SECTION: implementation
3015

31-
var el = this.el;
32-
var scope = this._scope || this.vm;
16+
var HANDLER = '_vue_clickaway_handler';
3317

34-
this.handler = function(ev) {
35-
// @NOTE: IE 5.0+
36-
// @REFERENCE: https://developer.mozilla.org/en/docs/Web/API/Node/contains
37-
if (!el.contains(ev.target)) {
38-
scope.$event = ev;
39-
var res = handler(ev);
40-
scope.$event = null;
41-
return res;
42-
}
43-
};
18+
function bind(el, binding) {
19+
unbind(el);
4420

45-
Vue.util.on(document.documentElement, 'click', this.handler);
46-
},
21+
var callback = binding.value;
22+
if (typeof callback !== 'function') {
23+
if ('development' !== 'production') {
24+
Vue.util.warn(
25+
'v-' + binding.name + '="' +
26+
binding.expression + '" expects a function value, ' +
27+
'got ' + callback
28+
);
29+
}
30+
return;
31+
}
32+
33+
el[HANDLER] = function(ev) {
34+
// @NOTE: IE 5.0+
35+
// @REFERENCE: https://developer.mozilla.org/en/docs/Web/API/Node/contains
36+
if (!el.contains(ev.target)) {
37+
return callback(ev);
38+
}
39+
};
4740

48-
reset: function() {
49-
Vue.util.off(document.documentElement, 'click', this.handler);
50-
},
41+
document.documentElement.addEventListener('click', el[HANDLER], false);
42+
}
5143

52-
unbind: function() {
53-
this.reset();
54-
},
44+
function unbind(el) {
45+
document.documentElement.removeEventListener('click', el[HANDLER], false);
46+
delete el[HANDLER];
47+
}
5548

49+
var directive = {
50+
bind: bind,
51+
update: function(el, binding) {
52+
if (binding.value === binding.oldValue) return;
53+
bind(el, binding);
54+
},
55+
unbind: unbind,
5656
};
5757

5858
var mixin = {

dist/vue-clickaway.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

+39-39
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
import Vue from 'vue';
22

3-
export var version = '1.1.5';
3+
export var version = '2.0.0-rc.1';
44

5-
var compatible = (/^1\./).test(Vue.version);
5+
var compatible = (/^2\./).test(Vue.version);
66
if (!compatible) {
7-
Vue.util.warn('VueClickaway ' + version + ' only supports Vue 1.x, and does not support Vue ' + Vue.version);
7+
Vue.util.warn('VueClickaway ' + version + ' only supports Vue 2.x, and does not support Vue ' + Vue.version);
88
}
99

10-
export var directive = {
1110

12-
acceptStatement: true,
13-
priority: 700,
14-
15-
update: function(handler) {
16-
if (typeof handler !== 'function') {
17-
if (process.env.NODE_ENV !== 'production') {
18-
Vue.util.warn(
19-
this.name + '="' +
20-
this.expression + '" expects a function value, ' +
21-
'got ' + handler
22-
);
23-
}
24-
return;
25-
}
2611

27-
this.reset();
12+
// @SECTION: implementation
2813

29-
var el = this.el;
30-
var scope = this._scope || this.vm;
14+
var HANDLER = '_vue_clickaway_handler';
3115

32-
this.handler = function(ev) {
33-
// @NOTE: IE 5.0+
34-
// @REFERENCE: https://developer.mozilla.org/en/docs/Web/API/Node/contains
35-
if (!el.contains(ev.target)) {
36-
scope.$event = ev;
37-
var res = handler(ev);
38-
scope.$event = null;
39-
return res;
40-
}
41-
};
16+
function bind(el, binding) {
17+
unbind(el);
4218

43-
Vue.util.on(document.documentElement, 'click', this.handler);
44-
},
19+
var callback = binding.value;
20+
if (typeof callback !== 'function') {
21+
if (process.env.NODE_ENV !== 'production') {
22+
Vue.util.warn(
23+
'v-' + binding.name + '="' +
24+
binding.expression + '" expects a function value, ' +
25+
'got ' + callback
26+
);
27+
}
28+
return;
29+
}
30+
31+
el[HANDLER] = function(ev) {
32+
// @NOTE: IE 5.0+
33+
// @REFERENCE: https://developer.mozilla.org/en/docs/Web/API/Node/contains
34+
if (!el.contains(ev.target)) {
35+
return callback(ev);
36+
}
37+
};
4538

46-
reset: function() {
47-
Vue.util.off(document.documentElement, 'click', this.handler);
48-
},
39+
document.documentElement.addEventListener('click', el[HANDLER], false);
40+
}
4941

50-
unbind: function() {
51-
this.reset();
52-
},
42+
function unbind(el) {
43+
document.documentElement.removeEventListener('click', el[HANDLER], false);
44+
delete el[HANDLER];
45+
}
5346

47+
export var directive = {
48+
bind: bind,
49+
update: function(el, binding) {
50+
if (binding.value === binding.oldValue) return;
51+
bind(el, binding);
52+
},
53+
unbind: unbind,
5454
};
5555

5656
export var mixin = {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-clickaway",
33
"description": "Reusable clickaway directive for reusable Vue.js components",
4-
"version": "1.1.5",
4+
"version": "2.0.0-rc.1",
55
"author": "Denis Karabaza <[email protected]>",
66
"browserify": {
77
"transform": [
@@ -33,7 +33,7 @@
3333
"license": "MIT",
3434
"main": "dist/vue-clickaway.common.js",
3535
"peerDependencies": {
36-
"vue": "^1.0.0"
36+
"vue": "^2.0.0-rc.1"
3737
},
3838
"repository": {
3939
"type": "git",

0 commit comments

Comments
 (0)