/*jshint forin:false, nonew:true, undef:true, strict:false, browser:true, jquery:true */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Tagger - Advanced Tagging v2 * * Author: Artanis (Erik Youngren ) * * Do not remove this notice. * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function byId(id) { return document.getElementById(id); } var Tagger = { initialize : function (image_id) { // object navigation this.tag.parent = this; this.position.parent = this; // components this.editor.container = byId('tagger_parent'); this.editor.titlebar = byId('tagger_titlebar'); this.editor.toolbar = byId('tagger_toolbar'); //this.editor.menu = byId('tagger_p-menu'); this.editor.body = byId('tagger_body'); this.editor.tags = byId('tagger_tags'); this.editor.form = this.editor.tags.parentNode; this.editor.statusbar = byId('tagger_statusbar'); // initial data this.tag.image = image_id; this.tag.query = config.make_link("tagger/tags"); this.tag.list = null; this.tag.suggest = null; this.tag.image_tags(); // reveal this.editor.container.style.display = ""; // dragging DragHandler.attach(this.editor.titlebar); // positioning this.position.load(); // events window.onunload = function () { Tagger.position.save(); }; }, alert : function (type,text,timeout) { var id = "tagger_alert-"+type; var t_alert = byId(id); if (t_alert) { if(text === false) { // remove t_alert.parentNode.removeChild(t_alert); } else { // update t_alert.innerHTML = text; } } else if (text) { // create t_alert = document.createElement("div"); t_alert.setAttribute("id",id); t_alert.appendChild(document.createTextNode(text)); this.editor.statusbar.appendChild(t_alert); if(timeout>1) { console.log("Tagger.alert('"+type+"',false,0)"); setTimeout("Tagger.alert('"+type+"',false,0)",timeout); } } }, editor : {}, tag : { submit : function () { var l = this.list.childNodes.length; var tags = []; for(var i=0; i 0) { var tag = document.createElement("tag"); tag.setAttribute("count","0"); tag.setAttribute("id","newTag_"+tag_name); tag.setAttribute("title","New - 0 uses"); tag.onclick = function() { Tagger.tag.toggle(this); }; tag.appendChild(document.createTextNode(tag_name)); Tagger.tag.list.appendChild(tag); } }, toggle : function (tag) { if(tag.parentNode == this.list) { this.list.removeChild(tag); } else { this.list.appendChild(tag); } }, ajax : function (url, callback) { var http = (new XMLHttpRequest() || new ActiveXObject("Microsoft.XMLHTTP")); http.open("GET",url,true); http.onreadystatechange = function () { if(http.readyState == 4) { callback(http); } }; http.send(null); } }, position : { set : function (x,y) { if (!x || !y) { this.parent.editor.container.style.top = "25px"; this.parent.editor.container.style.left = ""; this.parent.editor.container.style.right = "25px"; this.parent.editor.container.style.bottom = ""; var xy = this.get(); x = xy[0]; y = xy[1]; } this.parent.editor.container.style.top = y+"px"; this.parent.editor.container.style.left = x+"px"; this.parent.editor.container.style.right = ""; this.parent.editor.container.style.bottom = ""; }, get : function () { // http://www.quirksmode.org/js/findpos.html var left = 0; var top = 0; var obj = this.parent.editor.container; if(obj.offsetParent) { left = obj.offsetLeft; top = obj.offsetTop; while (obj = obj.offsetParent) { left += obj.offsetLeft; top += obj.offsetTop; } } return [left,top]; }, save : function (x,y) { if (!x || !y) { var xy = this.get(); x = xy[0]; y = xy[1]; } Cookies.set(config.title+"_tagger-position", x+" "+y, {expires: 14}); }, load : function () { var p = Cookies.get(config.title+"_tagger-position"); if(p) { var xy = p.split(" "); this.set(xy[0],xy[1]); } else { this.set(); } } } };