</button>
</div>
+ <div class="btn-group-vertical btn-block btn-group-lg" data-toggle="buttons">
+ <button type="button" class="btn btn-default" id="btnnotify">
+ <span class="glyphicon glyphicon-comment"></span> Notifications
+ </button>
+ </div>
+
</div>
</div><!-- /.col-md-2 -->
</div><!-- /.row -->
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/jquery-1.10.2.min.js"></script>
+ <script src="js/jquery.cookie.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-notify.js"></script>
<script src="js/bootstrap-slider.js"></script>
var socket;
var last_state;
var current_app;
+var lastSongTitle = "";
var current_song = new Object();
+var desktopNotification;
var app = $.sammy(function() {
this.before('/', function(e, data) {
socket.send("MPD_API_SET_SEEK,"+current_song.currentSongId+","+seekVal);
}
});
+
+ if(!notificationsSupported())
+ $('#btnnotify').addClass("disabled");
+ else
+ if ($.cookie("notification") === "true")
+ $('#btnnotify').addClass("active")
});
$(this).children().last().find("a").stop().remove();
}
});
-
break;
case "browse":
if(current_app !== 'browse')
notification += obj.data.artist + "<br />";
}
- $('.top-right').notify({
- message:{html: notification},
- type: "info",
- }).show();
+ if ($.cookie("notification") === "true")
+ songNotify(obj.data.title, obj.data.artist + " " + obj.data.album );
+ else
+ $('.top-right').notify({
+ message:{html: notification},
+ type: "info",
+ }).show();
+
break;
case "error":
$('.top-right').notify({
socket.send("MPD_API_TOGGLE_REPEAT," + ($(this).hasClass('active') ? 0 : 1));
});
+$('#btnnotify').on('click', function (e) {
+ console.log("setting this");
+ if($.cookie("notification") === "true")
+ $.cookie("notification", false);
+ else {
+ window.webkitNotifications.requestPermission();
+ if (window.webkitNotifications.checkPermission() == 0)
+ {
+ $.cookie("notification", true);
+ $('btnnotify').addClass("active");
+ }
+ }
+});
+
function getVersion()
{
$.get( "/api/get_version", function(response) {
$('#ympd_version').text(response.data.ympd_version);
$('#mpd_version').text(response.data.mpd_version);
});
-}
\ No newline at end of file
+}
+
+function notificationsSupported() {
+ return "webkitNotifications" in window;
+}
+
+function songNotify(artist, title) {
+ if (!notificationsSupported())
+ return;
+
+ if (window.webkitNotifications.checkPermission() == 0) {
+ var notification = window.webkitNotifications.createNotification("assets/favicon.ico", artist, title);
+ notification.show();
+ setTimeout(function(notification) {
+ notification.cancel();
+ }, 2000, notification);
+ } else {
+ window.webkitNotifications.requestPermission();
+ }
+}
{ "/js/bootstrap.min.js", "text/javascript" },
{ "/js/mpd.js", "text/javascript" },
{ "/js/jquery-1.10.2.min.js", "text/javascript" },
+ { "/js/jquery.cookie.js", "text/javascript" },
{ "/js/bootstrap-slider.js", "text/javascript" },
{ "/js/bootstrap-notify.js", "text/javascript" },
{ "/js/sammy.js", "text/javascript" },