2007-09-28 05:10:44 +00:00
|
|
|
// Tagger - Advanced Tagging
|
|
|
|
// Author: Artanis (Erik Youngren <artanis.00@gmail.com>)
|
|
|
|
// Do not remove this notice.
|
2007-09-27 08:52:10 +00:00
|
|
|
// All other code copyright by their authors, see comments for details.
|
|
|
|
|
2007-09-30 08:53:47 +00:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
|
|
|
* Tagger Management *
|
|
|
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
var remove_tagme = null;
|
|
|
|
function taggerInit() {
|
|
|
|
taggerResetPos();
|
|
|
|
tagger_tagIndicators()
|
|
|
|
DragHandler.attach(byId("tagger_titlebar"));
|
|
|
|
remove_tagme = byId('tagme');
|
|
|
|
}
|
2007-09-28 05:10:44 +00:00
|
|
|
|
2007-09-27 08:52:10 +00:00
|
|
|
function taggerResetPos() {
|
|
|
|
tagger = byId("tagger_window");
|
|
|
|
|
|
|
|
tagger.style.top="";
|
|
|
|
tagger.style.left="";
|
|
|
|
tagger.style.right="25px";
|
|
|
|
tagger.style.bottom="25px";
|
|
|
|
|
|
|
|
// get location in (left,top) terms
|
|
|
|
pos = findPos(tagger);
|
|
|
|
|
|
|
|
tagger.style.top = pos[1]+"px";
|
|
|
|
tagger.style.left = pos[0]+"px";
|
|
|
|
tagger.style.right="";
|
|
|
|
tagger.style.bottom="";
|
2007-09-25 21:28:09 +00:00
|
|
|
}
|
|
|
|
|
2007-09-30 08:53:47 +00:00
|
|
|
function tagger_tagIndicators() {
|
|
|
|
tags = byId("tags");
|
|
|
|
arObjTags = getElementsByTagNames('a',byId('tagger_body'));
|
2007-09-25 21:28:09 +00:00
|
|
|
|
2007-09-30 08:53:47 +00:00
|
|
|
for (i in arObjTags) {
|
|
|
|
objTag = arObjTags[i];
|
|
|
|
if(tagExists(objTag)) {
|
|
|
|
objTag.style.fontWeight="bold";
|
2007-09-25 21:28:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-30 08:53:47 +00:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
|
|
|
* Tagging *
|
|
|
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
function toggleTag(objTag) {
|
|
|
|
if(!tagExists(objTag)) {
|
|
|
|
addTag(objTag);
|
2007-09-30 19:32:40 +00:00
|
|
|
if (remove_tagme && objTag.getAttribute('tag') != 'tagme') {
|
2007-09-30 08:53:47 +00:00
|
|
|
remTag(remove_tagme);
|
2007-09-26 09:40:51 +00:00
|
|
|
}
|
|
|
|
} else {
|
2007-09-30 08:53:47 +00:00
|
|
|
remTag(objTag);
|
2007-09-27 18:06:58 +00:00
|
|
|
}
|
2007-09-30 08:53:47 +00:00
|
|
|
t = byId("tagger_new-tag");
|
|
|
|
if(t.value) { t.select(); }
|
2007-09-25 21:28:09 +00:00
|
|
|
}
|
|
|
|
|
2007-09-30 08:53:47 +00:00
|
|
|
function addTag (objTag) {
|
|
|
|
var tags = byId('tags');
|
|
|
|
|
|
|
|
delim = tags.value==" "?"":" ";
|
2007-09-25 21:28:09 +00:00
|
|
|
|
2007-09-30 19:32:40 +00:00
|
|
|
tags.value += delim + objTag.getAttribute('tag');
|
2007-09-28 05:10:44 +00:00
|
|
|
|
2007-09-30 08:53:47 +00:00
|
|
|
if(objTag.value != 'Add') {
|
|
|
|
objTag.style.fontWeight = "bold";
|
2007-09-28 05:10:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-30 08:53:47 +00:00
|
|
|
function remTag (objTag) {
|
2007-09-28 05:10:44 +00:00
|
|
|
var tags = byId("tags");
|
2007-09-26 09:40:51 +00:00
|
|
|
|
2007-09-30 08:53:47 +00:00
|
|
|
aTags = tags.value.split(" ");
|
|
|
|
|
|
|
|
tags.value="";
|
|
|
|
for(i in aTags) {
|
|
|
|
aTag = aTags[i];
|
2007-09-30 19:32:40 +00:00
|
|
|
if(aTag != objTag.getAttribute('tag')) {
|
2007-09-30 08:53:47 +00:00
|
|
|
if(tags.value=="") {
|
|
|
|
tags.value += aTag;
|
|
|
|
} else {
|
|
|
|
tags.value += " "+aTag;
|
|
|
|
}
|
2007-09-28 05:10:44 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-30 08:53:47 +00:00
|
|
|
if(objTag.value != 'Add') {
|
|
|
|
objTag.style.fontWeight = "";
|
2007-09-28 05:10:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-30 08:53:47 +00:00
|
|
|
function tagExists(objTag) {
|
2007-09-30 19:32:40 +00:00
|
|
|
return byId("tags").value.match(reescape(objTag.getAttribute('tag')));
|
2007-09-30 08:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
|
|
|
* Filtering *
|
|
|
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
var tagger_filter_focus = false;
|
|
|
|
function tagger_filter(override) {
|
|
|
|
if(tagger_filter_focus || override) {
|
|
|
|
var filter = byId('tagger_new-tag');
|
|
|
|
var arObjTags = getElementsByTagNames('a',byId('tagger_body'));
|
|
|
|
var prepend = filter.value.length<2? " ":"_";
|
|
|
|
var search = prepend + reescape(filter.value);
|
|
|
|
|
|
|
|
for(i in arObjTags) {
|
|
|
|
objTag = arObjTags[i];
|
2007-09-30 19:32:40 +00:00
|
|
|
tag = prepend + objTag.getAttribute('tag');
|
2007-09-30 08:53:47 +00:00
|
|
|
|
|
|
|
if(tag.match(search) && taggerFilterMode(objTag)) {
|
|
|
|
objTag.style.display='';
|
|
|
|
} else {
|
|
|
|
objTag.style.display='none';
|
|
|
|
}
|
2007-09-26 09:40:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-30 08:53:47 +00:00
|
|
|
function taggerToggleMode() {
|
|
|
|
var obj = byId('tagger_mode');
|
|
|
|
|
2007-09-30 19:32:40 +00:00
|
|
|
if(obj.getAttribute('mode')=='all') {
|
|
|
|
obj.setAttribute('mode', 'applied');
|
2007-09-30 08:53:47 +00:00
|
|
|
obj.innerHTML = 'View All Tags';
|
|
|
|
} else {
|
2007-09-30 19:32:40 +00:00
|
|
|
obj.setAttribute('mode','all');
|
2007-09-30 08:53:47 +00:00
|
|
|
obj.innerHTML = 'View Applied Tags';
|
|
|
|
}
|
|
|
|
tagger_filter(true);
|
|
|
|
}
|
|
|
|
function taggerFilterMode(objTag) {
|
|
|
|
var obj = byId('tagger_mode');
|
2007-09-30 19:32:40 +00:00
|
|
|
if(obj.getAttribute('mode') == 'all') {
|
2007-09-30 08:53:47 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return objTag.style.fontWeight=='bold';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
2007-09-30 19:32:40 +00:00
|
|
|
* Misc *
|
2007-09-30 08:53:47 +00:00
|
|
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
2007-09-26 09:40:51 +00:00
|
|
|
|
2007-09-28 21:26:59 +00:00
|
|
|
function pushSet(form_id) {
|
|
|
|
var set = getSetButton(form_id);
|
|
|
|
if(set) {
|
|
|
|
set.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSetButton(form_id) {
|
|
|
|
var form_nodes = getElementsByTagNames('input',byId(form_id));
|
|
|
|
for (i in form_nodes) {
|
|
|
|
node = form_nodes[i];
|
2007-09-30 19:32:40 +00:00
|
|
|
if (node.getAttribute('value')=="Set" && node.getAttribute('type')=="submit") {
|
2007-09-28 21:26:59 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-09-30 08:53:47 +00:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
|
|
|
* quirksmode.org *
|
|
|
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
2007-09-26 07:23:16 +00:00
|
|
|
|
2007-09-30 08:53:47 +00:00
|
|
|
// http://www.quirksmode.org/dom/getElementsByTagNames.html
|
2007-09-26 07:23:16 +00:00
|
|
|
function getElementsByTagNames(list,obj) {
|
|
|
|
if (!obj) var obj = document;
|
|
|
|
var tagNames = list.split(',');
|
|
|
|
var resultArray = new Array();
|
|
|
|
for (var i=0;i<tagNames.length;i++) {
|
|
|
|
var tags = obj.getElementsByTagName(tagNames[i]);
|
|
|
|
for (var j=0;j<tags.length;j++) {
|
|
|
|
resultArray.push(tags[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var testNode = resultArray[0];
|
|
|
|
if (!testNode) return [];
|
|
|
|
if (testNode.sourceIndex) {
|
|
|
|
resultArray.sort(function (a,b) {
|
|
|
|
return a.sourceIndex - b.sourceIndex;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else if (testNode.compareDocumentPosition) {
|
|
|
|
resultArray.sort(function (a,b) {
|
|
|
|
return 3 - (a.compareDocumentPosition(b) & 6);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return resultArray;
|
|
|
|
}
|
2007-09-30 08:53:47 +00:00
|
|
|
|
|
|
|
// http://www.quirksmode.org/js/findpos.html
|
2007-09-27 08:52:10 +00:00
|
|
|
function findPos(obj) {
|
|
|
|
var curleft = curtop = 0;
|
|
|
|
if (obj.offsetParent) {
|
|
|
|
curleft = obj.offsetLeft
|
|
|
|
curtop = obj.offsetTop
|
|
|
|
while (obj = obj.offsetParent) {
|
|
|
|
curleft += obj.offsetLeft
|
|
|
|
curtop += obj.offsetTop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [curleft,curtop];
|
|
|
|
}
|
2007-09-26 07:23:16 +00:00
|
|
|
|
2007-09-30 08:53:47 +00:00
|
|
|
// ripped from a forum.
|
|
|
|
// todo: cite source
|
|
|
|
function reescape(str){
|
|
|
|
var resp="()?:=[]*+{}^$|/,.!\\"
|
|
|
|
var found=false
|
|
|
|
var ret=""
|
|
|
|
for(var i=0;i<str.length;i++) {
|
|
|
|
found=false
|
|
|
|
for(var j=0;j<resp.length;j++) {
|
|
|
|
if(str.charAt(i)==resp.charAt(j)) {
|
|
|
|
found=true;break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(found) {
|
|
|
|
ret+="\\"
|
|
|
|
}
|
|
|
|
ret+=str.charAt(i)
|
|
|
|
}
|
|
|
|
return ret
|
2007-09-25 10:16:26 +00:00
|
|
|
}
|