2
0
mirror of https://github.com/tenrok/vue-native-notification.git synced 2026-06-11 06:12:25 +03:00

Merge pull request #1 from amandiobm/addEvents

Added events
This commit is contained in:
Dennis Bruner
2018-01-04 06:21:53 +01:00
committed by GitHub
3 changed files with 62 additions and 4 deletions
+60 -2
View File
@@ -1,6 +1,28 @@
// Notification object
var Notification = window.Notification || window.webkitNotification
const onerror = function onerror (event) {
}
const onclick = function onclick (event) {
event.preventDefault()
window.focus()
event.target.close()
}
const onclose = function onclose (event) {
}
const onshow = function onshow (event) {
}
const defaultEvents = {
onerror: onerror,
onclick: onclick,
onclose: onclose,
onshow: onshow
}
// Plugin
const VueNativeNotification = {
install: function (Vue, options) {
@@ -18,7 +40,12 @@ const VueNativeNotification = {
Vue.prototype.$notification.requestPermission = requestPermission
// Show function
var show = function (title, opts) {
var show = function (title, opts, {
onerror = defaultEvents.onerror,
onclick = defaultEvents.onclick,
onclose = defaultEvents.onclose,
onshow = defaultEvents.onshow
}) {
return Promise.resolve()
.then(function () {
if (options.requestOnNotify && Notification.permission !== 'granted') {
@@ -35,7 +62,38 @@ const VueNativeNotification = {
}
// Create Notification object
return new Notification(title, opts)
const notification = new Notification(title, opts)
const bindOnError = function (event) {
'use strict'
defaultEvents.onerror(event)
onerror(event)
}
const bindOnClick = function (event) {
'use strict'
defaultEvents.onclick(event)
onclick(event)
}
const bindOnClose = function (event) {
'use strict'
defaultEvents.onclose(event)
onclose(event)
}
const bindOnShow = function (event) {
'use strict'
defaultEvents.onshow(event)
onshow(event)
}
notification.onerror = bindOnError
notification.onclick = bindOnClick
notification.onclose = bindOnClose
notification.onshow = bindOnShow
return notification
})
}
Vue.notification.show = show
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "vue-native-notification",
"version": "1.0.0",
"version": "1.0.1",
"description": "Vue.js plugin for native notifications",
"main": "index.js",
"repository": "https://github.com/dennisbruner/vue-native-notification.git",
+1 -1
View File
@@ -1 +1 @@
(function e(n,t,i){function r(u,f){if(!t[u]){if(!n[u]){var s=typeof require=="function"&&require;if(!f&&s)return s(u,!0);if(o)return o(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var c=t[u]={exports:{}};n[u][0].call(c.exports,function(e){var t=n[u][1][e];return r(t?t:e)},c,c.exports,e,n,t,i)}return t[u].exports}var o=typeof require=="function"&&require;for(var u=0;u<i.length;u++)r(i[u]);return r})({1:[function(e,n,t){"use strict";Object.defineProperty(t,"__esModule",{value:true});var i=window.Notification||window.webkitNotification;var r={install:function e(n,t){t=t||{};t.requestOnNotify=t.requestOnNotify||true;n.notification={};n.prototype.$notification={};var r=function e(){return i.requestPermission()};n.notification.requestPermission=r;n.prototype.$notification.requestPermission=r;var o=function e(n,o){return Promise.resolve().then(function(){if(t.requestOnNotify&&i.permission!=="granted"){return r()}return i.permission}).then(function(e){if(e==="denied"){return new Error("No permission to show notification")}return new i(n,o)})};n.notification.show=o;n.prototype.$notification.show=o}};if(typeof window!=="undefined"&&window.Vue){window.Vue.use(r)}t.default=r},{}]},{},[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]);