From: Michael M Slusarz Date: Mon, 8 Dec 2008 01:58:24 +0000 (-0700) Subject: Use application/json as JSON return-type. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=e39bb21040bd0c16acec817e5b01a276a5cb8197;p=horde.git Use application/json as JSON return-type. Allows auto-eval of JSON code into responseJSON. --- diff --git a/imp/js/ContextSensitive.js b/imp/js/ContextSensitive.js index 2dbe02014..c97338643 100644 --- a/imp/js/ContextSensitive.js +++ b/imp/js/ContextSensitive.js @@ -1 +1 @@ -var ContextSensitive=Class.create({initialize:function(){this.current=this.target=null;this.elements=$H();document.observe("contextmenu",this.rightClickHandler.bindAsEventListener(this));document.observe("click",this.leftClickHandler.bindAsEventListener(this));document.observe(Prototype.Browser.Gecko?"DOMMouseScroll":"mousescroll",this.close.bind(this))},addElement:function(D,C,A){var B=Boolean(A.left);if(D&&!this.validElement(D,B)){this.elements.set(D+Number(B),new ContextSensitive.Element(D,C,A))}},removeElement:function(A){this.elements.unset(A+"0");this.elements.unset(A+"1")},close:function(A){if(this.current){if(A){this.current.hide()}else{Effect.Fade(this.current,{duration:0.2})}this.current=this.target=null}},element:function(){return this.target},currentmenu:function(){if(this.current&&this.current.visible()){return this.current}},validElement:function(B,A){return this.elements.get(B+Number(Boolean(A)))},disable:function(D,C,A){var B=this.validElement(D,C);if(B){B.disable=A}},leftClickHandler:function(A){if(A.isRightClick()){return}this.rightClickHandler(A,true)},rightClickHandler:function(B,A){if(this.trigger(B.element(),A,B.pointerX(),B.pointerY())){B.stop()}},trigger:function(F,E,H,G){var J,B,D,C,K,I,A;[F].concat(F.ancestors()).find(function(L){J=this.validElement(L.id,E);return J},this);if(!J||J.disable){this.close();return false}B=$(J.ctx);if(!B){this.close();return false}else{if(E&&B==this.current){return false}}this.current=B;this.target=$(J.id);D=J.opts.offset;if(!D&&(Object.isUndefined(H)||Object.isUndefined(G))){D=F.id}D=$(D);if(D){C=D.viewportOffset();A=document.viewport.getScrollOffsets();H=C[0]+A.left;G=C[1]+D.getHeight()+A.top}I=document.viewport.getDimensions();K=B.getDimensions();if((G+K.height)>I.height){G=I.height-K.height-10}if((H+K.width)>I.width){H=I.width-K.width-10}if(J.opts.onShow){J.opts.onShow(J)}Effect.Appear(B.setStyle({left:H+"px",top:G+"px"}),{duration:0.2});return true}});ContextSensitive.Element=Class.create({initialize:function(C,B,A){this.id=C;this.ctx=B;this.opts=A;this.opts.left=Boolean(A.left);this.disable=false}}); \ No newline at end of file +var ContextSensitive=Class.create({initialize:function(){this.current=this.target=null;this.elements=$H();document.observe("contextmenu",this.rightClickHandler.bindAsEventListener(this));document.observe("click",this.leftClickHandler.bindAsEventListener(this));document.observe(Prototype.Browser.Gecko?"DOMMouseScroll":"mousescroll",this.close.bind(this))},addElement:function(d,c,a){var b=Boolean(a.left);if(d&&!this.validElement(d,b)){this.elements.set(d+Number(b),new ContextSensitive.Element(d,c,a))}},removeElement:function(a){this.elements.unset(a+"0");this.elements.unset(a+"1")},close:function(a){if(this.current){if(a){this.current.hide()}else{Effect.Fade(this.current,{duration:0.2})}this.current=this.target=null}},element:function(){return this.target},currentmenu:function(){if(this.current&&this.current.visible()){return this.current}},validElement:function(b,a){return this.elements.get(b+Number(Boolean(a)))},disable:function(d,c,a){var b=this.validElement(d,c);if(b){b.disable=a}},leftClickHandler:function(a){if(a.isRightClick()){return}this.rightClickHandler(a,true)},rightClickHandler:function(b,a){if(this.trigger(b.element(),a,b.pointerX(),b.pointerY())){b.stop()}},trigger:function(f,e,h,g){var j,b,d,c,k,i,a;[f].concat(f.ancestors()).find(function(l){j=this.validElement(l.id,e);return j},this);if(!j||j.disable){this.close();return false}b=$(j.ctx);if(!b){this.close();return false}else{if(e&&b==this.current){return false}}this.current=b;this.target=$(j.id);d=j.opts.offset;if(!d&&(Object.isUndefined(h)||Object.isUndefined(g))){d=f.id}d=$(d);if(d){c=d.viewportOffset();a=document.viewport.getScrollOffsets();h=c[0]+a.left;g=c[1]+d.getHeight()+a.top}i=document.viewport.getDimensions();k=b.getDimensions();if((g+k.height)>i.height){g=i.height-k.height-10}if((h+k.width)>i.width){h=i.width-k.width-10}if(j.opts.onShow){j.opts.onShow(j)}Effect.Appear(b.setStyle({left:h+"px",top:g+"px"}),{duration:0.2});return true}});ContextSensitive.Element=Class.create({initialize:function(c,b,a){this.id=c;this.ctx=b;this.opts=a;this.opts.left=Boolean(a.left);this.disable=false}}); \ No newline at end of file diff --git a/imp/js/DimpCore.js b/imp/js/DimpCore.js index 6710dc6b8..d6ebe0ead 100644 --- a/imp/js/DimpCore.js +++ b/imp/js/DimpCore.js @@ -1 +1 @@ -var frames={horde_main:true},DimpCore={acount:0,remove_gc:[],server_error:0,view_id:1,buttons:["button_reply","button_forward","button_spam","button_ham","button_deleted"],debug:function(A,B){if(!this.is_logout&&DIMP.conf.debug){alert(A+": "+(B instanceof Error?B.name+"-"+B.message:Object.inspect(B)))}},toRangeString:function(A){var B="";$H(A).each(function(F){if(!F.value.size()){return}var D=F.value.numericSort(),E=last=D.shift(),C=[];D.each(function(G){if(last+1==G){last=G}else{C.push(E+(last==E?"":(":"+last)));E=last=G}});C.push(E+(last==E?"":(":"+last)));B+="{"+F.key.length+"}"+F.key+C.join(",")});return B},parseRangeString:function(G){var E,B,C,F,A={},D=[];G=G.strip();while(!G.blank()){if(!G.startsWith("{")){break}C=G.indexOf("}");E=parseInt(G.substr(1,C-1));F=G.substr(C+1,E);C+=E+1;B=G.indexOf("{",C);if(B==-1){uidstr=G.substr(C);G=""}else{uidstr=G.substr(C,B-C);G=G.substr(B)}uidstr.split(",").each(function(I){var H=I.split(":");if(H.size()==1){D.push(parseInt(I,10))}else{D=D.concat($A($R(parseInt(H[0],10),parseInt(H[1],10))))}});A[F]=D}return A},doAction:function(D,E,C,F,B){var A={};if(!this.doActionOpts){this.doActionOpts={onException:function(G,H){this.debug("onException",H)}.bind(this),onFailure:function(G,H){this.debug("onFailure",G)}.bind(this)}}B=Object.extend(this.doActionOpts,B||{});E=$H(E);D=D.startsWith("*")?D.substring(1):DIMP.conf.URI_IMP+"/"+D;if(C){if(C.viewport_selection){C.get("dataob").each(function(G){if(!A[G.view]){A[G.view]=[]}A[G.view].push(G.imapuid)});C=A}E.set("uid",DimpCore.toRangeString(C))}if(DIMP.conf.SESSION_ID){E.update(DIMP.conf.SESSION_ID.toQueryParams())}B.parameters=E.toQueryString();B.onComplete=function(G,H){this.doActionComplete(G,F)}.bind(this);new Ajax.Request(D,B)},doActionComplete:function(C,E){this.inAjaxCallback=true;var A=false,B={};if(!C.responseText||!C.responseText.length){A=true}else{try{B=C.responseText.evalJSON(true)}catch(D){this.debug("doActionComplete",D);A=true}}if(!B.msgs){B.msgs=[]}if(A){if(++this.server_error==3){this.showNotifications([{type:"horde.error",message:DIMP.text.ajax_timeout}])}this.inAjaxCallback=false;return}if(B.response&&Object.isFunction(E)){if(DIMP.conf.debug){E(B)}else{try{E(B)}catch(D){}}}if(this.server_error>=3){B.msgs.push({type:"horde.success",message:DIMP.text.ajax_recover})}this.server_error=0;if(!B.msgs_noauto){this.showNotifications(B.msgs)}if(this.onDoActionComplete){this.onDoActionComplete(B)}this.inAjaxCallback=false},setTitle:function(A){document.title=DIMP.conf.name+" :: "+A},showNotifications:function(A){if(!A.size()||this.is_logout){return}A.find(function(D){switch(D.type){case"dimp.timeout":this.is_logout=true;this.redirect(DIMP.conf.timeout_url);return true;case"horde.error":case"horde.message":case"horde.success":case"horde.warning":case"imp.reply":case"imp.forward":case"imp.redirect":case"dimp.request":case"dimp.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("dimp.request dimp.sticky").indexOf(D.type)==-1){C=C.unescapeHTML().unescapeHTML()}G.insert(B.update(C));if(DIMP.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 dimp.request dimp.sticky").indexOf(D.type)==-1){I.delay(D.type=="horde.warning"?10:3)}if(D.type=="dimp.request"){J=function(){I();document.stopObserving("click",J)};document.observe("click",J)}if(F=$("alertslog")){switch(D.type){case"horde.error":E=DIMP.text.alog_error;break;case"horde.message":E=DIMP.text.alog_message;break;case"horde.success":E=DIMP.text.alog_success;break;case"horde.warning":E=DIMP.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(DIMP.text.showalog)}else{Effect.BlindDown(C,B);A.update(DIMP.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)}},compose:function(C,B){var A=DIMP.conf.compose_url;B=B||{};if(C){B.type=C}this.popupWindow(this.addURLParam(A,B),"compose"+new Date().getTime())},popupWindow:function(B,A){if(!(window.open(B,A.replace(/\W/g,"_"),"width="+DIMP.conf.popup_width+",height="+DIMP.conf.popup_height+",status=1,scrollbars=yes,resizable=yes"))){this.showNotifications([{type:"horde.warning",message:DIMP.text.popup_block}])}},closePopup:function(){if(this.inAjaxCallback){this.closePopup.bind(this).defer()}else{window.close()}},logout:function(){this.is_logout=true;this.redirect(DIMP.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})},buildAddressLinks:function(D,A){var E,C,B=D.size();if(B>15){C=$("largeaddrspan").cloneNode(true);A.insert(C);E=C.down(".dispaddrlist");C=C.down();this.clickObserveHandler({d:C,f:function(F){[F.down(),F.down(1),F.next()].invoke("toggle")}.curry(C)});C=C.down();C.setText(C.getText().replace("%d",B))}else{E=A}D.each(function(H,G){var F;if(H.raw){F=H.raw}else{F=new Element("A",{className:"address",id:"addr"+this.acount++,personal:H.personal,email:H.inner,address:H.address}).insert(H.display?H.display:H.address);F.observe("mouseover",function(){F.stopObserving("mouseover");this.addMouseEvents({id:F.id,type:"contacts",offset:F,left:true})}.bind(this))}E.insert(F);if(G+1!=B){E.insert(", ")}},this);return A},removeAddressLinks:function(A){[A.select(".address"),A.select(".largeaddrtoggle")].flatten().compact().each(this.removeMouseEvents.bind(this))},messageOnLoad:function(){var B=this.clickObserveHandler,A;if($("partlist")){B({d:$("partlist_col").up(),f:function(){$("partlist","partlist_col","partlist_exp").invoke("toggle")}})}if(A=$("msg_print")){B({d:A,f:function(){window.print()}})}if(A=$("msg_view_source")){B({d:A,f:function(){view(DimpCore.addSID(DIMP.conf.URI_VIEW)+"&index="+DIMP.conf.msg_index+"&mailbox="+DIMP.conf.msg_folder,DIMP.conf.msg_index+"|"+DIMP.conf.msg_folder)}})}B({d:$("ctx_contacts_new"),f:function(){this.compose("new",{to:this.DMenu.element().readAttribute("address")})}.bind(this),ns:true});B({d:$("ctx_contacts_add"),f:function(){this.doAction("AddContact",{name:this.DMenu.element().readAttribute("personal"),email:this.DMenu.element().readAttribute("email")},null,true)}.bind(this),ns:true});if($("alertslog")){B({d:$("alertsloglink"),f:this.toggleAlertsLog.bind(this)})}},addGC:function(A){this.remove_gc=this.remove_gc.concat(A)},clickObserveHandler:function(A){return A.d.observe("click",DimpCore._clickFunc.curry(A))},_clickFunc:function(B,A){B.p?B.f(A):B.f();if(!B.ns){A.stop()}},addSID:function(A){if(!DIMP.conf.SESSION_ID){return A}return this.addURLParam(A,DIMP.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)},reloadMessage:function(A){if(typeof DimpFullmessage!="undefined"){window.location=this.addURLParam(document.location.href,A)}else{DimpBase.loadPreview(null,A)}}};if(typeof ContextSensitive!="undefined"){DimpCore.DMenu=new ContextSensitive()}document.observe("dom:loaded",function(){try{if(parent.opener&&parent.opener.location.host==window.location.host&&parent.opener.DimpCore){DIMP.baseWindow=parent.opener.DIMP.baseWindow||parent.opener}}catch(A){}if(!DIMP.conf.spam_reporting){DimpCore.buttons=DimpCore.buttons.without("button_spam")}if(!DIMP.conf.ham_reporting){DimpCore.buttons=DimpCore.buttons.without("button_ham")}new PeriodicalExecuter(function(){if(DimpCore.remove_gc.size()){try{$A(DimpCore.remove_gc.splice(0,75)).compact().invoke("stopObserving")}catch(B){DimpCore.debug("remove_gc[].stopObserving",B)}}},10)});Event.observe(window,"load",function(){DimpCore.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=3){a.msgs.push({type:"horde.success",message:DIMP.text.ajax_recover})}this.server_error=0;if(!a.msgs_noauto){this.showNotifications(a.msgs)}if(this.onDoActionComplete){this.onDoActionComplete(a)}this.inAjaxCallback=false},setTitle:function(a){document.title=DIMP.conf.name+" :: "+a},showNotifications:function(a){if(!a.size()||this.is_logout){return}a.find(function(d){switch(d.type){case"dimp.timeout":this.is_logout=true;this.redirect(DIMP.conf.timeout_url);return true;case"horde.error":case"horde.message":case"horde.success":case"horde.warning":case"imp.reply":case"imp.forward":case"imp.redirect":case"dimp.request":case"dimp.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("dimp.request dimp.sticky").indexOf(d.type)==-1){c=c.unescapeHTML().unescapeHTML()}g.insert(b.update(c));if(DIMP.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 dimp.request dimp.sticky").indexOf(d.type)==-1){i.delay(d.type=="horde.warning"?10:3)}if(d.type=="dimp.request"){j=function(){i();document.stopObserving("click",j)};document.observe("click",j)}if(f=$("alertslog")){switch(d.type){case"horde.error":e=DIMP.text.alog_error;break;case"horde.message":e=DIMP.text.alog_message;break;case"horde.success":e=DIMP.text.alog_success;break;case"horde.warning":e=DIMP.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(DIMP.text.showalog)}else{Effect.BlindDown(c,b);a.update(DIMP.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)}},compose:function(c,b){var a=DIMP.conf.compose_url;b=b||{};if(c){b.type=c}this.popupWindow(this.addURLParam(a,b),"compose"+new Date().getTime())},popupWindow:function(b,a){if(!(window.open(b,a.replace(/\W/g,"_"),"width="+DIMP.conf.popup_width+",height="+DIMP.conf.popup_height+",status=1,scrollbars=yes,resizable=yes"))){this.showNotifications([{type:"horde.warning",message:DIMP.text.popup_block}])}},closePopup:function(){if(this.inAjaxCallback){this.closePopup.bind(this).defer()}else{window.close()}},logout:function(){this.is_logout=true;this.redirect(DIMP.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})},buildAddressLinks:function(d,a){var e,c,b=d.size();if(b>15){c=$("largeaddrspan").cloneNode(true);a.insert(c);e=c.down(".dispaddrlist");c=c.down();this.clickObserveHandler({d:c,f:function(f){[f.down(),f.down(1),f.next()].invoke("toggle")}.curry(c)});c=c.down();c.setText(c.getText().replace("%d",b))}else{e=a}d.each(function(h,g){var f;if(h.raw){f=h.raw}else{f=new Element("A",{className:"address",id:"addr"+this.acount++,personal:h.personal,email:h.inner,address:h.address}).insert(h.display?h.display:h.address);f.observe("mouseover",function(){f.stopObserving("mouseover");this.addMouseEvents({id:f.id,type:"contacts",offset:f,left:true})}.bind(this))}e.insert(f);if(g+1!=b){e.insert(", ")}},this);return a},removeAddressLinks:function(a){[a.select(".address"),a.select(".largeaddrtoggle")].flatten().compact().each(this.removeMouseEvents.bind(this))},messageOnLoad:function(){var b=this.clickObserveHandler,a;if($("partlist")){b({d:$("partlist_col").up(),f:function(){$("partlist","partlist_col","partlist_exp").invoke("toggle")}})}if(a=$("msg_print")){b({d:a,f:function(){window.print()}})}if(a=$("msg_view_source")){b({d:a,f:function(){view(DimpCore.addSID(DIMP.conf.URI_VIEW)+"&index="+DIMP.conf.msg_index+"&mailbox="+DIMP.conf.msg_folder,DIMP.conf.msg_index+"|"+DIMP.conf.msg_folder)}})}b({d:$("ctx_contacts_new"),f:function(){this.compose("new",{to:this.DMenu.element().readAttribute("address")})}.bind(this),ns:true});b({d:$("ctx_contacts_add"),f:function(){this.doAction("AddContact",{name:this.DMenu.element().readAttribute("personal"),email:this.DMenu.element().readAttribute("email")},null,true)}.bind(this),ns:true});if($("alertslog")){b({d:$("alertsloglink"),f:this.toggleAlertsLog.bind(this)})}},addGC:function(a){this.remove_gc=this.remove_gc.concat(a)},clickObserveHandler:function(a){return a.d.observe("click",DimpCore._clickFunc.curry(a))},_clickFunc:function(b,a){b.p?b.f(a):b.f();if(!b.ns){a.stop()}},addSID:function(a){if(!DIMP.conf.SESSION_ID){return a}return this.addURLParam(a,DIMP.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)},reloadMessage:function(a){if(typeof DimpFullmessage!="undefined"){window.location=this.addURLParam(document.location.href,a)}else{DimpBase.loadPreview(null,a)}}};if(typeof ContextSensitive!="undefined"){DimpCore.DMenu=new ContextSensitive()}document.observe("dom:loaded",function(){try{if(parent.opener&&parent.opener.location.host==window.location.host&&parent.opener.DimpCore){DIMP.baseWindow=parent.opener.DIMP.baseWindow||parent.opener}}catch(a){}if(!DIMP.conf.spam_reporting){DimpCore.buttons=DimpCore.buttons.without("button_spam")}if(!DIMP.conf.ham_reporting){DimpCore.buttons=DimpCore.buttons.without("button_ham")}new PeriodicalExecuter(function(){if(DimpCore.remove_gc.size()){try{$A(DimpCore.remove_gc.splice(0,75)).compact().invoke("stopObserving")}catch(b){DimpCore.debug("remove_gc[].stopObserving",b)}}},10)});Event.observe(window,"load",function(){DimpCore.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(d,c){if(d>c){return 1}else{if(d0)&&(this.element.getStyle("position")=="absolute")){this.element.insert({after:''});this.iefix=$(this.element.id+"_iefix")}if(this.iefix){setTimeout(this.fixIEOverlapping.bind(this),50)}},fixIEOverlapping:function(){this.iefix.clonePosition(this.element).setStyle({zIndex:1}).show();this.element.setStyle({zIndex:2})},hide:function(){this.active=false;this.stopIndicator();if(this.element.visible()){this.options.onHide(this.element)}if(this.iefix){this.iefix.hide()}},startIndicator:function(){if(this.options.indicator){$(this.options.indicator).show()}},stopIndicator:function(){if(this.options.indicator){$(this.options.indicator).hide()}},onKeyPress:function(A){if(!this.active){return}switch(A.keyCode){case Event.KEY_TAB:case Event.KEY_RETURN:this.selectEntry();A.stop();case Event.KEY_ESC:this.hide();this.active=false;A.stop();return;case Event.KEY_LEFT:case Event.KEY_RIGHT:return;case Event.KEY_UP:this.markPrevious();this.render();A.stop();return;case Event.KEY_DOWN:this.markNext();this.render();A.stop();return}},onHover:function(C){var B=C.findElement("LI"),A=parseInt(B.readAttribute("autocompleteIndex"));if(this.index!=A){this.index=A;this.render()}C.stop()},onClick:function(B){var A=B.findElement("LI");this.index=parseInt(A.readAttribute("autocompleteIndex"));this.selectEntry();this.hide();B.stop()},onBlur:function(){setTimeout(this.hide.bind(this),250);this.active=false},render:function(){if(this.entryCount>0){for(var A=0;A0){this.index--}else{this.index=this.entryCount-1}},markNext:function(){if(this.index0)&&(this.element.getStyle("position")=="absolute")){this.element.insert({after:''});this.iefix=$(this.element.id+"_iefix")}if(this.iefix){setTimeout(this.fixIEOverlapping.bind(this),50)}},fixIEOverlapping:function(){this.iefix.clonePosition(this.element).setStyle({zIndex:1}).show();this.element.setStyle({zIndex:2})},hide:function(){this.active=false;this.stopIndicator();if(this.element.visible()){this.options.onHide(this.element)}if(this.iefix){this.iefix.hide()}},startIndicator:function(){if(this.options.indicator){$(this.options.indicator).show()}},stopIndicator:function(){if(this.options.indicator){$(this.options.indicator).hide()}},onKeyPress:function(a){if(!this.active){return}switch(a.keyCode){case Event.KEY_TAB:case Event.KEY_RETURN:this.selectEntry();a.stop();case Event.KEY_ESC:this.hide();this.active=false;a.stop();return;case Event.KEY_LEFT:case Event.KEY_RIGHT:return;case Event.KEY_UP:this.markPrevious();this.render();a.stop();return;case Event.KEY_DOWN:this.markNext();this.render();a.stop();return}},onHover:function(c){var b=c.findElement("LI"),a=parseInt(b.readAttribute("autocompleteIndex"));if(this.index!=a){this.index=a;this.render()}c.stop()},onClick:function(b){var a=b.findElement("LI");this.index=parseInt(a.readAttribute("autocompleteIndex"));this.selectEntry();this.hide();b.stop()},onBlur:function(){setTimeout(this.hide.bind(this),250);this.active=false},render:function(){if(this.entryCount>0){for(var a=0;a0){this.index--}else{this.index=this.entryCount-1}},markNext:function(){if(this.index'+J+"";E=E.replace(H,D);if(this.htmlAreaParent){E=E.replace(new RegExp("(<[^>]*)"+RegExp.escape(D)+"([^>]*>)","g"),"$1"+J+"$2")}},this);if(!this.reviewDiv){this.reviewDiv=new Element("div",{className:G.readAttribute("className")+" spellcheck"}).setStyle({overflow:"auto"});if(this.resumeOnDblClick){this.reviewDiv.observe("dblclick",this.resume.bind(this))}}F=G.getDimensions();this.reviewDiv.setStyle({width:F.width+"px",height:F.height+"px"});if(!this.htmlAreaParent){E=E.replace(/~~~/g,"
")}this.reviewDiv.update(E);this.reviewDiv.select('span[name="incorrect"]').invoke("observe","click",this.showSuggestions.bindAsEventListener(this));this.reviewDiv.select("A").invoke("observe","click",Event.stop);if(this.htmlAreaParent){Element.hide(this.htmlArea);$(this.htmlAreaParent).insert({bottom:this.reviewDiv})}else{G.hide().insert({before:this.reviewDiv})}this.status("ResumeEdit")},showSuggestions:function(D){var E,A=D.element(),B=new Element("UL");try{E=A.viewportOffset()}catch(C){E=[D.pointerX(),D.pointerY()]}this.removeChoices();this.choicesDiv=new Element("DIV",{className:"autocomplete"}).setStyle({left:E[0]+"px",top:(E[1]+16)+"px"}).hide();this.curWord=A;$A(this.suggestions[this.curWord.readAttribute("index")]).each(function(F){B.insert({bottom:new Element("LI").update(F)})});this.choicesDiv.insert({bottom:B});this.choices=new KeyNavList(this.choicesDiv,{onChoose:function(F){this.replaceWord(F,this.curWord)}.bind(this)}).show();$(document.body).insert(this.choicesDiv)},replaceWord:function(A,B){B.update(A.innerHTML).writeAttribute({className:"corrected"});this.removeChoices()},removeChoices:function(){if(this.choicesDiv){this.choicesDiv.remove();this.choicesDiv=null}},resume:function(){this.removeChoices();if(!this.reviewDiv){return}var A=$(this.target),B;this.reviewDiv.select('span[name="incorrect"]').each(function(C){C.replace(C.innerHTML)});this.reviewDiv.select("A").invoke("stopObserving","click");B=this.reviewDiv.innerHTML;if(!this.htmlAreaParent){B=B.replace(/
/gi,"~~~").unescapeHTML().replace(/~~~/g,"\n")}A.value=B;A.disabled=false;if(this.resumeOnDblClick){this.reviewDiv.stopObserving("dblclick")}this.reviewDiv.remove();this.reviewDiv=null;this.status("CheckSpelling");if(this.htmlAreaParent){Element.show(this.htmlArea)}else{A.show()}if(this.onAfterSpellCheck){this.onAfterSpellCheck()}},status:function(A){if(!this.statusButton){return}this.state=A;switch(this.statusButton.tagName){case"INPUT":this.statusButton.value=this.buttonStates[A];break;case"A":this.statusButton.update(this.buttonStates[A]);break}this.statusButton.className=this.statusClass+" "+A},isActive:function(){return(this.reviewDiv)}}); \ No newline at end of file +var SpellChecker=Class.create({options:{},resumeOnDblClick:true,state:"CheckSpelling",initialize:function(a,f,c,j,b,h){var g,i,e;this.url=a;this.target=f;this.statusButton=$(c);this.buttonStates=j;this.statusClass=h||"";this.statusButton.observe("click",this.process.bindAsEventListener(this));this.options.onComplete=this.onComplete.bind(this);if(b){g=new Element("DIV",{className:"autocomplete",id:"spellcheckpopdown"}).setStyle({position:"absolute"}).hide();e=new Element("UL");$H(b).each(function(d){e.insert({bottom:new Element("LI",{lc:d.key}).update(d.value)})});g.insert({bottom:e});this.localeChoices=new KeyNavList(g,{onChoose:this.setLocale.bindAsEventListener(this)});i=new Element("A",{className:"popdown"}).insert(" ").observe("click",function(){$("spellcheckpopdown").clonePosition(this.statusButton,{setHeight:false,setWidth:false,offsetTop:this.statusButton.getHeight()});this.localeChoices.show()}.bind(this));this.statusButton.insert({after:i});$(document.body).insert(g)}document.observe("click",this.onClick.bindAsEventListener(this));this.status("CheckSpelling")},setLocale:function(a){this.locale=a.readAttribute("lc")},targetValue:function(){var a=$(this.target);return(Object.isUndefined(a.value))?a.innerHTML:a.value},process:function(a){switch(this.state){case"CheckSpelling":this.spellCheck();break;case"ResumeEdit":this.resume();break}a.stop()},spellCheck:function(){if(this.onBeforeSpellCheck){this.onBeforeSpellCheck()}var b=Object.clone(this.options),c=$H(),a=this.url;this.status("Checking");this.removeChoices();c.set(this.target,this.targetValue());b.parameters=c.toQueryString();if(this.locale){a+="/locale="+this.locale}if(this.htmlAreaParent){a+="/html=1"}new Ajax.Request(a,b)},onClick:function(b){if(this.localeChoices){this.localeChoices.hide()}if(!this.choicesDiv){return true}var a=b.findElement("SPAN");if(a&&a==this.curWord){return true}this.removeChoices();this.curWord=null},onComplete:function(b){var a,f,g,j,e,c=0,h=$(this.target),k=b.responseJSON;this.removeChoices();if(Object.isUndefined(k)){this.resume();this.status("Error");return}a=k.bad||[];this.suggestions=k.suggestions||[];f=this.targetValue();if(this.htmlAreaParent){f=f.replace(/\r?\n/g,"")}else{f=f.replace(/\r?\n/g,"~~~").escapeHTML()}$A(a).each(function(d){j=new RegExp("(?:^|\\b)"+RegExp.escape(d)+"(?:\\b|$)","g");e=''+d+"";f=f.replace(j,e);if(this.htmlAreaParent){f=f.replace(new RegExp("(<[^>]*)"+RegExp.escape(e)+"([^>]*>)","g"),"$1"+d+"$2")}},this);if(!this.reviewDiv){this.reviewDiv=new Element("div",{className:h.readAttribute("className")+" spellcheck"}).setStyle({overflow:"auto"});if(this.resumeOnDblClick){this.reviewDiv.observe("dblclick",this.resume.bind(this))}}g=h.getDimensions();this.reviewDiv.setStyle({width:g.width+"px",height:g.height+"px"});if(!this.htmlAreaParent){f=f.replace(/~~~/g,"
")}this.reviewDiv.update(f);this.reviewDiv.select('span[name="incorrect"]').invoke("observe","click",this.showSuggestions.bindAsEventListener(this));this.reviewDiv.select("A").invoke("observe","click",Event.stop);if(this.htmlAreaParent){Element.hide(this.htmlArea);$(this.htmlAreaParent).insert({bottom:this.reviewDiv})}else{h.hide().insert({before:this.reviewDiv})}this.status("ResumeEdit")},showSuggestions:function(d){var f,a=d.element(),b=new Element("UL");try{f=a.viewportOffset()}catch(c){f=[d.pointerX(),d.pointerY()]}this.removeChoices();this.choicesDiv=new Element("DIV",{className:"autocomplete"}).setStyle({left:f[0]+"px",top:(f[1]+16)+"px"}).hide();this.curWord=a;$A(this.suggestions[this.curWord.readAttribute("index")]).each(function(e){b.insert({bottom:new Element("LI").update(e)})});this.choicesDiv.insert({bottom:b});this.choices=new KeyNavList(this.choicesDiv,{onChoose:function(e){this.replaceWord(e,this.curWord)}.bind(this)}).show();$(document.body).insert(this.choicesDiv)},replaceWord:function(a,b){b.update(a.innerHTML).writeAttribute({className:"corrected"});this.removeChoices()},removeChoices:function(){if(this.choicesDiv){this.choicesDiv.remove();this.choicesDiv=null}},resume:function(){this.removeChoices();if(!this.reviewDiv){return}var a=$(this.target),b;this.reviewDiv.select('span[name="incorrect"]').each(function(c){c.replace(c.innerHTML)});this.reviewDiv.select("A").invoke("stopObserving","click");b=this.reviewDiv.innerHTML;if(!this.htmlAreaParent){b=b.replace(/
/gi,"~~~").unescapeHTML().replace(/~~~/g,"\n")}a.value=b;a.disabled=false;if(this.resumeOnDblClick){this.reviewDiv.stopObserving("dblclick")}this.reviewDiv.remove();this.reviewDiv=null;this.status("CheckSpelling");if(this.htmlAreaParent){Element.show(this.htmlArea)}else{a.show()}if(this.onAfterSpellCheck){this.onAfterSpellCheck()}},status:function(a){if(!this.statusButton){return}this.state=a;switch(this.statusButton.tagName){case"INPUT":this.statusButton.value=this.buttonStates[a];break;case"A":this.statusButton.update(this.buttonStates[a]);break}this.statusButton.className=this.statusClass+" "+a},isActive:function(){return(this.reviewDiv)}}); \ No newline at end of file diff --git a/imp/js/ViewPort.js b/imp/js/ViewPort.js index 755bc9993..6a3773173 100644 --- a/imp/js/ViewPort.js +++ b/imp/js/ViewPort.js @@ -1 +1 @@ -var ViewPort=Class.create({initialize:function(A){A.content=$(A.content_container);A.empty=A.empty_container?$(A.empty_container):null;A.error=A.error_container?$(A.error_container):null;this.opts=A;this.scroller=new ViewPort_Scroller(this);this.template=new Template(A.template);this.current_req_lookup=$H();this.current_req=$H();this.fetch_hash=$H();this.slice_hash=$H();this.views=$H();this.showSplitPane(A.show_split_pane);this.isbusy=this.line_height=this.page_size=this.splitbar=this.splitbar_loc=this.uc_run=this.view=this.viewport_init=null;this.request_num=1},loadView:function(F,D,I,C){var E,H,G,B={},A;this._clearWait();if(this.page_size===null){A=this.getPageSize(this.show_split_pane?"default":"max");if(isNaN(A)){this.loadView.bind(this,F,D,I,C).defer();return}this.page_size=A}E=this._getBuffer();if(E){if(!C&&this.view){this.views.set(this.view,{buffer:E,offset:this.currentOffset()})}H=this.views.get(F)}else{G=true}if(C){B={background:true,view:F}}else{this.view=F;if(!this.viewport_init){this.viewport_init=1;this._renderViewport()}}if(H){this.setMetaData("additional_params",$H(D),F);this._updateContent(H.offset,B);if(!C){if(this.opts.onComplete){this.opts.onComplete()}this.opts.ajaxRequest(this.opts.fetch_action,this.addRequestParams({checkcache:1,rownum:this.currentOffset()+1}))}return true}else{if(!G){if(this.opts.onClearRows){this.opts.onClearRows(this.opts.content.childElements())}this.opts.content.update();this.scroller.clear()}}E=this._getBuffer(null,true);this.views.set(F,{buffer:E,offset:0});this.setMetaData({additional_params:$H(D)},F);if(I){B.search=I}else{B.offset=0}this._fetchBuffer(B);return false},deleteView:function(A){this.views.unset(A)},scrollTo:function(A,C){var B=this.scroller;B.noupdate=C;switch(this.isVisible(A)){case-1:B.moveScroll(A-1);break;case 1:B.moveScroll(Math.min(A,this.getMetaData("total_rows")-this.getPageSize()+1));break}B.noupdate=false},isVisible:function(A){var B=this.currentOffset();return(A(B+this.getPageSize("current")))?1:0)},reload:function(A){if(this.isFiltering()){this.filter.filter(null,A)}else{this._fetchBuffer({offset:this.currentOffset(),purge:true,params:A})}},remove:function(F,C){if(this.isbusy){this.remove.bind(this,F,cacheid,view).defer();return}if(!F.size()){return}C=C||{};this.isbusy=true;var A,B=0,E=F.get("div"),D=E.size();this.deselect(F);if(C.cacheid){this.setMetaData({cacheid:C.cacheid},C.view)}if(D){A={duration:0.3,to:0.01};E.each(function(G){if(++B==D){A.afterFinish=this._removeids.bind(this,F,C)}Effect.Fade(G,A)},this)}else{this._removeids(F,C)}},_removeids:function(B,A){this.setMetaData({total_rows:this.getMetaData("total_rows",A.view)-B.size()},A.view);if(this.opts.onRemoveRows){this.opts.onRemoveRows(B)}this._getBuffer().remove(B.get("rownum"));if(!A.noupdate){this.requestContentRefresh(this.currentOffset())}this.isbusy=false},addFilter:function(A,B){this.filter=new ViewPort_Filter(this,A,B)},runFilter:function(B,A){if(this.filter){this.filter.filter(Object.isUndefined(B)?null:B,A)}},isFiltering:function(){return this.filter?this.filter.isFiltering():false},stopFilter:function(A){if(this.filter){this.filter.clear(A)}},onResize:function(B,A){if(!this.uc_run||!this.opts.content.visible()){return}if(this.resizefunc){clearTimeout(this.resizefunc)}if(A){this._onResize(B)}else{this.resizefunc=this._onResize.bind(this,B).delay(0.1)}},_onResize:function(A){if(this.opts.onBeforeResize){this.opts.onBeforeResize()}this._renderViewport(A);if(this.opts.onAfterResize){this.opts.onAfterResize()}},requestContentRefresh:function(B){if(this._updateContent(B)){var A=this._getBuffer().isNearingLimit(B);if(A){this._fetchBuffer({offset:B,background:true,nearing:A})}return true}return false},_fetchBuffer:function(A){if(this.isbusy){this._fetchBuffer.bind(this,A).defer();return}this.isbusy=true;if(this.opts.onFetch&&!A.background){this.opts.onFetch()}var L=(A.view||this.view),G=this.opts.fetch_action,E,M=this._getBuffer(L),I,C,F=$H(A.params),D,P,Q,O,K,B,J,N,H;if(A.purge){F.set("purge",true)}if(A.search){J="search";N=A.search;C=this._lookbehind(L);F.update({search_before:C,search_after:M.bufferSize()-C})}else{J="rownum";N=A.offset+1;E=M.getAllRows();B=this._getSliceBounds(N,A.nearing,L);K=$A($R(B.start,B.end)).diff(E);if(!A.purge&&!K.size()){this.isbusy=false;return}F.update({slice_start:B.start,slice_end:B.end})}F.set(J,Object.toJSON(N));O=[L,J,N];if(this.isFiltering()){G=this.filter.getAction();F=this.filter.addFilterParams(F);O.push(F)}P=O.toJSON();D=this.fetch_hash.get(P);I=this.current_req.get(L);if(I){if(D&&I.get(D)){if(++I.get(D).count==4){this._displayFetchError();this._removeRequest(L,D);this.isbusy=false;return}}else{if(J=="rownum"){H=$A($R(N,N+this.getPageSize())).diff(E);if(!H.size()){this.isbusy=false;return}Q=I.keys().numericSort().find(function(R){var S=I.get(R).rlist;H=H.diff(S);if(!H.size()){return true}K=K.diff(S)});if(Q){if(!A.background){this._addRequest(L,Q,{background:false,offset:N-1})}this.isbusy=false;return}else{if(!A.background){I.keys().each(function(R){this._addRequest(L,R,{background:true})},this)}}}}}if(!this.opts.norows&&K){F.set("rows",K.toJSON())}if(!D){D=this.fetch_hash.set(P,this.request_num++)}F.set("request_id",D);this._addRequest(L,D,{background:A.background,offset:N-1,rlist:K});this.opts.ajaxRequest(G,this.addRequestParams(F,{noslice:true,view:L}));this._handleWait();this.isbusy=false},_getSliceBounds:function(C,D,A){var E=this._getBuffer(A).bufferSize(),B={};switch(D){case"bottom":B.start=C+this.getPageSize();B.end=B.start+E;break;case"top":B.start=Math.max(C-E,1);B.end=C;break;default:B.start=Math.max(C-this._lookbehind(A),1);B.end=B.start+E;break}return B},_lookbehind:function(A){return parseInt(0.4*this._getBuffer(A).bufferSize(),10)},addRequestParams:function(A,B){B=B||{};var E=this.getMetaData("cacheid",B.view),C=this.getMetaData("additional_params",B.view),D;if(E){C.update({cacheid:E})}if(!B.noslice){D=this._getSliceBounds(this.currentOffset(),null,B.view);C.update({slice_start:D.start,slice_end:D.end})}return C.merge(A)},ajaxResponse:function(E){if(this.isbusy){this.ajaxResponse.bind(this,E).defer();return}this.isbusy=true;this._clearWait();var A,D,B,F,C,H,G={};if(E.type=="slice"){F=E.data;C=Object.keys(F);C.each(function(I){F[I].view=E.id;G[I]=F[I].rownum});A=this._getBuffer(E.id);A.update(F,G,{slice:true});if(this.opts.onEndFetch){this.opts.onEndFetch()}D=this.slice_hash.get(E.request_id);if(D){D(new ViewPort_Selection(A,"uid",C));this.slice_hash.unset(E.request_id)}this.isbusy=false;return}H=(E.request_id)?this.current_req_lookup.get(E.request_id):E.id;D=this.current_req.get(H);if(D&&E.request_id){B=D.get(E.request_id)}if(this.viewport_init){this.viewport_init=2}A=this._getBuffer(H);A.update(E.data,E.rowlist,{update:E.update});A.setMetaData($H(E.other).merge({cacheid:E.cacheid,label:E.label,total_rows:E.totalrows}));if(E.request_id){this._removeRequest(H,E.request_id)}this.isbusy=false;if(!(this.view==H||E.search)||(B&&B.background)||!this._updateContent((B&&B.offset)?B.offset:(E.rownum?parseInt(E.rownum)-1:this.currentOffset()))){return}if(this.opts.onComplete){this.opts.onComplete()}if(this.opts.onEndFetch){this.opts.onEndFetch()}},_addRequest:function(A,B,E){var D=this.current_req.get(A),C;if(!D){D=this.current_req.set(A,$H())}C=D.get(B);if(!C){C=D.set(B,{count:1})}["background","offset","rlist"].each(function(F){if(!Object.isUndefined(E[F])){C[F]=E[F]}});this.current_req_lookup.set(B,A)},_removeRequest:function(A,B){var C=this.current_req.get(A);if(C){C.unset(B);if(!C.size()){this.current_req.unset(A)}}this.current_req_lookup.unset(B)},_updateContent:function(F,C){C=C||{};if(!this._getBuffer(C.view).sliceLoaded(F)){this._fetchBuffer($H(C).merge({offset:F}).toObject());return false}if(!this.uc_run){this.uc_run=true;if(this.opts.onFirstContent){this.opts.onFirstContent()}}var G=this.opts.content,A=[],B=this.getPageSize(),E,D=this.getSelected();if(this.opts.onClearRows){this.opts.onClearRows(G.childElements())}this.scroller.updateSize();this.scrollTo(F+1,true);F=this.currentOffset();E=this.createSelection("rownum",$A($R(F+1,F+B)));if(E.size()){E.get("dataob").each(function(I){var H=Object.clone(I);if(H.bg){H.bg=I.bg.clone();if(D.contains("uid",H.vp_id)){H.bg.push(this.opts.selected_class)}H.bg_string=H.bg.join(" ")}A.push(this.template.evaluate(H))},this);G.update(A.join(""))}else{G.update((this.opts.empty&&this.viewport_init!=1)?this.opts.empty.innerHTML:"")}if(this.opts.onContent){this.opts.onContent(E)}return true},_displayFetchError:function(){if(this.opts.onFail){this.opts.onFail()}if(this.opts.error){this.opts.content.update(this.opts.error.innerHTML)}},_getSlice:function(B,E){var D={rangeslice:1,start:B.min(),length:B.size()},A,C;C=this.createSelection("rownum",B);if(B.size()==C.size()){return C}if(this.opts.onFetch){this.opts.onFetch()}if(E){A=this.request_num++;D.request_id=A;this.slice_hash.set(A,E)}this.opts.ajaxRequest(this.opts.fetch_action,this.addRequestParams(D,{noslice:true}));return false},_handleWait:function(A){this._clearWait();if(A&&this.opts.onWait){this.opts.onWait()}if(this.opts.viewport_wait){this.waitHandler=this._handleWait.bind(this,true).delay(this.opts.viewport_wait)}},_clearWait:function(){if(this.waitHandler){clearTimeout(this.waitHandler);this.waitHandler=null}},visibleRows:function(){return this.opts.content.childElements()},getMetaData:function(B,A){return this._getBuffer(A).getMetaData(B)},setMetaData:function(B,A){this._getBuffer(A).setMetaData(B)},_getBuffer:function(B,C){if(!C){var A=this.views.get(B||this.view);if(A){return A.buffer}}return new ViewPort_Buffer(this,this.opts.buffer_pages,this.opts.limit_factor)},currentOffset:function(){return this.scroller.currentOffset()},updateFlag:function(C,A,B){this._updateFlag(C,A,B,this.isFiltering());this._updateClass(C,A,B)},_updateFlag:function(D,A,C,B){D.get("dataob").each(function(E){if(C){E.bg.push(A)}else{E.bg.splice(E.bg.indexOf(A),1)}if(B){this._updateFlag(this.createSelection("uid",E.vp_id,E.view),A,C)}},this)},_updateClass:function(C,A,B){C.get("div").each(function(D){if(B){D.addClassName(A)}else{D.removeClassName(A)}})},_getLineHeight:function(){if(this.line_height){return this.line_height}var A=new Element("DIV",{className:this.opts.content_class}).insert(new Element("DIV",{className:this.opts.row_class})).hide();$(document.body).insert(A);this.line_height=A.getHeight();A.remove();return this.line_height},getPageSize:function(A){switch(A){case"current":return Math.min(this.page_size,this.getMetaData("total_rows"));case"default":return Math.max(parseInt(this.getPageSize("max")*0.45),5);case"max":return parseInt(this._getMaxHeight()/this._getLineHeight());default:return this.page_size}},_getMaxHeight:function(){return document.viewport.getHeight()-this.opts.content.viewportOffset()[1]},showSplitPane:function(A){this.show_split_pane=A;this.onResize(false,true)},_renderViewport:function(D){if(!this.viewport_init){return}if(!this.opts.content.offsetHeight){return this._renderViewport.bind(this,D).defer()}var E,B,H,C,G=$(this.opts.content),F=document.documentElement,A=this._getLineHeight();if(this.opts.split_pane){H=$(this.opts.split_pane);if(this.show_split_pane){if(!H.visible()){this._initSplitBar();this.page_size=(this.splitbar_loc)?this.splitbar_loc:this.getPageSize("default")}C=true}else{if(H.visible()){this.splitbar_loc=this.page_size;$(H,this.splitbar).invoke("hide")}}}if(!C){this.page_size=this.getPageSize("max")}B=A*this.page_size;G.setStyle({height:B+"px"});if(C){H.setStyle({height:(this._getMaxHeight()-B-A)+"px"}).show();this.splitbar.show()}else{if(E=F.scrollHeight-F.clientHeight){G.setStyle({height:(A*(this.page_size-1))+"px"})}}if(!D){this.scroller.onResize()}},_initSplitBar:function(){if(this.splitbar){return}this.splitbar=$(this.opts.splitbar);new Drag(this.splitbar,{constraint:"vertical",ghosting:true,onStart:function(){var A=this._getLineHeight();this.sp={lh:A,pos:$(this.opts.content).positionedOffset()[1],max:parseInt((this._getMaxHeight()-100)/A),lines:this.page_size}}.bind(this),snap:function(A,D,C){var B=parseInt((D-this.sp.pos)/this.sp.lh);if(B<1){B=1}else{if(B>this.sp.max){B=this.sp.max}}this.sp.lines=B;return[A,this.sp.pos+(B*this.sp.lh)]}.bind(this),onEnd:function(){this.page_size=this.sp.lines;this._renderViewport()}.bind(this)});this.splitbar.observe("dblclick",function(){this.page_size=this.getPageSize("default");this._renderViewport()}.bind(this))},createSelection:function(D,C,B){var A=this._getBuffer(B);return A?new ViewPort_Selection(A,D,C):new ViewPort_Selection(this._getBuffer(this.view))},getViewportSelection:function(B){var A=this._getBuffer(B);return this.createSelection("uid",A?A.getAllUIDs():[],B)},select:function(D,B){B=B||{};if(B.range){D=this._getSlice(D,this.select.bind(this));if(D===false){return}}var A=this._getBuffer(),C;if(!B.add){C=this.getSelected();A.deselect(C,true);this._updateClass(C,this.opts.selected_class,false)}A.select(D);this._updateClass(D,this.opts.selected_class,true);if(this.opts.selectCallback){this.opts.selectCallback(D,B)}},deselect:function(B,A){A=A||{};if(!B.size()){return}if(this._getBuffer().deselect(B,A&&A.clearall)){this._updateClass(B,this.opts.selected_class,false);if(this.opts.deselectCallback){this.opts.deselectCallback(B,A)}}},getSelected:function(){return Object.clone(this._getBuffer().getSelected())}}),ViewPort_Scroller=Class.create({initialize:function(A){this.vp=A},_createScrollBar:function(){if(this.scrollDiv){return false}var A=this.vp.opts.content;this.scrollDiv=new Element("DIV",{className:"sbdiv",style:"height:"+A.getHeight()+"px;"}).hide();A.insert({after:this.scrollDiv}).setStyle({marginRight:"-"+this.scrollDiv.getWidth()+"px"});this.scrollbar=new DimpSlider(this.scrollDiv,{buttonclass:{up:"sbup",down:"sbdown"},cursorclass:"sbcursor",onChange:this._onScroll.bind(this),onSlide:this.vp.opts.onSlide?this.vp.opts.onSlide:null,pagesize:this.vp.getPageSize(),totalsize:this.vp.getMetaData("total_rows")});A.observe(Prototype.Browser.Gecko?"DOMMouseScroll":"mousewheel",function(C){if(Prototype.Browser.Gecko&&C.eventPhase==2){return}var B=this.vp.getPageSize();B=(B>3)?3:B;this.moveScroll(this.currentOffset()+((C.wheelDelta>=0||C.detail<0)?(-1*B):B))}.bindAsEventListener(this));return true},onResize:function(){if(!this.scrollDiv){return}this.scrollsize=this.vp.opts.content.getHeight();this.scrollDiv.setStyle({height:this.scrollsize+"px"});this.updateSize();this.vp.requestContentRefresh(this.currentOffset())},updateSize:function(){if(!this._createScrollBar()){this.scrollbar.updateHandleLength(this.vp.getPageSize(),this.vp.getMetaData("total_rows"))}},clear:function(){if(this.scrollDiv){this.scrollbar.updateHandleLength(0,0)}},moveScroll:function(A){this._createScrollBar();this.scrollbar.setScrollPosition(A)},_onScroll:function(){if(!this.noupdate){if(this.vp.opts.onScroll){this.vp.opts.onScroll()}this.vp.requestContentRefresh(this.currentOffset());if(this.vp.opts.onScrollIdle){this.vp.opts.onScrollIdle()}}},currentOffset:function(){return this.scrollbar?this.scrollbar.getValue():0}}),ViewPort_Buffer=Class.create({initialize:function(B,C,A){this.bufferPages=C;this.limitFactor=A;this.vp=B;this.clear()},_limitTolerance:function(){return Math.round(this.bufferSize()*(this.limitFactor/100))},bufferSize:function(){return Math.round(Math.max(this.vp.getPageSize("max")+1,this.bufferPages*this.vp.getPageSize()))},update:function(C,A,B){C=$H(C);A=$H(A);B=B||{};if(B.slice){C.each(function(D){if(!this.data.get(D.key)){this.data.set(D.key,D.value);this.inc.set(D.key,true)}},this)}else{if(this.data.size()){this.data.update(C);if(this.inc.size()){C.keys().each(function(D){this.inc.unset(D)},this)}}else{this.data=C}}this.uidlist=(B.update)?A:(this.uidlist.size()?this.uidlist.merge(A):A);if(B.update){this.rowlist=$H()}A.each(function(D){this.rowlist.set(D.value,D.key)},this)},sliceLoaded:function(A){return!this._rangeCheck($A($R(A+1,Math.min(A+this.vp.getPageSize()-1,this.getMetaData("total_rows")))))},isNearingLimit:function(A){if(this.uidlist.size()!=this.getMetaData("total_rows")){if(A!=0&&this._rangeCheck($A($R(Math.max(A+1-this._limitTolerance(),1),A)))){return"top"}else{if(this._rangeCheck($A($R(A+1,Math.min(A+this._limitTolerance()+this.vp.getPageSize()-1,this.getMetaData("total_rows")))).reverse())){return"bottom"}}}return false},_rangeCheck:function(A){var B=this.inc.size();return A.any(function(D){var C=this.rowlist.get(D);return(Object.isUndefined(C)||(B&&this.inc.get(C)))},this)},getData:function(A){return A.collect(function(B){var C=this.data.get(B);if(!Object.isUndefined(C)){C.domid="vp_row"+B;C.rownum=this.uidlist.get(B);C.vp_id=B;return C}},this).compact()},getAllUIDs:function(){return this.uidlist.keys()},getAllRows:function(){return this.rowlist.keys()},rowsToUIDs:function(A){return A.collect(function(B){return this.rowlist.get(B)},this).compact()},select:function(A){this.selected.add("uid",A.get("uid"))},deselect:function(C,B){var A=this.selected.size();if(B){this.selected.clear()}else{this.selected.remove("uid",C.get("uid"))}return A!=this.selected.size()},getSelected:function(){return this.selected},remove:function(B){var C=B.min(),D,E=this.rowlist.size(),A=0;D=E-B.size();return this.rowlist.keys().each(function(H){if(H>=C){var G=this.rowlist.get(H),F;if(B.include(H)){this.data.unset(G);this.uidlist.unset(G);A++}else{if(A){F=H-A;this.rowlist.set(F,G);this.uidlist.set(G,F)}}if(H>D){this.rowlist.unset(H)}}},this)},clear:function(){this.data=$H();this.inc=$H();this.mdata=$H({total_rows:0});this.rowlist=$H();this.selected=new ViewPort_Selection(this);this.uidlist=$H()},getMetaData:function(A){return this.mdata.get(A)},setMetaData:function(A){this.mdata.update(A)}}),ViewPort_Filter=Class.create({initialize:function(A,B,C){this.vp=A;this.action=B;this.callback=C;this.filterid=0;this.filtering=this.last_filter=this.last_folder=this.last_folder_params=null},filter:function(C,B){B=B||{};if(C===null){C=this.last_filter}else{C=C.toLowerCase();if(C==this.last_filter){return}}if(!C){this.clear();return}this.last_filter=C;if(this.filtering){this.vp._fetchBuffer({offset:0,params:B});return}this.filtering=++this.filterid+"%search%";this.last_folder=this.vp.view;this.last_folder_params=this.vp.getMetaData("additional_params").merge(B);var D=this.vp.opts.content,A;A=D.childElements().findAll(function(E){return E.collectTextNodes().toLowerCase().indexOf(C)==-1});if(this.vp.opts.onClearRows){this.vp.opts.onClearRows(A)}A.invoke("remove");this.vp.scroller.clear();if(this.vp.opts.empty&&!D.childElements().size()){D.update(this.vp.opts.empty.innerHTML)}this.vp.loadView(this.filtering,this.last_folder_params)},isFiltering:function(){return this.filtering},getAction:function(){return this.action},addFilterParams:function(A){if(!this.filtering){return A}A.update({filter:this.last_filter});if(this.callback){A.update(this.callback())}return A},clear:function(A){if(this.filtering){this.filtering=null;if(!A){this.vp.loadView(this.last_folder,this.last_folder_params)}this.vp.deleteView(this.filtering);this.last_filter=this.last_folder=null}}}),ViewPort_Selection=Class.create({initialize:function(A,C,B){this.buffer=A;this.clear();if(!Object.isUndefined(C)){this.add(C,B)}this.viewport_selection=true},add:function(A,B){var C=this._convert(A,B);this.data=(this.data.size())?this.data.concat(C).uniq():C},remove:function(A,B){this.data=this.data.diff(this._convert(A,B))},_convert:function(A,B){B=Object.isArray(B)?B:[B];switch(A){case"dataob":return B.pluck("vp_id");case"div":return B.pluck("id").invoke("substring",6);case"domid":return B.invoke("substring",6);case"rownum":return this.buffer.rowsToUIDs(B);case"uid":return B}},clear:function(){this.data=[]},get:function(A){A=Object.isUndefined(A)?"uid":A;if(A=="uid"){return this.data}var B=this.buffer.getData(this.data);switch(A){case"dataob":return B;case"div":return B.pluck("domid").collect(function(C){return $(C)}).compact();case"domid":return B.pluck("domid");case"rownum":return B.pluck("rownum")}},contains:function(A,B){return this.data.include(this._convert(A,B).first())},search:function(A){return new ViewPort_Selection(this.buffer,"uid",this.get("dataob").findAll(function(B){return $H(A).all(function(C){return $H(C.value).all(function(D){switch(D.key){case"equal":case"not":var E=B[C.key]&&D.value.include(B[C.key]);return(D.key=="equal")?E:!E;case"regex":return B[C.key].match(D.value)}})})}).pluck("vp_id"))},size:function(){return this.data.size()},set:function(A){this.get("dataob").each(function(B){$H(A).each(function(C){B[C.key]=C.value})})}});Object.extend(Array.prototype,{diff:function(A){return this.select(function(B){return!A.include(B)})},numericSort:function(){return this.sort(function(B,A){return(B>A)?1:((B(b+this.getPageSize("current")))?1:0)},reload:function(a){if(this.isFiltering()){this.filter.filter(null,a)}else{this._fetchBuffer({offset:this.currentOffset(),purge:true,params:a})}},remove:function(f,c){if(this.isbusy){this.remove.bind(this,f,cacheid,view).defer();return}if(!f.size()){return}c=c||{};this.isbusy=true;var a,b=0,e=f.get("div"),d=e.size();this.deselect(f);if(c.cacheid){this.setMetaData({cacheid:c.cacheid},c.view)}if(d){a={duration:0.3,to:0.01};e.each(function(g){if(++b==d){a.afterFinish=this._removeids.bind(this,f,c)}Effect.Fade(g,a)},this)}else{this._removeids(f,c)}},_removeids:function(b,a){this.setMetaData({total_rows:this.getMetaData("total_rows",a.view)-b.size()},a.view);if(this.opts.onRemoveRows){this.opts.onRemoveRows(b)}this._getBuffer().remove(b.get("rownum"));if(!a.noupdate){this.requestContentRefresh(this.currentOffset())}this.isbusy=false},addFilter:function(a,b){this.filter=new ViewPort_Filter(this,a,b)},runFilter:function(b,a){if(this.filter){this.filter.filter(Object.isUndefined(b)?null:b,a)}},isFiltering:function(){return this.filter?this.filter.isFiltering():false},stopFilter:function(a){if(this.filter){this.filter.clear(a)}},onResize:function(b,a){if(!this.uc_run||!this.opts.content.visible()){return}if(this.resizefunc){clearTimeout(this.resizefunc)}if(a){this._onResize(b)}else{this.resizefunc=this._onResize.bind(this,b).delay(0.1)}},_onResize:function(a){if(this.opts.onBeforeResize){this.opts.onBeforeResize()}this._renderViewport(a);if(this.opts.onAfterResize){this.opts.onAfterResize()}},requestContentRefresh:function(b){if(this._updateContent(b)){var a=this._getBuffer().isNearingLimit(b);if(a){this._fetchBuffer({offset:b,background:true,nearing:a})}return true}return false},_fetchBuffer:function(a){if(this.isbusy){this._fetchBuffer.bind(this,a).defer();return}this.isbusy=true;if(this.opts.onFetch&&!a.background){this.opts.onFetch()}var m=(a.view||this.view),h=this.opts.fetch_action,f,n=this._getBuffer(m),j,d,g=$H(a.params),e,q,r,p,l,c,k,o,i;if(a.purge){g.set("purge",true)}if(a.search){k="search";o=a.search;d=this._lookbehind(m);g.update({search_before:d,search_after:n.bufferSize()-d})}else{k="rownum";o=a.offset+1;f=n.getAllRows();c=this._getSliceBounds(o,a.nearing,m);l=$A($R(c.start,c.end)).diff(f);if(!a.purge&&!l.size()){this.isbusy=false;return}g.update({slice_start:c.start,slice_end:c.end})}g.set(k,Object.toJSON(o));p=[m,k,o];if(this.isFiltering()){h=this.filter.getAction();g=this.filter.addFilterParams(g);p.push(g)}q=p.toJSON();e=this.fetch_hash.get(q);j=this.current_req.get(m);if(j){if(e&&j.get(e)){if(++j.get(e).count==4){this._displayFetchError();this._removeRequest(m,e);this.isbusy=false;return}}else{if(k=="rownum"){i=$A($R(o,o+this.getPageSize())).diff(f);if(!i.size()){this.isbusy=false;return}r=j.keys().numericSort().find(function(b){var s=j.get(b).rlist;i=i.diff(s);if(!i.size()){return true}l=l.diff(s)});if(r){if(!a.background){this._addRequest(m,r,{background:false,offset:o-1})}this.isbusy=false;return}else{if(!a.background){j.keys().each(function(b){this._addRequest(m,b,{background:true})},this)}}}}}if(!this.opts.norows&&l){g.set("rows",l.toJSON())}if(!e){e=this.fetch_hash.set(q,this.request_num++)}g.set("request_id",e);this._addRequest(m,e,{background:a.background,offset:o-1,rlist:l});this.opts.ajaxRequest(h,this.addRequestParams(g,{noslice:true,view:m}));this._handleWait();this.isbusy=false},_getSliceBounds:function(c,d,a){var e=this._getBuffer(a).bufferSize(),b={};switch(d){case"bottom":b.start=c+this.getPageSize();b.end=b.start+e;break;case"top":b.start=Math.max(c-e,1);b.end=c;break;default:b.start=Math.max(c-this._lookbehind(a),1);b.end=b.start+e;break}return b},_lookbehind:function(a){return parseInt(0.4*this._getBuffer(a).bufferSize(),10)},addRequestParams:function(a,b){b=b||{};var e=this.getMetaData("cacheid",b.view),c=this.getMetaData("additional_params",b.view),d;if(e){c.update({cacheid:e})}if(!b.noslice){d=this._getSliceBounds(this.currentOffset(),null,b.view);c.update({slice_start:d.start,slice_end:d.end})}return c.merge(a)},ajaxResponse:function(e){if(this.isbusy){this.ajaxResponse.bind(this,e).defer();return}this.isbusy=true;this._clearWait();var a,d,b,f,c,h,g={};if(e.type=="slice"){f=e.data;c=Object.keys(f);c.each(function(i){f[i].view=e.id;g[i]=f[i].rownum});a=this._getBuffer(e.id);a.update(f,g,{slice:true});if(this.opts.onEndFetch){this.opts.onEndFetch()}d=this.slice_hash.get(e.request_id);if(d){d(new ViewPort_Selection(a,"uid",c));this.slice_hash.unset(e.request_id)}this.isbusy=false;return}h=(e.request_id)?this.current_req_lookup.get(e.request_id):e.id;d=this.current_req.get(h);if(d&&e.request_id){b=d.get(e.request_id)}if(this.viewport_init){this.viewport_init=2}a=this._getBuffer(h);a.update(e.data,e.rowlist,{update:e.update});a.setMetaData($H(e.other).merge({cacheid:e.cacheid,label:e.label,total_rows:e.totalrows}));if(e.request_id){this._removeRequest(h,e.request_id)}this.isbusy=false;if(!(this.view==h||e.search)||(b&&b.background)||!this._updateContent((b&&b.offset)?b.offset:(e.rownum?parseInt(e.rownum)-1:this.currentOffset()))){return}if(this.opts.onComplete){this.opts.onComplete()}if(this.opts.onEndFetch){this.opts.onEndFetch()}},_addRequest:function(a,b,e){var d=this.current_req.get(a),c;if(!d){d=this.current_req.set(a,$H())}c=d.get(b);if(!c){c=d.set(b,{count:1})}["background","offset","rlist"].each(function(f){if(!Object.isUndefined(e[f])){c[f]=e[f]}});this.current_req_lookup.set(b,a)},_removeRequest:function(a,b){var c=this.current_req.get(a);if(c){c.unset(b);if(!c.size()){this.current_req.unset(a)}}this.current_req_lookup.unset(b)},_updateContent:function(g,d){d=d||{};if(!this._getBuffer(d.view).sliceLoaded(g)){this._fetchBuffer($H(d).merge({offset:g}).toObject());return false}if(!this.uc_run){this.uc_run=true;if(this.opts.onFirstContent){this.opts.onFirstContent()}}var h=this.opts.content,a=[],b=this.getPageSize(),f,e=this.getSelected();if(this.opts.onClearRows){this.opts.onClearRows(h.childElements())}this.scroller.updateSize();this.scrollTo(g+1,true);g=this.currentOffset();f=this.createSelection("rownum",$A($R(g+1,g+b)));if(f.size()){f.get("dataob").each(function(i){var c=Object.clone(i);if(c.bg){c.bg=i.bg.clone();if(e.contains("uid",c.vp_id)){c.bg.push(this.opts.selected_class)}c.bg_string=c.bg.join(" ")}a.push(this.template.evaluate(c))},this);h.update(a.join(""))}else{h.update((this.opts.empty&&this.viewport_init!=1)?this.opts.empty.innerHTML:"")}if(this.opts.onContent){this.opts.onContent(f)}return true},_displayFetchError:function(){if(this.opts.onFail){this.opts.onFail()}if(this.opts.error){this.opts.content.update(this.opts.error.innerHTML)}},_getSlice:function(b,e){var d={rangeslice:1,start:b.min(),length:b.size()},a,c;c=this.createSelection("rownum",b);if(b.size()==c.size()){return c}if(this.opts.onFetch){this.opts.onFetch()}if(e){a=this.request_num++;d.request_id=a;this.slice_hash.set(a,e)}this.opts.ajaxRequest(this.opts.fetch_action,this.addRequestParams(d,{noslice:true}));return false},_handleWait:function(a){this._clearWait();if(a&&this.opts.onWait){this.opts.onWait()}if(this.opts.viewport_wait){this.waitHandler=this._handleWait.bind(this,true).delay(this.opts.viewport_wait)}},_clearWait:function(){if(this.waitHandler){clearTimeout(this.waitHandler);this.waitHandler=null}},visibleRows:function(){return this.opts.content.childElements()},getMetaData:function(b,a){return this._getBuffer(a).getMetaData(b)},setMetaData:function(b,a){this._getBuffer(a).setMetaData(b)},_getBuffer:function(c,d){if(!d){var a=this.views.get(c||this.view);if(a){return a.buffer}}return new ViewPort_Buffer(this,this.opts.buffer_pages,this.opts.limit_factor)},currentOffset:function(){return this.scroller.currentOffset()},updateFlag:function(c,a,b){this._updateFlag(c,a,b,this.isFiltering());this._updateClass(c,a,b)},_updateFlag:function(d,a,c,b){d.get("dataob").each(function(e){if(c){e.bg.push(a)}else{e.bg.splice(e.bg.indexOf(a),1)}if(b){this._updateFlag(this.createSelection("uid",e.vp_id,e.view),a,c)}},this)},_updateClass:function(c,a,b){c.get("div").each(function(e){if(b){e.addClassName(a)}else{e.removeClassName(a)}})},_getLineHeight:function(){if(this.line_height){return this.line_height}var a=new Element("DIV",{className:this.opts.content_class}).insert(new Element("DIV",{className:this.opts.row_class})).hide();$(document.body).insert(a);this.line_height=a.getHeight();a.remove();return this.line_height},getPageSize:function(a){switch(a){case"current":return Math.min(this.page_size,this.getMetaData("total_rows"));case"default":return Math.max(parseInt(this.getPageSize("max")*0.45),5);case"max":return parseInt(this._getMaxHeight()/this._getLineHeight());default:return this.page_size}},_getMaxHeight:function(){return document.viewport.getHeight()-this.opts.content.viewportOffset()[1]},showSplitPane:function(a){this.show_split_pane=a;this.onResize(false,true)},_renderViewport:function(e){if(!this.viewport_init){return}if(!this.opts.content.offsetHeight){return this._renderViewport.bind(this,e).defer()}var f,b,j,d,i=$(this.opts.content),g=document.documentElement,a=this._getLineHeight();if(this.opts.split_pane){j=$(this.opts.split_pane);if(this.show_split_pane){if(!j.visible()){this._initSplitBar();this.page_size=(this.splitbar_loc)?this.splitbar_loc:this.getPageSize("default")}d=true}else{if(j.visible()){this.splitbar_loc=this.page_size;$(j,this.splitbar).invoke("hide")}}}if(!d){this.page_size=this.getPageSize("max")}b=a*this.page_size;i.setStyle({height:b+"px"});if(d){j.setStyle({height:(this._getMaxHeight()-b-a)+"px"}).show();this.splitbar.show()}else{if(f=g.scrollHeight-g.clientHeight){i.setStyle({height:(a*(this.page_size-1))+"px"})}}if(!e){this.scroller.onResize()}},_initSplitBar:function(){if(this.splitbar){return}this.splitbar=$(this.opts.splitbar);new Drag(this.splitbar,{constraint:"vertical",ghosting:true,onStart:function(){var a=this._getLineHeight();this.sp={lh:a,pos:$(this.opts.content).positionedOffset()[1],max:parseInt((this._getMaxHeight()-100)/a),lines:this.page_size}}.bind(this),snap:function(a,d,c){var b=parseInt((d-this.sp.pos)/this.sp.lh);if(b<1){b=1}else{if(b>this.sp.max){b=this.sp.max}}this.sp.lines=b;return[a,this.sp.pos+(b*this.sp.lh)]}.bind(this),onEnd:function(){this.page_size=this.sp.lines;this._renderViewport()}.bind(this)});this.splitbar.observe("dblclick",function(){this.page_size=this.getPageSize("default");this._renderViewport()}.bind(this))},createSelection:function(d,c,b){var a=this._getBuffer(b);return a?new ViewPort_Selection(a,d,c):new ViewPort_Selection(this._getBuffer(this.view))},getViewportSelection:function(b){var a=this._getBuffer(b);return this.createSelection("uid",a?a.getAllUIDs():[],b)},select:function(e,c){c=c||{};if(c.range){e=this._getSlice(e,this.select.bind(this));if(e===false){return}}var a=this._getBuffer(),d;if(!c.add){d=this.getSelected();a.deselect(d,true);this._updateClass(d,this.opts.selected_class,false)}a.select(e);this._updateClass(e,this.opts.selected_class,true);if(this.opts.selectCallback){this.opts.selectCallback(e,c)}},deselect:function(b,a){a=a||{};if(!b.size()){return}if(this._getBuffer().deselect(b,a&&a.clearall)){this._updateClass(b,this.opts.selected_class,false);if(this.opts.deselectCallback){this.opts.deselectCallback(b,a)}}},getSelected:function(){return Object.clone(this._getBuffer().getSelected())}}),ViewPort_Scroller=Class.create({initialize:function(a){this.vp=a},_createScrollBar:function(){if(this.scrollDiv){return false}var a=this.vp.opts.content;this.scrollDiv=new Element("DIV",{className:"sbdiv",style:"height:"+a.getHeight()+"px;"}).hide();a.insert({after:this.scrollDiv}).setStyle({marginRight:"-"+this.scrollDiv.getWidth()+"px"});this.scrollbar=new DimpSlider(this.scrollDiv,{buttonclass:{up:"sbup",down:"sbdown"},cursorclass:"sbcursor",onChange:this._onScroll.bind(this),onSlide:this.vp.opts.onSlide?this.vp.opts.onSlide:null,pagesize:this.vp.getPageSize(),totalsize:this.vp.getMetaData("total_rows")});a.observe(Prototype.Browser.Gecko?"DOMMouseScroll":"mousewheel",function(c){if(Prototype.Browser.Gecko&&c.eventPhase==2){return}var b=this.vp.getPageSize();b=(b>3)?3:b;this.moveScroll(this.currentOffset()+((c.wheelDelta>=0||c.detail<0)?(-1*b):b))}.bindAsEventListener(this));return true},onResize:function(){if(!this.scrollDiv){return}this.scrollsize=this.vp.opts.content.getHeight();this.scrollDiv.setStyle({height:this.scrollsize+"px"});this.updateSize();this.vp.requestContentRefresh(this.currentOffset())},updateSize:function(){if(!this._createScrollBar()){this.scrollbar.updateHandleLength(this.vp.getPageSize(),this.vp.getMetaData("total_rows"))}},clear:function(){if(this.scrollDiv){this.scrollbar.updateHandleLength(0,0)}},moveScroll:function(a){this._createScrollBar();this.scrollbar.setScrollPosition(a)},_onScroll:function(){if(!this.noupdate){if(this.vp.opts.onScroll){this.vp.opts.onScroll()}this.vp.requestContentRefresh(this.currentOffset());if(this.vp.opts.onScrollIdle){this.vp.opts.onScrollIdle()}}},currentOffset:function(){return this.scrollbar?this.scrollbar.getValue():0}}),ViewPort_Buffer=Class.create({initialize:function(b,c,a){this.bufferPages=c;this.limitFactor=a;this.vp=b;this.clear()},_limitTolerance:function(){return Math.round(this.bufferSize()*(this.limitFactor/100))},bufferSize:function(){return Math.round(Math.max(this.vp.getPageSize("max")+1,this.bufferPages*this.vp.getPageSize()))},update:function(c,a,b){c=$H(c);a=$H(a);b=b||{};if(b.slice){c.each(function(d){if(!this.data.get(d.key)){this.data.set(d.key,d.value);this.inc.set(d.key,true)}},this)}else{if(this.data.size()){this.data.update(c);if(this.inc.size()){c.keys().each(function(d){this.inc.unset(d)},this)}}else{this.data=c}}this.uidlist=(b.update)?a:(this.uidlist.size()?this.uidlist.merge(a):a);if(b.update){this.rowlist=$H()}a.each(function(d){this.rowlist.set(d.value,d.key)},this)},sliceLoaded:function(a){return!this._rangeCheck($A($R(a+1,Math.min(a+this.vp.getPageSize()-1,this.getMetaData("total_rows")))))},isNearingLimit:function(a){if(this.uidlist.size()!=this.getMetaData("total_rows")){if(a!=0&&this._rangeCheck($A($R(Math.max(a+1-this._limitTolerance(),1),a)))){return"top"}else{if(this._rangeCheck($A($R(a+1,Math.min(a+this._limitTolerance()+this.vp.getPageSize()-1,this.getMetaData("total_rows")))).reverse())){return"bottom"}}}return false},_rangeCheck:function(a){var b=this.inc.size();return a.any(function(d){var c=this.rowlist.get(d);return(Object.isUndefined(c)||(b&&this.inc.get(c)))},this)},getData:function(a){return a.collect(function(b){var c=this.data.get(b);if(!Object.isUndefined(c)){c.domid="vp_row"+b;c.rownum=this.uidlist.get(b);c.vp_id=b;return c}},this).compact()},getAllUIDs:function(){return this.uidlist.keys()},getAllRows:function(){return this.rowlist.keys()},rowsToUIDs:function(a){return a.collect(function(b){return this.rowlist.get(b)},this).compact()},select:function(a){this.selected.add("uid",a.get("uid"))},deselect:function(c,b){var a=this.selected.size();if(b){this.selected.clear()}else{this.selected.remove("uid",c.get("uid"))}return a!=this.selected.size()},getSelected:function(){return this.selected},remove:function(b){var c=b.min(),d,e=this.rowlist.size(),a=0;d=e-b.size();return this.rowlist.keys().each(function(h){if(h>=c){var g=this.rowlist.get(h),f;if(b.include(h)){this.data.unset(g);this.uidlist.unset(g);a++}else{if(a){f=h-a;this.rowlist.set(f,g);this.uidlist.set(g,f)}}if(h>d){this.rowlist.unset(h)}}},this)},clear:function(){this.data=$H();this.inc=$H();this.mdata=$H({total_rows:0});this.rowlist=$H();this.selected=new ViewPort_Selection(this);this.uidlist=$H()},getMetaData:function(a){return this.mdata.get(a)},setMetaData:function(a){this.mdata.update(a)}}),ViewPort_Filter=Class.create({initialize:function(a,b,c){this.vp=a;this.action=b;this.callback=c;this.filterid=0;this.filtering=this.last_filter=this.last_folder=this.last_folder_params=null},filter:function(d,b){b=b||{};if(d===null){d=this.last_filter}else{d=d.toLowerCase();if(d==this.last_filter){return}}if(!d){this.clear();return}this.last_filter=d;if(this.filtering){this.vp._fetchBuffer({offset:0,params:b});return}this.filtering=++this.filterid+"%search%";this.last_folder=this.vp.view;this.last_folder_params=this.vp.getMetaData("additional_params").merge(b);var e=this.vp.opts.content,a;a=e.childElements().findAll(function(c){return c.collectTextNodes().toLowerCase().indexOf(d)==-1});if(this.vp.opts.onClearRows){this.vp.opts.onClearRows(a)}a.invoke("remove");this.vp.scroller.clear();if(this.vp.opts.empty&&!e.childElements().size()){e.update(this.vp.opts.empty.innerHTML)}this.vp.loadView(this.filtering,this.last_folder_params)},isFiltering:function(){return this.filtering},getAction:function(){return this.action},addFilterParams:function(a){if(!this.filtering){return a}a.update({filter:this.last_filter});if(this.callback){a.update(this.callback())}return a},clear:function(a){if(this.filtering){this.filtering=null;if(!a){this.vp.loadView(this.last_folder,this.last_folder_params)}this.vp.deleteView(this.filtering);this.last_filter=this.last_folder=null}}}),ViewPort_Selection=Class.create({initialize:function(a,c,b){this.buffer=a;this.clear();if(!Object.isUndefined(c)){this.add(c,b)}this.viewport_selection=true},add:function(a,b){var e=this._convert(a,b);this.data=(this.data.size())?this.data.concat(e).uniq():e},remove:function(a,b){this.data=this.data.diff(this._convert(a,b))},_convert:function(a,b){b=Object.isArray(b)?b:[b];switch(a){case"dataob":return b.pluck("vp_id");case"div":return b.pluck("id").invoke("substring",6);case"domid":return b.invoke("substring",6);case"rownum":return this.buffer.rowsToUIDs(b);case"uid":return b}},clear:function(){this.data=[]},get:function(a){a=Object.isUndefined(a)?"uid":a;if(a=="uid"){return this.data}var b=this.buffer.getData(this.data);switch(a){case"dataob":return b;case"div":return b.pluck("domid").collect(function(c){return $(c)}).compact();case"domid":return b.pluck("domid");case"rownum":return b.pluck("rownum")}},contains:function(a,b){return this.data.include(this._convert(a,b).first())},search:function(a){return new ViewPort_Selection(this.buffer,"uid",this.get("dataob").findAll(function(b){return $H(a).all(function(c){return $H(c.value).all(function(d){switch(d.key){case"equal":case"not":var e=b[c.key]&&d.value.include(b[c.key]);return(d.key=="equal")?e:!e;case"regex":return b[c.key].match(d.value)}})})}).pluck("vp_id"))},size:function(){return this.data.size()},set:function(a){this.get("dataob").each(function(b){$H(a).each(function(c){b[c.key]=c.value})})}});Object.extend(Array.prototype,{diff:function(a){return this.select(function(b){return!a.include(b)})},numericSort:function(){return this.sort(function(d,c){return(d>c)?1:((d#{1}")))});this.update.update(C);this.entryCount=E.size();C.childElements().each(this.addObservers.bind(this));this.stopIndicator();this.index=0;if(this.entryCount==1&&this.options.autoSelect){this.selectEntry()}else{this.render()}}},addObservers:function(A){$(A).observe("mouseover",this._onHover.bindAsEventListener(this)).observe("click",this._onClick.bindAsEventListener(this))},onObserverEvent:function(){this.changed=false;if(this.getToken().length>=this.options.minChars){this.getUpdatedChoices()}else{this.active=false;this.hide()}this.oldval=$F(this.element)},getToken:function(){var A=this.getTokenBounds();return $F(this.element).substring(A[0],A[1]).strip()},getTokenBounds:function(){var I,E,F,C,D,G,K=this.options.tokens,J=$F(this.element),H=J.length,B=-1,A=Math.min(H,this.oldval.length);if(J.strip().empty()){return[-1,0]}I=A;for(E=0;EB){B=G}G=J.indexOf(K[F],I+D);if(G!=-1&&G=D.partialChars&&D.partialSearch&&(D.fullSearch||/\s/.test(E.substr(F-1,1)))))){++A;return true}return false},this)}}); \ No newline at end of file +var Autocompleter={};Autocompleter.Base=Class.create({baseInitialize:function(b,c,a){this.element=$(b);this.update=$(c).hide();this.active=this.changed=this.hasFocus=false;this.entryCount=this.index=0;this.observer=null;this.oldval=$F(this.element);this.options=Object.extend({paramName:this.element.name,tokens:[],frequency:0.4,minChars:1,onHide:this._onHide.bind(this),onShow:this._onShow.bind(this)},(this._setOptions?this._setOptions(a):(a||{})));if(!this.options.tokens.include("\n")){this.options.tokens.push("\n")}this.element.writeAttribute("autocomplete","off").observe("blur",this._onBlur.bindAsEventListener(this)).observe(Prototype.Browser.Gecko?"keypress":"keydown",this._onKeyPress.bindAsEventListener(this))},_onShow:function(a,e){var d,b=e.getStyle("position");if(!b||b=="absolute"){d=(Prototype.Browser.IE)?a.cumulativeScrollOffset():[0];e.setStyle({position:"absolute"}).clonePosition(a,{setHeight:false,offsetTop:a.offsetHeight,offsetLeft:d[0]})}new Effect.Appear(e,{duration:0.15})},_onHide:function(a,b){new Effect.Fade(b,{duration:0.15})},show:function(){if(!this.update.visible()){this.options.onShow(this.element,this.update)}if(Prototype.Browser.IE&&!this.iefix&&this.update.getStyle("position")=="absolute"){this.iefix=new Element("IFRAME",{src:"javascript:false;",frameborder:0,scrolling:"no"}).setStyle({position:"absolute",filter:"progid:DXImageTransform.Microsoft.Alpha(opactiy=0)",zIndex:1}).hide();this.update.setStyle({zIndex:2}).insert({after:this.iefix})}if(this.iefix){this._fixIEOverlapping.bind(this).delay(0.05)}},_fixIEOverlapping:function(){this.iefix.clonePosition(this.update).show()},hide:function(){this.stopIndicator();if(this.update.visible()){this.options.onHide(this.element,this.update);if(this.iefix){this.iefix.hide()}}},startIndicator:function(){if(this.options.indicator){$(this.options.indicator).show()}},stopIndicator:function(){if(this.options.indicator){$(this.options.indicator).hide()}},_onKeyPress:function(a){if(this.active){switch(a.keyCode){case Event.KEY_TAB:case Event.KEY_RETURN:this.selectEntry();a.stop();return;case Event.KEY_ESC:this.hide();this.active=false;a.stop();return;case Event.KEY_LEFT:case Event.KEY_RIGHT:return;case Event.KEY_UP:case Event.KEY_DOWN:if(a.keyCode==Event.KEY_UP){this.markPrevious()}else{this.markNext()}this.render();a.stop();return}}else{switch(a.keyCode){case 0:if(!Prototype.Browser.WebKit){break}case Event.KEY_TAB:case Event.KEY_RETURN:return}}this.changed=this.hasFocus=true;if(this.observer){clearTimeout(this.observer)}this.observer=this.onObserverEvent.bind(this).delay(this.options.frequency)},_onHover:function(c){var b=c.findElement("LI"),a=b.readAttribute("acIndex");if(this.index!=a){this.index=a;this.render()}c.stop()},_onClick:function(a){this.index=a.findElement("LI").readAttribute("acIndex");this.selectEntry()},_onBlur:function(a){this.hide.bind(this).delay(0.25);this.active=this.hasFocus=false},render:function(){var a=0;if(this.entryCount){this.update.down().childElements().each(function(b){[b].invoke(this.index==a++?"addClassName":"removeClassName","selected")},this);if(this.hasFocus){this.show();this.active=true}}else{this.active=false;this.hide()}},markPrevious:function(){if(this.index){--this.index}else{this.index=this.entryCount-1}this.getEntry(this.index).scrollIntoView(true)},markNext:function(){if(this.index#{1}")))});this.update.update(c);this.entryCount=e.size();c.childElements().each(this.addObservers.bind(this));this.stopIndicator();this.index=0;if(this.entryCount==1&&this.options.autoSelect){this.selectEntry()}else{this.render()}}},addObservers:function(a){$(a).observe("mouseover",this._onHover.bindAsEventListener(this)).observe("click",this._onClick.bindAsEventListener(this))},onObserverEvent:function(){this.changed=false;if(this.getToken().length>=this.options.minChars){this.getUpdatedChoices()}else{this.active=false;this.hide()}this.oldval=$F(this.element)},getToken:function(){var a=this.getTokenBounds();return $F(this.element).substring(a[0],a[1]).strip()},getTokenBounds:function(){var j,e,f,c,d,g,m=this.options.tokens,k=$F(this.element),h=k.length,b=-1,a=Math.min(h,this.oldval.length);if(k.strip().empty()){return[-1,0]}j=a;for(e=0;eb){b=g}g=k.indexOf(m[f],j+d);if(g!=-1&&g=d.partialChars&&d.partialSearch&&(d.fullSearch||/\s/.test(e.substr(f-1,1)))))){++a;return true}return false},this)}}); \ No newline at end of file diff --git a/imp/js/compose-dimp.js b/imp/js/compose-dimp.js index 37984b06f..2c85c2fc9 100644 --- a/imp/js/compose-dimp.js +++ b/imp/js/compose-dimp.js @@ -1 +1 @@ -var DimpCompose={last_msg:"",textarea_ready:true,confirmCancel:function(){if(window.confirm(DIMP.text_compose.cancel)){if(DIMP.conf_compose.auto_save_interval_val){DimpCore.doAction("DeleteDraft",{index:$F("index")})}return this._closeCompose()}},_closeCompose:function(){if(DIMP.conf_compose.qreply){this.closeQReply()}else{if(DIMP.baseWindow||DIMP.conf_compose.popup){DimpCore.closePopup()}else{DimpCore.redirect(DIMP.conf.URI_DIMP_INBOX)}}},closeQReply:function(){var A=$("attach_list").childElements();this.last_msg="";if(A.size()){this.removeAttach(A)}$("draft_index","composeCache").invoke("setValue","");$("qreply","sendcc","sendbcc").invoke("hide");[$("msgData"),$("togglecc").up(),$("togglebcc").up()].invoke("show");if(this.editor_on){this.toggleHtmlEditor()}$("compose").reset();if(this.auto_save_interval){this.auto_save_interval.stop()}},change_identity:function(){var E,B,G,F,A=$F("identity"),I=this.get_identity($F("last_identity")),H=$("message"),D=this.get_identity(A),C=$("save_sent_mail");$("sent_mail_folder_label").setText(D.id[5]);$("bcc").setValue(D.id[6]);if(C){C.writeAttribute("checked",D.id[4])}if(this.editor_on){B=FCKeditorAPI.GetInstance("message").GetHTML().replace(/\r\n/g,"\n");E="

";G="

"+D.sig.replace(/^ ?
\n/,"").replace(/ +/g," ")+"

";B=B.replace(/

\s*[\s\S]*?\s*<\/p>/,E)}else{B=$F(H).replace(/\r\n/g,"\n");E=I.sig;G=D.sig}F=(I.id[2])?B.indexOf(E):B.lastIndexOf(E);if(F!=-1){if(D.id[2]==I.id[2]){B=B.substring(0,F)+G+B.substring(F+E.length,B.length)}else{if(D.id[2]){B=G+B.substring(0,F)+B.substring(F+E.length,B.length)}else{B=B.substring(0,F)+B.substring(F+E.length,B.length)+G}}B=B.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n");if(this.editor_on){FCKeditorAPI.GetInstance("message").SetHTML(B)}else{H.setValue(B)}$("last_identity").setValue(A)}},get_identity:function(B,A){A=Object.isUndefined(A)?this.editor_on:A;return{id:DIMP.conf_compose.identities[B],sig:DIMP.conf_compose.identities[B][(A?1:0)].replace(/^\n/,"")}},uniqueSubmit:function(B){var A,C,E,D=$("compose");if(DIMP.SpellCheckerObject){DIMP.SpellCheckerObject.resume();if(!this.textarea_ready){this.uniqueSubmit.bind(this,B).defer();return}}D.setStyle({cursor:"wait"});if(B=="send_message"||B=="save_draft"){this.button_pressed=true;switch(B){case"send_message":if(!this.sbtext){E=$("send_button");this.sbtext=E.getText();E.setText(DIMP.text_compose.sending)}break;case"save_draft":if(!this.dbtext){A=$("draft_button");this.dbtext=A.getText();A.setText(DIMP.text_compose.saving)}break}if(this.uploading){(function(){if(this.button_pressed){this.uniqueSubmit(B)}}).bind(this).delay(0.25);return}}$("action").setValue(B);if(B=="add_attachment"){this.uploading=true;D.submit()}else{if(this.editor_on){FCKeditorAPI.GetInstance("message").UpdateLinkedField()}C=D.serialize(true);if(!DIMP.baseWindow){C.nonotify=true}DimpCore.doAction("*"+DIMP.conf.compose_url,C,null,this.uniqueSubmitCallback.bind(this))}},uniqueSubmitCallback:function(B){var A,C=B.response;if(!C){return}if(C.imp_compose){$("composeCache").setValue(C.imp_compose)}if(C.success||C.action=="add_attachment"){switch(C.action){case"auto_save_draft":this.button_pressed=false;$("draft_index").setValue(C.draft_index);break;case"save_draft":this.button_pressed=false;if(DIMP.baseWindow){DIMP.baseWindow.DimpBase.pollFolders();DIMP.baseWindow.DimpCore.showNotifications(B.msgs)}if(DIMP.conf_compose.close_draft){return this._closeCompose()}break;case"send_message":this.button_pressed=false;if(DIMP.baseWindow){if(C.reply_type=="reply"){DIMP.baseWindow.DimpBase.flag("answered",C.index,C.reply_folder)}if(C.folder){DIMP.baseWindow.DimpBase.createFolder(C.folder)}if(C.draft_delete){DIMP.baseWindow.DimpBase.pollFolders()}DIMP.baseWindow.DimpCore.showNotifications(B.msgs)}return this._closeCompose();case"add_attachment":this.uploading=false;if(C.success){this.addAttach(C.info.number,C.info.name,C.info.type,C.info.size)}else{this.button_pressed=false}if(DIMP.conf_compose.attach_limit!=-1&&$("attach_list").childElements().size()>DIMP.conf_compose.attach_limit){$("upload").writeAttribute("disabled",false);A=new Element("DIV",[DIMP.text_compose.attachment_limit])}else{A=new Element("INPUT",{type:"file",name:"file_1"});A.observe("change",this.uploadAttachment.bind(this))}$("upload_wait").replace(A.writeAttribute("id","upload"));this.resizeMsgArea();break}}else{this.button_pressed=false}$("compose").setStyle({cursor:null});if(!this.button_pressed){if(this.sbtext){$("send_button").setText(this.sbtext)}if(this.dbtext){$("draft_button").setText(this.dbtext)}this.dbtext=this.sbtext=null}DimpCore.showNotifications(B.msgs)},toggleHtmlEditor:function(A){if(!DIMP.conf_compose.rte_avail){return}A=A||false;if(DIMP.SpellCheckerObject){DIMP.SpellCheckerObject.resume()}var C;if(this.editor_on){this.editor_on=false;C=FCKeditorAPI.GetInstance("message").GetHTML();$("messageParent").childElements().invoke("hide");$("message").show();DimpCore.doAction("Html2Text",{text:C},null,this.setMessageText.bind(this),{asynchronous:false})}else{this.editor_on=true;if(!A){DimpCore.doAction("Text2Html",{text:$F("message")},null,this.setMessageText.bind(this),{asynchronous:false})}oFCKeditor.Height=this.getMsgAreaHeight();try{FCKeditorAPI.GetInstance("message").SetHTML($F("message"));$("messageParent").childElements().invoke("show");$("message").hide()}catch(B){this._RTELoading("show");FCKeditor_OnComplete=this._RTELoading.curry("hide");oFCKeditor.ReplaceTextarea()}}$("htmlcheckbox").checked=this.editor_on;$("html").setValue(this.editor_on?1:0)},_RTELoading:function(B){var C,A;if(!$("rteloading")){A=new Element("DIV",{id:"rteloading"}).clonePosition($("messageParent"));$(document.body).insert(A);C=A.viewportOffset();$(document.body).insert(new Element("SPAN",{id:"rteloadingtxt"}).setStyle({top:(C.top+15)+"px",left:(C.left+15)+"px"}).insert(DIMP.text.loading))}$("rteloading","rteloadingtxt").invoke(B)},toggleHtmlCheckbox:function(){if(!this.editor_on||window.confirm(DIMP.text_compose.toggle_html)){this.toggleHtmlEditor()}},getMsgAreaHeight:function(){return document.viewport.getHeight()-$("messageParent").cumulativeOffset()[1]-this.mp_padding},initializeSpellChecker:function(){if(!DIMP.conf_compose.rte_avail){return}if(typeof DIMP.SpellCheckerObject!="object"){this.initializeSpellChecker.bind(this).defer();return}DIMP.SpellCheckerObject.onBeforeSpellCheck=function(){if(!this.editor_on){return}DIMP.SpellCheckerObject.htmlAreaParent="messageParent";DIMP.SpellCheckerObject.htmlArea=$("message").adjacent("iframe[id*=message]").first();$("message").setValue(FCKeditorAPI.GetInstance("message").GetHTML());this.textarea_ready=false}.bind(this);DIMP.SpellCheckerObject.onAfterSpellCheck=function(){if(!this.editor_on){return}DIMP.SpellCheckerObject.htmlArea=DIMP.SpellCheckerObject.htmlAreaParent=null;var A=FCKeditorAPI.GetInstance("message");A.SetHTML($F("message"));A.Events.AttachEvent("OnAfterSetHTML",function(){this.textarea_ready=true}.bind(this))}.bind(this)},setMessageText:function(B){var A=$("message");if(!A){$("messageParent").insert(new Element("TEXTAREA",{id:"message",name:"message",style:"width:100%;"}).insert(B.response.text))}else{A.setValue(B.response.text)}if(!this.editor_on){this.resizeMsgArea()}},fillForm:function(G,H,B,E){if(!this.resizeto){this.fillForm.bind(this,G,H,B,E).defer();return}var A,D,C=this.get_identity($F("last_identity")),F=$("message");if(!this.last_msg.empty()&&this.last_msg!=$F(F).replace(/\r/g,"")&&!window.confirm(DIMP.text_compose.fillform)){return}if(DIMP.conf_compose.auto_save_interval_val&&!this.auto_save_interval){this.auto_save_interval=new PeriodicalExecuter(function(){var I;if(this.editor_on){I=FCKeditorAPI.GetInstance("message").GetHTML()}else{I=$F(F)}I=I.replace(/\r/g,"");if(!I.empty()&&this.last_msg!=I){this.uniqueSubmit("auto_save_draft");this.last_msg=I}}.bind(this),DIMP.conf_compose.auto_save_interval_val*60)}if(this.editor_on){D=FCKeditorAPI.GetInstance("message");D.SetHTML(G);this.last_msg=D.GetHTML().replace(/\r/g,"")}else{F.setValue(G);this.setCursorPosition(F);this.last_msg=$F(F).replace(/\r/g,"")}$("to").setValue(H.to);this.resizeto.resizeNeeded();if(H.cc){$("cc").setValue(H.cc);this.resizecc.resizeNeeded()}if(DIMP.conf_compose.cc){this.toggleCC("cc")}if(H.bcc){$("bcc").setValue(H.bcc);this.resizebcc.resizeNeeded()}if(C.id[6]){A=$F("bcc");if(A){A+=", "}$("bcc").setValue(A+C.id[6])}if(DIMP.conf_compose.bcc){this.toggleCC("bcc")}$("subject").setValue(H.subject);$("in_reply_to").setValue(H.in_reply_to);$("references").setValue(H.references);$("reply_type").setValue(H.replytype);Field.focus(B||"to");this.resizeMsgArea();if(DIMP.conf_compose.show_editor){if(!this.editor_on){this.toggleHtmlEditor(E||false)}if(B=="message"){this.focusEditor()}}},focusEditor:function(){try{FCKeditorAPI.GetInstance("message").Focus()}catch(A){this.focusEditor.bind(this).defer()}},addAttach:function(E,B,D,C){var F=new Element("DIV").insert(B+" ["+D+"] ("+C+" KB) "),A=new Element("INPUT",{type:"button",atc_id:E,value:DIMP.text_compose.remove});F.insert(A);$("attach_list").insert(F);A.observe("click",this.removeAttach.bind(this,[A.up()]));this.resizeMsgArea()},removeAttach:function(B){var A=[];B.each(function(C){C=$(C);A.push(C.firstDescendant().readAttribute("atc_id"));C.remove()});DimpCore.doAction("DeleteAttach",{atc_indices:A,imp_compose:$F("composeCache")});this.resizeMsgArea()},resizeMsgArea:function(){var A,B,D=document.documentElement,C=$("message");if(!DimpCore.window_load){this.resizeMsgArea.bind(this).defer();return}if(this.editor_on){A=$("messageParent").select("iframe").last();if(A){A.setStyle({height:this.getMsgAreaHeight()+"px"})}else{this.resizeMsgArea.bind(this).defer()}return}this.mp_padding=$("messageParent").getHeight()-C.getHeight();if(!this.row_height){A=$(C.cloneNode(false)).writeAttribute({id:null,name:null}).setStyle({visibility:"hidden"});$(document.body).insert(A);A.writeAttribute("rows",1);this.row_height=A.getHeight();A.writeAttribute("rows",2);this.row_height=A.getHeight()-this.row_height;A.remove()}B=parseInt(this.getMsgAreaHeight()/this.row_height);C.writeAttribute({rows:B,disabled:false});if(D.scrollHeight-D.clientHeight){C.writeAttribute({rows:B-1})}$("composeloading").hide()},uploadAttachment:function(){var A=$("upload");$("submit_frame").observe("load",this.attachmentComplete.bind(this));this.uniqueSubmit("add_attachment");A.stopObserving("change").replace(new Element("DIV",{id:"upload_wait"}).insert(DIMP.text_compose.uploading+" "+$F(A)))},attachmentComplete:function(){var A=$("submit_frame"),B=A.contentDocument||A.contentWindow.document;A.stopObserving("load");DimpCore.doActionComplete({responseText:B.body.innerHTML},this.uniqueSubmitCallback.bind(this))},toggleCC:function(A){$("send"+A).show();$("toggle"+A).up().hide()},setCursorPosition:function(B){var C,A;switch(DIMP.conf_compose.compose_cursor){case"top":C=0;$("message").setValue("\n"+$F("message"));break;case"bottom":C=$F("message").length;break;case"sig":C=$F("message").replace(/\r\n/g,"\n").lastIndexOf(this.get_identity($F("last_identity")).sig)-1;break;default:return}if(B.setSelectionRange){Field.focus(B);B.setSelectionRange(C,C)}else{if(B.createTextRange){A=B.createTextRange();A.collapse(true);A.moveStart("character",C);A.moveEnd("character",0);Field.select(A);A.scrollIntoView(true)}}},openAddressbook:function(){window.open(DIMP.conf_compose.abook_url,"contacts","toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,width=550,height=300,left=100,top=100")}},ResizeTextArea=Class.create({maxRows:5,initialize:function(C,B){this.field=$(C);this.defaultRows=Math.max(this.field.readAttribute("rows"),1);this.onResize=B;var A=this.resizeNeeded.bindAsEventListener(this);this.field.observe("mousedown",A).observe("keyup",A);this.resizeNeeded()},resizeNeeded:function(){var A=$F(this.field).split("\n"),C=this.field.readAttribute("cols"),B=A.size(),D=this.field.readAttribute("rows");A.each(function(E){if(E.length>=C){B+=Math.floor(E.length/C)}});if(B!=D){this.field.writeAttribute("rows",(B>D)?Math.min(B,this.maxRows):Math.max(this.defaultRows,B));if(this.onResize){this.onResize()}}}});document.observe("dom:loaded",function(){var B,A=DimpCompose,D=A.resizeMsgArea.bind(A),E=DimpCore.clickObserveHandler;A.resizeMsgArea();A.initializeSpellChecker();$("upload").observe("change",A.uploadAttachment.bind(A));A.resizeto=new ResizeTextArea("to",D);A.resizecc=new ResizeTextArea("cc",D);A.resizebcc=new ResizeTextArea("bcc",D);if(Prototype.Browser.WebKit){$("submit_frame").writeAttribute({position:"absolute",width:"1px",height:"1px"}).setStyle({left:"-999px"}).show()}if(B=$("compose_close")){E({d:B,f:A.confirmCancel.bind(A)})}E({d:$("send_button"),f:A.uniqueSubmit.bind(A,"send_message")});E({d:$("draft_button"),f:A.uniqueSubmit.bind(A,"save_draft")});["cc","bcc"].each(function(C){E({d:$("toggle"+C),f:A.toggleCC.bind(A,C)})});if(B=$("htmlcheckbox")){E({d:B,f:A.toggleHtmlCheckbox.bind(A),ns:true})}if(B=$("compose_specialchars")){E({d:B,f:function(){window.open(DIMP.conf_compose.specialchars_url,"chars","height=220,width=400")}})}$("writemsg").select(".composeAddrbook").each(function(C){E({d:C,f:A.openAddressbook.bind(A)})});$("compose").observe("submit",Event.stop);$("identity").observe("change",A.change_identity.bind(A));$("togglecc").observe("click",D);$("togglebcc").observe("click",D);Event.observe(window,"resize",D)}); \ No newline at end of file +var DimpCompose={last_msg:"",textarea_ready:true,confirmCancel:function(){if(window.confirm(DIMP.text_compose.cancel)){if(DIMP.conf_compose.auto_save_interval_val){DimpCore.doAction("DeleteDraft",{index:$F("index")})}return this._closeCompose()}},_closeCompose:function(){if(DIMP.conf_compose.qreply){this.closeQReply()}else{if(DIMP.baseWindow||DIMP.conf_compose.popup){DimpCore.closePopup()}else{DimpCore.redirect(DIMP.conf.URI_DIMP_INBOX)}}},closeQReply:function(){var a=$("attach_list").childElements();this.last_msg="";if(a.size()){this.removeAttach(a)}$("draft_index","composeCache").invoke("setValue","");$("qreply","sendcc","sendbcc").invoke("hide");[$("msgData"),$("togglecc").up(),$("togglebcc").up()].invoke("show");if(this.editor_on){this.toggleHtmlEditor()}$("compose").reset();if(this.auto_save_interval){this.auto_save_interval.stop()}},change_identity:function(){var e,b,g,f,a=$F("identity"),i=this.get_identity($F("last_identity")),h=$("message"),d=this.get_identity(a),c=$("save_sent_mail");$("sent_mail_folder_label").setText(d.id[5]);$("bcc").setValue(d.id[6]);if(c){c.writeAttribute("checked",d.id[4])}if(this.editor_on){b=FCKeditorAPI.GetInstance("message").GetHTML().replace(/\r\n/g,"\n");e="

";g="

"+d.sig.replace(/^ ?
\n/,"").replace(/ +/g," ")+"

";b=b.replace(/

\s*[\s\S]*?\s*<\/p>/,e)}else{b=$F(h).replace(/\r\n/g,"\n");e=i.sig;g=d.sig}f=(i.id[2])?b.indexOf(e):b.lastIndexOf(e);if(f!=-1){if(d.id[2]==i.id[2]){b=b.substring(0,f)+g+b.substring(f+e.length,b.length)}else{if(d.id[2]){b=g+b.substring(0,f)+b.substring(f+e.length,b.length)}else{b=b.substring(0,f)+b.substring(f+e.length,b.length)+g}}b=b.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n");if(this.editor_on){FCKeditorAPI.GetInstance("message").SetHTML(b)}else{h.setValue(b)}$("last_identity").setValue(a)}},get_identity:function(b,a){a=Object.isUndefined(a)?this.editor_on:a;return{id:DIMP.conf_compose.identities[b],sig:DIMP.conf_compose.identities[b][(a?1:0)].replace(/^\n/,"")}},uniqueSubmit:function(b){var a,d,f,e=$("compose");if(DIMP.SpellCheckerObject){DIMP.SpellCheckerObject.resume();if(!this.textarea_ready){this.uniqueSubmit.bind(this,b).defer();return}}e.setStyle({cursor:"wait"});if(b=="send_message"||b=="save_draft"){this.button_pressed=true;switch(b){case"send_message":if(!this.sbtext){f=$("send_button");this.sbtext=f.getText();f.setText(DIMP.text_compose.sending)}break;case"save_draft":if(!this.dbtext){a=$("draft_button");this.dbtext=a.getText();a.setText(DIMP.text_compose.saving)}break}if(this.uploading){(function(){if(this.button_pressed){this.uniqueSubmit(b)}}).bind(this).delay(0.25);return}}$("action").setValue(b);if(b=="add_attachment"){this.uploading=true;e.submit()}else{if(this.editor_on){FCKeditorAPI.GetInstance("message").UpdateLinkedField()}d=e.serialize(true);if(!DIMP.baseWindow){d.nonotify=true}DimpCore.doAction("*"+DIMP.conf.compose_url,d,null,this.uniqueSubmitCallback.bind(this))}},uniqueSubmitCallback:function(b){var a,c=b.response;if(!c){return}if(c.imp_compose){$("composeCache").setValue(c.imp_compose)}if(c.success||c.action=="add_attachment"){switch(c.action){case"auto_save_draft":this.button_pressed=false;$("draft_index").setValue(c.draft_index);break;case"save_draft":this.button_pressed=false;if(DIMP.baseWindow){DIMP.baseWindow.DimpBase.pollFolders();DIMP.baseWindow.DimpCore.showNotifications(b.msgs)}if(DIMP.conf_compose.close_draft){return this._closeCompose()}break;case"send_message":this.button_pressed=false;if(DIMP.baseWindow){if(c.reply_type=="reply"){DIMP.baseWindow.DimpBase.flag("answered",c.index,c.reply_folder)}if(c.folder){DIMP.baseWindow.DimpBase.createFolder(c.folder)}if(c.draft_delete){DIMP.baseWindow.DimpBase.pollFolders()}DIMP.baseWindow.DimpCore.showNotifications(b.msgs)}return this._closeCompose();case"add_attachment":this.uploading=false;if(c.success){this.addAttach(c.info.number,c.info.name,c.info.type,c.info.size)}else{this.button_pressed=false}if(DIMP.conf_compose.attach_limit!=-1&&$("attach_list").childElements().size()>DIMP.conf_compose.attach_limit){$("upload").writeAttribute("disabled",false);a=new Element("DIV",[DIMP.text_compose.attachment_limit])}else{a=new Element("INPUT",{type:"file",name:"file_1"});a.observe("change",this.uploadAttachment.bind(this))}$("upload_wait").replace(a.writeAttribute("id","upload"));this.resizeMsgArea();break}}else{this.button_pressed=false}$("compose").setStyle({cursor:null});if(!this.button_pressed){if(this.sbtext){$("send_button").setText(this.sbtext)}if(this.dbtext){$("draft_button").setText(this.dbtext)}this.dbtext=this.sbtext=null}DimpCore.showNotifications(b.msgs)},toggleHtmlEditor:function(a){if(!DIMP.conf_compose.rte_avail){return}a=a||false;if(DIMP.SpellCheckerObject){DIMP.SpellCheckerObject.resume()}var c;if(this.editor_on){this.editor_on=false;c=FCKeditorAPI.GetInstance("message").GetHTML();$("messageParent").childElements().invoke("hide");$("message").show();DimpCore.doAction("Html2Text",{text:c},null,this.setMessageText.bind(this),{asynchronous:false})}else{this.editor_on=true;if(!a){DimpCore.doAction("Text2Html",{text:$F("message")},null,this.setMessageText.bind(this),{asynchronous:false})}oFCKeditor.Height=this.getMsgAreaHeight();try{FCKeditorAPI.GetInstance("message").SetHTML($F("message"));$("messageParent").childElements().invoke("show");$("message").hide()}catch(b){this._RTELoading("show");FCKeditor_OnComplete=this._RTELoading.curry("hide");oFCKeditor.ReplaceTextarea()}}$("htmlcheckbox").checked=this.editor_on;$("html").setValue(this.editor_on?1:0)},_RTELoading:function(b){var c,a;if(!$("rteloading")){a=new Element("DIV",{id:"rteloading"}).clonePosition($("messageParent"));$(document.body).insert(a);c=a.viewportOffset();$(document.body).insert(new Element("SPAN",{id:"rteloadingtxt"}).setStyle({top:(c.top+15)+"px",left:(c.left+15)+"px"}).insert(DIMP.text.loading))}$("rteloading","rteloadingtxt").invoke(b)},toggleHtmlCheckbox:function(){if(!this.editor_on||window.confirm(DIMP.text_compose.toggle_html)){this.toggleHtmlEditor()}},getMsgAreaHeight:function(){return document.viewport.getHeight()-$("messageParent").cumulativeOffset()[1]-this.mp_padding},initializeSpellChecker:function(){if(!DIMP.conf_compose.rte_avail){return}if(typeof DIMP.SpellCheckerObject!="object"){this.initializeSpellChecker.bind(this).defer();return}DIMP.SpellCheckerObject.onBeforeSpellCheck=function(){if(!this.editor_on){return}DIMP.SpellCheckerObject.htmlAreaParent="messageParent";DIMP.SpellCheckerObject.htmlArea=$("message").adjacent("iframe[id*=message]").first();$("message").setValue(FCKeditorAPI.GetInstance("message").GetHTML());this.textarea_ready=false}.bind(this);DIMP.SpellCheckerObject.onAfterSpellCheck=function(){if(!this.editor_on){return}DIMP.SpellCheckerObject.htmlArea=DIMP.SpellCheckerObject.htmlAreaParent=null;var a=FCKeditorAPI.GetInstance("message");a.SetHTML($F("message"));a.Events.AttachEvent("OnAfterSetHTML",function(){this.textarea_ready=true}.bind(this))}.bind(this)},setMessageText:function(b){var a=$("message");if(!a){$("messageParent").insert(new Element("TEXTAREA",{id:"message",name:"message",style:"width:100%;"}).insert(b.response.text))}else{a.setValue(b.response.text)}if(!this.editor_on){this.resizeMsgArea()}},fillForm:function(g,h,b,e){if(!this.resizeto){this.fillForm.bind(this,g,h,b,e).defer();return}var a,d,c=this.get_identity($F("last_identity")),f=$("message");if(!this.last_msg.empty()&&this.last_msg!=$F(f).replace(/\r/g,"")&&!window.confirm(DIMP.text_compose.fillform)){return}if(DIMP.conf_compose.auto_save_interval_val&&!this.auto_save_interval){this.auto_save_interval=new PeriodicalExecuter(function(){var i;if(this.editor_on){i=FCKeditorAPI.GetInstance("message").GetHTML()}else{i=$F(f)}i=i.replace(/\r/g,"");if(!i.empty()&&this.last_msg!=i){this.uniqueSubmit("auto_save_draft");this.last_msg=i}}.bind(this),DIMP.conf_compose.auto_save_interval_val*60)}if(this.editor_on){d=FCKeditorAPI.GetInstance("message");d.SetHTML(g);this.last_msg=d.GetHTML().replace(/\r/g,"")}else{f.setValue(g);this.setCursorPosition(f);this.last_msg=$F(f).replace(/\r/g,"")}$("to").setValue(h.to);this.resizeto.resizeNeeded();if(h.cc){$("cc").setValue(h.cc);this.resizecc.resizeNeeded()}if(DIMP.conf_compose.cc){this.toggleCC("cc")}if(h.bcc){$("bcc").setValue(h.bcc);this.resizebcc.resizeNeeded()}if(c.id[6]){a=$F("bcc");if(a){a+=", "}$("bcc").setValue(a+c.id[6])}if(DIMP.conf_compose.bcc){this.toggleCC("bcc")}$("subject").setValue(h.subject);$("in_reply_to").setValue(h.in_reply_to);$("references").setValue(h.references);$("reply_type").setValue(h.replytype);Field.focus(b||"to");this.resizeMsgArea();if(DIMP.conf_compose.show_editor){if(!this.editor_on){this.toggleHtmlEditor(e||false)}if(b=="message"){this.focusEditor()}}},focusEditor:function(){try{FCKeditorAPI.GetInstance("message").Focus()}catch(a){this.focusEditor.bind(this).defer()}},addAttach:function(e,b,d,c){var f=new Element("DIV").insert(b+" ["+d+"] ("+c+" KB) "),a=new Element("INPUT",{type:"button",atc_id:e,value:DIMP.text_compose.remove});f.insert(a);$("attach_list").insert(f);a.observe("click",this.removeAttach.bind(this,[a.up()]));this.resizeMsgArea()},removeAttach:function(b){var a=[];b.each(function(c){c=$(c);a.push(c.firstDescendant().readAttribute("atc_id"));c.remove()});DimpCore.doAction("DeleteAttach",{atc_indices:a,imp_compose:$F("composeCache")});this.resizeMsgArea()},resizeMsgArea:function(){var a,b,d=document.documentElement,c=$("message");if(!DimpCore.window_load){this.resizeMsgArea.bind(this).defer();return}if(this.editor_on){a=$("messageParent").select("iframe").last();if(a){a.setStyle({height:this.getMsgAreaHeight()+"px"})}else{this.resizeMsgArea.bind(this).defer()}return}this.mp_padding=$("messageParent").getHeight()-c.getHeight();if(!this.row_height){a=$(c.cloneNode(false)).writeAttribute({id:null,name:null}).setStyle({visibility:"hidden"});$(document.body).insert(a);a.writeAttribute("rows",1);this.row_height=a.getHeight();a.writeAttribute("rows",2);this.row_height=a.getHeight()-this.row_height;a.remove()}b=parseInt(this.getMsgAreaHeight()/this.row_height);c.writeAttribute({rows:b,disabled:false});if(d.scrollHeight-d.clientHeight){c.writeAttribute({rows:b-1})}$("composeloading").hide()},uploadAttachment:function(){var a=$("upload");$("submit_frame").observe("load",this.attachmentComplete.bind(this));this.uniqueSubmit("add_attachment");a.stopObserving("change").replace(new Element("DIV",{id:"upload_wait"}).insert(DIMP.text_compose.uploading+" "+$F(a)))},attachmentComplete:function(){var a=$("submit_frame"),b=a.contentDocument||a.contentWindow.document;a.stopObserving("load");DimpCore.doActionComplete({responseJSON:b.body.innerHTML.evalJSON(true)},this.uniqueSubmitCallback.bind(this))},toggleCC:function(a){$("send"+a).show();$("toggle"+a).up().hide()},setCursorPosition:function(b){var c,a;switch(DIMP.conf_compose.compose_cursor){case"top":c=0;$("message").setValue("\n"+$F("message"));break;case"bottom":c=$F("message").length;break;case"sig":c=$F("message").replace(/\r\n/g,"\n").lastIndexOf(this.get_identity($F("last_identity")).sig)-1;break;default:return}if(b.setSelectionRange){Field.focus(b);b.setSelectionRange(c,c)}else{if(b.createTextRange){a=b.createTextRange();a.collapse(true);a.moveStart("character",c);a.moveEnd("character",0);Field.select(a);a.scrollIntoView(true)}}},openAddressbook:function(){window.open(DIMP.conf_compose.abook_url,"contacts","toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,width=550,height=300,left=100,top=100")}},ResizeTextArea=Class.create({maxRows:5,initialize:function(c,b){this.field=$(c);this.defaultRows=Math.max(this.field.readAttribute("rows"),1);this.onResize=b;var a=this.resizeNeeded.bindAsEventListener(this);this.field.observe("mousedown",a).observe("keyup",a);this.resizeNeeded()},resizeNeeded:function(){var a=$F(this.field).split("\n"),c=this.field.readAttribute("cols"),b=a.size(),d=this.field.readAttribute("rows");a.each(function(e){if(e.length>=c){b+=Math.floor(e.length/c)}});if(b!=d){this.field.writeAttribute("rows",(b>d)?Math.min(b,this.maxRows):Math.max(this.defaultRows,b));if(this.onResize){this.onResize()}}}});document.observe("dom:loaded",function(){var b,a=DimpCompose,c=a.resizeMsgArea.bind(a),d=DimpCore.clickObserveHandler;a.resizeMsgArea();a.initializeSpellChecker();$("upload").observe("change",a.uploadAttachment.bind(a));a.resizeto=new ResizeTextArea("to",c);a.resizecc=new ResizeTextArea("cc",c);a.resizebcc=new ResizeTextArea("bcc",c);if(Prototype.Browser.WebKit){$("submit_frame").writeAttribute({position:"absolute",width:"1px",height:"1px"}).setStyle({left:"-999px"}).show()}if(b=$("compose_close")){d({d:b,f:a.confirmCancel.bind(a)})}d({d:$("send_button"),f:a.uniqueSubmit.bind(a,"send_message")});d({d:$("draft_button"),f:a.uniqueSubmit.bind(a,"save_draft")});["cc","bcc"].each(function(e){d({d:$("toggle"+e),f:a.toggleCC.bind(a,e)})});if(b=$("htmlcheckbox")){d({d:b,f:a.toggleHtmlCheckbox.bind(a),ns:true})}if(b=$("compose_specialchars")){d({d:b,f:function(){window.open(DIMP.conf_compose.specialchars_url,"chars","height=220,width=400")}})}$("writemsg").select(".composeAddrbook").each(function(e){d({d:e,f:a.openAddressbook.bind(a)})});$("compose").observe("submit",Event.stop);$("identity").observe("change",a.change_identity.bind(a));$("togglecc").observe("click",c);$("togglebcc").observe("click",c);Event.observe(window,"resize",c)}); \ No newline at end of file diff --git a/imp/js/compose.js b/imp/js/compose.js index 035ce1309..0a1464b77 100644 --- a/imp/js/compose.js +++ b/imp/js/compose.js @@ -1 +1 @@ -var display_unload_warning=true,textarea_ready=true;function confirmCancel(A){if(window.confirm(IMP.text.compose_cancel)){display_unload_warning=false;if(popup){if(cancel_url){self.location=cancel_url}else{self.close()}}else{window.location=cancel_url}return true}else{Event.extend(A);A.stop();return false}}function setCursorPosition(C,A){if(C.setSelectionRange){Field.focus(C);C.setSelectionRange(A,A)}else{if(C.createTextRange){var B=C.createTextRange();B.collapse(true);B.moveStart("character",A);B.moveEnd("character",0);Field.select(B);B.scrollIntoView(true)}}}function redirectSubmit(A){if($F("to")==""){alert(IMP.text.compose_recipient);$("to").focus();Event.extend(A);A.stop();return false}$("redirect").setStyle({cursor:"wait"});display_unload_warning=false;return true}function change_identity(A){var L=identities[$F("last_identity")],D=identities[A],B,E,G,K;if(rtemode){E=FCKeditorAPI.GetInstance("message");B=E.GetHTML.replace(/\r\n/g,"\n");G="

";K="

"+D[0].replace(/^ ?
\n/,"").replace(/ +/g," ")+"

";B=B.replace(/

\s*[\s\S]*?\s*<\/p>/,G)}else{B=$F("message").replace(/\r\n/g,"\n");G=L[0].replace(/^\n/,"");K=D[0].replace(/^\n/,"")}var J=(L[1])?B.indexOf(G):B.lastIndexOf(G);if(J!=-1){if(D[1]==L[1]){B=B.substring(0,J)+K+B.substring(J+G.length,B.length)}else{if(D[1]){B=K+B.substring(0,J)+B.substring(J+G.length,B.length)}else{B=B.substring(0,J)+B.substring(J+G.length,B.length)+K}}B=B.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n");$("last_identity").setValue(A);window.status=IMP.text.compose_sigreplace}else{window.status=IMP.text.compose_signotreplace}if(rtemode){E.SetHTML(B)}else{$("message").setValue(B)}var I=$("sent_mail_folder");if(smf_check){var C=0;$A(I.options).detect(function(N){if(N.value==D[2]){I.selectedIndex=C;return true}++C})}else{if(I.firstChild){I.replaceChild(document.createTextNode(D[2]),I.firstChild)}else{I.appendChild(document.createTextNode(D[2]))}}var H=$("ssm");if(H){H.checked=D[3]}var F=$("bcc");if(F){bccval=F.value;if(L[4]){var M=new RegExp(L[4]+",? ?","gi");bccval=bccval.replace(M,"");if(bccval){bccval=bccval.replace(/, ?$/,"")}}if(D[4]){if(bccval){bccval+=", "}bccval+=D[4]}F.setValue(bccval)}}function uniqSubmit(B,A){if(A){Event.extend(A);A.stop()}if(B=="send_message"){if(($F("subject")=="")&&!window.confirm(IMP.text.compose_nosubject)){return}if(compose_spellcheck&&IMP.SpellCheckerObject&&!IMP.SpellCheckerObject.isActive()){IMP.SpellCheckerObject.spellCheck();return}}if(IMP.SpellCheckerObject){IMP.SpellCheckerObject.resume()}if(!Prototype.Browser.WebKit){$("compose").setStyle({cursor:"wait"})}display_unload_warning=false;$("actionID").setValue(B);_uniqSubmit()}function _uniqSubmit(){if(textarea_ready){$("compose").submit()}else{_uniqSubmit.defer()}}function attachmentChanged(){var A=[],E=0;$("upload_atc").select('input[type="file"]').each(function(G){A[A.length]=G});if(max_attachments!==null&&A.length==max_attachments){return}A.each(function(G){if(G.value.length>0){E++}});if(E==A.length){var D=$("attachment_row_"+E);if(D){var F=new Element("TD",{align:"left"}).insert(new Element("STRONG").insert(IMP.text.compose_file+" "+(E+1)+":")).insert(" ");var C=new Element("INPUT",{type:"file",name:"upload_"+(E+1),size:25});C.observe("change",attachmentChanged);F.insert(C);var B=new Element("TR",{id:"attachment_row_"+(E+1)}).insert(F);D.parentNode.insertBefore(B,D.nextSibling)}}}function initializeSpellChecker(){if(typeof IMP.SpellCheckerObject!="object"){initializeSpellChecker.defer();return}IMP.SpellCheckerObject.onBeforeSpellCheck=function(){IMP.SpellCheckerObject.htmlAreaParent="messageParent";IMP.SpellCheckerObject.htmlArea=$("message").adjacent("iframe[id*=message]").first();$("message").setValue(FCKeditorAPI.GetInstance("message").GetHTML());textarea_ready=false};IMP.SpellCheckerObject.onAfterSpellCheck=function(){IMP.SpellCheckerObject.htmlArea=IMP.SpellCheckerObject.htmlAreaParent=null;var A=FCKeditorAPI.GetInstance("message");A.SetHTML($("message").value);A.Events.AttachEvent("OnAfterSetHTML",function(){textarea_ready=true})}}document.observe("dom:loaded",function(){$$("INPUT").each(function(A){if(A.type!="submit"&&A.type!="button"){A.observe("keydown",function(B){if(B.keyCode==10||B.keyCode==Event.KEY_RETURN){B.stop();return false}})}});if(cursor_pos!==null&&$("message")){setCursorPosition($("message"),cursor_pos)}if(redirect){$("to").focus()}else{if(Prototype.Browser.IE){$("subject").observe("keydown",function(A){if(A.keyCode==Event.KEY_TAB&&!A.shiftKey){A.stop();$("message").focus()}})}if(rtemode){initializeSpellChecker()}if($("to")&&!$F("to")){$("to").focus()}else{if(!$F("subject")){if(rtemode){$("subject").focus()}else{$("message").focus()}}}}});Event.observe(window,"load",function(){if(compose_popup&&!reloaded){var B,A=redirect?$("redirect"):$("compose");B=Math.min(A.getHeight(),screen.height-100)-document.viewport.getHeight();if(B>0){window.resizeBy(0,B)}}});Event.observe(window,"beforeunload",function(){if(display_unload_warning){return IMP.text.compose_discard}}); \ No newline at end of file +var display_unload_warning=true,textarea_ready=true;function confirmCancel(a){if(window.confirm(IMP.text.compose_cancel)){display_unload_warning=false;if(popup){if(cancel_url){self.location=cancel_url}else{self.close()}}else{window.location=cancel_url}return true}else{Event.extend(a);a.stop();return false}}function setCursorPosition(c,a){if(c.setSelectionRange){Field.focus(c);c.setSelectionRange(a,a)}else{if(c.createTextRange){var b=c.createTextRange();b.collapse(true);b.moveStart("character",a);b.moveEnd("character",0);Field.select(b);b.scrollIntoView(true)}}}function redirectSubmit(a){if($F("to")==""){alert(IMP.text.compose_recipient);$("to").focus();Event.extend(a);a.stop();return false}$("redirect").setStyle({cursor:"wait"});display_unload_warning=false;return true}function change_identity(a){var m=identities[$F("last_identity")],d=identities[a],b,e,g,l;if(rtemode){e=FCKeditorAPI.GetInstance("message");b=e.GetHTML.replace(/\r\n/g,"\n");g="

";l="

"+d[0].replace(/^ ?
\n/,"").replace(/ +/g," ")+"

";b=b.replace(/

\s*[\s\S]*?\s*<\/p>/,g)}else{b=$F("message").replace(/\r\n/g,"\n");g=m[0].replace(/^\n/,"");l=d[0].replace(/^\n/,"")}var k=(m[1])?b.indexOf(g):b.lastIndexOf(g);if(k!=-1){if(d[1]==m[1]){b=b.substring(0,k)+l+b.substring(k+g.length,b.length)}else{if(d[1]){b=l+b.substring(0,k)+b.substring(k+g.length,b.length)}else{b=b.substring(0,k)+b.substring(k+g.length,b.length)+l}}b=b.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n");$("last_identity").setValue(a);window.status=IMP.text.compose_sigreplace}else{window.status=IMP.text.compose_signotreplace}if(rtemode){e.SetHTML(b)}else{$("message").setValue(b)}var j=$("sent_mail_folder");if(smf_check){var c=0;$A(j.options).detect(function(i){if(i.value==d[2]){j.selectedIndex=c;return true}++c})}else{if(j.firstChild){j.replaceChild(document.createTextNode(d[2]),j.firstChild)}else{j.appendChild(document.createTextNode(d[2]))}}var h=$("ssm");if(h){h.checked=d[3]}var f=$("bcc");if(f){bccval=f.value;if(m[4]){var n=new RegExp(m[4]+",? ?","gi");bccval=bccval.replace(n,"");if(bccval){bccval=bccval.replace(/, ?$/,"")}}if(d[4]){if(bccval){bccval+=", "}bccval+=d[4]}f.setValue(bccval)}}function uniqSubmit(b,a){if(a){Event.extend(a);a.stop()}if(b=="send_message"){if(($F("subject")=="")&&!window.confirm(IMP.text.compose_nosubject)){return}if(compose_spellcheck&&IMP.SpellCheckerObject&&!IMP.SpellCheckerObject.isActive()){IMP.SpellCheckerObject.spellCheck();return}}if(IMP.SpellCheckerObject){IMP.SpellCheckerObject.resume()}if(!Prototype.Browser.WebKit){$("compose").setStyle({cursor:"wait"})}display_unload_warning=false;$("actionID").setValue(b);_uniqSubmit()}function _uniqSubmit(){if(textarea_ready){$("compose").submit()}else{_uniqSubmit.defer()}}function attachmentChanged(){var a=[],e=0;$("upload_atc").select('input[type="file"]').each(function(g){a[a.length]=g});if(max_attachments!==null&&a.length==max_attachments){return}a.each(function(g){if(g.value.length>0){e++}});if(e==a.length){var d=$("attachment_row_"+e);if(d){var f=new Element("TD",{align:"left"}).insert(new Element("STRONG").insert(IMP.text.compose_file+" "+(e+1)+":")).insert(" ");var c=new Element("INPUT",{type:"file",name:"upload_"+(e+1),size:25});c.observe("change",attachmentChanged);f.insert(c);var b=new Element("TR",{id:"attachment_row_"+(e+1)}).insert(f);d.parentNode.insertBefore(b,d.nextSibling)}}}function initializeSpellChecker(){if(typeof IMP.SpellCheckerObject!="object"){initializeSpellChecker.defer();return}IMP.SpellCheckerObject.onBeforeSpellCheck=function(){IMP.SpellCheckerObject.htmlAreaParent="messageParent";IMP.SpellCheckerObject.htmlArea=$("message").adjacent("iframe[id*=message]").first();$("message").setValue(FCKeditorAPI.GetInstance("message").GetHTML());textarea_ready=false};IMP.SpellCheckerObject.onAfterSpellCheck=function(){IMP.SpellCheckerObject.htmlArea=IMP.SpellCheckerObject.htmlAreaParent=null;var a=FCKeditorAPI.GetInstance("message");a.SetHTML($("message").value);a.Events.AttachEvent("OnAfterSetHTML",function(){textarea_ready=true})}}document.observe("dom:loaded",function(){$$("INPUT").each(function(a){if(a.type!="submit"&&a.type!="button"){a.observe("keydown",function(b){if(b.keyCode==10||b.keyCode==Event.KEY_RETURN){b.stop();return false}})}});if(cursor_pos!==null&&$("message")){setCursorPosition($("message"),cursor_pos)}if(redirect){$("to").focus()}else{if(Prototype.Browser.IE){$("subject").observe("keydown",function(a){if(a.keyCode==Event.KEY_TAB&&!a.shiftKey){a.stop();$("message").focus()}})}if(rtemode){initializeSpellChecker()}if($("to")&&!$F("to")){$("to").focus()}else{if(!$F("subject")){if(rtemode){$("subject").focus()}else{$("message").focus()}}}}});Event.observe(window,"load",function(){if(compose_popup&&!reloaded){var b,a=redirect?$("redirect"):$("compose");b=Math.min(a.getHeight(),screen.height-100)-document.viewport.getHeight();if(b>0){window.resizeBy(0,b)}}});Event.observe(window,"beforeunload",function(){if(display_unload_warning){return IMP.text.compose_discard}}); \ No newline at end of file diff --git a/imp/js/contacts.js b/imp/js/contacts.js index db46bc37e..9f526d2db 100644 --- a/imp/js/contacts.js +++ b/imp/js/contacts.js @@ -1 +1 @@ -function passAddresses(){var A="";$("selected_addresses").childElements().each(function(B){if(!B.value){return}A+=B.value+"|"});$("sa").setValue(A)}function sameOption(E,D,A){var C=E+": "+D.value,B=A.value;return Try.these(function(){return(C==B)||(decodeURIComponent(C)==decodeURIComponent(B))},function(){return(C==B)})}function addAddress(D){var C=$("search_results");if(!$F(C).size()){alert(IMP.text.contacts_select);return false}else{var E=$("selected_addresses"),A=$A(E).length,B;C.childElements().each(function(F){if(F.value&&F.selected){if(!$A(E).any(function(G){return sameOption(D,F,G)})){B=D+": "+F.value;E[A++]=new Option(B,B)}}})}return true}function updateMessage(){if(parent.opener.closed){alert(IMP.text.contacts_closed);this.close();return}if(!parent.opener.document[formname]){alert(IMP.text.contacts_called);this.close();return}$("selected_addresses").childElements().each(function(C){var A=C.value,D,E=null,F,B;F=A.indexOf(":");D=A.substring(0,F);A=A.substring(F+2,A.length);if(D=="to"){E=parent.opener.document[formname].to}else{if(!to_only&&D=="cc"){E=parent.opener.document[formname].cc}else{if(!to_only&&D=="bcc"){E=parent.opener.document[formname].bcc}else{return}}}if(E.value.length){B=E.value.replace(/, +/g,",").split(",").findAll(function(G){return G});E.value=B.join(", ");if(E.value.lastIndexOf(";")!=E.value.length-1){E.value+=","}E.value+=" "+A}else{E.value=A}if(A.lastIndexOf(";")!=A.length-1){E.value+=", "}});this.close()}function removeAddress(){$("selected_addresses").childElements().each(function(A){if(A.selected){A.remove()}})}; \ No newline at end of file +function passAddresses(){var a="";$("selected_addresses").childElements().each(function(b){if(!b.value){return}a+=b.value+"|"});$("sa").setValue(a)}function sameOption(e,d,a){var c=e+": "+d.value,b=a.value;return Try.these(function(){return(c==b)||(decodeURIComponent(c)==decodeURIComponent(b))},function(){return(c==b)})}function addAddress(e){var c=$("search_results");if(!$F(c).size()){alert(IMP.text.contacts_select);return false}else{var g=$("selected_addresses"),a=$A(g).length,b;c.childElements().each(function(d){if(d.value&&d.selected){if(!$A(g).any(function(f){return sameOption(e,d,f)})){b=e+": "+d.value;g[a++]=new Option(b,b)}}})}return true}function updateMessage(){if(parent.opener.closed){alert(IMP.text.contacts_closed);this.close();return}if(!parent.opener.document[formname]){alert(IMP.text.contacts_called);this.close();return}$("selected_addresses").childElements().each(function(c){var a=c.value,d,e=null,g,b;g=a.indexOf(":");d=a.substring(0,g);a=a.substring(g+2,a.length);if(d=="to"){e=parent.opener.document[formname].to}else{if(!to_only&&d=="cc"){e=parent.opener.document[formname].cc}else{if(!to_only&&d=="bcc"){e=parent.opener.document[formname].bcc}else{return}}}if(e.value.length){b=e.value.replace(/, +/g,",").split(",").findAll(function(f){return f});e.value=b.join(", ");if(e.value.lastIndexOf(";")!=e.value.length-1){e.value+=","}e.value+=" "+a}else{e.value=a}if(a.lastIndexOf(";")!=a.length-1){e.value+=", "}});this.close()}function removeAddress(){$("selected_addresses").childElements().each(function(a){if(a.selected){a.remove()}})}; \ No newline at end of file diff --git a/imp/js/dragdrop.js b/imp/js/dragdrop.js index 01c7648c3..590a92b29 100644 --- a/imp/js/dragdrop.js +++ b/imp/js/dragdrop.js @@ -1 +1 @@ -var DragDrop={Drags:{drags:$H(),register:function(A){if(!this.drags.size()){if(!this.div){this.div=new Element("DIV",{className:A.options.classname}).hide()}$(document.body).insert(this.div)}this.drags.set(A.element.readAttribute("id"),A)},unregister:function(A){if(this.drag==A.element){this.drag.deactivate()}this.drags.unset(A.element.readAttribute("id"));if(!this.drags.size()&&this.div){this.div.remove()}},get_drag:function(A){return this.drags.get(Object.isElement(A)?$(A).readAttribute("id"):A)},activate:function(A){if(this.drag){this.deactivate()}this.drag=A;this.mousemoveE=A._mouseMove.bindAsEventListener(A);this.mouseupE=A._mouseUp.bindAsEventListener(A);document.observe("mousemove",this.mousemoveE);document.observe("mouseup",this.mouseupE)},deactivate:function(){if(this.drag){this.drag=null;document.stopObserving("mousemove",this.mousemoveE);document.stopObserving("mouseup",this.mouseupE)}}},Drops:{drops:$H(),register:function(A){this.drops.set(A.element.readAttribute("id"),A)},unregister:function(A){if(this.drop==A.element){this.drop=null}this.drops.unset(A.element.readAttribute("id"))},get_drop:function(A){return this.drops.get(Object.isElement(A)?$(A).readAttribute("id"):A)}},validDrop:function(A){var B=DragDrop.Drops.drop;return(B&&A&&A!=B.element&&(!B.options.accept.size()||B.options.accept.include(A.tagName)))}},Drag=Class.create({initialize:function(A){this.element=$(A);this.options=Object.extend({caption:"",classname:"drag",constraint:null,ghosting:false,scroll:null,snap:null,threshold:0,onDrag:null,onEnd:null,onStart:null},arguments[1]||{});this.mousedownE=this._mouseDown.bindAsEventListener(this);this.element.observe("mousedown",this.mousedownE);if(this.options.scroll){this.options.scroll=$(this.options.scroll)}DragDrop.Drags.register(this);if(Prototype.Browser.IE){this.element.observe("selectstart",Event.stop)}else{if(Prototype.Browser.Gecko){this.element.setStyle({MozUserSelect:"none"})}}},destroy:function(){this.element.stopObserving("mousedown",this.mousedownE);DragDrop.Drags.unregister(this)},_mouseDown:function(A){$(document.body).setStyle({cursor:"default"});DragDrop.Drags.activate(this);this.move=0;this.wasDragged=false;this.lastcaption=null;if(Object.isFunction(this.options.onStart)){this.options.onStart(this,A)}if(!Prototype.Browser.IE&&!Prototype.Browser.Gecko){A.stop()}},_mouseMove:function(E){var B,C,A,D;if(++this.move<=this.options.threshold){return}this.lastCoord=D=[E.pointerX(),E.pointerY()];if(this.options.ghosting){if(!this.ghost){B=this.element.offsetLeft;C=this.element.offsetTop;this.ghost=$(this.element.cloneNode(true)).writeAttribute("id",null).setOpacity(0.7).clonePosition(this.element,{setLeft:false,setTop:false}).setStyle({left:B+"px",position:"absolute",top:C+"px",zIndex:parseInt(this.element.getStyle("zIndex"))+1});this.element.insert({before:this.ghost});A=this.ghost.viewportOffset();this.ghostOffset=[A[0]-B,A[1]-C]}D[0]-=this.ghostOffset[0];D[1]-=this.ghostOffset[1];switch(this.options.constraint){case"horizontal":D[1]=this.ghost.offsetTop;break;case"vertical":D[0]=this.ghost.offsetLeft;break}if(this.options.snap){D=this.options.snap(D[0],D[1],this.element)}if(this.options.offset){D[0]+=this.options.offset.x;D[1]+=this.options.offset.y}this._setContents(this.ghost,D[0],D[1])}this._onMoveDrag(D,E);if(Object.isFunction(this.options.onDrag)){this.options.onDrag(this,E)}this.wasDragged=true;if(this.options.scroll){this._onMoveScroll()}},_mouseUp:function(A){var B=DragDrop.Drops.drop;this._stopScrolling();if(this.ghost){this.ghost.remove();this.ghost=null}DragDrop.Drags.div.hide();if(DragDrop.validDrop(this.element)&&Object.isFunction(B.options.onDrop)){B.options.onDrop(B.element,this.element,A)}DragDrop.Drags.deactivate();if(Object.isFunction(this.options.onEnd)){this.options.onEnd(this,A)}},_onMoveDrag:function(I,E){var G,H,D,C,F=DragDrop.Drops.drop,A=DragDrop.Drags.div,B=true;if(F&&DragDrop.validDrop(this.element)){C=F.options.caption;if(C){H=Object.isFunction(C)?C(F.element,this.element,E):C;if(H&&F.options.hoverclass){D=F.options.hoverclass}}else{B=false}}if(B){if(!H){G=this.options.caption;H=Object.isFunction(G)?G(this.element):G}if(H!=this.lastcaption){this.lastcaption=H;A.update(H).writeAttribute({className:D||this.options.classname});if(H.empty()){A.hide()}}}if(!this.lastcaption.empty()){this._setContents(A,I[0]+15,I[1]+(this.ghost?(this.ghost.getHeight()+5):5))}},_onMoveScroll:function(){this._stopScrolling();var E,D,B,A=this.options.scroll,C=A.getDimensions();if(A.scrollHeight==C.height){return}E=document.viewport.getScrollOffsets();D=A.viewportOffset(),B=[0,0];D[0]+=A.scrollLeft+E.left;D[2]=D[0]+C.width;if(this.lastCoord[0]>D[2]||this.lastCoord[0]D[3]){B[1]=this.lastCoord[1]-D[3]}if(B[0]||B[1]){this.lastScrolled=new Date();this.scrollInterval=setInterval(this._scroll.bind(this,B[0]*15,B[1]*15),10)}},_stopScrolling:function(){if(this.scrollInterval){clearInterval(this.scrollInterval);this.scrollInterval=null}},_scroll:function(A,E){var C=new Date(),D=C-this.lastScrolled,B=this.options.scroll;this.lastScrolled=C;B.scrollTop+=E*D/1000},_setContents:function(C,A,E){var D=document.viewport.getDimensions(),B=C.getDimensions();if((A+B.width>D.width)||(E+B.height>D.height)){C.hide()}else{C.setStyle({left:A+"px",top:E+"px"}).show()}}}),Drop=Class.create({initialize:function(A){this.element=$(A);this.options=Object.extend({accept:[],caption:"",hoverclass:"",onDrop:null,onOut:null,onOver:null},arguments[1]||{});this.mouseoverE=this._mouseOver.bindAsEventListener(this);this.mouseoutE=this._mouseOut.bindAsEventListener(this);this.element.observe("mouseover",this.mouseoverE);this.element.observe("mouseout",this.mouseoutE);DragDrop.Drops.register(this)},destroy:function(){this.element.stopObserving("mouseover",this.mouseoverE);this.element.stopObserving("mouseout",this.mouseoutE);DragDrop.Drops.unregister(this)},_mouseOver:function(A){if(DragDrop.Drags.drag){DragDrop.Drops.drop=this;if(Object.isFunction(this.options.onOver)){this.options.onOver(this.element,DragDrop.Drags.drag)}}},_mouseOut:function(A){if(Object.isFunction(this.options.onOut)){this.options.onOut(this.element,DragDrop.Drags.drag)}DragDrop.Drops.drop=null}}); \ No newline at end of file +var DragDrop={Drags:{drags:$H(),register:function(a){if(!this.drags.size()){if(!this.div){this.div=new Element("DIV",{className:a.options.classname}).hide()}$(document.body).insert(this.div)}this.drags.set(a.element.readAttribute("id"),a)},unregister:function(a){if(this.drag==a.element){this.drag.deactivate()}this.drags.unset(a.element.readAttribute("id"));if(!this.drags.size()&&this.div){this.div.remove()}},get_drag:function(a){return this.drags.get(Object.isElement(a)?$(a).readAttribute("id"):a)},activate:function(a){if(this.drag){this.deactivate()}this.drag=a;this.mousemoveE=a._mouseMove.bindAsEventListener(a);this.mouseupE=a._mouseUp.bindAsEventListener(a);document.observe("mousemove",this.mousemoveE);document.observe("mouseup",this.mouseupE)},deactivate:function(){if(this.drag){this.drag=null;document.stopObserving("mousemove",this.mousemoveE);document.stopObserving("mouseup",this.mouseupE)}}},Drops:{drops:$H(),register:function(a){this.drops.set(a.element.readAttribute("id"),a)},unregister:function(a){if(this.drop==a.element){this.drop=null}this.drops.unset(a.element.readAttribute("id"))},get_drop:function(a){return this.drops.get(Object.isElement(a)?$(a).readAttribute("id"):a)}},validDrop:function(a){var b=DragDrop.Drops.drop;return(b&&a&&a!=b.element&&(!b.options.accept.size()||b.options.accept.include(a.tagName)))}},Drag=Class.create({initialize:function(a){this.element=$(a);this.options=Object.extend({caption:"",classname:"drag",constraint:null,ghosting:false,scroll:null,snap:null,threshold:0,onDrag:null,onEnd:null,onStart:null},arguments[1]||{});this.mousedownE=this._mouseDown.bindAsEventListener(this);this.element.observe("mousedown",this.mousedownE);if(this.options.scroll){this.options.scroll=$(this.options.scroll)}DragDrop.Drags.register(this);if(Prototype.Browser.IE){this.element.observe("selectstart",Event.stop)}else{if(Prototype.Browser.Gecko){this.element.setStyle({MozUserSelect:"none"})}}},destroy:function(){this.element.stopObserving("mousedown",this.mousedownE);DragDrop.Drags.unregister(this)},_mouseDown:function(a){$(document.body).setStyle({cursor:"default"});DragDrop.Drags.activate(this);this.move=0;this.wasDragged=false;this.lastcaption=null;if(Object.isFunction(this.options.onStart)){this.options.onStart(this,a)}if(!Prototype.Browser.IE&&!Prototype.Browser.Gecko){a.stop()}},_mouseMove:function(f){var b,c,a,d;if(++this.move<=this.options.threshold){return}this.lastCoord=d=[f.pointerX(),f.pointerY()];if(this.options.ghosting){if(!this.ghost){b=this.element.offsetLeft;c=this.element.offsetTop;this.ghost=$(this.element.cloneNode(true)).writeAttribute("id",null).setOpacity(0.7).clonePosition(this.element,{setLeft:false,setTop:false}).setStyle({left:b+"px",position:"absolute",top:c+"px",zIndex:parseInt(this.element.getStyle("zIndex"))+1});this.element.insert({before:this.ghost});a=this.ghost.viewportOffset();this.ghostOffset=[a[0]-b,a[1]-c]}d[0]-=this.ghostOffset[0];d[1]-=this.ghostOffset[1];switch(this.options.constraint){case"horizontal":d[1]=this.ghost.offsetTop;break;case"vertical":d[0]=this.ghost.offsetLeft;break}if(this.options.snap){d=this.options.snap(d[0],d[1],this.element)}if(this.options.offset){d[0]+=this.options.offset.x;d[1]+=this.options.offset.y}this._setContents(this.ghost,d[0],d[1])}this._onMoveDrag(d,f);if(Object.isFunction(this.options.onDrag)){this.options.onDrag(this,f)}this.wasDragged=true;if(this.options.scroll){this._onMoveScroll()}},_mouseUp:function(a){var b=DragDrop.Drops.drop;this._stopScrolling();if(this.ghost){this.ghost.remove();this.ghost=null}DragDrop.Drags.div.hide();if(DragDrop.validDrop(this.element)&&Object.isFunction(b.options.onDrop)){b.options.onDrop(b.element,this.element,a)}DragDrop.Drags.deactivate();if(Object.isFunction(this.options.onEnd)){this.options.onEnd(this,a)}},_onMoveDrag:function(k,g){var i,j,f,c,h=DragDrop.Drops.drop,a=DragDrop.Drags.div,b=true;if(h&&DragDrop.validDrop(this.element)){c=h.options.caption;if(c){j=Object.isFunction(c)?c(h.element,this.element,g):c;if(j&&h.options.hoverclass){f=h.options.hoverclass}}else{b=false}}if(b){if(!j){i=this.options.caption;j=Object.isFunction(i)?i(this.element):i}if(j!=this.lastcaption){this.lastcaption=j;a.update(j).writeAttribute({className:f||this.options.classname});if(j.empty()){a.hide()}}}if(!this.lastcaption.empty()){this._setContents(a,k[0]+15,k[1]+(this.ghost?(this.ghost.getHeight()+5):5))}},_onMoveScroll:function(){this._stopScrolling();var e,d,b,a=this.options.scroll,c=a.getDimensions();if(a.scrollHeight==c.height){return}e=document.viewport.getScrollOffsets();d=a.viewportOffset(),b=[0,0];d[0]+=a.scrollLeft+e.left;d[2]=d[0]+c.width;if(this.lastCoord[0]>d[2]||this.lastCoord[0]d[3]){b[1]=this.lastCoord[1]-d[3]}if(b[0]||b[1]){this.lastScrolled=new Date();this.scrollInterval=setInterval(this._scroll.bind(this,b[0]*15,b[1]*15),10)}},_stopScrolling:function(){if(this.scrollInterval){clearInterval(this.scrollInterval);this.scrollInterval=null}},_scroll:function(a,e){var c=new Date(),d=c-this.lastScrolled,b=this.options.scroll;this.lastScrolled=c;b.scrollTop+=e*d/1000},_setContents:function(c,a,e){var d=document.viewport.getDimensions(),b=c.getDimensions();if((a+b.width>d.width)||(e+b.height>d.height)){c.hide()}else{c.setStyle({left:a+"px",top:e+"px"}).show()}}}),Drop=Class.create({initialize:function(a){this.element=$(a);this.options=Object.extend({accept:[],caption:"",hoverclass:"",onDrop:null,onOut:null,onOver:null},arguments[1]||{});this.mouseoverE=this._mouseOver.bindAsEventListener(this);this.mouseoutE=this._mouseOut.bindAsEventListener(this);this.element.observe("mouseover",this.mouseoverE);this.element.observe("mouseout",this.mouseoutE);DragDrop.Drops.register(this)},destroy:function(){this.element.stopObserving("mouseover",this.mouseoverE);this.element.stopObserving("mouseout",this.mouseoutE);DragDrop.Drops.unregister(this)},_mouseOver:function(a){if(DragDrop.Drags.drag){DragDrop.Drops.drop=this;if(Object.isFunction(this.options.onOver)){this.options.onOver(this.element,DragDrop.Drags.drag)}}},_mouseOut:function(a){if(Object.isFunction(this.options.onOut)){this.options.onOut(this.element,DragDrop.Drags.drag)}DragDrop.Drops.drop=null}}); \ No newline at end of file diff --git a/imp/js/encrypt.js b/imp/js/encrypt.js index f96a341f2..f7cb51f9c 100644 --- a/imp/js/encrypt.js +++ b/imp/js/encrypt.js @@ -1 +1 @@ -var IMPEncrypt={display:function(A){A=decodeURIComponent(A).evalJSON(true);this.action=A.action;this.params=A.params;this.uri=A.uri;var B=new Element("FORM",{action:"#",id:"RB_confirm"}).insert(new Element("P").insert(A.text)).insert(new Element("INPUT",{type:"text",size:15})).insert(new Element("INPUT",{type:"button",className:"button",value:A.ok_text}).observe("click",this._onClick.bind(this))).insert(new Element("INPUT",{type:"button",className:"button",value:A.cancel_text}).observe("click",this._close.bind(this))).observe("keydown",function(C){if((C.keyCode||C.charCode)==Event.KEY_RETURN){C.stop();this._onClick(C)}}.bind(this));RedBox.overlay=true;RedBox.onDisplay=Form.focusFirstElement.curry(B);RedBox.showHtml(B)},_close:function(){var A=RedBox.getWindowContents();[A,A.descendants()].flatten().compact().invoke("stopObserving");RedBox.close()},_onClick:function(A){params=this.params||{};params.passphrase=$F(A.findElement("form").down("input"));new Ajax.Request(this.uri,{parameters:params,onSuccess:this._onSuccess.bind(this),onFailure:this._onFailure.bind(this)})},_onSuccess:function(A){try{A=A.responseText.evalJSON(true)}catch(B){}if(A.response.success){this._close();if(this.action){this.action()}else{location.reload()}}else{if(A.response.error){alert(A.response.error)}}},_onFailure:function(A){}}; \ No newline at end of file +var IMPEncrypt={display:function(a){a=decodeURIComponent(a).evalJSON(true);this.action=a.action;this.params=a.params;this.uri=a.uri;var b=new Element("FORM",{action:"#",id:"RB_confirm"}).insert(new Element("P").insert(a.text)).insert(new Element("INPUT",{type:"text",size:15})).insert(new Element("INPUT",{type:"button",className:"button",value:a.ok_text}).observe("click",this._onClick.bind(this))).insert(new Element("INPUT",{type:"button",className:"button",value:a.cancel_text}).observe("click",this._close.bind(this))).observe("keydown",function(c){if((c.keyCode||c.charCode)==Event.KEY_RETURN){c.stop();this._onClick(c)}}.bind(this));RedBox.overlay=true;RedBox.onDisplay=Form.focusFirstElement.curry(b);RedBox.showHtml(b)},_close:function(){var a=RedBox.getWindowContents();[a,a.descendants()].flatten().compact().invoke("stopObserving");RedBox.close()},_onClick:function(a){params=this.params||{};params.passphrase=$F(a.findElement("form").down("input"));new Ajax.Request(this.uri,{parameters:params,onSuccess:this._onSuccess.bind(this),onFailure:this._onFailure.bind(this)})},_onSuccess:function(a){try{a=a.responseText.evalJSON(true)}catch(b){}if(a.response.success){this._close();if(this.action){this.action()}else{location.reload()}}else{if(a.response.error){alert(a.response.error)}}},_onFailure:function(a){}}; \ No newline at end of file diff --git a/imp/js/fetchmailprefs.js b/imp/js/fetchmailprefs.js index cea892b04..e04354517 100644 --- a/imp/js/fetchmailprefs.js +++ b/imp/js/fetchmailprefs.js @@ -1 +1 @@ -var fmprefs_loading=false;function accountSubmit(A){if(!fmprefs_loading&&((A!=null)||!$F("account").empty())){fmprefs_loading=true;$("fm_switch").submit()}}function driverSubmit(){if(!fmprefs_loading&&$F("fm_driver")){fmprefs_loading=true;$("fm_driver_form").submit()}}; \ No newline at end of file +var fmprefs_loading=false;function accountSubmit(a){if(!fmprefs_loading&&((a!=null)||!$F("account").empty())){fmprefs_loading=true;$("fm_switch").submit()}}function driverSubmit(){if(!fmprefs_loading&&$F("fm_driver")){fmprefs_loading=true;$("fm_driver_form").submit()}}; \ No newline at end of file diff --git a/imp/js/folders.js b/imp/js/folders.js index f5065ba09..4c8f47e64 100644 --- a/imp/js/folders.js +++ b/imp/js/folders.js @@ -1 +1 @@ -function getChecked(){return getFolders().findAll(function(A){return A.checked})}function getFolders(){return $("fmanager").getInputs(null,"folder_list[]")}function selectedFoldersDisplay(){var A=0,B="";getFolders().each(function(C){if(C.checked){B+=displayNames[A]+"\n"}++A});if(B.endsWith("\n")){B=B.substring(0,B.length-1)}return B}function chooseAction(C){var D=(C.element().id=="action_choose0")?0:1;var A=$("action_choose"+D);var B=$F(A);A.selectedIndex=0;if(B=="create_folder"){createMailbox()}else{if(B=="rebuild_tree"){submitAction(B)}else{if(!getChecked().size()){if(B!=""){alert(IMP.text.folders_select)}}else{if(B=="rename_folder"){renameMailbox()}else{if(B=="subscribe_folder"||B=="unsubscribe_folder"||B=="poll_folder"||B=="expunge_folder"||B=="nopoll_folder"||B=="mark_folder_seen"||B=="mark_folder_unseen"||B=="delete_folder_confirm"||B=="folders_empty_mailbox_confirm"||B=="mbox_size"){submitAction(B)}else{if(B=="download_folder"||B=="download_folder_zip"){downloadMailbox(B)}else{if(B=="import_mbox"){if(getChecked().length>1){alert(IMP.text.folders_oneselect)}else{submitAction(B)}}}}}}}}}function submitAction(A){$("actionID").setValue(A);$("fmanager").submit()}function createMailbox(){var A=getChecked().size(),B;if(A>1){window.alert(IMP.text.folders_oneselect);return}if(A==1){B=window.prompt(IMP.text.folders_subfolder1+" "+selectedFoldersDisplay()+".\n"+IMP.text.folders_subfolder2+"\n","")}else{B=window.prompt(IMP.text.folders_toplevel,"")}if(B){$("new_mailbox").setValue(B);submitAction("create_folder")}}function downloadMailbox(A){if(window.confirm(IMP.text.folders_download1+"\n"+selectedFoldersDisplay()+"\n"+IMP.text.folders_download2)){submitAction(A)}}function renameMailbox(){var B="",C="",A=0;getFolders().each(function(E){if(E.checked){if(IMP.conf.fixed_folders.indexOf(displayNames[A])!=-1){window.alert(IMP.text.folders_no_rename+" "+displayNames[A])}else{var D=window.prompt(IMP.text.folders_rename1+" "+displayNames[A]+"\n"+IMP.text.folders_rename2,displayNames[A]);if(D){B+=D+"\n";C+=E.value+"\n"}}}++A});if(!B){return}if(B.endsWith("\n")){B=B.substring(0,B.length-1)}if(C.endsWith("\n")){C=C.substring(0,C.length-1)}$("new_names").setValue(B);$("old_names").setValue(C);submitAction("rename_folder");return true}function toggleSelection(){var C=getChecked().size(),A=getFolders();var B=(C!=A.size());A.each(function(D){D.checked=B})}document.observe("dom:loaded",function(){if($("checkAll0")){$("checkAll0").observe("click",toggleSelection);$("action_choose0").observe("change",chooseAction)}if($("checkAll1")){$("checkAll1").observe("click",toggleSelection);$("action_choose1").observe("change",chooseAction)}}); \ No newline at end of file +function getChecked(){return getFolders().findAll(function(a){return a.checked})}function getFolders(){return $("fmanager").getInputs(null,"folder_list[]")}function selectedFoldersDisplay(){var a=0,b="";getFolders().each(function(c){if(c.checked){b+=displayNames[a]+"\n"}++a});if(b.endsWith("\n")){b=b.substring(0,b.length-1)}return b}function chooseAction(d){var f=(d.element().id=="action_choose0")?0:1;var b=$("action_choose"+f);var c=$F(b);b.selectedIndex=0;if(c=="create_folder"){createMailbox()}else{if(c=="rebuild_tree"){submitAction(c)}else{if(!getChecked().size()){if(c!=""){alert(IMP.text.folders_select)}}else{if(c=="rename_folder"){renameMailbox()}else{if(c=="subscribe_folder"||c=="unsubscribe_folder"||c=="poll_folder"||c=="expunge_folder"||c=="nopoll_folder"||c=="mark_folder_seen"||c=="mark_folder_unseen"||c=="delete_folder_confirm"||c=="folders_empty_mailbox_confirm"||c=="mbox_size"){submitAction(c)}else{if(c=="download_folder"||c=="download_folder_zip"){downloadMailbox(c)}else{if(c=="import_mbox"){if(getChecked().length>1){alert(IMP.text.folders_oneselect)}else{submitAction(c)}}}}}}}}}function submitAction(b){$("actionID").setValue(b);$("fmanager").submit()}function createMailbox(){var a=getChecked().size(),b;if(a>1){window.alert(IMP.text.folders_oneselect);return}if(a==1){b=window.prompt(IMP.text.folders_subfolder1+" "+selectedFoldersDisplay()+".\n"+IMP.text.folders_subfolder2+"\n","")}else{b=window.prompt(IMP.text.folders_toplevel,"")}if(b){$("new_mailbox").setValue(b);submitAction("create_folder")}}function downloadMailbox(a){if(window.confirm(IMP.text.folders_download1+"\n"+selectedFoldersDisplay()+"\n"+IMP.text.folders_download2)){submitAction(a)}}function renameMailbox(){var b="",c="",a=0;getFolders().each(function(e){if(e.checked){if(IMP.conf.fixed_folders.indexOf(displayNames[a])!=-1){window.alert(IMP.text.folders_no_rename+" "+displayNames[a])}else{var d=window.prompt(IMP.text.folders_rename1+" "+displayNames[a]+"\n"+IMP.text.folders_rename2,displayNames[a]);if(d){b+=d+"\n";c+=e.value+"\n"}}}++a});if(!b){return}if(b.endsWith("\n")){b=b.substring(0,b.length-1)}if(c.endsWith("\n")){c=c.substring(0,c.length-1)}$("new_names").setValue(b);$("old_names").setValue(c);submitAction("rename_folder");return true}function toggleSelection(){var c=getChecked().size(),a=getFolders();var b=(c!=a.size());a.each(function(d){d.checked=b})}document.observe("dom:loaded",function(){if($("checkAll0")){$("checkAll0").observe("click",toggleSelection);$("action_choose0").observe("change",chooseAction)}if($("checkAll1")){$("checkAll1").observe("click",toggleSelection);$("action_choose1").observe("change",chooseAction)}}); \ No newline at end of file diff --git a/imp/js/fullmessage-dimp.js b/imp/js/fullmessage-dimp.js index 2b03e8a1f..c03a730e9 100644 --- a/imp/js/fullmessage-dimp.js +++ b/imp/js/fullmessage-dimp.js @@ -1 +1 @@ -var DimpFullmessage={quickreply:function(B){var C,A={};A[$F("folder")]=[$F("index")];$("msgData").hide();$("qreply").show();switch(B){case"reply":case"reply_all":case"reply_list":C="GetReplyData";break;case"forward_all":case"forward_body":case"forward_attachments":C="GetForwardData";break}DimpCore.doAction(C,{imp_compose:$F("composeCache"),type:B},A,this.msgTextCallback.bind(this))},msgTextCallback:function(B){if(!B.response){return}var D=B.response,A=((D.format=="html")&&!DimpCompose.editor_on),E=(D.identity===null)?$F("identity"):D.identity,C=DimpCompose.get_identity(E,A);$("identity","last_identity").invoke("setValue",E);DimpCompose.fillForm((C.id[2])?("\n"+C.sig+D.body):(D.body+"\n"+C.sig),D.header);if(D.fwd_list&&D.fwd_list.length){D.fwd_list.each(function(F){DimpCompose.addAttach(F.number,F.name,F.type,F.size)})}if(A){DimpCompose.toggleHtmlEditor(true)}if(D.imp_compose){$("composeCache").setValue(D.imp_compose)}}};document.observe("dom:loaded",function(){window.focus();DimpCore.messageOnLoad();DimpCore.addPopdown("reply_link","replypopdown");DimpCore.addPopdown("forward_link","fwdpopdown");["from","to","cc","bcc","replyTo"].each(function(B){if(DimpFullmessage[B]){var C=$("msgHeader"+B.charAt(0).toUpperCase()+B.substring(1)).down("TD",1);C.replace(DimpCore.buildAddressLinks(DimpFullmessage[B],C.cloneNode(false)))}});var A=DimpCore.clickObserveHandler;A({d:$("windowclose"),f:function(){window.close()}});A({d:$("reply_link"),f:DimpFullmessage.quickreply.bind(DimpFullmessage,"reply")});A({d:$("forward_link"),f:DimpFullmessage.quickreply.bind(DimpFullmessage,DIMP.conf.forward_default)});["spam","ham","deleted"].each(function(B){var C=$("button_"+B);if(C){A({d:C,f:function(D){DIMP.baseWindow.DimpBase.flag(D,DIMP.conf.msg_index,DIMP.conf.msg_folder);window.close()}.curry(B)})}});A({d:$("qreply").select("div.headercloseimg img").first(),f:DimpCompose.confirmCancel.bind(DimpCompose)});["reply","reply_all","reply_list"].each(function(B){var C=$("ctx_replypopdown_"+B);if(C){A({d:C,f:DimpFullmessage.quickreply.bind(DimpFullmessage,B),ns:true})}});["forward_all","forward_body","forward_attachments"].each(function(B){A({d:$("ctx_fwdpopdown_"+B),f:DimpFullmessage.quickreply.bind(DimpFullmessage,B),ns:true})})}); \ No newline at end of file +var DimpFullmessage={quickreply:function(b){var c,a={};a[$F("folder")]=[$F("index")];$("msgData").hide();$("qreply").show();switch(b){case"reply":case"reply_all":case"reply_list":c="GetReplyData";break;case"forward_all":case"forward_body":case"forward_attachments":c="GetForwardData";break}DimpCore.doAction(c,{imp_compose:$F("composeCache"),type:b},a,this.msgTextCallback.bind(this))},msgTextCallback:function(b){if(!b.response){return}var d=b.response,a=((d.format=="html")&&!DimpCompose.editor_on),e=(d.identity===null)?$F("identity"):d.identity,c=DimpCompose.get_identity(e,a);$("identity","last_identity").invoke("setValue",e);DimpCompose.fillForm((c.id[2])?("\n"+c.sig+d.body):(d.body+"\n"+c.sig),d.header);if(d.fwd_list&&d.fwd_list.length){d.fwd_list.each(function(f){DimpCompose.addAttach(f.number,f.name,f.type,f.size)})}if(a){DimpCompose.toggleHtmlEditor(true)}if(d.imp_compose){$("composeCache").setValue(d.imp_compose)}}};document.observe("dom:loaded",function(){window.focus();DimpCore.messageOnLoad();DimpCore.addPopdown("reply_link","replypopdown");DimpCore.addPopdown("forward_link","fwdpopdown");["from","to","cc","bcc","replyTo"].each(function(b){if(DimpFullmessage[b]){var c=$("msgHeader"+b.charAt(0).toUpperCase()+b.substring(1)).down("TD",1);c.replace(DimpCore.buildAddressLinks(DimpFullmessage[b],c.cloneNode(false)))}});var a=DimpCore.clickObserveHandler;a({d:$("windowclose"),f:function(){window.close()}});a({d:$("reply_link"),f:DimpFullmessage.quickreply.bind(DimpFullmessage,"reply")});a({d:$("forward_link"),f:DimpFullmessage.quickreply.bind(DimpFullmessage,DIMP.conf.forward_default)});["spam","ham","deleted"].each(function(b){var c=$("button_"+b);if(c){a({d:c,f:function(d){DIMP.baseWindow.DimpBase.flag(d,DIMP.conf.msg_index,DIMP.conf.msg_folder);window.close()}.curry(b)})}});a({d:$("qreply").select("div.headercloseimg img").first(),f:DimpCompose.confirmCancel.bind(DimpCompose)});["reply","reply_all","reply_list"].each(function(b){var c=$("ctx_replypopdown_"+b);if(c){a({d:c,f:DimpFullmessage.quickreply.bind(DimpFullmessage,b),ns:true})}});["forward_all","forward_body","forward_attachments"].each(function(b){a({d:$("ctx_fwdpopdown_"+b),f:DimpFullmessage.quickreply.bind(DimpFullmessage,b),ns:true})})}); \ No newline at end of file diff --git a/imp/js/login.js b/imp/js/login.js index d7667d15b..363ed2405 100644 --- a/imp/js/login.js +++ b/imp/js/login.js @@ -1 +1 @@ -function setFocus(){if(!$F("imapuser")){$("imapuser").focus()}else{$("pass").focus()}}function imp_reload(){window.top.document.location=autologin_url+$F("server_key")}function submit_login(){if(show_list&&$F("server").startsWith("_")){return false}if(!$F("imapuser")){alert(IMP.text.login_username);$("imapuser").focus();return false}else{if(!$F("pass")){alert(IMP.text.login_password);$("pass").focus();return false}else{$("loginButton").disable();if(ie_clientcaps){try{$("ie_version").setValue(objCCaps.getComponentVersion("{89820200-ECBD-11CF-8B85-00AA005B4383}","componentid"))}catch(A){}}$("imp_login").submit();return true}}}function selectLang(){if(!$F("imapuser")&&!$F("pass")){var A={new_lang:$F("new_lang")};if(lang_url!==null){A.url=lang_url}self.location="login.php?"+Object.toQueryString(A)}}function removeHash(A){return(Object.isString(A)&&A.startsWith("#"))?A.substring(1):A}document.observe("dom:loaded",function(){if(imp_auth){if(parent.frames.horde_main){if(nomenu){parent.location=self.location}else{document.imp_login.target="_parent"}}}if(location.hash){$("anchor_string").setValue(removeHash(location.hash))}}); \ No newline at end of file +function setFocus(){if(!$F("imapuser")){$("imapuser").focus()}else{$("pass").focus()}}function imp_reload(){window.top.document.location=autologin_url+$F("server_key")}function submit_login(){if(show_list&&$F("server").startsWith("_")){return false}if(!$F("imapuser")){alert(IMP.text.login_username);$("imapuser").focus();return false}else{if(!$F("pass")){alert(IMP.text.login_password);$("pass").focus();return false}else{$("loginButton").disable();if(ie_clientcaps){try{$("ie_version").setValue(objCCaps.getComponentVersion("{89820200-ECBD-11CF-8B85-00AA005B4383}","componentid"))}catch(a){}}$("imp_login").submit();return true}}}function selectLang(){if(!$F("imapuser")&&!$F("pass")){var a={new_lang:$F("new_lang")};if(lang_url!==null){a.url=lang_url}self.location="login.php?"+Object.toQueryString(a)}}function removeHash(a){return(Object.isString(a)&&a.startsWith("#"))?a.substring(1):a}document.observe("dom:loaded",function(){if(imp_auth){if(parent.frames.horde_main){if(nomenu){parent.location=self.location}else{document.imp_login.target="_parent"}}}if(location.hash){$("anchor_string").setValue(removeHash(location.hash))}}); \ No newline at end of file diff --git a/imp/js/mailbox.js b/imp/js/mailbox.js index 5af45ebf9..c7fecec1a 100644 --- a/imp/js/mailbox.js +++ b/imp/js/mailbox.js @@ -1 +1 @@ -var keyId,startrange=null;function anySelected(){return $H(messagelist).keys().detect(function(A){return $("check"+A).checked})}function selectRow(C,A){var B=$(C.replace(/check/,"row"));if(A){B.addClassName("selectedRow")}else{B.removeClassName("selectedRow");B.removeClassName("selectedRow-over")}$(C).checked=A}function imp_confirm(A,B){RedBox.overlay=true;RedBox.showHtml('

'+B+'

')}function messages_submit(A){if(!anySelected()){alert(IMP.text.mailbox_submit);return}if(A=="delete_messages"){if(IMP.conf.pop3&&!confirm(IMP.text.mailbox_delete)){return}}else{if(A=="spam_report"){if(!confirm(IMP.text.spam_report)){return}}else{if(A=="notspam_report"){if(!confirm(IMP.text.notspam_report)){return}}}}$("actionID").setValue(A);$("messages").submit()}function makeSelection(B){var A="";switch(parseInt(B)){case-1:if($("checkAll").checked){A="!"}A+=IMP.conf.IMP_ALL;break;case 1:A=$F("filter1");break;default:A=$F("filter2")}if(A.empty()){return}else{if(A.startsWith("!")){selectFlagged(parseInt(A.substring(1)),false)}else{if(A.startsWith("+")){selectFlagged(A.substring(0,1),null)}else{selectFlagged(parseInt(A),true)}}}switch(parseInt(B)){case-1:break;case 1:$("select1").reset();break;default:$("select2").reset()}}function selectRange(C){Event.extend(C);var F=C.element().id,D=$(F);if(!D){return}var B=D.checked;if(startrange!==null&&C.shiftKey){var E=[$(startrange).id,D.id];var A=0;$H(messagelist).keys().detect(function(G){G="check"+G;if(E.indexOf(G)!=-1){++A}if(A){selectRow(G,B);if(A==2){return true}}})}else{selectRow(F,B)}startrange=F}function updateFolders(D){var A=$("targetMailbox2");if(A){var B=$("targetMailbox1");if((D==1&&$F(B)!="")||(D==2&&$F(A)!="")){var C=(D==1)?B.selectedIndex:A.selectedIndex;B.selectedIndex=A.selectedIndex=C}}}function transfer(D,B){if(anySelected()){var A=$("targetMbox");A.setValue((B==1)?$F("targetMailbox1"):$F("targetMailbox2"));if($F(A)=="*new*"){var C=prompt(IMP.text.newfolder,"");if(C!=null&&C!=""){$("newMbox").setValue(1);A.setValue(C);messages_submit(D)}}else{if($F(A)==""){alert(IMP.text.target_mbox)}else{messages_submit(D)}}}else{alert(IMP.text.mailbox_selectone)}}function selectFlagged(A,B){$H(messagelist).keys().each(function(E){var C,D=$("check"+E);if(A=="+"){C=!D.checked}else{if(A&messagelist[E]){C=B}else{C=!B}}selectRow(D.id,C)})}function flagMessages(B){var A=$("flag1"),C=$("flag2");if((B==1&&$F(A)!="")||(B==2&&$F(C)!="")){if(anySelected()){document.messages.flag.value=(B==1)?$F(A):$F(C);messages_submit("flag_messages")}else{if(B==1){A.selectedIndex=0}else{C.selectedIndex=0}alert(IMP.text.mailbox_selectone)}}}function getMessage(E,D){if(!D){return E}var A=$H(messagelist).keys();var C=A.indexOf(E);if(C!=-1){var B=C+D;if(B>=0&&B0)?$H(messagelist).keys().first():$H(messagelist).keys().last();if(Event.KEY_UP||Event.KEY_DOWN){E=$("subject"+keyId)}}}}else{if(I==32&&B.id.indexOf("subject")==0&&B.tagName=="A"){startrange="check"+keyId;selectRow(startrange,!$(startrange).checked)}else{if(!H.shiftKey){var G;if(I==Event.KEY_LEFT&&$("prev")){G=$("prev").href}else{if(I==Event.KEY_RIGHT&&$("next")){G=$("next").href}}if(G){document.location.href=G}return}else{return}}}if(E){E.focus();var J=$("row"+keyId);if(H.altKey){var A=E.id.replace(/subject/,"check");selectRow(A,!$(A).checked)}else{if(C!=E.id&&J.className.indexOf("-over")==-1){J.className+="-over"}}if(C){J=$("row"+C);if(C!=E.id){J.className=J.className.replace(/-over/,"")}}}H.stop()}if(IMP.conf.hasDOM){document.observe("dom:loaded",function(){document.observe("keydown",onKeyDownHandler)})}; \ No newline at end of file +var keyId,startrange=null;function anySelected(){return $H(messagelist).keys().detect(function(a){return $("check"+a).checked})}function selectRow(c,a){var b=$(c.replace(/check/,"row"));if(a){b.addClassName("selectedRow")}else{b.removeClassName("selectedRow");b.removeClassName("selectedRow-over")}$(c).checked=a}function imp_confirm(a,b){RedBox.overlay=true;RedBox.showHtml('

'+b+'

')}function messages_submit(a){if(!anySelected()){alert(IMP.text.mailbox_submit);return}if(a=="delete_messages"){if(IMP.conf.pop3&&!confirm(IMP.text.mailbox_delete)){return}}else{if(a=="spam_report"){if(!confirm(IMP.text.spam_report)){return}}else{if(a=="notspam_report"){if(!confirm(IMP.text.notspam_report)){return}}}}$("actionID").setValue(a);$("messages").submit()}function makeSelection(b){var a="";switch(parseInt(b)){case-1:if($("checkAll").checked){a="!"}a+=IMP.conf.IMP_ALL;break;case 1:a=$F("filter1");break;default:a=$F("filter2")}if(a.empty()){return}else{if(a.startsWith("!")){selectFlagged(parseInt(a.substring(1)),false)}else{if(a.startsWith("+")){selectFlagged(a.substring(0,1),null)}else{selectFlagged(parseInt(a),true)}}}switch(parseInt(b)){case-1:break;case 1:$("select1").reset();break;default:$("select2").reset()}}function selectRange(c){Event.extend(c);var f=c.element().id,d=$(f);if(!d){return}var b=d.checked;if(startrange!==null&&c.shiftKey){var e=[$(startrange).id,d.id];var a=0;$H(messagelist).keys().detect(function(g){g="check"+g;if(e.indexOf(g)!=-1){++a}if(a){selectRow(g,b);if(a==2){return true}}})}else{selectRow(f,b)}startrange=f}function updateFolders(d){var a=$("targetMailbox2");if(a){var b=$("targetMailbox1");if((d==1&&$F(b)!="")||(d==2&&$F(a)!="")){var c=(d==1)?b.selectedIndex:a.selectedIndex;b.selectedIndex=a.selectedIndex=c}}}function transfer(d,b){if(anySelected()){var a=$("targetMbox");a.setValue((b==1)?$F("targetMailbox1"):$F("targetMailbox2"));if($F(a)=="*new*"){var c=prompt(IMP.text.newfolder,"");if(c!=null&&c!=""){$("newMbox").setValue(1);a.setValue(c);messages_submit(d)}}else{if($F(a)==""){alert(IMP.text.target_mbox)}else{messages_submit(d)}}}else{alert(IMP.text.mailbox_selectone)}}function selectFlagged(a,b){$H(messagelist).keys().each(function(f){var c,d=$("check"+f);if(a=="+"){c=!d.checked}else{if(a&messagelist[f]){c=b}else{c=!b}}selectRow(d.id,c)})}function flagMessages(b){var a=$("flag1"),c=$("flag2");if((b==1&&$F(a)!="")||(b==2&&$F(c)!="")){if(anySelected()){document.messages.flag.value=(b==1)?$F(a):$F(c);messages_submit("flag_messages")}else{if(b==1){a.selectedIndex=0}else{c.selectedIndex=0}alert(IMP.text.mailbox_selectone)}}}function getMessage(e,d){if(!d){return e}var a=$H(messagelist).keys();var c=a.indexOf(e);if(c!=-1){var b=c+d;if(b>=0&&b0)?$H(messagelist).keys().first():$H(messagelist).keys().last();if(Event.KEY_UP||Event.KEY_DOWN){f=$("subject"+keyId)}}}}else{if(j==32&&b.id.indexOf("subject")==0&&b.tagName=="A"){startrange="check"+keyId;selectRow(startrange,!$(startrange).checked)}else{if(!i.shiftKey){var h;if(j==Event.KEY_LEFT&&$("prev")){h=$("prev").href}else{if(j==Event.KEY_RIGHT&&$("next")){h=$("next").href}}if(h){document.location.href=h}return}else{return}}}if(f){f.focus();var k=$("row"+keyId);if(i.altKey){var a=f.id.replace(/subject/,"check");selectRow(a,!$(a).checked)}else{if(c!=f.id&&k.className.indexOf("-over")==-1){k.className+="-over"}}if(c){k=$("row"+c);if(c!=f.id){k.className=k.className.replace(/-over/,"")}}}i.stop()}if(IMP.conf.hasDOM){document.observe("dom:loaded",function(){document.observe("keydown",onKeyDownHandler)})}; \ No newline at end of file diff --git a/imp/js/message.js b/imp/js/message.js index e3239a511..def77167b 100644 --- a/imp/js/message.js +++ b/imp/js/message.js @@ -1 +1 @@ -function arrowHandler(A){if(A.altKey||A.shiftKey||A.ctrlKey){return}switch(A.keyCode||A.charCode){case Event.KEY_LEFT:if($("prev")){document.location.href=$("prev").href}break;case Event.KEY_RIGHT:if($("next")){document.location.href=$("next").href}break}}function message_submit(A){if(A=="spam_report"){if(!window.confirm(IMP.text.spam_report)){return}}else{if(A=="notspam_report"){if(!window.confirm(IMP.text.notspam_report)){return}}}$("actionID").setValue(A);$("messages").submit()}function flagMessage(B){var A=$("flag1"),C=$("flag2");if((B==1&&$F(A))||(B==2&&$F(C))){$("flag").setValue((B==1)?$F(A):$F(C));message_submit("flag_message")}}function transfer(D,B){var A=$("targetMbox");A.setValue((B==1)?$F("target1"):$F("target2"));if($F(A)=="*new*"){var C=window.prompt(IMP.text.newfolder,"");if(C!=null&&C!=""){$("newMbox").setValue(1);A.setValue(C);message_submit(D)}}else{if(!$F(A)){window.alert(IMP.text.target_mbox)}else{message_submit(D)}}}function updateFolders(A){var B=(A==1)?2:1;$("target"+B).selectedIndex=$("target"+A).selectedIndex}function messageActionsHover(){var A=new Element("IFRAME",{scrolling:"no",frameborder:0}).hide();A.setStyle({position:"absolute"});A.setAttribute("src","javascript:false;");$$("UL.msgactions LI").each(function(B){var C,E=B.down("UL"),D;if(!E){return}C=A.cloneNode(false);B.insert(C);C.clonePosition(E);D=B.getStyle("zIndex");if(D==""){B.setStyle({zIndex:2});C.setStyle({zIndex:1})}else{C.setStyle({zIndex:parseInt(D)-1})}B.observe("mouseout",function(){this.removeClassName("hover");B.down("iframe").hide()});B.observe("mouseover",function(){this.addClassName("hover");B.down("iframe").show()})})}document.observe("dom:loaded",function(){document.observe("keydown",arrowHandler);if(Prototype.Browser.IE){messageActionsHover()}}); \ No newline at end of file +function arrowHandler(a){if(a.altKey||a.shiftKey||a.ctrlKey){return}switch(a.keyCode||a.charCode){case Event.KEY_LEFT:if($("prev")){document.location.href=$("prev").href}break;case Event.KEY_RIGHT:if($("next")){document.location.href=$("next").href}break}}function message_submit(a){if(a=="spam_report"){if(!window.confirm(IMP.text.spam_report)){return}}else{if(a=="notspam_report"){if(!window.confirm(IMP.text.notspam_report)){return}}}$("actionID").setValue(a);$("messages").submit()}function flagMessage(b){var a=$("flag1"),c=$("flag2");if((b==1&&$F(a))||(b==2&&$F(c))){$("flag").setValue((b==1)?$F(a):$F(c));message_submit("flag_message")}}function transfer(d,b){var a=$("targetMbox");a.setValue((b==1)?$F("target1"):$F("target2"));if($F(a)=="*new*"){var c=window.prompt(IMP.text.newfolder,"");if(c!=null&&c!=""){$("newMbox").setValue(1);a.setValue(c);message_submit(d)}}else{if(!$F(a)){window.alert(IMP.text.target_mbox)}else{message_submit(d)}}}function updateFolders(a){var b=(a==1)?2:1;$("target"+b).selectedIndex=$("target"+a).selectedIndex}function messageActionsHover(){var a=new Element("IFRAME",{scrolling:"no",frameborder:0}).hide();a.setStyle({position:"absolute"});a.setAttribute("src","javascript:false;");$$("UL.msgactions LI").each(function(b){var c,e=b.down("UL"),d;if(!e){return}c=a.cloneNode(false);b.insert(c);c.clonePosition(e);d=b.getStyle("zIndex");if(d==""){b.setStyle({zIndex:2});c.setStyle({zIndex:1})}else{c.setStyle({zIndex:parseInt(d)-1})}b.observe("mouseout",function(){this.removeClassName("hover");b.down("iframe").hide()});b.observe("mouseover",function(){this.addClassName("hover");b.down("iframe").show()})})}document.observe("dom:loaded",function(){document.observe("keydown",arrowHandler);if(Prototype.Browser.IE){messageActionsHover()}}); \ No newline at end of file diff --git a/imp/js/popup.js b/imp/js/popup.js index f1768e8c0..2949d5bc2 100644 --- a/imp/js/popup.js +++ b/imp/js/popup.js @@ -1 +1 @@ -function popup_imp(D,E,A,C){var F,G,H=$H(),B=new Date().getTime();A=Math.min(screen.height-75,A||500);E=Math.min(screen.width-75,E||600);F=D.indexOf("?");if(F!=-1){H=$H(D.toQueryParams());D=D.substring(0,F)}if(C){$H(C.toQueryParams()).each(function(I){H.set(I.key,unescape(I.value))})}H.set("uniq",B);G=window.open(D+"?"+H.toQueryString(),B,"toolbar=no,location=no,status=yes,scrollbars=yes,resizable=yes,width="+E+",height="+A+",left=0,top=0");if(!G){alert(IMP.text.popup_block)}else{if(Object.isUndefined(G.name)){G.name=B}if(Object.isUndefined(G.opener)){G.opener=self}G.focus()}}; \ No newline at end of file +function popup_imp(d,e,a,c){var f,g,h=$H(),b=new Date().getTime();a=Math.min(screen.height-75,a||500);e=Math.min(screen.width-75,e||600);f=d.indexOf("?");if(f!=-1){h=$H(d.toQueryParams());d=d.substring(0,f)}if(c){$H(c.toQueryParams()).each(function(i){h.set(i.key,unescape(i.value))})}h.set("uniq",b);g=window.open(d+"?"+h.toQueryString(),b,"toolbar=no,location=no,status=yes,scrollbars=yes,resizable=yes,width="+e+",height="+a+",left=0,top=0");if(!g){alert(IMP.text.popup_block)}else{if(Object.isUndefined(g.name)){g.name=b}if(Object.isUndefined(g.opener)){g.opener=self}g.focus()}}; \ No newline at end of file diff --git a/imp/js/redbox.js b/imp/js/redbox.js index 8efb84cf8..32e500f52 100644 --- a/imp/js/redbox.js +++ b/imp/js/redbox.js @@ -1 +1 @@ -var RedBox={overlay:true,onDisplay:null,showInline:function(A){this.appearWindow();this.cloneWindowContents(A)},showHtml:function(A){this.appearWindow();this.htmlWindowContents(A)},appearWindow:function(){var C=$("RB_loading");if(C&&C.visible()){C.hide()}else{this.showOverlay()}var B={duration:0.4,queue:"end"},A=$("RB_window");if(this.onDisplay){B.afterFinish=this.onDisplay}new Effect.Appear(A,B);A.scrollTo()},loading:function(){this.showOverlay();var A=$("RB_loading");if(A){A.show()}this.setWindowPosition()},close:function(){new Effect.Fade("RB_window",{duration:0.4});if(this.overlay){new Effect.Fade("RB_overlay",{duration:0.4})}},showOverlay:function(){var B=$("RB_redbox");if(!B){B=new Element("DIV",{id:"RB_redbox",align:"center"});$(document.body).insert(B);var A=new Element("DIV",{id:"RB_overlay"}).hide();B.insert({top:new Element("DIV",{id:"RB_window"}).hide()}).insert({top:A});if(this.overlay){A.insert({top:new Element("DIV",{id:"RB_loading"}).hide()})}}if(this.overlay){this.setOverlaySize();new Effect.Appear("RB_overlay",{duration:0.4,to:0.6,queue:"end"})}},setOverlaySize:function(){if(window.innerHeight&&window.scrollMaxY){yScroll=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){yScroll=document.body.scrollHeight}else{yScroll=document.body.offsetHeight}}Element.setStyle("RB_overlay",{height:yScroll+"px"})},setWindowPosition:function(){var B=$("RB_window");var C=B.getDimensions(),A=document.viewport.getDimensions();B.setStyle({width:"auto",height:"auto",left:((A.width-C.width)/2)+"px",top:((A.height-C.height)/2)+"px"})},cloneWindowContents:function(A){$("RB_window").appendChild($($(A).cloneNode(true)).setStyle({display:"block"}));this.setWindowPosition()},htmlWindowContents:function(A){$("RB_window").update(A);this.setWindowPosition()},getWindowContents:function(){var A=$("RB_window");return A.visible()?A.down():null},overlayVisible:function(){var A=$("RB_overlay");return A&&A.visible()}}; \ No newline at end of file +var RedBox={overlay:true,onDisplay:null,showInline:function(a){this.appearWindow();this.cloneWindowContents(a)},showHtml:function(a){this.appearWindow();this.htmlWindowContents(a)},appearWindow:function(){var c=$("RB_loading");if(c&&c.visible()){c.hide()}else{this.showOverlay()}var b={duration:0.4,queue:"end"},a=$("RB_window");if(this.onDisplay){b.afterFinish=this.onDisplay}new Effect.Appear(a,b);a.scrollTo()},loading:function(){this.showOverlay();var a=$("RB_loading");if(a){a.show()}this.setWindowPosition()},close:function(){new Effect.Fade("RB_window",{duration:0.4});if(this.overlay){new Effect.Fade("RB_overlay",{duration:0.4})}},showOverlay:function(){var b=$("RB_redbox");if(!b){b=new Element("DIV",{id:"RB_redbox",align:"center"});$(document.body).insert(b);var a=new Element("DIV",{id:"RB_overlay"}).hide();b.insert({top:new Element("DIV",{id:"RB_window"}).hide()}).insert({top:a});if(this.overlay){a.insert({top:new Element("DIV",{id:"RB_loading"}).hide()})}}if(this.overlay){this.setOverlaySize();new Effect.Appear("RB_overlay",{duration:0.4,to:0.6,queue:"end"})}},setOverlaySize:function(){if(window.innerHeight&&window.scrollMaxY){yScroll=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){yScroll=document.body.scrollHeight}else{yScroll=document.body.offsetHeight}}Element.setStyle("RB_overlay",{height:yScroll+"px"})},setWindowPosition:function(){var b=$("RB_window");var c=b.getDimensions(),a=document.viewport.getDimensions();b.setStyle({width:"auto",height:"auto",left:((a.width-c.width)/2)+"px",top:((a.height-c.height)/2)+"px"})},cloneWindowContents:function(a){$("RB_window").appendChild($($(a).cloneNode(true)).setStyle({display:"block"}));this.setWindowPosition()},htmlWindowContents:function(a){$("RB_window").update(a);this.setWindowPosition()},getWindowContents:function(){var a=$("RB_window");return a.visible()?a.down():null},overlayVisible:function(){var a=$("RB_overlay");return a&&a.visible()}}; \ No newline at end of file diff --git a/imp/js/search.js b/imp/js/search.js index d9f4f56c6..a8395d5c2 100644 --- a/imp/js/search.js +++ b/imp/js/search.js @@ -1 +1 @@ -function toggleAll(A){$("search").getInputs(null,"search_folders[]").each(function(B){B.checked=A})}function dateCheck(B){var A=$("search_"+B+"_month"),C=$("search_"+B+"_day"),D=$("search_"+B+"_year");if(A.selectedIndex==0){A.selectedIndex=search_month}if(C.selectedIndex==0){C.selectedIndex=search_day}if(D.value==""){D.value=search_year}}function formCheck(){if(not_search&&(!$("preselected_folders")||!$F("preselected_folders"))){if(!Form.getInputs("search",null,"search_folders[]").detect(function(A){return A.checked})){alert(IMP.text.search_select);return false}}$("actionID").setValue("do_search");return true}function search_reset(){$("actionID").setValue("reset_search");$("search").submit();return true}function saveCache(){$("edit_query").setValue($F("save_cache"));$("search").submit()}function delete_field(A){$("delete_field_id").setValue(A);$("actionID").setValue("delete_field");$("search").submit();return true}function show_subscribed(A){$("show_subscribed_only").setValue(A);$("search").submit();return false}; \ No newline at end of file +function toggleAll(a){$("search").getInputs(null,"search_folders[]").each(function(b){b.checked=a})}function dateCheck(b){var a=$("search_"+b+"_month"),c=$("search_"+b+"_day"),e=$("search_"+b+"_year");if(a.selectedIndex==0){a.selectedIndex=search_month}if(c.selectedIndex==0){c.selectedIndex=search_day}if(e.value==""){e.value=search_year}}function formCheck(){if(not_search&&(!$("preselected_folders")||!$F("preselected_folders"))){if(!Form.getInputs("search",null,"search_folders[]").detect(function(a){return a.checked})){alert(IMP.text.search_select);return false}}$("actionID").setValue("do_search");return true}function search_reset(){$("actionID").setValue("reset_search");$("search").submit();return true}function saveCache(){$("edit_query").setValue($F("save_cache"));$("search").submit()}function delete_field(a){$("delete_field_id").setValue(a);$("actionID").setValue("delete_field");$("search").submit();return true}function show_subscribed(a){$("show_subscribed_only").setValue(a);$("search").submit();return false}; \ No newline at end of file diff --git a/imp/js/src/DimpCore.js b/imp/js/src/DimpCore.js index d5508d9ff..cf5d53cc0 100644 --- a/imp/js/src/DimpCore.js +++ b/imp/js/src/DimpCore.js @@ -113,7 +113,9 @@ DimpCore = { }.bind(this), onFailure: function(t, o) { this.debug('onFailure', t); - }.bind(this) + }.bind(this), + evalJS: false, + evalJSON: true }; }; @@ -145,24 +147,9 @@ DimpCore = { doActionComplete: function(request, callback) { this.inAjaxCallback = true; - var error = false, r = {}; - - if (!request.responseText || !request.responseText.length) { - error = true; - } else { - try { - r = request.responseText.evalJSON(true); - } catch (e) { - this.debug('doActionComplete', e); - error = true; - } - } - - if (!r.msgs) { - r.msgs = []; - } + var r; - if (error) { + if (!request.responseJSON) { if (++this.server_error == 3) { this.showNotifications([ { type: 'horde.error', message: DIMP.text.ajax_timeout } ]); } @@ -170,6 +157,12 @@ DimpCore = { return; } + r = request.responseJSON; + + if (!r.msgs) { + r.msgs = []; + } + if (r.response && Object.isFunction(callback)) { if (DIMP.conf.debug) { callback(r); diff --git a/imp/js/src/SpellChecker.js b/imp/js/src/SpellChecker.js index f96fa0b36..a237ddb33 100644 --- a/imp/js/src/SpellChecker.js +++ b/imp/js/src/SpellChecker.js @@ -155,7 +155,7 @@ var SpellChecker = Class.create({ var bad, content, d, re, re_text, i = 0, input = $(this.target), - result = request.responseText.evalJSON(true); + result = request.responseJSON; this.removeChoices(); diff --git a/imp/js/src/autocomplete.js b/imp/js/src/autocomplete.js index 6074291ca..dcfa64a88 100644 --- a/imp/js/src/autocomplete.js +++ b/imp/js/src/autocomplete.js @@ -402,7 +402,7 @@ Ajax.Autocompleter = Class.create(Autocompleter.Base, { _onComplete: function(request) { - this.updateChoices(this.cache.set(this.getToken(), request.responseText.evalJSON(true))); + this.updateChoices(this.cache.set(this.getToken(), request.responseJSON)); } }); diff --git a/imp/js/src/compose-dimp.js b/imp/js/src/compose-dimp.js index 78cece127..fddf1d4ed 100644 --- a/imp/js/src/compose-dimp.js +++ b/imp/js/src/compose-dimp.js @@ -565,7 +565,7 @@ var DimpCompose = { var sf = $('submit_frame'), doc = sf.contentDocument || sf.contentWindow.document; sf.stopObserving('load'); - DimpCore.doActionComplete({ responseText: doc.body.innerHTML }, this.uniqueSubmitCallback.bind(this)); + DimpCore.doActionComplete({ responseJSON: doc.body.innerHTML.evalJSON(true) }, this.uniqueSubmitCallback.bind(this)); }, toggleCC: function(type) diff --git a/imp/js/unblockImages.js b/imp/js/unblockImages.js index 4dc099dde..a2ef8a548 100644 --- a/imp/js/unblockImages.js +++ b/imp/js/unblockImages.js @@ -1 +1 @@ -var IMP=window.IMP||{};IMP.unblockImages=function(B,C){var A;if(!B){return true}$(B).select("[blocked]").each(function(D){var E=decodeURIComponent(D.readAttribute("blocked"));if(D.hasAttribute("src")){D.writeAttribute("src",E)}else{if(D.hasAttribute("background")){D.writeAttribute("background",E)}else{if(D.style.backgroundImage){D.setStyle({backgroundImage:"url("+E+")"})}}}});C=$(C);if(C){A=C.up();C.remove();if(!A.childElements().size()){A=A.up("TABLE.mimeStatusMessage");if(A){A.remove()}}}return false}; \ No newline at end of file +var IMP=window.IMP||{};IMP.unblockImages=function(b,c){var a;if(!b){return true}$(b).select("[blocked]").each(function(d){var e=decodeURIComponent(d.readAttribute("blocked"));if(d.hasAttribute("src")){d.writeAttribute("src",e)}else{if(d.hasAttribute("background")){d.writeAttribute("background",e)}else{if(d.style.backgroundImage){d.setStyle({backgroundImage:"url("+e+")"})}}}});c=$(c);if(c){a=c.up();c.remove();if(!a.childElements().size()){a=a.up("TABLE.mimeStatusMessage");if(a){a.remove()}}}return false}; \ No newline at end of file diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 74bee351f..7b52b7a85 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -1424,8 +1424,9 @@ class IMP */ static public function sendHTTPResponse($data, $ct) { + $charset = NLS::getCharset(); + // Output headers and encoded response. - $charset = '; charset=' . NLS::getCharset(); switch ($ct) { case 'json': case 'js-json': @@ -1433,7 +1434,7 @@ class IMP // includes the response in a member named 'response', and an // additional array of messages in 'msgs' which may be updates // for the server or notification messages. - $s_data = Horde_Serialize::serialize($data, SERIALIZE_JSON, NLS::getCharset()); + $s_data = Horde_Serialize::serialize($data, SERIALIZE_JSON, $charset); // Make sure no null bytes sneak into the JSON output stream. // Null bytes cause IE to stop reading from the input stream, @@ -1443,11 +1444,11 @@ class IMP $s_data = str_replace("\00", '', $s_data); if ($ct == 'json') { - header('Content-Type: text/x-json' . $charset); + header('Content-Type: application/json'); // Add prototype security delimiters to returned JSON. - echo '/*-secure-' . $s_data . '*/'; + echo '/*-secure-' . String::convertCharset($s_data, $charset, 'UTF-8') . '*/'; } else { - header('Content-Type: text/html' . $charset); + header('Content-Type: text/html; charset=' . $charset); echo htmlspecialchars($s_data); } break; @@ -1455,7 +1456,7 @@ class IMP case 'html': case 'plain': case 'xml': - header('Content-Type: text/' . $ct . $charset); + header('Content-Type: text/' . $ct . '; charset=' . $charset); echo $data; break;