/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this sample’s licensing information
Abstract:
The notifications sample code with helper functions to add an alert to the left-hand menu,
to clear 'new' notifications, and to render the notifications in a table.
*/
CKCatalog.tabs['notifications'] = (function() {
var alertTextContainer = document.getElementById('number-of-alerts');
var notificationsAlertContainer = document.querySelector('.menu-item[href="#notifications"] .alert');
var notificationsSubtitle = document.getElementById('connected-text');
var unseenNotifications = 0;
var areNotificationsVisible = function() {
return window.location.hash === '#notifications';
};
var setUnseenNotifications = function(val) {
unseenNotifications = val;
alertTextContainer.textContent = val + '';
};
var showOrHideAlert = function() {
if(areNotificationsVisible() || unseenNotifications === 0) {
notificationsAlertContainer.classList.add('hide');
} else {
notificationsAlertContainer.classList.remove('hide');
}
};
var updateNotificationsSubtitle = function(text) {
notificationsSubtitle.innerHTML = '' + text + '';
};
window.addEventListener('hashchange',function(hashChangeEvent) {
// Let's remove the 'new' class from the rows when leaving the notifications page and reset unseen notifications.
if(/#notifications/.test(hashChangeEvent.oldURL)) {
setUnseenNotifications(0);
var rows = notificationsTable.body.childNodes;
for(var i=0; i