/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 4.0.0 Alpha 5
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2009 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
function vB_Text_Editor_CMS(A,F,B,D,C,E){this._construct(A,F,B,D,C,E);this.init(C)}vBulletin.extend(vB_Text_Editor_CMS,vB_Text_Editor);vB_Text_Editor_CMS.prototype._parent=vB_Text_Editor.prototype;vB_Text_Editor_CMS.prototype._construct=function(A,F,B,D,C,E){this._parent._construct.call(this,A,F,B,D,C,E);this.dialog_props={};this.dialog=null;this.dialog_overlay=null;this.dialog_submitted=false;this.dialog_confirm_callback=null;this.formatstate=null;this.formatoptions={p:{description:vbphrase.formatting_normal},pagebreak:{description:vbphrase.page_break,extra:"pagebreak",tag:"h3"},h1:{description:vbphrase.heading_1},h2:{description:vbphrase.heading_2},h3:{description:vbphrase.heading_3},h4:{description:vbphrase.heading_4},h5:{description:vbphrase.heading_5},h6:{description:vbphrase.heading_6}}};vB_Text_Editor_CMS.prototype.init=function(A){this._parent.init.call(this,A);if(this.wysiwyg_mode){if(PHP.in_array("subscript",contextcontrols)<0){contextcontrols.push("subscript");contextcontrols.push("superscript")}if(is_moz){this.editdoc.execCommand("enableInlineTableEditing",false,false)}}};vB_Text_Editor_CMS.prototype.init_popup_formatting=function(C){menu=this.init_menu_container("formatting","auto","auto","auto");for(var A in this.formatoptions){if(YAHOO.lang.hasOwnProperty(this.formatoptions,A)){var B=document.createElement(this.formatoptions[A].tag?this.formatoptions[A].tag:A);B.innerHTML=this.formatoptions[A].description;B.title=this.formatoptions[A].description;B.extra=this.formatoptions[A].extra;B.cmd=C.cmd;B.controlkey=C.id;B.editorid=this.editorid;B.className="oformat";B.onmouseover=B.onmouseout=B.onmouseup=B.onmousedown=vB_Text_Editor_Events.prototype.menuoption_onmouseevent;B.onclick=vB_Text_Editor_Events.prototype.formatting_option_format_onclick;menu.appendChild(B)}}return menu};vB_Text_Editor_CMS.prototype.recreate_editor=function(A,F,B,D,C,E){return new vB_Text_Editor_CMS(A,F,B,D,C,E)};vB_Text_Editor_CMS.prototype.set_context=function(){this._parent.set_context.call(this);this.set_format_context()};vB_Text_Editor_CMS.prototype.set_format_context=function(){if(!this.buttons.formatting||!this.wysiwyg_mode){return }var E;try{E=this.editdoc.queryCommandValue("formatblock")}catch(F){E=""}var A=E.match(/(\d+)/);if(A){E="h"+A[1]}else{E="p"}if(E=="h3"){var D=this.get_selection_container_element();if(D){if((D.tagName.toLowerCase()=="h3"&&YAHOO.util.Dom.hasClass(D,"wysiwyg_pagebreak"))||YAHOO.util.Dom.getElementsByClassName("wysiwyg_pagebreak","h3",D).length){E="pagebreak"}else{var C=YAHOO.util.Dom.getAncestorByTagName(D,"h3");if(C&&YAHOO.util.Dom.hasClass(C,"wysiwyg_pagebreak")){E="pagebreak"}}}}if(E!=this.formatstate){this.formatstate=E;if(this.popupmode){var G=fetch_object(this.editorid+"_formatting_out");G.innerHTML=this.formatoptions[E].description}else{}var B=fetch_object(this.editorid+"_cmd_insertpagebreak");B.state=(E=="pagebreak");this.button_context(B,"mouseout")}};vB_Text_Editor.prototype.switch_editor_ajax=function(){var A=(this.wysiwyg_mode?0:1);YAHOO.util.Connect.asyncRequest("POST","content.php?r=editor/switch",{success:do_switch_editor_mode,timeout:vB_Default_Timeout,argument:[this.editorid,A]},SESSIONURL+"securitytoken="+SECURITYTOKEN+"&do=editorswitch&towysiwyg="+A+"&parsetype="+this.parsetype+"&allowsmilie="+this.parsesmilies+"&message="+PHP.urlencode(this.get_editor_contents())+(this.ajax_extra?("&"+this.ajax_extra):"")+(typeof this.textobj.form["options[allowbbcode]"]!="undefined"?"&allowbbcode="+this.textobj.form["options[allowbbcode]"].checked:""))};vB_Text_Editor_CMS.prototype.previewbreak=function(C){if(this.wysiwyg_mode){var A=YAHOO.util.Dom.getElementsByClassName("previewbreak","hr",this.editdoc.documentElement.childNodes[1]);if(A.length==0){return this.insert_text('<hr class="previewbreak" title="'+vbphrase.preview_break+'">',false)}else{alert(vbphrase.this_message_already_contains_a_preview_break)}}else{var B=this.editdoc.value.match(/\[prbreak\]\[\/prbreak\]/i);if(B){alert(vbphrase.this_message_already_contains_a_preview_break)}else{return this.insert_text("[PRBREAK][/PRBREAK]")}}};vB_Text_Editor_CMS.prototype.inserttable=function(A){this.create_editor_dialog('<img src="'+IMGDIR_MISC+'/lightbox_progress.gif" alt="" />',this.inserttable_confirm);this.dialog_props={range:this.get_range_from_selection(this.get_selection_object())};YAHOO.util.Connect.asyncRequest("POST","content.php?r=editor/tableoverlay",{success:this.inserttable_ajax,failure:this.remove_editor_dialog,timeout:vB_Default_Timeout,scope:this},"sessionurl="+SESSIONURL+"&securitytoken="+SECURITYTOKEN+"&ajax=1")};vB_Text_Editor_CMS.prototype.inserttable_ajax=function(B){if(B.responseXML){var A=B.responseXML.getElementsByTagName("html");if(A.length){this.create_editor_dialog(A[0].firstChild.nodeValue,this.inserttable_confirm);return }}this.remove_editor_dialog()};vB_Text_Editor_CMS.prototype.inserttable_confirm=function(){var E=this.dialog_props.range;if(E){this.select_range(E)}var A={rows:parseInt(this.dialog.elements.rows.value,10),columns:parseInt(this.dialog.elements.columns.value,10),width:"","class":this.dialog.elements["class"].value};var H="";for(var D=0;D<this.dialog.elements.width_type.length;D++){if(this.dialog.elements.width_type[D].checked){H=this.dialog.elements.width_type[D].value}}switch(H){case"pixels":A.width=this.dialog.elements.width_pixels.value;break;case"percent":if(this.dialog.elements.width_percent.value){A.width=this.dialog.elements.width_percent.value+"%";break}case"auto":default:A.width=""}if(A.rows<1){A.rows=1}if(A.columns<1){A.columns=1}if(!A.width.match(/^\d+%?$/)){A.width=""}if(!A["class"].match(/^[a-zA-Z0-9_]+$/)){A["class"]=""}var G=this.get_selection(),C="";var I,B;if(this.wysiwyg_mode){if(!A["class"]){A["class"]=["wysiwyg_dashes"]}else{A["class"]=["wysiwyg_dashes","wysiwyg_cms_table_"+A["class"]]}C+="<table";if(A.width){C+=' width="'+A.width+'"'}if(A["class"]){C+=' class="'+A["class"].join(" ")+'"'}C+=">";for(I=0;I<A.rows;I++){C+='<tr valign="top"';if(A["class"]){C+=' class="'+A["class"].join("_tr ")+'_tr"'}C+=">";for(B=0;B<A.columns;B++){C+="<td";if(A["class"]){C+=' class="'+A["class"].join("_td ")+'_td"'}C+=">"+G+"</td>";G=""}C+="</tr>"}C+="</table>";if(is_ie){C+="<p></p>"}else{C+="<br />"}}else{var F=[];if(A.width){F.push("width:"+A.width)}if(A["class"]){F.push("class:"+A["class"])}C+="[table";if(F.length){C+='="'+F.join(", ")+'"'}C+="]\n";for(I=0;I<A.rows;I++){C+="[tr]\n";for(B=0;B<A.columns;B++){C+="\t[td]"+G+"[/td]\n";G=""}C+="[/tr]\n"}C+="[/table]\n"}this.remove_editor_dialog();this.insert_text(C)};vB_Text_Editor_CMS.prototype.subscript=function(A){if(this.wysiwyg_mode){this.editdoc.execCommand("subscript",false,true)}else{this.wrap_tags("sub",false)}};vB_Text_Editor_CMS.prototype.superscript=function(A){if(this.wysiwyg_mode){this.editdoc.execCommand("superscript",false,true)}else{this.wrap_tags("sup",false)}};vB_Text_Editor_CMS.prototype.inserthorizontalrule=function(A){if(this.wysiwyg_mode){this.editdoc.execCommand("inserthorizontalrule",false,true)}else{this.wrap_tags("hr",false)}};vB_Text_Editor_CMS.prototype.insertpagebreak=function(C){if(this.wysiwyg_mode){var B=fetch_object(this.editorid+"_cmd_insertpagebreak");if(B&&B.state){this.apply_formatblock("<p>");var A=this.get_selection_container_element();if(A){YAHOO.util.Dom.removeClass(this.find_by_tag_name(A,"p"),"wysiwyg_pagebreak")}}else{this.apply_formatblock("<h3>");var A=this.get_selection_container_element();if(A){YAHOO.util.Dom.addClass(this.find_by_tag_name(A,"h3"),"wysiwyg_pagebreak")}}}else{this.wrap_tags("page",false)}};vB_Text_Editor_CMS.prototype.formatting=function(F,A){var C=A.tagName.match(/^h[1-6]$/i);if(this.wysiwyg_mode){var B;if(C){B="<"+A.tagName+">"}else{B="<p>"}this.apply_formatblock(B);var D=this.get_selection_container_element();if(D){var G=this.find_by_tag_name(D,"h3");if(!G||!G.length){G=YAHOO.util.Dom.getAncestorByTagName(D,"h3")}if(A.extra=="pagebreak"){YAHOO.util.Dom.addClass(G,"wysiwyg_pagebreak")}else{YAHOO.util.Dom.removeClass(G,"wysiwyg_pagebreak")}}}else{if(C){var E=(A.extra=="pagebreak"?"page":A.tagName);this.wrap_tags(E,false)}}};vB_Text_Editor_CMS.prototype.find_by_tag_name=function(A,B){if(!A||!A.tagName){return[]}if(A.tagName.toLowerCase()==B.toLowerCase()){return[A]}else{return A.getElementsByTagName(B)}};vB_Text_Editor_CMS.prototype.apply_formatblock=function(C){try{this.editdoc.execCommand("formatblock",false,C);return }catch(A){var B=this.get_range_from_selection();if(!B){return }if(B.collapsed&&B.insertNode){B.insertNode(this.editdoc.createTextNode(" "))}this.editdoc.execCommand("formatblock",false,C)}};vB_Text_Editor_CMS.prototype.get_selection_container_element=function(A){if(typeof (A)=="undefined"){A=this.get_range_from_selection()}var B;if(A.commonAncestorContainer){if(A.commonAncestorContainer.nodeName=="#text"){B=A.commonAncestorContainer.parentNode}else{B=A.commonAncestorContainer}}else{if(A.parentElement()){B=A.parentElement()}}return B};vB_Text_Editor_CMS.prototype.select_range=function(A){if(A.select){A.select()}else{var B=this.get_selection_object();if(B&&B.removeAllRanges){B.removeAllRanges();B.addRange(A)}}};vB_Text_Editor_CMS.prototype.get_selection_object=function(){var B,A;if(this.wysiwyg_mode){B=this.editwin;A=this.editdoc}else{B=window;A=document}if(B.getSelection){return B.getSelection()}else{return A.selection}};vB_Text_Editor_CMS.prototype.get_range_from_selection=function(A){if(typeof (A)=="undefined"){A=this.get_selection_object()}if(!A){return null}if(A.createRange){return A.createRange()}else{if(A.getRangeAt){return A.getRangeAt(0)}else{if(this.editdoc.createRange){return this.editdoc.createRange()}else{return null}}}};vB_Text_Editor_Events.prototype.formatting_option_format_onclick=function(A){vB_Editor[this.editorid].format(A,this.cmd,this);vBmenu.hide()};