// Tags
function preventSubmit(e)
{
e = e || event;
return (e.keyCode || event.which || event.charCode || 0) !== 13;
}
function selectTag(data, li, input, autoPost)
{
var display = data.value.replace('\\', '');
// Fix this and get it from the data object passed in, eventually, somehow
var linktable = data.linktable;
// Check for duplicates
if (ID('tags[0]') != undefined) {
var numberTags = ID('numberTags').value;
for (i = 0; i < numberTags; i++) {
if (ID('tags[' + i + ']').value == data.tagid) {
alert('This item has already been tagged with ' + display + '.');
return;
}
}
}
var o = '
\n\n";
o += '
\n\n';
o += reply;
o += '
';
tag.parentNode.innerHTML += o;
}
});
}
function changeTagPrivacy(box, tagid, pending)
{
image = pending ? 'pendingVisibility' : 'visibility';
if (box.selectedIndex == 0) {
ID(image + tagid).src = ID('visibility' + tagid).src.replace('public', 'private').replace('semi', 'private');
} else if (box.options[box.selectedIndex].value == -1) {
ID(image + tagid).src = ID('visibility' + tagid).src.replace('private', 'public').replace('semi', 'public');
} else {
ID(image + tagid).src = ID('visibility' + tagid).src.replace('public', 'semi').replace('private', 'semi');
}
}
function closeTagSettings(parentid, tagid)
{
hideID('privacySettings' + tagid);
}
function setTagPrivacy(button, parentid, tagid)
{
tagVisibility = button.parentNode.parentNode.parentNode.children[2].cells[0].children[0];
tagLevel = button.parentNode.parentNode.parentNode.children[2].cells[1].children[0];
entityid = tagVisibility.options[tagVisibility.selectedIndex].value;
level = tagLevel.options[tagLevel.selectedIndex].value;
var data = {'method': 'setTagPrivacy', 'tagid': tagid, 'parentid': parentid, 'entityid': entityid, 'level': level };
$.get(handler, data, function(reply) {
if (reply.error) {
alert(reply.error);
} else {
changeTagPrivacy(tagVisibility, tagid, 0);
closeTagSettings(parentid, tagid);
}
});
}
// Votes
function vote(id, direction, anonymous)
{
if (anonymous) {
document.location = '/signup/index.html?attempt=vote';
return;
}
$.get(handler, { 'method': 'vote', 'id': id, 'd': direction }, function(reply) {
if (! reply) {
alert('There was no response from the server.');
} else if (reply.error) {
alert(reply.error);
} else {
var directions = new Array('Down', 'Up');
var button = id + '-vote' + directions[direction];
var active = ID(button).src.search('2') !== -1;
var otherDirection = 1 - direction;
var otherPressed = ID(id + '-vote' + directions[otherDirection]).src.search('2') !== -1;
if (direction == 0)
direction = -1;
if (otherPressed)
ID(id + '-votes').innerHTML = forceNumber(ID(id + '-votes').innerHTML) + (forceNumber(direction));
if (! active) {
ID(button).src = ID(button).src.replace('1', '2');
} else {
ID(button).src = ID(button).src.replace('2', '1');
}
ID(id + '-vote' + directions[otherDirection]).src = ID(id + '-vote' + directions[otherDirection]).src.replace('2', '1');
ID(id + '-votes').innerHTML = forceNumber(ID(id + '-votes').innerHTML) + (forceNumber(direction) * (ID(button).src.search('2') === -1 ? -1 : 1));
}
});
}