Created
May 26, 2016 18:23
-
-
Save ctsstc/69233ed473593516679f27cf24733045 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
var qpNotification = { | |
enabled: true, | |
notificationTimeout: 5000, | |
getPermission: function(callback) { | |
if (typeof Notification == 'undefined') { | |
return false; | |
} | |
Notification.requestPermission(function (permission) { | |
if (callback !== undefined) | |
{ | |
callback(permission); | |
} | |
}); | |
}, | |
showNotification: function(title, message, iconPath) { | |
if (qpNotification.enabled) | |
{ | |
iconPath = iconPath == undefined ? "/static/components/widgets/blog-feed/images/thumbnail.png" : iconPath; | |
qpNotification.getPermission(function(permission) { | |
if (permission !== 'granted') return; | |
var notification = new Notification(title, { | |
icon: iconPath, | |
body: message, | |
}); | |
notification.onclick = function () { | |
window.focus(); | |
this.close(); | |
}; | |
// hide after a given time | |
setTimeout(function() { | |
notification.close(); | |
}, qpNotification.notificationTimeout); | |
}); | |
} | |
}, | |
showQpNotification: function(e) { | |
var song = e.next.song; | |
var title = song.title; | |
var ytid = song.cid; | |
var iconPath = "//i.ytimg.com/vi/"+ytid+"/"+YTThumbQuality._default+".jpg"; | |
qpNotification.showNotification("musiqpad", title, iconPath); | |
}, | |
test: function() { | |
qpNotification.showNotification("Wauw", "It works! C'est fantastic!"); | |
}, | |
} | |
qpNotification.getPermission(function() { | |
// on success | |
qpNotification.test(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment