Здравствуйте.
У меня в панели стоит уведомление с сигналом, не могу решить проблему установки cookie на весь сайт. Чтобы если выключил колокольчик, то он выключался не только в разделе системы, но вообще во всей системе.
код такой:
$(document).ready(function(){
$('.notification-icon').click(function(){
$(this).next('.notification-block').slideToggle();
$(this).toggleClass('n-active');
if ($(this).hasClass('n-active')) $(this).find('span').html('▲')
else $(this).find('span').html('▼')
});
if (getCookie('soundjob')) {soudcont = getCookie('soundjob'); $('.control-sound').addClass(soudcont); } else { $('.control-sound').addClass('on'); cetcooke('on'); }
$('.control-sound').click(function(){ if($(this).hasClass("on")) { $(this).removeClass('on').addClass('off'); cetcooke('off'); } else { $(this).removeClass('off').addClass('on'); cetcooke('on'); } });
});
function soundClick() {
if (getCookie('soundjob') == 'on') {
var audio = new Audio(); // Создаём новый элемент Audio
audio.src = '/js/n3.mp3'; // Указываем путь к аудио файлу
audio.autoplay = true; // Автоматически запускаем
}
}
function notification(){
$.ajax({
// прочие параметры
url: "/ajax_notification.php",
dataType: 'json',
success: function(json){
if (json[0]) {
$(".notification-content").html(json[0]);
soundClick();
$(".notification-icon").addClass('bell');
} else {
$(".notification-content").html('<div class="none-notification">У вас нет новых оповещений! </div>');
$(".notification-icon").removeClass('bell');
}
if (json[1] > 0) {
$(".notification-count").html(json[1]);
$(".notification-count").addClass('red-count');
} else {
$(".notification-count").html('');
$(".notification-count").removeClass('red-count');
}
}
});
}
// закись в куку
function getCookie(name)
{
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : false;
}
function cetcooke(status) {
var date = new Date;
date.setDate(date.getDate() + 15); // время жизни куки
document.cookie = "soundjob="+ status +";expires="+date.toUTCString()+"; path='*'"; // ставим куку
}
$(document).ready(function(){ notification(); setInterval('notification()',20000); });