2
0
mirror of https://github.com/tenrok/vue-native-notification.git synced 2026-05-17 03:59:37 +03:00

Events are called twice

This commit is contained in:
Amandio Magalhaes
2018-01-04 15:35:02 -02:00
parent 957fa7d6f5
commit 4d35cd7646
4 changed files with 71 additions and 11 deletions
+57 -1
View File
@@ -37,7 +37,7 @@ export default {
// https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification#Parameters // https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification#Parameters
this.$notification.show('Hello World', { this.$notification.show('Hello World', {
body: 'This is an example!' body: 'This is an example!'
}) }, {})
} }
} }
} }
@@ -61,6 +61,62 @@ this.$notification.requestPermission()
.then(console.log) .then(console.log)
``` ```
### Events
https://developer.mozilla.org/en-US/docs/Web/API/Notification
We now supports all notifications events
#### onerror
https://developer.mozilla.org/en-US/docs/Web/API/Notification/onerror
Is an empty function. Nothing will be executed
#### onclick
https://developer.mozilla.org/en-US/docs/Web/API/Notification/onclick
When notification is clicked, we set the focus on the context browser and close the notification
#### onclose
https://developer.mozilla.org/en-US/docs/Web/API/Notification/onclose
Is an empty function. Nothing will be executed
#### onshow
https://developer.mozilla.org/en-US/docs/Web/API/Notification/onshow
Is an empty function. Nothing will be executed
#### Usage
```javascript
const notification = {
title: 'Your title',
options: {
body: 'This is an example!'
},
events: {
onerror: function () {
console.log('Custom error event was called');
},
onclick: function () {
console.log('Custom click event was called');
},
onclose: function () {
console.log('Custom close event was called');
},
onshow: function () {
console.log('Custom show event was called');
}
}
}
this.$notification.show(notification.title, notification.options, notification.events)
```
## License ## License
[MIT](LICENSE.md) [MIT](LICENSE.md)
+12 -8
View File
@@ -2,18 +2,22 @@
var Notification = window.Notification || window.webkitNotification var Notification = window.Notification || window.webkitNotification
const onerror = function onerror (event) { const onerror = function onerror (event) {
// console.log('On error event was called')
} }
const onclick = function onclick (event) { const onclick = function onclick (event) {
// console.log('On click event was called')
event.preventDefault() event.preventDefault()
window.focus() window.focus()
event.target.close() event.target.close()
} }
const onclose = function onclose (event) { const onclose = function onclose (event) {
// console.log('On close event was called')
} }
const onshow = function onshow (event) { const onshow = function onshow (event) {
// console.log('On show event was called')
} }
const defaultEvents = { const defaultEvents = {
@@ -41,10 +45,10 @@ const VueNativeNotification = {
// Show function // Show function
var show = function (title, opts, { var show = function (title, opts, {
onerror = defaultEvents.onerror, onerror = function () { },
onclick = defaultEvents.onclick, onclick = function () { },
onclose = defaultEvents.onclose, onclose = function () { },
onshow = defaultEvents.onshow onshow = function () { }
}) { }) {
return Promise.resolve() return Promise.resolve()
.then(function () { .then(function () {
@@ -67,25 +71,25 @@ const VueNativeNotification = {
const bindOnError = function (event) { const bindOnError = function (event) {
'use strict' 'use strict'
defaultEvents.onerror(event) defaultEvents.onerror(event)
onerror(event) onerror()
} }
const bindOnClick = function (event) { const bindOnClick = function (event) {
'use strict' 'use strict'
defaultEvents.onclick(event) defaultEvents.onclick(event)
onclick(event) onclick()
} }
const bindOnClose = function (event) { const bindOnClose = function (event) {
'use strict' 'use strict'
defaultEvents.onclose(event) defaultEvents.onclose(event)
onclose(event) onclose()
} }
const bindOnShow = function (event) { const bindOnShow = function (event) {
'use strict' 'use strict'
defaultEvents.onshow(event) defaultEvents.onshow(event)
onshow(event) onshow()
} }
notification.onerror = bindOnError notification.onerror = bindOnError
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "vue-native-notification", "name": "vue-native-notification",
"version": "1.0.1", "version": "1.0.2",
"description": "Vue.js plugin for native notifications", "description": "Vue.js plugin for native notifications",
"main": "index.js", "main": "index.js",
"repository": "https://github.com/dennisbruner/vue-native-notification.git", "repository": "https://github.com/dennisbruner/vue-native-notification.git",
+1 -1
View File
@@ -1 +1 @@
(function n(o,r,e){function i(u,c){if(!r[u]){if(!o[u]){var f=typeof require=="function"&&require;if(!c&&f)return f(u,!0);if(t)return t(u,!0);var s=new Error("Cannot find module '"+u+"'");throw s.code="MODULE_NOT_FOUND",s}var a=r[u]={exports:{}};o[u][0].call(a.exports,function(n){var r=o[u][1][n];return i(r?r:n)},a,a.exports,n,o,r,e)}return r[u].exports}var t=typeof require=="function"&&require;for(var u=0;u<e.length;u++)i(e[u]);return i})({1:[function(n,o,r){"use strict";Object.defineProperty(r,"__esModule",{value:true});var e=window.Notification||window.webkitNotification;var i=function n(o){};var t=function n(o){o.preventDefault();window.focus();o.target.close()};var u=function n(o){};var c=function n(o){};var f={onerror:i,onclick:t,onclose:u,onshow:c};var s={install:function n(o,r){r=r||{};r.requestOnNotify=r.requestOnNotify||true;o.notification={};o.prototype.$notification={};var i=function n(){return e.requestPermission()};o.notification.requestPermission=i;o.prototype.$notification.requestPermission=i;var t=function n(o,t,u){var c=u.onerror,s=c===undefined?f.onerror:c,a=u.onclick,d=a===undefined?f.onclick:a,w=u.onclose,v=w===undefined?f.onclose:w,l=u.onshow,p=l===undefined?f.onshow:l;return Promise.resolve().then(function(){if(r.requestOnNotify&&e.permission!=="granted"){return i()}return e.permission}).then(function(n){if(n==="denied"){return new Error("No permission to show notification")}var r=new e(o,t);var i=function n(o){"use strict";f.onerror(o);s(o)};var u=function n(o){"use strict";f.onclick(o);d(o)};var c=function n(o){"use strict";f.onclose(o);v(o)};var a=function n(o){"use strict";f.onshow(o);p(o)};r.onerror=i;r.onclick=u;r.onclose=c;r.onshow=a;return r})};o.notification.show=t;o.prototype.$notification.show=t}};if(typeof window!=="undefined"&&window.Vue){window.Vue.use(s)}r.default=s},{}]},{},[1]); (function n(o,r,e){function i(u,f){if(!r[u]){if(!o[u]){var c=typeof require=="function"&&require;if(!f&&c)return c(u,!0);if(t)return t(u,!0);var s=new Error("Cannot find module '"+u+"'");throw s.code="MODULE_NOT_FOUND",s}var a=r[u]={exports:{}};o[u][0].call(a.exports,function(n){var r=o[u][1][n];return i(r?r:n)},a,a.exports,n,o,r,e)}return r[u].exports}var t=typeof require=="function"&&require;for(var u=0;u<e.length;u++)i(e[u]);return i})({1:[function(n,o,r){"use strict";Object.defineProperty(r,"__esModule",{value:true});var e=window.Notification||window.webkitNotification;var i=function n(o){};var t=function n(o){o.preventDefault();window.focus();o.target.close()};var u=function n(o){};var f=function n(o){};var c={onerror:i,onclick:t,onclose:u,onshow:f};var s={install:function n(o,r){r=r||{};r.requestOnNotify=r.requestOnNotify||true;o.notification={};o.prototype.$notification={};var i=function n(){return e.requestPermission()};o.notification.requestPermission=i;o.prototype.$notification.requestPermission=i;var t=function n(o,t,u){var f=u.onerror,s=f===undefined?function(){}:f,a=u.onclick,d=a===undefined?function(){}:a,v=u.onclose,w=v===undefined?function(){}:v,l=u.onshow,p=l===undefined?function(){}:l;return Promise.resolve().then(function(){if(r.requestOnNotify&&e.permission!=="granted"){return i()}return e.permission}).then(function(n){if(n==="denied"){return new Error("No permission to show notification")}var r=new e(o,t);var i=function n(o){"use strict";c.onerror(o);s()};var u=function n(o){"use strict";c.onclick(o);d()};var f=function n(o){"use strict";c.onclose(o);w()};var a=function n(o){"use strict";c.onshow(o);p()};r.onerror=i;r.onclick=u;r.onclose=f;r.onshow=a;return r})};o.notification.show=t;o.prototype.$notification.show=t}};if(typeof window!=="undefined"&&window.Vue){window.Vue.use(s)}r.default=s},{}]},{},[1]);