/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Tagger - Advanced Tagging v2 * * Author: Artanis (Erik Youngren ) * * Do not remove this notice. * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Tagger Window Object * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function Tagger() { // components this.t_parent = null; this.t_title = null; this.t_toolbar = null; this.t_menu = null; this.t_body = null; this.t_tags = null; this.t_form = null; this.t_status = null; // data this.searchTags = null; this.appliedTags = null; // methods this.initialize = initialize; this.submit = submit; this.tagSearch = tagSearch; this.searchRequest = searchRequest; this.searchReceive = searchReceive; this.tagListReceive = tagListReceive; this.tagPublish = tagPublish; this.prepTags = prepTags; this.createTag = createTag; this.buildPages = buildPages; this.tagsToString = tagsToString; this.toggleTag = toggleTag; this.setAlert = setAlert; // definitions function initialize () { // components this.t_parent = document.getElementById("tagger_parent"); this.t_title = document.getElementById("tagger_titlebar"); this.t_toolbar = document.getElementById("tagger_toolbar"); this.t_menu = document.getElementById("tagger_p-menu"); this.t_body = document.getElementById("tagger_body"); this.t_tags = document.getElementById("tagger_tags"); this.t_form = this.t_tags.parentNode; this.t_status = document.getElementById("tagger_statusbar"); //pages //this.buildPages(); // initial data ajaxXML(query+"/"+image_id,tagListReceive); // reveal this.t_parent.style.display = ""; } function submit() { this.t_tags.value = Tagger.tagsToString(Tagger.appliedTags); } function tagSearch(s,ms) { clearTimeout(tagger_filter_timer); tagger_filter_timer = setTimeout("Tagger.searchRequest('"+s+"')",ms); } function searchRequest(s) { var s_query = !s? query+"?s" : query+"?s="+sqlescape(s); if(!this.searchTags) { ajaxXML(s_query,searchReceive); return true; } else { var prv_s = this.searchTags.getAttribute('query'); if(s==prv_s) { return false; }else if(!s || s.length <= 2 || s.length 2 && s.match(reescape(prv_s))) { var len = this.searchTags.childNodes.length; for (var i=len-1; i>=0; i--) { var tag = this.searchTags.childNodes[i]; var t_name = tag.firstChild.data; if(!t_name.match(reescape(s))) { this.searchTags.removeChild(tag); // TODO: Fix so back searches are not needlessly re-queried. //tag.setAttribute("style","display:none;"); } else { //tag.setAttribute("style",""); } } if (len != this.searchTags.childNodes.length) { this.searchTags.setAttribute('query',s); } } } return false; } function searchReceive(xml) { Tagger.searchTags = document.importNode(xml.getElementsByTagName("list")[0],true); tagPublish(Tagger.searchTags,document.getElementById("tagger_p-search")); if(Tagger.searchTags.getAttribute("max")) { Tagger.setAlert("maxout","Limited to "+Tagger.searchTags.getAttribute("rows")+" of "+Tagger.searchTags.getAttribute("max")+" tags"); } else { Tagger.setAlert("maxout",false); } } function tagListReceive(xml) { Tagger.appliedTags = document.importNode(xml.getElementsByTagName("list")[0],true); tagPublish(Tagger.appliedTags,document.getElementById("tagger_p-applied")); } function tagPublish(tag_list,page) { page.innerHTML = ""; Tagger.prepTags(tag_list); page.appendChild(tag_list); } function prepTags(tag_list) { var len = tag_list.childNodes.length; for(var i=0; i0) { var tag = document.createElement("tag"); tag.setAttribute("count","0"); tag.setAttribute("id","newTag_"+tag_name); tag.onclick = function() { toggleTag(this); }; tag.appendChild(document.createTextNode(tag_name)); Tagger.appliedTags.appendChild(tag); } } function buildPages () { var pages = getElementsByTagNames("div",document.getElementById("tagger_body")); var len = pages.length; for(var i=0; i"+ pages[i].getAttribute('name')+""; } } function tagsToString(tags) { var len = tags.childNodes.length; var str = ""; for (var i=0; i