Added notifyjs support

This commit is contained in:
Jeroen Bobbeldijk 2014-03-18 00:30:02 +01:00
parent fc231e1c0b
commit d82fcd6b43
4 changed files with 27 additions and 20 deletions

View file

@ -24,6 +24,7 @@
<script src="js/plugins/jquery.scrollTo.min.js" type="text/javascript"></script>
<script src="js/plugins/UnityShim.js" type="text/javascript"></script>
<script src="js/plugins/jplayer/jquery.jplayer.min.js" type="text/javascript"></script>
<script src="js/plugins/notifyjs/notify.js" type="text/javascript"></script>
<script src="js/app.js" type="text/javascript"></script>
<script src="js/utils.js" type="text/javascript"></script>
<script src="js/controllers/main.js" type="text/javascript"></script>

View file

@ -210,42 +210,47 @@ JamStash.service('notifications', function ($rootScope, globals) {
}
}
this.requestPermissionIfRequired = function () {
if (!this.hasNotificationPermission() && (window.webkitNotifications)) {
window.webkitNotifications.requestPermission();
if (window.Notify.isSupported() && window.Notify.needsPermission()) {
window.Notify.requestPermission();
}
}
this.hasNotificationPermission = function () {
return !!(window.webkitNotifications) && (window.webkitNotifications.checkPermission() == 0);
return (window.Notify.needsPermission() === false);
}
this.hasNotificationSupport = function () {
return window.Notify.isSupported();
}
var notifications = new Array();
this.showNotification = function (pic, title, text, type, bind) {
if (this.hasNotificationPermission()) {
//closeAllNotifications()
var popup;
if (type == 'text') {
popup = window.webkitNotifications.createNotification(pic, title, text);
} else if (type == 'html') {
popup = window.webkitNotifications.createHTMLNotification(text);
}
var settings = {}
if (bind = '#NextTrack') {
popup.addEventListener('click', function (bind) {
//$(bind).click();
settings.notifyClick = function() {
$rootScope.nextTrack();
this.cancel();
})
this.close();
};
}
notifications.push(popup);
if (type == 'text') {
settings.body = text;
settings.icon = pic;
} else if (type == 'html') {
settings.body = text;
}
var notification = new Notify(title, settings);
notifications.push(notification);
setTimeout(function (notWin) {
notWin.cancel();
}, globals.settings.NotificationTimeout, popup);
popup.show();
notWin.close();
}, globals.settings.NotificationTimeout, notification);
notification.show();
} else {
console.log("showNotification: No Permission");
}
}
this.closeAllNotifications = function () {
for (notification in notifications) {
notifications[notification].cancel();
notifications[notification].close();
}
}
});

View file

@ -29,13 +29,13 @@ function SettingsCtrl($scope, $routeParams, $location, utils, globals, json, not
if ($scope.settings.Password != '' && globals.settings.Password.substring(0, 4) != 'enc:') { $scope.settings.Password = 'enc:' + utils.HexEncode($scope.settings.Password); }
if (globals.settings.NotificationSong) {
notifications.requestPermissionIfRequired();
if (!notifications.hasNotificationPermission()) {
if (!notifications.hasNotificationSupport()) {
alert('HTML5 Notifications are not available for your current browser, Sorry :(');
}
}
if (globals.settings.NotificationNowPlaying) {
notifications.requestPermissionIfRequired();
if (!notifications.hasNotificationPermission()) {
if (!notifications.hasNotificationSupport()) {
alert('HTML5 Notifications are not available for your current browser, Sorry :(');
}
}

1
js/plugins/notifyjs Submodule

@ -0,0 +1 @@
Subproject commit 5ee07d7122386d3ab2606e9094a6716ba4deaa13