Merge event handling from IMP.
authorJan Schneider <jan@horde.org>
Mon, 26 Jan 2009 15:46:19 +0000 (16:46 +0100)
committerJan Schneider <jan@horde.org>
Mon, 26 Jan 2009 15:48:32 +0000 (16:48 +0100)
kronolith/js/kronolith.js
kronolith/js/src/kronolith.js

index f381f83..5a9deb0 100644 (file)
@@ -1 +1 @@
-var frames={horde_main:true},KronolithCore={view:"",remove_gc:[],debug:function(A,B){if(!this.is_logout&&Kronolith.conf.debug){alert(A+": "+(B instanceof Error?B.name+"-"+B.message:Object.inspect(B)))}},setTitle:function(A){document.title=Kronolith.conf.name+" :: "+A},showNotifications:function(A){if(!A.size()||this.is_logout){return}A.find(function(D){switch(D.type){case"kronolith.timeout":this.logout(Kronolith.conf.timeout_url);return true;case"horde.error":case"horde.message":case"horde.success":case"horde.warning":case"kronolith.request":case"kronolith.sticky":var H,I,K,E,J,F,G=$("alerts"),B=new Element("DIV",{className:D.type.replace(".","-")}),C=D.message;if(!G){G=new Element("DIV",{id:"alerts"});$(document.body).insert(G)}if($w("kronolith.request kronolith.sticky").indexOf(D.type)==-1){C=C.unescapeHTML().unescapeHTML()}G.insert(B.update(C));if(Kronolith.conf.is_ie6){K=new Element("DIV",{className:"ie6alertsfix"}).clonePosition(B,{setLeft:false,setTop:false});H=K;K.insert(B.remove());G.insert(K)}else{H=B}I=Effect.Fade.bind(this,B,{duration:1.5,afterFinish:this.removeAlert.bind(this)});H.observe("click",I);if($w("horde.error kronolith.request kronolith.sticky").indexOf(D.type)==-1){I.delay(D.type=="horde.warning"?10:3)}if(D.type=="kronolith.request"){J=function(){I();document.stopObserving("click",J)};document.observe("click",J)}if(F=$("alertslog")){switch(D.type){case"horde.error":E=Kronolith.text.alog_error;break;case"horde.message":E=Kronolith.text.alog_message;break;case"horde.success":E=Kronolith.text.alog_success;break;case"horde.warning":E=Kronolith.text.alog_warning;break}if(E){F=F.down("DIV UL");if(F.down().hasClassName("noalerts")){F.down().remove()}F.insert(new Element("LI").insert(new Element("P",{className:"label"}).insert(E)).insert(new Element("P",{className:"indent"}).insert(C).insert(new Element("SPAN",{className:"alertdate"}).insert("["+(new Date).toLocaleString()+"]"))))}}}},this)},toggleAlertsLog:function(){var A=$("alertsloglink").down("A"),C=$("alertslog").down("DIV"),B={duration:0.5};if(C.visible()){Effect.BlindUp(C,B);A.update(Kronolith.text.showalog)}else{Effect.BlindDown(C,B);A.update(Kronolith.text.hidealog)}},removeAlert:function(C){try{var A=$(C.element),B=A.up();if(B&&B.parentNode){this.addGC(A.remove());if(!B.childElements().size()&&B.hasClassName("ie6alertsfix")){this.addGC(B.remove())}}}catch(D){this.debug("removeAlert",D)}},logout:function(A){this.is_logout=true;this.redirect(A||(Kronolith.conf.URI_IMP+"/LogOut"))},redirect:function(A){A=this.addSID(A);if(parent.frames.horde_main){parent.location=A}else{window.location=A}},addMouseEvents:function(A){this.DMenu.addElement(A.id,"ctx_"+A.type,A)},removeMouseEvents:function(A){this.DMenu.removeElement($(A).readAttribute("id"));this.addGC(A)},addPopdown:function(B,A){var C=$(B);C.insert({after:$($("popdown_img").cloneNode(false)).writeAttribute("id",B+"_img").show()});this.addMouseEvents({id:B+"_img",type:A,offset:C.up(),left:true})},addGC:function(A){this.remove_gc=this.remove_gc.concat(A)},clickObserveHandler:function(A){return A.d.observe("click",KronolithCore._clickFunc.curry(A))},_clickFunc:function(B,A){B.p?B.f(A):B.f();if(!B.ns){A.stop()}},addSID:function(A){if(!Kronolith.conf.SESSION_ID){return A}return this.addURLParam(A,Kronolith.conf.SESSION_ID.toQueryParams())},addURLParam:function(A,C){var B=A.indexOf("?");if(B!=-1){C=$H(A.toQueryParams()).merge(C).toObject();A=A.substring(0,B)}return A+"?"+Object.toQueryString(C)},go:function(A,D){var G,C,E;if(A.startsWith("compose:")){return}var B=A.split(":");var F=B.shift();switch(F){case"day":case"week":case"month":case"year":case"agenda":case"tasks":if(this.view==F){break}var H=F.capitalize();this._addHistory(A);["Day","Week","Month","Year","Tasks","Agenda"].each(function(I){$("kronolithNav"+I).removeClassName("on")});if(this.view){$("kronolithView"+this.view.capitalize()).fade()}if($("kronolithView"+H)){$("kronolithView"+H).appear()}$("kronolithNav"+H).addClassName("on");switch(F){case"day":case"week":case"month":case"year":$("kronolithMinical").select("td").each(function(I){I.removeClassName("kronolithSelected");if(B.length){if(!I.hasClassName("kronolithMinicalWeek")&&(F=="month"||(F=="day"&&I.readAttribute("date")==B[0]))){I.addClassName("kronolithSelected")}}});if(F=="week"&&B.length){$("kronolithMinical").select("td").each(function(J){if(J.readAttribute("date")==B[0]){var I=J.parentNode.childNodes;for(i=0;i<I.length;i++){if(I.item(i)!=J&&I.item(i).tagName=="TD"){$(I.item(i)).addClassName("kronolithSelected")}}throw $break}})}$("kronolithBody").select("div.kronolithEvent").each(function(I){KronolithCore.clickObserveHandler({d:I,f:$("kronolithEventForm").appear.bind($("kronolithEventForm"))});I.observe("mouseover",I.addClassName.curry("kronolithSelected"));I.observe("mouseout",I.removeClassName.curry("kronolithSelected"))});break}this.view=F;break;case"options":this._addHistory(F);KronolithCore.setTitle(Kronolith.text.prefs);this.iframeContent(F,Kronolith.conf.prefs_url);break}},_addHistory:function(B,A){if(Horde.dhtmlHistory.getCurrentLocation()!=B){Horde.dhtmlHistory.add(B,A)}},iframeContent:function(B,D){if(B===null){B=D}var A=$("dimpmain_portal"),C;if(!A){KronolithCore.showNotifications([{type:"horde.error",message:"Bad portal!"}]);return}C=new Element("IFRAME",{id:"iframe"+B,className:"iframe",frameBorder:0,src:D});this._resizeIE6Iframe(C);if(B=="options"){C.observe("load",function(){$("iframeoptions").contentWindow.document.getElementById("menu").style.display="none"})}A.insert(C)},_onMenuShow:function(A){var E,C,B,D;switch(A.ctx){case"ctx_folder":E=$("ctx_folder_create","ctx_folder_rename","ctx_folder_delete");C=KronolithCore.DMenu.element();if(C.readAttribute("mbox")=="INBOX"){E.invoke("hide")}else{if(Kronolith.conf.fixed_folders.indexOf(C.readAttribute("mbox"))!=-1){E.shift();E.invoke("hide")}else{E.invoke("show")}}if(C.hasAttribute("u")){$("ctx_folder_poll").hide();$("ctx_folder_nopoll").show()}else{$("ctx_folder_poll").show();$("ctx_folder_nopoll").hide()}break;case"ctx_message":[$("ctx_message_reply_list")].invoke(this.viewport.createSelection("domid",A.id).get("dataob").first().listmsg?"show":"hide");break;case"ctx_reply":D=this.viewport.getSelected();if(D.size()==1){B=D.get("dataob").first()}[$("ctx_reply_reply_list")].invoke(B&&B.listmsg?"show":"hide");break;case"ctx_otheractions":$("oa_seen","oa_unseen","oa_flagged","oa_clear","oa_sep1","oa_blacklist","oa_whitelist","oa_sep2").compact().invoke(this.viewport.getSelected().size()?"show":"hide");break}return true},_onResize:function(B,A){if(this.viewport){this.viewport.onResize(B,A)}this._resizeIE6()},updateTitle:function(){var B,A,C;if(this.viewport.isFiltering()){A=Kronolith.text.search+" :: "+this.viewport.getMetaData("total_rows")+" "+Kronolith.text.resfound}else{B=$(this.getFolderId(this.folder));if(B){C=B.readAttribute("u");A=B.readAttribute("l");if(C>0){A+=" ("+C+")"}}else{A=this.viewport.getMetaData("label")}}KronolithCore.setTitle(A)},_keydownHandler:function(D){if(D.findElement("FORM")||RedBox.overlayVisible()){return}var G,F,B,E,C,A=D.keyCode||D.charCode;switch(A){case Event.KEY_ESC:$("kronolithEventForm").fade({duration:0.5});break;case Event.KEY_DELETE:case Event.KEY_BACKSPACE:if(sel.size()==1){B=sel.get("dataob").first();if(D.shiftKey){this.moveSelected(B.rownum+((B.rownum==this.viewport.getMetaData("total_rows"))?-1:1),true)}this.flag("deleted",B)}else{this.flag("deleted")}D.stop();break;case Event.KEY_UP:case Event.KEY_DOWN:if(D.shiftKey&&this.lastrow!=-1){E=this.viewport.createSelection("rownum",this.lastrow+((A==Event.KEY_UP)?-1:1));if(E.size()){E=E.get("dataob").first();this.viewport.scrollTo(E.rownum);this.msgSelect(E.domid,{shift:true})}}else{this.moveSelected(A==Event.KEY_UP?-1:1)}D.stop();break;case Event.KEY_PAGEUP:case Event.KEY_PAGEDOWN:if(!D.ctrlKey&&!D.shiftKey&&!D.altKey&&!D.metaKey){F=this.viewport.getPageSize()-1;move=F*(A==Event.KEY_PAGEUP?-1:1);if(sel.size()==1){G=this.viewport.currentOffset();C=sel.get("rownum").first()-1;switch(A){case Event.KEY_PAGEUP:if(G!=C){move=G-C}break;case Event.KEY_PAGEDOWN:if((G+F)!=C){move=G+F-C}break}}this.moveSelected(move);D.stop()}break;case Event.KEY_HOME:case Event.KEY_END:this.moveSelected(A==Event.KEY_HOME?1:this.viewport.getMetaData("total_rows"),true);D.stop();break;case Event.KEY_RETURN:if(!D.element().match("input")){if(sel.size()==1){this.msgWindow(sel.get("dataob").first())}}D.stop();break;case 65:case 97:if(D.ctrlKey){this.selectAll();D.stop()}break}},_closeRedBox:function(){var A=RedBox.getWindowContents();KronolithCore.addGC([A,A.descendants()].flatten());RedBox.close()},_onLoad:function(){var B,D=KronolithCore.clickObserveHandler,A=KronolithCore.DMenu;if(Horde.dhtmlHistory.initialize()){Horde.dhtmlHistory.addListener(this.go.bind(this))}if(!Horde.dhtmlHistory.getCurrentLocation()){this.go(Kronolith.conf.login_view)}B=$("kronolithLogo");if(B.visible()){D({d:B.down("a"),f:this.go.bind(this,"portal")})}D({d:$("id_fullday"),f:function(){$("kronolithEventForm").select(".edit_at").each(Element.toggle)}});D({d:$("kronolithNewEvent"),f:KronolithCore.editEvent});$("kronolithEventActions").select("input.button").each(function(C){D({d:C,f:function(){Effect.Fade("kronolithEventForm")}})});$("kronolithEventForm").select("div.kronolithTags span").each(function(C){$("id_tags").value=$F("id_tags")+C.getText()+", "});["Day","Week","Month","Year","Tasks","Agenda"].each(function(C){D({d:$("kronolithNav"+C),f:KronolithCore.go.bind(KronolithCore,C.toLowerCase())})});$("kronolithMenu").select("div.kronolithCalendars div").each(function(C){D({d:C,f:KronolithCore.toggleCalendar.bind(KronolithCore,C)});C.observe("mouseover",C.addClassName.curry("kronolithCalOver"));C.observe("mouseout",C.removeClassName.curry("kronolithCalOver"))});D({d:$("kronolithMinicalDate"),f:KronolithCore.go.bind(KronolithCore,"month:"+$("kronolithMinicalDate").readAttribute("date"))});$("kronolithMinical").select("td").each(function(C){D({d:C,f:function(){if(C.hasClassName("kronolithMinicalWeek")){KronolithCore.go("week:"+C.readAttribute("date"))}else{if(!C.hasClassName("empty")){KronolithCore.go("day:"+C.readAttribute("date"))}}}})});$("kronolithViewMonth").select(".kronolithFirstCol").each(function(C){D({d:C,f:KronolithCore.go.bind(KronolithCore,"week")})});$("kronolithViewMonth").select(".kronolithDay").each(function(C){D({d:C,f:KronolithCore.go.bind(KronolithCore,"day")})});this._resizeIE6()},_resizeIE6:function(){var C=(($("kronolithViewMonth").getWidth()-20-2-2-16)/7)-2-2;$("kronolithViewMonth").select(".kronolithCol").invoke("setStyle",{width:C+"px"});var A=(($("kronolithViewMonth").getHeight()-25)/6)-2-2;$("kronolithViewMonth").select(".kronolithViewBody .kronolithCol").invoke("setStyle",{height:A+"px"});$("kronolithViewMonth").select(".kronolithViewBody .kronolithFirstCol").invoke("setStyle",{height:A+"px"});$("kronolithViewWeek").select(".kronolithCol").invoke("setStyle",{width:(C-1)+"px"});var B=$("kronolithViewDay").getWidth()-20-2-2-16-3;var C=((B+7)/7)-1;$("kronolithViewDay").select(".kronolithViewHead .kronolithCol").invoke("setStyle",{width:B+"px"});$("kronolithViewDay").select(".kronolithViewBody .kronolithCol").invoke("setStyle",{width:C+"px"});$("kronolithViewDay").select(".kronolithViewBody .kronolithAllDay .kronolithCol").invoke("setStyle",{width:B+"px"})},_resizeIE6Iframe:function(A){if(Kronolith.conf.is_ie6){A.setStyle({width:$("kronolithmain").getStyle("width"),height:(document.viewport.getHeight()-20)+"px"})}},editEvent:function(){$("kronolithEventForm").appear({duration:0.5})},toggleCalendar:function(A){if(A.hasClassName("on")){A.removeClassName("on")}else{A.addClassName("on")}}};if(typeof ContextSensitive!="undefined"){KronolithCore.DMenu=new ContextSensitive()}document.observe("dom:loaded",function(){try{if(parent.opener&&parent.opener.location.host==window.location.host&&parent.opener.KronolithCore){Kronolith.baseWindow=parent.opener.Kronolith.baseWindow||parent.opener}}catch(A){}new PeriodicalExecuter(function(){if(KronolithCore.remove_gc.size()){try{$A(KronolithCore.remove_gc.splice(0,75)).compact().invoke("stopObserving")}catch(B){KronolithCore.debug("remove_gc[].stopObserving",B)}}},10);KronolithCore._onLoad();document.observe("keydown",KronolithCore._keydownHandler.bind(KronolithCore));Event.observe(window,"resize",KronolithCore._onResize.bind(KronolithCore));if(Kronolith.conf.is_ie6){document.observe("selectstart",Event.stop);$("foobar").compact().invoke("select","LI").flatten().compact().each(function(B){B.observe("mouseover",B.addClassName.curry("over")).observe("mouseout",B.removeClassName.curry("over"))})}});Event.observe(window,"load",function(){KronolithCore.window_load=true});Element.addMethods({setText:function(B,C){var A=0;$A(B.childNodes).each(function(D){if(D.nodeType==3){if(A++){Element.remove(D)}else{D.nodeValue=C}}});if(!A){$(B).insert(C)}},getText:function(B,A){var C="";$A(B.childNodes).each(function(D){if(D.nodeType==3){C+=D.nodeValue}else{if(A&&D.hasChildNodes()){C+=$(D).getText(true)}}});return C}});Object.extend(Array.prototype,{numericSort:function(){return this.sort(function(B,A){if(B>A){return 1}else{if(B<A){return-1}}return 0})}});Object.extend(String.prototype,{evalScripts:function(){var re=/function\s+([^\s(]+)/g;this.extractScripts().each(function(s){var func;eval(s);while(func=re.exec(s)){window[func[1]]=eval(func[1])}})}});
\ No newline at end of file
+var frames={horde_main:true},KronolithCore={view:"",remove_gc:[],debug:function(A,B){if(!this.is_logout&&Kronolith.conf.debug){alert(A+": "+(B instanceof Error?B.name+"-"+B.message:Object.inspect(B)))}},setTitle:function(A){document.title=Kronolith.conf.name+" :: "+A},showNotifications:function(A){if(!A.size()||this.is_logout){return}A.find(function(B){switch(B.type){case"kronolith.timeout":this.logout(Kronolith.conf.timeout_url);return true;case"horde.error":case"horde.message":case"horde.success":case"horde.warning":case"kronolith.request":case"kronolith.sticky":var E,D,C,G=$("alerts"),H=new Element("DIV",{className:B.type.replace(".","-")}),F=B.message;if(!G){G=new Element("DIV",{id:"alerts"});$(document.body).insert(G)}if($w("kronolith.request kronolith.sticky").indexOf(B.type)==-1){F=F.unescapeHTML().unescapeHTML()}G.insert(H.update(F));if(Kronolith.conf.is_ie6){E=new Element("DIV",{id:"ie6alertsfix"}).clonePosition(H,{setLeft:false,setTop:false});E.insert(H.remove());G.insert(E)}if($w("horde.error kronolith.request kronolith.sticky").indexOf(B.type)==-1){this.alertsFade.bind(this,H).delay(B.type=="horde.warning"?10:3)}if(B.type=="kronolith.request"){this.alertrequest=H}if(C=$("alertslog")){switch(B.type){case"horde.error":D=Kronolith.text.alog_error;break;case"horde.message":D=Kronolith.text.alog_message;break;case"horde.success":D=Kronolith.text.alog_success;break;case"horde.warning":D=Kronolith.text.alog_warning;break}if(D){C=C.down("DIV UL");if(C.down().hasClassName("noalerts")){C.down().remove()}C.insert(new Element("LI").insert(new Element("P",{className:"label"}).insert(D)).insert(new Element("P",{className:"indent"}).insert(F).insert(new Element("SPAN",{className:"alertdate"}).insert("["+(new Date).toLocaleString()+"]"))))}}}},this)},alertsFade:function(A){if(A){Effect.Fade(A,{duration:1.5,afterFinish:this.removeAlert.bind(this)})}},toggleAlertsLog:function(){var A=$("alertsloglink").down("A"),C=$("alertslog").down("DIV"),B={duration:0.5};if(C.visible()){Effect.BlindUp(C,B);A.update(Kronolith.text.showalog)}else{Effect.BlindDown(C,B);A.update(Kronolith.text.hidealog)}},removeAlert:function(C){try{var A=$(C.element),B=A.up();A.remove();if(!B.childElements().size()&&B.readAttribute("id")=="ie6alertsfix"){B.remove()}}catch(D){this.debug("removeAlert",D)}},logout:function(A){this.is_logout=true;this.redirect(A||(Kronolith.conf.URI_IMP+"/LogOut"))},redirect:function(A){A=this.addSID(A);if(parent.frames.horde_main){parent.location=A}else{window.location=A}},addMouseEvents:function(A){this.DMenu.addElement(A.id,"ctx_"+A.type,A)},removeMouseEvents:function(A){this.DMenu.removeElement($(A).identify());this.addGC(A)},addPopdown:function(B,A){var C=$(B);C.insert({after:$($("popdown_img").cloneNode(false)).writeAttribute("id",B+"_img").show()});this.addMouseEvents({id:B+"_img",type:A,offset:C.up(),left:true})},addGC:function(A){this.remove_gc=this.remove_gc.concat(A)},addSID:function(A){if(!Kronolith.conf.SESSION_ID){return A}return this.addURLParam(A,Kronolith.conf.SESSION_ID.toQueryParams())},addURLParam:function(A,C){var B=A.indexOf("?");if(B!=-1){C=$H(A.toQueryParams()).merge(C).toObject();A=A.substring(0,B)}return A+"?"+Object.toQueryString(C)},go:function(A,D){var G,C,E;if(A.startsWith("compose:")){return}var B=A.split(":");var F=B.shift();switch(F){case"day":case"week":case"month":case"year":case"agenda":case"tasks":if(this.view==F){break}var H=F.capitalize();this._addHistory(A);["Day","Week","Month","Year","Tasks","Agenda"].each(function(I){$("kronolithNav"+I).removeClassName("on")});if(this.view){$("kronolithView"+this.view.capitalize()).fade()}if($("kronolithView"+H)){$("kronolithView"+H).appear()}$("kronolithNav"+H).addClassName("on");switch(F){case"day":case"week":case"month":case"year":$("kronolithMinical").select("td").each(function(I){I.removeClassName("kronolithSelected");if(B.length){if(!I.hasClassName("kronolithMinicalWeek")&&(F=="month"||(F=="day"&&I.readAttribute("date")==B[0]))){I.addClassName("kronolithSelected")}}});if(F=="week"&&B.length){$("kronolithMinical").select("td").each(function(J){if(J.readAttribute("date")==B[0]){var I=J.parentNode.childNodes;for(i=0;i<I.length;i++){if(I.item(i)!=J&&I.item(i).tagName=="TD"){$(I.item(i)).addClassName("kronolithSelected")}}throw $break}})}$("kronolithBody").select("div.kronolithEvent").each(function(I){I.observe("mouseover",I.addClassName.curry("kronolithSelected"));I.observe("mouseout",I.removeClassName.curry("kronolithSelected"))});break}this.view=F;break;case"options":this._addHistory(F);this.setTitle(Kronolith.text.prefs);this.iframeContent(F,Kronolith.conf.prefs_url);break}},_addHistory:function(B,A){if(Horde.dhtmlHistory.getCurrentLocation()!=B){Horde.dhtmlHistory.add(B,A)}},iframeContent:function(B,D){if(B===null){B=D}var A=$("dimpmain_portal"),C;if(!A){this.showNotifications([{type:"horde.error",message:"Bad portal!"}]);return}C=new Element("IFRAME",{id:"iframe"+B,className:"iframe",frameBorder:0,src:D});this._resizeIE6Iframe(C);if(B=="options"){C.observe("load",function(){$("iframeoptions").contentWindow.document.getElementById("menu").style.display="none"})}A.insert(C)},_onMenuShow:function(A){var E,C,B,D;switch(A.ctx){case"ctx_folder":E=$("ctx_folder_create","ctx_folder_rename","ctx_folder_delete");C=this.DMenu.element();if(C.readAttribute("mbox")=="INBOX"){E.invoke("hide")}else{if(Kronolith.conf.fixed_folders.indexOf(C.readAttribute("mbox"))!=-1){E.shift();E.invoke("hide")}else{E.invoke("show")}}if(C.hasAttribute("u")){$("ctx_folder_poll").hide();$("ctx_folder_nopoll").show()}else{$("ctx_folder_poll").show();$("ctx_folder_nopoll").hide()}break;case"ctx_message":[$("ctx_message_reply_list")].invoke(this.viewport.createSelection("domid",A.id).get("dataob").first().listmsg?"show":"hide");break;case"ctx_reply":D=this.viewport.getSelected();if(D.size()==1){B=D.get("dataob").first()}[$("ctx_reply_reply_list")].invoke(B&&B.listmsg?"show":"hide");break;case"ctx_otheractions":$("oa_seen","oa_unseen","oa_flagged","oa_clear","oa_sep1","oa_blacklist","oa_whitelist","oa_sep2").compact().invoke(this.viewport.getSelected().size()?"show":"hide");break}return true},_onResize:function(B,A){if(this.viewport){this.viewport.onResize(B,A)}this._resizeIE6()},updateTitle:function(){var B,A,C;if(this.viewport.isFiltering()){A=Kronolith.text.search+" :: "+this.viewport.getMetaData("total_rows")+" "+Kronolith.text.resfound}else{B=$(this.getFolderId(this.folder));if(B){C=B.readAttribute("u");A=B.readAttribute("l");if(C>0){A+=" ("+C+")"}}else{A=this.viewport.getMetaData("label")}}this.setTitle(A)},_keydownHandler:function(B){var A=B.keyCode||B.charCode;switch(A){case Event.KEY_ESC:$("kronolithEventForm").fade({duration:0.5});break}},_keyupHandler:function(A){},_clickHandler:function(D,C){if(D.isRightClick()){return}var A=D.element(),F=D.element(),E,B;if(this.alertrequest){this.alertsFade(this.alertrequest);this.alertrequest=null}while(Object.isElement(A)){E=A.readAttribute("id");switch(E){case"kronolithLogo":this.go("portal");D.stop();return;case"id_fullday":$("kronolithEventForm").select(".edit_at").each(Element.toggle);D.stop();return;case"kronolithNewEvent":this.editEvent();D.stop();return;case"kronolithEventActions":if(F.match("input.button")){$("kronolithEventForm").fade()}D.stop();return;case"kronolithNavDay":case"kronolithNavWeek":case"kronolithNavMonth":case"kronolithNavYear":case"kronolithNavTasks":case"kronolithNavAgenda":this.go(E.substring(12).toLowerCase());D.stop();return;case"kronolithMenu":if(F.match("div.kronolithCalendars div")){this.toggleCalendar(F)}D.stop();return;case"kronolithMinicalDate":this.go("month:"+$("kronolithMinicalDate").readAttribute("date"));D.stop();return;case"kronolithMinical":var B=F;if(B.tagName!="td"){B.up("td")}if(B){if(B.hasClassName("kronolithMinicalWeek")){this.go("week:"+B.readAttribute("date"))}else{if(!B.hasClassName("empty")){this.go("day:"+B.readAttribute("date"))}}}D.stop();return;case"kronolithViewMonth":if(F.hasClassName("kronolithFirstCol")){this.go("week")}else{if(F.hasClassName("kronolithDay")){this.go("day")}}D.stop();return;case"kronolithBody":var B=F;if(!B.match("div.kronolithEvent")){B=B.up("div.kronolithEvent")}if(B){$("kronolithEventForm").appear()}D.stop();return;case"alertsloglink":this.toggleAlertsLog();break;case"alerts":this.alertsFade(A);break}A=A.up()}},_mouseHandler:function(B,A){},_closeRedBox:function(){RedBox.close()},_onLoad:function(){var A,B=this.clickObserveHandler;if(Horde.dhtmlHistory.initialize()){Horde.dhtmlHistory.addListener(this.go.bind(this))}if(!Horde.dhtmlHistory.getCurrentLocation()){this.go(Kronolith.conf.login_view)}$("kronolithEventForm").select("div.kronolithTags span").each(function(C){$("id_tags").value=$F("id_tags")+C.getText()+", "});$("kronolithMenu").select("div.kronolithCalendars div").each(function(C){C.observe("mouseover",C.addClassName.curry("kronolithCalOver"));C.observe("mouseout",C.removeClassName.curry("kronolithCalOver"))});this._resizeIE6()},_resizeIE6:function(){var C=(($("kronolithViewMonth").getWidth()-20-2-2-16)/7)-2-2;$("kronolithViewMonth").select(".kronolithCol").invoke("setStyle",{width:C+"px"});var A=(($("kronolithViewMonth").getHeight()-25)/6)-2-2;$("kronolithViewMonth").select(".kronolithViewBody .kronolithCol").invoke("setStyle",{height:A+"px"});$("kronolithViewMonth").select(".kronolithViewBody .kronolithFirstCol").invoke("setStyle",{height:A+"px"});$("kronolithViewWeek").select(".kronolithCol").invoke("setStyle",{width:(C-1)+"px"});var B=$("kronolithViewDay").getWidth()-20-2-2-16-3;var C=((B+7)/7)-1;$("kronolithViewDay").select(".kronolithViewHead .kronolithCol").invoke("setStyle",{width:B+"px"});$("kronolithViewDay").select(".kronolithViewBody .kronolithCol").invoke("setStyle",{width:C+"px"});$("kronolithViewDay").select(".kronolithViewBody .kronolithAllDay .kronolithCol").invoke("setStyle",{width:B+"px"})},_resizeIE6Iframe:function(A){if(Kronolith.conf.is_ie6){A.setStyle({width:$("kronolithmain").getStyle("width"),height:(document.viewport.getHeight()-20)+"px"})}},editEvent:function(){$("kronolithEventForm").appear({duration:0.5})},toggleCalendar:function(A){if(A.hasClassName("on")){A.removeClassName("on")}else{A.addClassName("on")}}};if(typeof ContextSensitive!="undefined"){KronolithCore.DMenu=new ContextSensitive()}document.observe("dom:loaded",function(){try{if(parent.opener&&parent.opener.location.host==window.location.host&&parent.opener.KronolithCore){Kronolith.baseWindow=parent.opener.Kronolith.baseWindow||parent.opener}}catch(A){}new PeriodicalExecuter(function(){if(KronolithCore.remove_gc.size()){try{$A(KronolithCore.remove_gc.splice(0,75)).compact().invoke("stopObserving")}catch(B){KronolithCore.debug("remove_gc[].stopObserving",B)}}},10);KronolithCore._onLoad();document.observe("keydown",KronolithCore._keydownHandler.bindAsEventListener(KronolithCore));document.observe("keyup",KronolithCore._keyupHandler.bindAsEventListener(KronolithCore));document.observe("click",KronolithCore._clickHandler.bindAsEventListener(KronolithCore));document.observe("dblclick",KronolithCore._clickHandler.bindAsEventListener(KronolithCore,true));document.observe("mouseover",KronolithCore._mouseHandler.bindAsEventListener(KronolithCore,"over"));Event.observe(window,"resize",KronolithCore._onResize.bind(KronolithCore));if(Kronolith.conf.is_ie6){document.observe("selectstart",Event.stop);$("foobar").compact().invoke("select","LI").flatten().compact().each(function(B){B.observe("mouseover",B.addClassName.curry("over")).observe("mouseout",B.removeClassName.curry("over"))})}});Event.observe(window,"load",function(){KronolithCore.window_load=true});Element.addMethods({setText:function(B,C){var A=0;$A(B.childNodes).each(function(D){if(D.nodeType==3){if(A++){Element.remove(D)}else{D.nodeValue=C}}});if(!A){$(B).insert(C)}},getText:function(B,A){var C="";$A(B.childNodes).each(function(D){if(D.nodeType==3){C+=D.nodeValue}else{if(A&&D.hasChildNodes()){C+=$(D).getText(true)}}});return C}});Object.extend(Array.prototype,{numericSort:function(){return this.sort(function(B,A){if(B>A){return 1}else{if(B<A){return-1}}return 0})}});Object.extend(String.prototype,{evalScripts:function(){var re=/function\s+([^\s(]+)/g;this.extractScripts().each(function(s){var func;eval(s);while(func=re.exec(s)){window[func[1]]=eval(func[1])}})}});
\ No newline at end of file
index d050939..b15e056 100644 (file)
@@ -51,10 +51,10 @@ KronolithCore = {
             case 'horde.warning':
             case 'kronolith.request':
             case 'kronolith.sticky':
-                var clickdiv, fadeeffect, iefix, log, requestfunc, tmp,
+                var iefix, log, tmp,
                     alerts = $('alerts'),
                     div = new Element('DIV', { className: m.type.replace('.', '-') }),
-                    msg = m.message;;
+                    msg = m.message;
 
                 if (!alerts) {
                     alerts = new Element('DIV', { id: 'alerts' });
@@ -76,28 +76,17 @@ KronolithCore = {
                 // overlay the div with a like sized div containing a clear
                 // gif, which tricks IE into the correct behavior.
                 if (Kronolith.conf.is_ie6) {
-                    iefix = new Element('DIV', { className: 'ie6alertsfix' }).clonePosition(div, { setLeft: false, setTop: false });
-                    clickdiv = iefix;
+                    iefix = new Element('DIV', { id: 'ie6alertsfix' }).clonePosition(div, { setLeft: false, setTop: false });
                     iefix.insert(div.remove());
                     alerts.insert(iefix);
-                } else {
-                    clickdiv = div;
                 }
 
-                fadeeffect = Effect.Fade.bind(this, div, { duration: 1.5, afterFinish: this.removeAlert.bind(this) });
-
-                clickdiv.observe('click', fadeeffect);
-
                 if ($w('horde.error kronolith.request kronolith.sticky').indexOf(m.type) == -1) {
-                    fadeeffect.delay(m.type == 'horde.warning' ? 10 : 3);
+                    this.alertsFade.bind(this, div).delay(m.type == 'horde.warning' ? 10 : 3);
                 }
 
                 if (m.type == 'kronolith.request') {
-                    requestfunc = function() {
-                        fadeeffect();
-                        document.stopObserving('click', requestfunc)
-                    };
-                    document.observe('click', requestfunc);
+                    this.alertrequest = div;
                 }
 
                 if (tmp = $('alertslog')) {
@@ -131,6 +120,13 @@ KronolithCore = {
         }, this);
     },
 
+    alertsFade: function(elt)
+    {
+        if (elt) {
+            Effect.Fade(elt, { duration: 1.5, afterFinish: this.removeAlert.bind(this) });
+        }
+    },
+
     toggleAlertsLog: function()
     {
         var alink = $('alertsloglink').down('A'),
@@ -150,15 +146,11 @@ KronolithCore = {
         try {
             var elt = $(effect.element),
                 parent = elt.up();
-            // We may have already removed this element from the DOM tree
-            // (if the user clicked on the notification), so check parentNode
-            // here - will return null if node is not part of DOM tree.
-            if (parent && parent.parentNode) {
-                this.addGC(elt.remove());
-                if (!parent.childElements().size() &&
-                    parent.hasClassName('ie6alertsfix')) {
-                    this.addGC(parent.remove());
-                }
+
+            elt.remove();
+            if (!parent.childElements().size() &&
+                parent.readAttribute('id') == 'ie6alertsfix') {
+                parent.remove();
             }
         } catch (e) {
             this.debug('removeAlert', e);
@@ -197,7 +189,7 @@ KronolithCore = {
     /* elt = DOM element */
     removeMouseEvents: function(elt)
     {
-        this.DMenu.removeElement($(elt).readAttribute('id'));
+        this.DMenu.removeElement($(elt).identify());
         this.addGC(elt);
     },
 
@@ -215,25 +207,6 @@ KronolithCore = {
         this.remove_gc = this.remove_gc.concat(elt);
     },
 
-    // o: (object) Contains the following items:
-    //    'd'  - (required) The DOM element
-    //    'f'  - (required) The function to bind to the click event
-    //    'ns' - (optional) If set, don't stop the event's propogation
-    //    'p'  - (optional) If set, passes in the event object to the called
-    //                      function
-    clickObserveHandler: function(o)
-    {
-        return o.d.observe('click', KronolithCore._clickFunc.curry(o));
-    },
-
-    _clickFunc: function(o, e)
-    {
-        o.p ? o.f(e) : o.f();
-        if (!o.ns) {
-            e.stop();
-        }
-    },
-
     addSID: function(url)
     {
         if (!Kronolith.conf.SESSION_ID) {
@@ -339,7 +312,6 @@ KronolithCore = {
                     });
                 }
                 $('kronolithBody').select('div.kronolithEvent').each(function(s) {
-                    KronolithCore.clickObserveHandler({ d: s, f: $('kronolithEventForm').appear.bind($('kronolithEventForm')) });
                     s.observe('mouseover', s.addClassName.curry('kronolithSelected'));
                     s.observe('mouseout', s.removeClassName.curry('kronolithSelected'));
                 });
@@ -353,7 +325,7 @@ KronolithCore = {
         case 'options':
             //this.highlightSidebar('appoptions');
             this._addHistory(loc);
-            KronolithCore.setTitle(Kronolith.text.prefs);
+            this.setTitle(Kronolith.text.prefs);
             this.iframeContent(loc, Kronolith.conf.prefs_url);
             break;
         }
@@ -374,7 +346,7 @@ KronolithCore = {
 
         var container = $('dimpmain_portal'), iframe;
         if (!container) {
-            KronolithCore.showNotifications([ { type: 'horde.error', message: 'Bad portal!' } ]);
+            this.showNotifications([ { type: 'horde.error', message: 'Bad portal!' } ]);
             return;
         }
 
@@ -388,6 +360,7 @@ KronolithCore = {
 
         container.insert(iframe);
     },
+
     _onMenuShow: function(ctx)
     {
         var elts, folder, ob, sel;
@@ -395,7 +368,7 @@ KronolithCore = {
         switch (ctx.ctx) {
         case 'ctx_folder':
             elts = $('ctx_folder_create', 'ctx_folder_rename', 'ctx_folder_delete');
-            folder = KronolithCore.DMenu.element();
+            folder = this.DMenu.element();
             if (folder.readAttribute('mbox') == 'INBOX') {
                 elts.invoke('hide');
             } else if (Kronolith.conf.fixed_folders.indexOf(folder.readAttribute('mbox')) != -1) {
@@ -458,121 +431,164 @@ KronolithCore = {
                 label = this.viewport.getMetaData('label');
             }
         }
-        KronolithCore.setTitle(label);
+        this.setTitle(label);
     },
 
     /* Keydown event handler */
     _keydownHandler: function(e)
     {
-        // Only catch keyboard shortcuts in message list view. Disable catching
-        // when in form elements or the RedBox overlay is visible.
-        if (e.findElement('FORM') ||
-            RedBox.overlayVisible()) {
-            return;
-        }
-
-        var co, ps, r, row, rowoff,
-            kc = e.keyCode || e.charCode;
+        var kc = e.keyCode || e.charCode;
 
         switch (kc) {
         case Event.KEY_ESC:
             $('kronolithEventForm').fade({ duration: 0.5 });
             break;
+        }
+    },
 
-        case Event.KEY_DELETE:
-        case Event.KEY_BACKSPACE:
-            if (sel.size() == 1) {
-                r = sel.get('dataob').first();
-                if (e.shiftKey) {
-                    this.moveSelected(r.rownum + ((r.rownum == this.viewport.getMetaData('total_rows')) ? -1 : 1), true);
+    _keyupHandler: function(e)
+    {
+        /*
+        if (e.element().readAttribute('id') == 'foo') {
+        }
+        */
+    },
+
+    _clickHandler: function(e, dblclick)
+    {
+        if (e.isRightClick()) {
+            return;
+        }
+
+        var elt = e.element(),
+            orig = e.element(),
+            id, tmp;
+
+        if (this.alertrequest) {
+            this.alertsFade(this.alertrequest);
+            this.alertrequest = null;
+        }
+
+        while (Object.isElement(elt)) {
+            id = elt.readAttribute('id');
+
+            switch (id) {
+            case 'kronolithLogo':
+                this.go('portal');
+                e.stop();
+                return;
+
+            case 'id_fullday':
+                $('kronolithEventForm').select('.edit_at').each(Element.toggle); 
+                e.stop();
+                return;
+
+            case 'kronolithNewEvent':
+                this.editEvent();
+                e.stop();
+                return;
+
+            case 'kronolithEventActions':
+                if (orig.match('input.button')) {
+                   $('kronolithEventForm').fade();
                 }
-                this.flag('deleted', r);
-            } else {
-                this.flag('deleted');
-            }
-            e.stop();
-            break;
+                e.stop();
+                return;
+
+            case 'kronolithNavDay':
+            case 'kronolithNavWeek':
+            case 'kronolithNavMonth':
+            case 'kronolithNavYear':
+            case 'kronolithNavTasks':
+            case 'kronolithNavAgenda':
+                this.go(id.substring(12).toLowerCase());
+                e.stop();
+                return;
 
-        case Event.KEY_UP:
-        case Event.KEY_DOWN:
-            if (e.shiftKey && this.lastrow != -1) {
-                row = this.viewport.createSelection('rownum', this.lastrow + ((kc == Event.KEY_UP) ? -1 : 1));
-                if (row.size()) {
-                    row = row.get('dataob').first();
-                    this.viewport.scrollTo(row.rownum);
-                    this.msgSelect(row.domid, { shift: true });
+            case 'kronolithMenu':
+                if (orig.match('div.kronolithCalendars div')) {
+                    this.toggleCalendar(orig);
                 }
-            } else {
-                this.moveSelected(kc == Event.KEY_UP ? -1 : 1);
-            }
-            e.stop();
-            break;
+                e.stop();
+                return;
 
-        case Event.KEY_PAGEUP:
-        case Event.KEY_PAGEDOWN:
-            if (!e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey) {
-                ps = this.viewport.getPageSize() - 1;
-                move = ps * (kc == Event.KEY_PAGEUP ? -1 : 1);
-                if (sel.size() == 1) {
-                    co = this.viewport.currentOffset();
-                    rowoff = sel.get('rownum').first() - 1;
-                    switch (kc) {
-                    case Event.KEY_PAGEUP:
-                        if (co != rowoff) {
-                            move = co - rowoff;
-                        }
-                        break;
+            case 'kronolithMinicalDate':
+                this.go('month:' + $('kronolithMinicalDate').readAttribute('date'));
+                e.stop();
+                return;
 
-                    case Event.KEY_PAGEDOWN:
-                        if ((co + ps) != rowoff) {
-                            move = co + ps - rowoff;
-                        }
-                        break;
-                    }
+            case 'kronolithMinical':
+                var tmp = orig;
+                if (tmp.tagName != 'td') {
+                    tmp.up('td');
+                }
+                if (tmp) {
+                    if (tmp.hasClassName('kronolithMinicalWeek')) {
+                       this.go('week:' + tmp.readAttribute('date'));
+                   } else if (!tmp.hasClassName('empty')) {
+                       this.go('day:' + tmp.readAttribute('date'));
+                   }
                 }
-                this.moveSelected(move);
                 e.stop();
-            }
-            break;
+                return;
 
-        case Event.KEY_HOME:
-        case Event.KEY_END:
-            this.moveSelected(kc == Event.KEY_HOME ? 1 : this.viewport.getMetaData('total_rows'), true);
-            e.stop();
-            break;
+            case 'kronolithViewMonth':
+                if (orig.hasClassName('kronolithFirstCol')) {
+                    this.go('week');
+                } else if (orig.hasClassName('kronolithDay')) {
+                    this.go('day');
+                }
+                e.stop();
+                return;
 
-        case Event.KEY_RETURN:
-            if (!e.element().match('input')) {
-                // Popup message window if single message is selected.
-                if (sel.size() == 1) {
-                    this.msgWindow(sel.get('dataob').first());
+            case 'kronolithBody':
+                var tmp = orig;
+                if (!tmp.match('div.kronolithEvent')) {
+                    tmp = tmp.up('div.kronolithEvent');
                 }
+                if (tmp) {
+                     $('kronolithEventForm').appear();
+                }
+                e.stop();
+                return;
+
+            case 'alertsloglink':
+                this.toggleAlertsLog();
+                break;
+
+            case 'alerts':
+                this.alertsFade(elt);
+                break;
             }
-            e.stop();
-            break;
 
-        case 65: // A
-        case 97: // a
-            if (e.ctrlKey) {
-                this.selectAll();
-                e.stop();
+            elt = elt.up();
+        }
+    },
+
+    _mouseHandler: function(e, type)
+    {
+        /*
+        var elt = e.element();
+
+        switch (type) {
+        case 'over':
+            if (DragDrop.Drags.drag && elt.hasClassName('exp')) {
+                this._toggleSubFolder(elt.up(), 'exp');
             }
             break;
         }
+        */
     },
 
     _closeRedBox: function()
     {
-        var c = RedBox.getWindowContents();
-        KronolithCore.addGC([ c, c.descendants() ].flatten());
         RedBox.close();
     },
 
     /* Onload function. */
     _onLoad: function() {
         var tmp,
-             C = KronolithCore.clickObserveHandler,
-             dmenu = KronolithCore.DMenu;
+             C = this.clickObserveHandler;
 
         if (Horde.dhtmlHistory.initialize()) {
             Horde.dhtmlHistory.addListener(this.go.bind(this));
@@ -587,168 +603,22 @@ KronolithCore = {
 
         /* Add popdown menus. */
         /*
-        KronolithCore.addPopdown('button_reply', 'reply');
-        dmenu.disable('button_reply_img', true, true);
-        KronolithCore.addPopdown('button_forward', 'forward');
-        dmenu.disable('button_forward_img', true, true);
-        KronolithCore.addPopdown('button_other', 'otheractions');
+        this.addPopdown('button_reply', 'reply');
+        this.DMenu.disable('button_reply_img', true, true);
+        this.addPopdown('button_forward', 'forward');
+        this.DMenu.disable('button_forward_img', true, true);
+        this.addPopdown('button_other', 'otheractions');
         */
 
-        /* Set up click event observers for elements on main page. */
-        tmp = $('kronolithLogo');
-        if (tmp.visible()) {
-            C({ d: tmp.down('a'), f: this.go.bind(this, 'portal') });
-        }
-
-        C({ d: $('id_fullday'), f: function() { $('kronolithEventForm').select('.edit_at').each(Element.toggle); } });
-
-        C({ d: $('kronolithNewEvent'), f: KronolithCore.editEvent });
-
-        $('kronolithEventActions').select('input.button').each(function(s) {
-           C({ d: s, f: function() { Effect.Fade('kronolithEventForm');} });
-        });
-
         $('kronolithEventForm').select('div.kronolithTags span').each(function(s) {
            $('id_tags').value = $F('id_tags') + s.getText() + ', ';
         });
 
-        [ 'Day', 'Week', 'Month', 'Year', 'Tasks', 'Agenda' ].each(function(a) {
-            C({ d: $('kronolithNav' + a), f: KronolithCore.go.bind(KronolithCore, a.toLowerCase()) });
-        });
-
         $('kronolithMenu').select('div.kronolithCalendars div').each(function(s) {
-            C({ d: s, f: KronolithCore.toggleCalendar.bind(KronolithCore, s) });
             s.observe('mouseover', s.addClassName.curry('kronolithCalOver'));
             s.observe('mouseout', s.removeClassName.curry('kronolithCalOver'));
         });
 
-        C({ d: $('kronolithMinicalDate'), f: KronolithCore.go.bind(KronolithCore, 'month:' + $('kronolithMinicalDate').readAttribute('date')) });
-        $('kronolithMinical').select('td').each(function(td) {
-            C({ d: td, f: function() {
-                if (td.hasClassName('kronolithMinicalWeek')) {
-                   KronolithCore.go('week:' + td.readAttribute('date'));
-               } else if (!td.hasClassName('empty')) {
-                   KronolithCore.go('day:' + td.readAttribute('date'));
-               }
-            }});
-        });
-
-        /* Set up click event observers for elements on month view. */
-        $('kronolithViewMonth').select('.kronolithFirstCol').each(function(l) {
-            C({ d: l, f: KronolithCore.go.bind(KronolithCore, 'week') });
-        });
-        $('kronolithViewMonth').select('.kronolithDay').each(function(l) {
-            C({ d: l, f: KronolithCore.go.bind(KronolithCore, 'day') });
-        });
-
-        /*
-        C({ d: $('composelink'), f: KronolithCore.compose.bind(KronolithCore, 'new') });
-        C({ d: $('checkmaillink'), f: this.pollFolders.bind(this) });
-
-        [ 'portal', 'options' ].each(function(a) {
-            var d = $('app' + a);
-            if (d) {
-                C({ d: d, f: this.go.bind(this, a) });
-            }
-        }, this);
-        tmp = $('applogout');
-        if (tmp) {
-            C({ d: tmp, f: function() { $('applogout').down('A').update('[' + KronolithText.onlogout + ']'); KronolithCore.logout(); } });
-        }
-
-        tmp = $('applicationfolders');
-        if (tmp) {
-            tmp.select('li.custom a').each(function(s) {
-                C({ d: s, f: this.go.bind(this, 'app:' + s.readAttribute('app')) });
-            }, this);
-        }
-
-        C({ d: $('newfolder'), f: this.createBaseFolder.bind(this) });
-        new Drop('dropbase', this._folderDropConfig);
-        tmp = $('hometab');
-        if (tmp) {
-            C({ d: tmp, f: this.go.bind(this, 'portal') });
-        }
-        $('tabbar').select('a.applicationtab').each(function(a) {
-            C({ d: a, f: this.go.bind(this, 'app:' + a.readAttribute('app')) });
-        }, this);
-        C({ d: $('button_reply'), f: this.composeMailbox.bind(this, 'reply'), ns: true });
-        C({ d: $('button_forward'), f: this.composeMailbox.bind(this, Kronolith.conf.forward_default), ns: true });
-        [ 'spam', 'ham', 'deleted' ].each(function(a) {
-            var d = $('button_' + a);
-            if (d) {
-                C({ d: d, f: this.flag.bind(this, a) });
-            }
-        }, this);
-        C({ d: $('button_compose').down('A'), f: KronolithCore.compose.bind(KronolithCore, 'new') });
-        C({ d: $('button_other'), f: function(e) { dmenu.trigger(e.findElement('A').next(), true); }, p: true });
-        C({ d: $('qoptions').down('.qclose a'), f: this.searchfilterClear.bind(this, false) });
-        [ 'all', 'current' ].each(function(a) {
-            var d = $('sf_' + a);
-            if (d) {
-                C({ d: d, f: this.updateSearchfilter.bind(this, a, 'folder') });
-            }
-        }, this);
-        [ 'msgall', 'from', 'to', 'subject' ].each(function(a) {
-            C({ d: $('sf_' + a), f: this.updateSearchfilter.bind(this, a, 'msg') });
-        }, this);
-        C({ d: $('msglistHeader'), f: this.sort.bind(this), p: true });
-        C({ d: $('ctx_folder_create'), f: function() { this.createSubFolder(dmenu.element()); }.bind(this), ns: true });
-        C({ d: $('ctx_folder_rename'), f: function() { this.renameFolder(dmenu.element()); }.bind(this), ns: true });
-        C({ d: $('ctx_folder_empty'), f: function() { var mbox = dmenu.element().readAttribute('mbox'); dmenu.close(true); if (window.confirm(Kronolith.text.empty_folder)) { KronolithCore.doAction('EmptyFolder', { folder: mbox }, null, this._emptyFolderCallback.bind(this)); } }.bind(this), ns: true });
-        C({ d: $('ctx_folder_delete'), f: function() { var mbox = dmenu.element().readAttribute('mbox'); dmenu.close(true); if (window.confirm(Kronolith.text.delete_folder)) { KronolithCore.doAction('DeleteFolder', { folder: mbox }, null, this.bcache.get('folderC') || this.bcache.set('folderC', this._folderCallback.bind(this))); } }.bind(this), ns: true });
-        [ 'ctx_folder_seen', 'ctx_folder_unseen' ].each(function(a) {
-            C({ d: $(a), f: function(type) { this.flag(type, null, dmenu.element().readAttribute('mbox')); }.bind(this, a == 'ctx_folder_seen' ? 'allSeen' : 'allUnseen'), ns: true });
-        }, this);
-        [ 'ctx_folder_poll', 'ctx_folder_nopoll' ].each(function(a) {
-            C({ d: $(a), f: function(modify) { this.modifyPollFolder(dmenu.element().readAttribute('mbox'), modify); }.bind(this, a == 'ctx_folder_poll'), ns: true });
-        }, this);
-        C({ d: $('ctx_container_create'), f: function() { this.createSubFolder(dmenu.element()); }.bind(this), ns: true });
-        C({ d: $('ctx_container_rename'), f: function() { this.renameFolder(dmenu.element()); }.bind(this), ns: true });
-        [ 'reply', 'reply_all', 'reply_list', 'forward_all', 'forward_body', 'forward_attachments' ].each(function(a) {
-            C({ d: $('ctx_message_' + a), f: this.composeMailbox.bind(this, a), ns: true });
-        }, this);
-        [ 'seen', 'unseen', 'flagged', 'clear', 'spam', 'ham', 'blacklist', 'whitelist', 'deleted', 'undeleted' ].each(function(a) {
-            var d = $('ctx_message_' + a);
-            if (d) {
-                C({ d: d, f: this.flag.bind(this, a), ns: true });
-            }
-        }, this);
-        C({ d: $('ctx_draft_resume'), f: this.composeMailbox.bind(this, 'resume') });
-        [ 'flagged', 'clear', 'deleted', 'undeleted' ].each(function(a) {
-            var d = $('ctx_draft_' + a);
-            if (d) {
-                C({ d: d, f: this.flag.bind(this, a), ns: true });
-            }
-        }, this);
-        [ 'reply', 'reply_all', 'reply_list' ].each(function(a) {
-            C({ d: $('ctx_reply_' + a), f: this.composeMailbox.bind(this, a), ns: true });
-        }, this);
-        [ 'forward_all', 'forward_body', 'forward_attachments' ].each(function(a) {
-            C({ d: $('ctx_forward_' + a), f: this.composeMailbox.bind(this, a), ns: true });
-        }, this);
-        C({ d: $('previewtoggle'), f: this.togglePreviewPane.bind(this), ns: true });
-        [ 'seen', 'unseen', 'flagged', 'clear', 'blacklist', 'whitelist' ].each(function(a) {
-            var d = $('oa_' + a);
-            if (d) {
-                C({ d: d, f: this.flag.bind(this, a), ns: true });
-            }
-        }, this);
-        C({ d: $('oa_selectall'), f: this.selectAll.bind(this), ns: true });
-
-        tmp = $('oa_purge_deleted');
-        if (tmp) {
-            C({ d: tmp, f: this.purgeDeleted.bind(this), ns: true });
-        }
-
-        $('toggleHeaders').select('A').each(function(a) {
-            C({ d: a, f: function() { [ a.up().select('A'), $('msgHeadersColl', 'msgHeaders') ].flatten().invoke('toggle'); }, ns: true });
-        });
-        $('msg_newwin', 'msg_newwin_options').compact().each(function(a) {
-            C({ d: a, f: function() { this.msgWindow(this.viewport.getViewportSelection().search({ imapuid: { equal: [ Kronolith.conf.msg_index ] } , view: { equal: [ Kronolith.conf.msg_folder ] } }).get('dataob').first()); }.bind(this) });
-        }, this);
-        */
-
         this._resizeIE6();
     },
 
@@ -855,7 +725,13 @@ document.observe('dom:loaded', function() {
     KronolithCore._onLoad();
 
     /* Bind key shortcuts. */
-    document.observe('keydown', KronolithCore._keydownHandler.bind(KronolithCore));
+    document.observe('keydown', KronolithCore._keydownHandler.bindAsEventListener(KronolithCore));
+    document.observe('keyup', KronolithCore._keyupHandler.bindAsEventListener(KronolithCore));
+
+    /* Bind mouse clicks. */
+    document.observe('click', KronolithCore._clickHandler.bindAsEventListener(KronolithCore));
+    document.observe('dblclick', KronolithCore._clickHandler.bindAsEventListener(KronolithCore, true));
+    document.observe('mouseover', KronolithCore._mouseHandler.bindAsEventListener(KronolithCore, 'over'));
 
     /* Resize elements on window size change. */
     Event.observe(window, 'resize', KronolithCore._onResize.bind(KronolithCore));