var JosephJiang={};var JJ=JosephJiang;var YUE=YAHOO.util.Event;var YUD=YAHOO.util.Dom;var YUC=YAHOO.util.Connect;var setTextPrompt=function(D,A,E){var B=YAHOO.util.Event;var C=YAHOO.util.Dom;if(!D||!A){return ;}C.setStyle(D,"color","#999");D.value=A;B.on(D,"mouseup",function(){if(this.value===A){this.value="";C.setStyle(D,"color","#000");}});B.on(D,"blur",function(){if(this.value===""){this.value=A;C.setStyle(D,"color","#999");}});if(E){B.on(E,"click",function(){if(D.value===A){D.value="";}});B.on(E,"change",function(){if(D.value===A){D.value="";}});}};JJ.module=new function(){this.ArticleForm=function(){var Q,J,E,P,L,D,N,K;E=this;var O=function(){J=E.getElementsByTagName("form")[0];L=J.getElementsByTagName("textarea")[0];D=0;P=document.createElement("a");P.innerHTML="使用 HTML 精靈";P.className="switch-to-editor";P.setAttribute("href","#");L.parentNode.insertBefore(P,L);L.value=L.value.replace(/^<!--\s{0,2}/,"");L.value=L.value.replace(/\s{0,2}-->$/,"");YUE.on(P,"click",F);YUE.on(window,"beforeunload",C);YUE.on(document,"click",function(T){var U=YUE.getTarget(T);if(U.nodeName==="A"||U.nodeName==="INPUT"){YUE.removeListener(window,"beforeunload",C);}});YUE.on(L,"keyup",G);var R=new YAHOO.widget.Overlay("calendarmenu");var S=new YAHOO.widget.Button({type:"menu",id:"calendarpicker",label:"請選擇日期",menu:R,container:"datefields"});S.on("click",B);};var H=function(R){var T=/(<[\/\d="a-zA-Z ]+>)</gi;if(J.elements["nl2br"].options[J.elements["nl2br"].selectedIndex].value=="y"){var S="$1\n<";R=R.replace(/<br>/g,"\n");R=R.replace(T,S);R=R.replace(T,S);}return R;};var M=function(R){if(J.elements["nl2br"].options[J.elements["nl2br"].selectedIndex].value=="y"){var T=/(<[\/\d="a-zA-Z ]+>)\s+</gi;var S="$1<";R=R.replace(T,S);R=R.replace(T,S);R=R.replace(/\n/g,"<br>");}return R;};var A=function(){YUD.generateId(L);L.value=M(L.value);K=new YAHOO.widget.Editor(L.id,{height:"300px",width:"522px",dompath:true,animate:false});K.on("afterRender",function(){N=K.get("element_cont");L=K.get("element");});K.render();};YUE.on(J,"submit",function(R){if(YUD.hasClass(P,"switch-to-textarea")){YUE.removeListener(window,"beforeunload",C);K.saveHTML();L.value=H(L.value);}else{L.value=H(L.value);}});var C=function(R){YUE.stopEvent(R);};var F=function(S){YUE.preventDefault(S);dTarget=YUE.getTarget(S);switch(dTarget.className){case"switch-to-editor":if(!K){A();}else{N.replaceClass("yui-textarea-container","yui-editor-container");K._setDesignMode("on");var R=K.get("textarea").value;K.setEditorHTML(M(R));}P.innerHTML="檢視原始碼";YUD.replaceClass(P,"switch-to-editor","switch-to-textarea");break;case"switch-to-textarea":K.saveHTML();var R=K.get("textarea").value;K.get("textarea").value=H(R);N.replaceClass("yui-editor-container","yui-textarea-container");P.innerHTML="使用 HTML 精靈";YUD.replaceClass(P,"switch-to-textarea","switch-to-editor");break;}};var B=function(){oCalendarMenu.setBody("&#32;");oCalendarMenu.body.id="calendarcontainer";oCalendarMenu.render(this.get("container"));oCalendarMenu.align();var R=new YAHOO.widget.Calendar("buttoncalendar",oCalendarMenu.body.id);R.render();R.changePageEvent.subscribe(function(){window.setTimeout(function(){oCalendarMenu.show();},0);});R.selectEvent.subscribe(function(U,S){var T;if(S){T=S[0][0];J.elements["date"].value=T.join("-");}oCalendarMenu.hide();});this.unsubscribe("click",B);};var I={success:function(R){}};var G=function(){D+=1;console.log(D);if(D%5){return ;}YUC.setForm(J);YUC.asyncRequest("POST","../service/rest/index.php?method=blog.update",I);};O();};this.MastHead=function(){var A=this.getElementsByTagName("form")[0];setTextPrompt(A.elements["p"],"用 Yahoo! 來查詢本站內容",A.elements["post"]);var A=this.getElementsByTagName("form")[1];setTextPrompt(A.elements["q"],"用 Google 來查詢本站內容",A.elements["sa"]);};this.ArticleContent=function(){if(typeof dp==="undefined"){return ;}dp.SyntaxHighlighter.HighlightAll("code");};this.RecentStatus=function(){var C=this;var B=C.getElementsByTagName("ol")[0];var A=new YAHOO.util.NewsRotator(B);};this.ArticleCommentForm=function(){var B=this;var A=B.getElementsByTagName("form")[0];YUE.on(A,"submit",function(C){A.action=location.href;});};this.ArticleCommentList=function(){var B=this;var A=YUD.getElementsByClassName("comment","div",B);updateURL2Link(A);};};(function(){YUE.onContentReady("af",JJ.module.ArticleForm);YUE.onContentReady("acf",JJ.module.ArticleCommentForm);YUE.onContentReady("acl",JJ.module.ArticleCommentList);YUE.onContentReady("mh",JJ.module.MastHead);YUE.onContentReady("ac",JJ.module.ArticleContent);YUE.onContentReady("rs",JJ.module.RecentStatus);})();
