Is it possible to create an option to hide chatbox (with cookie)?
Extra question: Also, is it possible to move the chatbox up and down the main page?
Extra question: Also, is it possible to move the chatbox up and down the main page?
$(function() {
if (!document.getElementById('frame_chatbox')) return;
var fa = document.getElementById('frame_chatbox'), frame;
// create toggle buttons
$('#chatbox_top').before('<div class="online-chat">Members in chat : <span id="members-chat" style="color:#F00;">0</span></div><div id="cbOpen" class="cbButton">Click to open chatbox</div><div id="cbClose" class="cbButton">Click to close chatbox</div>');
$('#chatbox_top, #cbClose').hide();
fa.onload = function() {
if (fa.contentDocument) frame = fa.contentDocument;
else if (fa.contentWindow) frame = fa.contentWindow.document;
// kill the interval if archives are toggled
var a = frame.getElementsByTagName('A');
for (i=0; i<a.length; i++) if (/archives/.test(a[i].href)) a[i].onclick = function() { window.clearInterval(_chat_refresh) };
// get the amount of members and compare change
then = frame.getElementById('chatbox_members').getElementsByTagName('li').length;
var members = document.getElementById('members-chat');
members.innerHTML = then;
_chat_refresh = window.setInterval(function() {
var now = frame.getElementById('chatbox_members').getElementsByTagName('li').length;
// change the chat member number
if (now < 1 || then < 1) members.style.color = '#F00';
else if (now > 0 || then > 0) members.style.color = '#39C';
// check if there is a change in members
if (now > then || now < then) {
members.innerHTML = now;
then = now;
}
},1);
};
// open chat function
$('#cbOpen').click(function() {
$('#chatbox_top, #cbClose').show();
$('#cbOpen').hide();
// adjust scroll
if (fa.contentDocument) fa.contentDocument.getElementById('chatbox').scrollTop = 99999;
else if (fa.contentWindow) fa.contentWindow.document.getElementById('chatbox').scrollTop = 99999;
});
// close chat function
$('#cbClose').click(function() {
$('#chatbox_top, #cbClose').hide();
$('#cbOpen').show();
});
});
.cbButton {
cursor:pointer;
text-align:center;
font-weight:bold;
font-size:12px;
margin:3px;
}