mirror of
https://github.com/tenrok/vue-native-notification.git
synced 2026-06-10 04:22:26 +03:00
Initial commit
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"presets": [
|
||||
["env", {
|
||||
"targets": {
|
||||
"browsers": ["last 2 versions", "safari >= 7"]
|
||||
}
|
||||
}]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
node_modules/
|
||||
.npm
|
||||
.yarn-integrity
|
||||
@@ -0,0 +1,52 @@
|
||||
// Notification object
|
||||
var Notification = window.Notification || window.webkitNotification
|
||||
|
||||
// Plugin
|
||||
const VueNativeNotification = {
|
||||
install: function (Vue, options) {
|
||||
options = options || {}
|
||||
options.requestOnNotify = options.requestOnNotify || true
|
||||
|
||||
Vue.notification = {}
|
||||
Vue.prototype.$notification = {}
|
||||
|
||||
// Manual permission request
|
||||
var requestPermission = function () {
|
||||
return Notification.requestPermission()
|
||||
}
|
||||
Vue.notification.requestPermission = requestPermission
|
||||
Vue.prototype.$notification.requestPermission = requestPermission
|
||||
|
||||
// Show function
|
||||
var show = function (title, opts) {
|
||||
return Promise.resolve()
|
||||
.then(function () {
|
||||
if (options.requestOnNotify && Notification.permission !== 'granted') {
|
||||
return requestPermission()
|
||||
}
|
||||
|
||||
return Notification.permission
|
||||
})
|
||||
.then(function (permission) {
|
||||
// "default" doesn't mean "denied"
|
||||
// It means the user has dismissed the request
|
||||
if (permission === 'denied') {
|
||||
return new Error('No permission to show notification')
|
||||
}
|
||||
|
||||
// Create Notification object
|
||||
return new Notification(title, opts)
|
||||
})
|
||||
}
|
||||
Vue.notification.show = show
|
||||
Vue.prototype.$notification.show = show
|
||||
}
|
||||
}
|
||||
|
||||
// Automatic installation
|
||||
if (typeof window !== 'undefined' && window.Vue) {
|
||||
window.Vue.use(VueNativeNotification)
|
||||
}
|
||||
|
||||
// Export plugin
|
||||
export default VueNativeNotification
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "vue-native-notification",
|
||||
"version": "1.0.0",
|
||||
"description": "Vue.js plugin for native notifications",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/dennisbruner/vue-native-notification.git",
|
||||
"author": "Dennis Bruner <contact@dennisbruner.de>",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"vue",
|
||||
"vuejs",
|
||||
"native",
|
||||
"notification",
|
||||
"notify",
|
||||
"html5",
|
||||
"api"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "browserify index.js -t babelify | uglifyjs -m > vue-native-notification.min.js",
|
||||
"test": "standard"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-preset-env": "^1.6.0",
|
||||
"babelify": "^7.3.0",
|
||||
"browserify": "^14.4.0",
|
||||
"standard": "*",
|
||||
"uglify-js": "^3.0.28"
|
||||
}
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +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]);
|
||||
Reference in New Issue
Block a user