2007-09-30 08:53:47 +00:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
2007-10-23 22:08:22 +00:00
|
|
|
* Tagger - Advanced Tagging v2 *
|
|
|
|
* Author: Artanis (Erik Youngren <artanis.00@gmail.com>) *
|
|
|
|
* Do not remove this notice. *
|
2007-09-30 08:53:47 +00:00
|
|
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
2007-10-01 19:36:28 +00:00
|
|
|
|
2007-10-23 22:08:22 +00:00
|
|
|
/* Tagger Window Object
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
function Tagger() {
|
|
|
|
// components
|
2007-10-26 02:55:40 +00:00
|
|
|
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;
|
2007-10-23 22:08:22 +00:00
|
|
|
// data
|
2007-10-26 02:55:40 +00:00
|
|
|
this.searchTags = null;
|
|
|
|
this.appliedTags = null;
|
2007-10-23 22:08:22 +00:00
|
|
|
// methods
|
2007-10-26 02:55:40 +00:00
|
|
|
this.initialize = initialize;
|
|
|
|
this.submit = submit;
|
|
|
|
this.getPosition = function () { return findPos(this.t_parent); };
|
|
|
|
this.setPosition = setPosition;
|
|
|
|
this.setSavedPosition = setSavedPosition;
|
|
|
|
this.getSavedPosition = getSavedPosition;
|
|
|
|
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;
|
2007-10-23 23:03:41 +00:00
|
|
|
|
2007-10-02 18:44:29 +00:00
|
|
|
|
2007-10-23 22:08:22 +00:00
|
|
|
// definitions
|
|
|
|
function initialize () {
|
|
|
|
// components
|
2007-10-26 02:55:40 +00:00
|
|
|
this.t_parent = byId("tagger_parent");
|
|
|
|
this.t_title = byId("tagger_titlebar");
|
|
|
|
this.t_toolbar = byId("tagger_toolbar");
|
|
|
|
this.t_menu = byId("tagger_p-menu");
|
|
|
|
this.t_body = byId("tagger_body");
|
|
|
|
this.t_tags = byId("tagger_tags");
|
2007-10-23 22:08:22 +00:00
|
|
|
this.t_form = this.t_tags.parentNode;
|
2007-10-26 02:55:40 +00:00
|
|
|
this.t_status = byId("tagger_statusbar");
|
2007-10-23 22:08:22 +00:00
|
|
|
//pages
|
|
|
|
//this.buildPages();
|
|
|
|
// initial data
|
|
|
|
ajaxXML(query+"/"+image_id,tagListReceive);
|
|
|
|
// reveal
|
|
|
|
this.t_parent.style.display = "";
|
2007-10-23 23:03:41 +00:00
|
|
|
// dragging
|
|
|
|
DragHandler.attach(this.t_title);
|
2007-10-26 02:55:40 +00:00
|
|
|
// set position
|
|
|
|
var pos = ( Tagger.getSavedPosition() || Tagger.getPosition() );
|
2007-10-23 23:03:41 +00:00
|
|
|
setPosition(pos[0],pos[1]);
|
2007-10-26 02:55:40 +00:00
|
|
|
// events
|
|
|
|
window.onunload = function () {Tagger.setSavedPosition(); };
|
|
|
|
|
2007-10-02 18:44:29 +00:00
|
|
|
}
|
2007-10-23 22:08:22 +00:00
|
|
|
function submit() {
|
|
|
|
this.t_tags.value = Tagger.tagsToString(Tagger.appliedTags);
|
2007-10-02 18:44:29 +00:00
|
|
|
}
|
2007-10-23 23:03:41 +00:00
|
|
|
function setPosition(x,y) {
|
|
|
|
if(!x || !y) {
|
|
|
|
with(Tagger.t_parent.style) {
|
|
|
|
top = "25px";
|
|
|
|
left = "";
|
|
|
|
right = "25px";
|
|
|
|
bottom = "";
|
|
|
|
}
|
|
|
|
var pos = Tagger.getPosition();
|
|
|
|
x = pos[0];
|
|
|
|
y = pos[1];
|
|
|
|
}
|
|
|
|
with(Tagger.t_parent.style) {
|
|
|
|
top = y+"px";
|
|
|
|
left = x+"px";
|
|
|
|
right="";
|
|
|
|
bottom="";
|
|
|
|
}
|
|
|
|
}
|
2007-10-26 02:55:40 +00:00
|
|
|
function setSavedPosition(x,y) {
|
|
|
|
if (!x || !y) {
|
|
|
|
var p = Tagger.getPosition();
|
|
|
|
x = p[0];
|
|
|
|
y = p[1];
|
|
|
|
}
|
|
|
|
setCookie("shimmie_tagger-position",x+" "+y,14);
|
|
|
|
}
|
|
|
|
function getSavedPosition() {
|
|
|
|
var p = getCookie("shimmie_tagger-position");
|
|
|
|
if(p) {
|
|
|
|
return p.split(" ");
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2007-10-23 22:08:22 +00:00
|
|
|
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);
|
2007-10-02 18:44:29 +00:00
|
|
|
|
2007-10-23 22:08:22 +00:00
|
|
|
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<prv_s.length ||
|
|
|
|
this.searchTags.getAttribute("max"))
|
|
|
|
{
|
|
|
|
ajaxXML(s_query,searchReceive);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else if(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);
|
|
|
|
}
|
|
|
|
}
|
2007-09-25 21:28:09 +00:00
|
|
|
}
|
2007-10-23 22:08:22 +00:00
|
|
|
return false;
|
2007-09-25 21:28:09 +00:00
|
|
|
}
|
2007-10-23 22:08:22 +00:00
|
|
|
function searchReceive(xml) {
|
|
|
|
Tagger.searchTags = document.importNode(xml.getElementsByTagName("list")[0],true);
|
2007-10-26 02:55:40 +00:00
|
|
|
tagPublish(Tagger.searchTags,byId("tagger_p-search"));
|
2007-10-23 22:08:22 +00:00
|
|
|
|
|
|
|
if(Tagger.searchTags.getAttribute("max")) {
|
2007-10-26 02:55:40 +00:00
|
|
|
Tagger.setAlert("maxout","Showing "+Tagger.searchTags.getAttribute("rows")+" of "+Tagger.searchTags.getAttribute("max")+" tags");
|
2007-10-23 22:08:22 +00:00
|
|
|
} else {
|
|
|
|
Tagger.setAlert("maxout",false);
|
2007-09-26 09:40:51 +00:00
|
|
|
}
|
2007-09-27 18:06:58 +00:00
|
|
|
}
|
2007-09-28 05:10:44 +00:00
|
|
|
|
2007-10-23 22:08:22 +00:00
|
|
|
function tagListReceive(xml) {
|
|
|
|
Tagger.appliedTags = document.importNode(xml.getElementsByTagName("list")[0],true);
|
2007-10-26 02:55:40 +00:00
|
|
|
tagPublish(Tagger.appliedTags,byId("tagger_p-applied"));
|
2007-09-28 05:10:44 +00:00
|
|
|
}
|
2007-10-23 22:08:22 +00:00
|
|
|
function tagPublish(tag_list,page) {
|
|
|
|
page.innerHTML = "";
|
|
|
|
Tagger.prepTags(tag_list);
|
|
|
|
page.appendChild(tag_list);
|
2007-09-28 05:10:44 +00:00
|
|
|
}
|
2007-10-23 22:08:22 +00:00
|
|
|
function prepTags(tag_list) {
|
|
|
|
var len = tag_list.childNodes.length;
|
|
|
|
|
|
|
|
for(var i=0; i<len;i++) {
|
|
|
|
var tag = tag_list.childNodes[i];
|
2007-10-26 02:55:40 +00:00
|
|
|
tag.onclick = function() { toggleTag(this); byId("tagger_filter").select(); };
|
|
|
|
//tag.style.display="block";
|
2007-10-23 22:08:22 +00:00
|
|
|
tag.setAttribute("title",tag.getAttribute("count")+" uses");
|
|
|
|
}
|
2007-09-28 05:10:44 +00:00
|
|
|
}
|
2007-10-23 22:08:22 +00:00
|
|
|
function createTag(tag_name) {
|
|
|
|
if (tag_name.length>0) {
|
|
|
|
var tag = document.createElement("tag");
|
|
|
|
tag.setAttribute("count","0");
|
|
|
|
tag.setAttribute("id","newTag_"+tag_name);
|
2007-10-26 02:55:40 +00:00
|
|
|
tag.setAttribute("count",1);
|
|
|
|
tag.setAttribute("title","New");
|
2007-10-23 22:08:22 +00:00
|
|
|
tag.onclick = function() { toggleTag(this); };
|
|
|
|
tag.appendChild(document.createTextNode(tag_name));
|
|
|
|
Tagger.appliedTags.appendChild(tag);
|
2007-09-26 09:40:51 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-23 22:08:22 +00:00
|
|
|
function buildPages () {
|
2007-10-26 02:55:40 +00:00
|
|
|
var pages = getElementsByTagNames("div",byId("tagger_body"));
|
2007-10-23 22:08:22 +00:00
|
|
|
var len = pages.length;
|
|
|
|
for(var i=0; i<len; i++) {
|
|
|
|
this.t_menu.innerHTML += "<li onclick='Tagger.togglePages("+
|
|
|
|
"\""+pages[i].getAttribute("id")+"\")'>"+
|
|
|
|
pages[i].getAttribute('name')+"</li>";
|
|
|
|
}
|
2007-09-30 08:53:47 +00:00
|
|
|
}
|
2007-10-23 22:08:22 +00:00
|
|
|
function tagsToString(tags) {
|
|
|
|
var len = tags.childNodes.length;
|
|
|
|
var str = "";
|
|
|
|
for (var i=0; i<len; i++) {
|
|
|
|
str += tags.childNodes[i].firstChild.data+" ";
|
|
|
|
}
|
|
|
|
return str;
|
2007-09-30 08:53:47 +00:00
|
|
|
}
|
2007-10-23 22:08:22 +00:00
|
|
|
function toggleTag(tag) {
|
|
|
|
if(tag.parentNode == Tagger.appliedTags) {
|
|
|
|
Tagger.appliedTags.removeChild(tag);
|
|
|
|
} else {
|
|
|
|
Tagger.appliedTags.appendChild(tag);
|
|
|
|
}
|
2007-10-01 19:36:28 +00:00
|
|
|
}
|
2007-10-23 22:08:22 +00:00
|
|
|
function setAlert(type,arg) {
|
2007-10-26 02:55:40 +00:00
|
|
|
var alert = byId("tagger_alert_"+type);
|
2007-10-23 22:08:22 +00:00
|
|
|
if (alert) {
|
|
|
|
if (arg==false) {
|
|
|
|
//remove existing
|
|
|
|
alert.parentNode.removeChild(alert);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//update prior
|
|
|
|
alert.innerHTML = arg;
|
|
|
|
} else if (arg!=false) {
|
|
|
|
//create
|
|
|
|
var status = document.createElement("div");
|
|
|
|
status.setAttribute("id","tagger_alert_"+type);
|
|
|
|
status.innerHTML = arg;
|
|
|
|
Tagger.t_status.appendChild(status);
|
|
|
|
}
|
2007-09-28 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-23 22:08:22 +00:00
|
|
|
/* AJAX
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
function ajaxXML(url, callback) {
|
|
|
|
//var http = getHTTPObject();
|
|
|
|
var http = (new XMLHttpRequest() || new ActiveXObject("Microsoft.XMLHTTP"));
|
|
|
|
http.open("GET", url, true);
|
|
|
|
http.onreadystatechange = function() {
|
|
|
|
if(http.readyState == 4) callback(http.responseXML);
|
2007-09-28 21:26:59 +00:00
|
|
|
}
|
2007-10-23 22:08:22 +00:00
|
|
|
http.send(null);
|
2007-09-28 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2007-10-23 22:08:22 +00:00
|
|
|
/* Miscellaneous Code
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
2007-09-26 07:23:16 +00:00
|
|
|
|
2007-10-23 22:08:22 +00:00
|
|
|
// Quirksmode
|
2007-10-26 02:55:40 +00:00
|
|
|
// http://www.quirksmode.org/dom/getElementsByTagNames.htmlgetElementbyId
|
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
|
|
|
}
|
2007-10-23 22:08:22 +00:00
|
|
|
|
|
|
|
// Modified from above
|
|
|
|
function sqlescape(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
|
|
|
|
}
|