// 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 = '
'; o += '\n\n'; o += '\n'; o += ''; o += '\n\n'; o += '
'; o += '' + display.replace(' ', ' ') + 'Delete
\n\n'; o += '
\n\n'; ID(data.linktable + 'TagResults').innerHTML += o; ID(data.linktable + 'Tag').value = ''; if (parseInt(ID(data.linktable + 'AutoPost').value)) { var data = { 'method': 'linkTag', 'tagid': data.tagid, 'linkid': ID('id').value, 'linktable': data.linktable }; $.get(handler, data, function(reply) { if (! reply.tagid) alert('There was a problem adding your tag.'); $('.auto-complete-list').hide(); }); } } function removeTag(id) { $('#tagResults input[value=' + id + ']').parent().remove(); } function digestTag(box, event) { if (event.keyCode == 13 && box.value != '') { $.get(handler, { 'method': 'digestTag', 'q': box.value }, function(reply) { if (! reply.tagid) { alert('Please type in a phrase for your tag that is at least three characters long.'); } else { var li = { 'selectValue': box.value, 'extra': new Array(2) } li.extra[0] = reply.tagid; li.extra[1] = box.form.name; if (! reply.value) reply.value = box.value; selectTag(reply, li, box); } }); } } function deletePendingTag(index) { document.getElementById('tag' + index).parentNode.removeChild(document.getElementById('tag' + index)); } function deleteExistingTag(id, index, linkTable) { var data = {'method': 'deleteTag', 'id': id, 'l': linkTable, 'index': index}; $.post(handler, data, function(reply) { if (! reply) { alert('There was no response from the server.'); } else if (reply.error) { alert(reply.error); } else { deletePendingTag(index); } }); } function digestOrganization(box, field) { if (document.forms['tags'].elements[field].value) document.forms['tags'].elements[field].value = ''; } function tagTypeChange(box, index) { if (box.options[box.selectedIndex].text == 'Text') { hideID('choices' + index); hideID('tag' + index); showID('size' + index); } else if (box.options[box.selectedIndex].text == 'Pick One' || box.options[box.selectedIndex].text == 'Pick Several') { hideID('size' + index); hideID('tag' + index); showID('choices' + index); } else if (box.options[box.selectedIndex].text == 'ThinkLink Data') { hideID('size' + index); hideID('choices' + index); showID('tag' + index); } else { hideID('choices' + index); hideID('size' + index); } } function showTagRow(index) { hideID('exclude' + index); showID('type' + index); hideID('showTagRow' + index); showID('hideTagRow' + index); } function hideTagRow(index) { hideID('type' + index); showID('exclude' + index); hideID('hideTagRow' + index); showID('showTagRow' + index); } function tagPrivacy(tag, tagid, parentid, visibility) { $('.privacy').html(''); var data = {'method': 'getTagPrivacy', 'tagid': tagid, 'parentid': parentid, 'visibility': visibility }; $.get(handler, data, function(reply) { if (reply.error) { alert(reply.error); } else { 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)); } }); }