Last active
March 28, 2016 01:41
-
-
Save williampsena/a4758fa48b967b0c04f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function RequestPermission(callback){ | |
callback = callback || function(status) { | |
console.log('Status da permissão: ' + status); | |
callback(status === "granted"); | |
}; | |
Notification.requestPermission(callback); | |
} | |
function SendNotification(message, callback){ | |
if(Notification.permission === 'default') { | |
RequestPermission(); | |
return; | |
} | |
callback = callback = {}; | |
if(typeof message !== 'object'|| !message.body || !message.title){ | |
throw new Error('Invalid message!'); | |
return; | |
} | |
var notification = new Notification(message.title, { | |
body: message.body, | |
tag: message.tag, | |
icon: message.icon | |
}); | |
notification.onshow = callback.show || function show() { | |
console.log('OnShow: Yeah! Notification success'); | |
}; | |
notification.onclick = callback.click || function click() { | |
console.log('OnClick: Notification clicked'); | |
}; | |
notification.onclose = callback.close || function close() { | |
console.log('OnClose: Notification closed'); | |
}; | |
notification.onerror = callback.error || function error() { | |
console.log('OnError: Unexpected error'); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment