/** Simple GTD Task List Manager for PmWiki Written by (c) Petko Yotov 2008 This script is POSTCARDWARE, if you like it or use it, please send me a postcard. Details at http://galleries.accent.bg/Cookbook/Postcard This text is written for PmWiki; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. See pmwiki.php for full details and lack of warranty. Copyright 2008 Petko Yotov http://5ko.fr File modified 2008-06-16 */ function btn(event) // http://unixpapa.com/js/mouse.html { var button; if (event.which == null) /* IE case */ button= (event.button < 2) ? "LEFT" : ((event.button == 4) ? "MIDDLE" : "RIGHT"); else /* All others */ button= (event.which < 2) ? "LEFT" : ((event.which == 2) ? "MIDDLE" : "RIGHT"); if(button == "LEFT" && CTRLdown)button = "MIDDLE"; else if(button == "LEFT" && SHIFTdown)button = "RIGHT"; return button; } function keyCapt(e, ff) { if(typeof window.event!="undefined") { e=window.event;//code for IE } if(e.type=="keydown") { if(e.keyCode==16) SHIFTdown = 1; else if(e.keyCode==17) CTRLdown = 1; else if(e.keyCode==13 && ff) { go(document.GTDactionform.command.value); return false; } } else if(e.type=="keyup") { if(e.keyCode==16) SHIFTdown = 0; else if(e.keyCode==17) CTRLdown = 0; } } function clear_list(obj, from) { ln = obj.options.length; for(var i=ln; i>=from; i--)obj.options[i] = null; } function click_itemlist(b, opt, idx) { if(b == "MIDDLE") document.GTDactionform.command.value = "= " + opt.text; else if(b == "RIGHT") { var _status = opt.text.charAt(0); var txt = opt.text.replace(/^[\.\?:;!]\s*(.*)\s*$/, '$1'); var newcmdpos = Status.indexOf(_status)+1; var newcmd = (Status.length > newcmdpos)? Status.charAt(newcmdpos)+' ' : ''; DATA[opt.value] = newcmd + txt; opt.text = newcmd + txt; setstyle(idx); } } function click_taglist(t, b) { if(b == "MIDDLE") with(document.GTDactionform.command) value = value + " " + t; // else if(b == "LEFT") go("? "+t); else if(b == "DOUBLE") go("? "+t); else if(b == "RIGHT")go("?"); } function click_list(obj, button) { var n = obj.name; var si = obj.selectedIndex; document.GTDactionform.command.focus(); if(si<0 || si>=obj.length) return false; if(n=='taglist') click_taglist(obj.options[si].text, button); else if(n=='itemlist') click_itemlist(button, obj.options[si], si); return false; } function extract_tags(t) { return t.match(/(^| )[\$@][-_\w\x80-\xfe\.:]+/g); } function track_tags(t, updatelist) { var x = extract_tags(t); var pTAGS = rTAGS; if(x) for(var j=0; j0) append_item(document.GTDactionform.taglist, _P[i], i); } } function go(command) { if(command.length==0)return false; var cmd = command.charAt(0); var txt = command.replace(/^[\+\?=\*%]\s*(.*)\s*$/, '$1'); if(cmd == "+" ) { txt += " "+AUTOAPPEND; prepend_item(txt, -1); track_tags(txt, 1); document.GTDactionform.command.value = ''; } else if(cmd == '=') { var O = document.GTDactionform.itemlist; if(O.selectedIndex<0||O.selectedIndex>=O.options.length) return false; var Oi = O.options[O.selectedIndex]; DATA[Oi.value] = txt; if(txt.length>0) {Oi.text = txt;setstyle(O.selectedIndex);} else O.options[O.selectedIndex] = null; document.GTDactionform.command.value = ''; track_tags(txt, 1); } else if(cmd == '*') { AUTOAPPEND = txt; alert(AutoAppendStr + " \""+AUTOAPPEND+"\"."); document.GTDactionform.command.value = ''; } else if(cmd == '?') { filter_items(txt); } else if(cmd == '%') { for(var i=0; i0 && snj.charAt(0) == c ) eval("document.GTDactionform.show_"+snj+".checked = "+chkd); } } go('?'); } document.GTDactionform.command.focus(); return false; } function prepend_item(t, v) { if(t.length == 0) return; var O = document.GTDactionform.itemlist.options; if(v==-1) v = DATA.length; DATA[v] = t; for(var i=O.length; i>0; i--) { O[i] = new Option(O[i-1].text, O[i-1].value); setstyle(i); } O[0] = new Option(t, v); setstyle(0); } function append_item(obj, t, v) { if(t.length == 0) return; var ln = obj.options.length; obj.options[ln] = new Option(t, v); if(obj == document.GTDactionform.itemlist) setstyle(ln); } function filter_items(keywords) { var a = keywords.split(/\s/); var yeah = new Array(); var nope = new Array(); for(var i=0; i1) nope[nope.length] = a[i].toLowerCase().substring(1); else yeah[yeah.length] = a[i].toLowerCase(); } var _F = new Array(); var fen; for(var i=0 ; i<=Status.length; i++) _F[i] = new Array(); for(var i=0 ; i=0) found = 1; if(found == 1) continue; _F[k+1][_F[k+1].length] = new Array(i, Di); } var tmp = _F[1]; _F[1] = _F[0]; _F[0] = tmp; clear_list(document.GTDactionform.itemlist, 0); for(var k=0; k0) { append_item(document.GTDactionform.itemlist, _F[k][i][1], _F[k][i][0]); } } } } function setstyle(idx) { var L = document.GTDactionform.itemlist; var Li = L.options[idx]; var _status = Li.text.charAt(0); var i = Status.indexOf(_status); Li.className = StatusNames[ (i==-1)? 5 : i ]; } function trim(tx) { return tx.replace(/^\s+/, '').replace(/\s+$/, ''); } function populate_itemlist(startup) { if(document.GTDdataform == undefined) return; rDATA = document.GTDdataform.rawdata.value; DATA = rDATA.split("\n").sort(); for(var i=0 ; i