
В любом шаблоне перед пишем:
Code
создаём папку js и в ней два файла: cookie.js, ualert.js и вставляем перед
В ualert.js пишем:
Code
setTimeout(function () {
var source = new EventSource('/php/evstream/index.php');
source.addEventListener('message', function(e) {
// Пришли какие-то данные
var data = e.data;
data = data.split('alert: ');
eval('var newalert = '+data[1]+';');
for( i = 0; i < 4; i++ ){
if(!$('#uBox_'+newalert[i].id).html() && cookie('uBox_'+newalert[i].id)==null){
$('#pmm_player').remove();
$('body').append('');
$('.uBox').animate({bottom:'10'}, {queue:false}).fadeIn().append('');
}
}
}, false);
source.addEventListener('open', function(e) {
// Соединение было открыто
}, false);
source.addEventListener('error', function(e) {
if (e.eventPhase == EventSource.CLOSED) {
// Соединение закрыто
}
}, false);
}, 5);
function ualert_hide(id){
cookie('uBox_'+id, '1', {expires: 1});
$('#uBox_'+id).animate({bottom:'10'}).fadeOut();
}
var source = new EventSource('/php/evstream/index.php');
source.addEventListener('message', function(e) {
// Пришли какие-то данные
var data = e.data;
data = data.split('alert: ');
eval('var newalert = '+data[1]+';');
for( i = 0; i < 4; i++ ){
if(!$('#uBox_'+newalert[i].id).html() && cookie('uBox_'+newalert[i].id)==null){
$('#pmm_player').remove();
$('body').append('');
$('.uBox').animate({bottom:'10'}, {queue:false}).fadeIn().append('');
}
}
}, false);
source.addEventListener('open', function(e) {
// Соединение было открыто
}, false);
source.addEventListener('error', function(e) {
if (e.eventPhase == EventSource.CLOSED) {
// Соединение закрыто
}
}, false);
}, 5);
function ualert_hide(id){
cookie('uBox_'+id, '1', {expires: 1});
$('#uBox_'+id).animate({bottom:'10'}).fadeOut();
}
В cookie.js пишим:
Code
function cookie(name, value, options) {
if (typeof value != 'undefined') {
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' ||
options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString();
}
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain,
secure].join('');
} else {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
if (typeof value != 'undefined') {
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' ||
options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString();
}
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain,
secure].join('');
} else {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
Создаём в папке php папку evstream, в ней создаём 2 файла: base.php, index.php
Своего рода базой является base.php, в нём пишем:
Code


