function cRichTextEditor(){ this.emwindow = new Array; this.editor = "body_1"; this.table = ""; this.id = "1"; this.saveFlag = 0; this.signatures = false; this.replyController = false; this.newImageId = false; this.plain = new Array; this.editorReady = true; this.hoho = ''; } // This code was written by Tyler Akins and has been placed in the // public domain. It would be nice if you left this header intact. // Base64 code from Tyler Akins -- http://rumkin.com var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; var ua = navigator.userAgent.toLowerCase(); if (ua.indexOf(" chrome/") >= 0 || ua.indexOf(" firefox/") >= 0 || ua.indexOf(' gecko/') >= 0) { var StringMaker = function () { this.str = ""; this.length = 0; this.append = function (s) { this.str += s; this.length += s.length; } this.prepend = function (s) { this.str = s + this.str; this.length += s.length; } this.toString = function () { return this.str; } } } else { var StringMaker = function () { this.parts = []; this.length = 0; this.append = function (s) { this.parts.push(s); this.length += s.length; } this.prepend = function (s) { this.parts.unshift(s); this.length += s.length; } this.toString = function () { return this.parts.join(''); } } } cRichTextEditor.prototype.fromJSON = function( value ) { if(!value) return ''; return (new Function( "return " + this.decode64( value )))(); } cRichTextEditor.prototype.decode64 = function(input) { if( typeof input === "undefined" ) return ''; var output = new StringMaker(); var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; // remove all characters that are not A-Z, a-z, 0-9, +, /, or = input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = keyStr.indexOf(input.charAt(i++)); enc2 = keyStr.indexOf(input.charAt(i++)); enc3 = keyStr.indexOf(input.charAt(i++)); enc4 = keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output.append(String.fromCharCode(chr1)); if (enc3 != 64) { output.append(String.fromCharCode(chr2)); } if (enc4 != 64) { output.append(String.fromCharCode(chr3)); } } return output.toString(); } cRichTextEditor.prototype.loadEditor = function(ID) { var parentDiv = document.getElementById("body_position_" + ID); var pObj = "body_" + ID; var textArea = document.createElement("TEXTAREA"); textArea.id = pObj; textArea.style.width = '100%'; parentDiv.appendChild(textArea); RichTextEditor.plain[ID] = false; if(preferences.plain_text_editor == 1) { RichTextEditor.plain[ID] = true; RichTextEditor.editorReady = true; } else RichTextEditor.active(pObj); } cRichTextEditor.prototype.loadEditor2 = function(ID) { var pObj = "body_" + ID; RichTextEditor.plain[ID] = false; if(preferences.plain_text_editor == 1) { RichTextEditor.plain[ID] = true; RichTextEditor.editorReady = true; } else RichTextEditor.active(pObj); } cRichTextEditor.prototype.getSignaturesOptions = function() { if(RichTextEditor.signatures !== false) return RichTextEditor.signatures; var signatures = this.fromJSON( preferences.signatures ); var signature_types = this.fromJSON( preferences.signature_types ); for( key in signatures ) if( !signature_types[key] ) signatures[key] = signatures[key].replace( /\n/g, "
" ); RichTextEditor.signatures = signatures; return signatures; } cRichTextEditor.prototype.getSignatureDefault = function() { if(RichTextEditor.signatures === false) RichTextEditor.signatures = RichTextEditor.getSignaturesOptions(); if(!RichTextEditor.signatures || !RichTextEditor.signatures[preferences.signature_default || ""]) { preferences.use_signature = "0"; //Desabilita o uso da assinatura return ''; } return unescape(RichTextEditor.signatures[preferences.signature_default]); } cRichTextEditor.prototype.execPosInstance = function(inst) { if(RichTextEditor.editorReady === false) { var editor = CKEDITOR.instances[inst]; var id = inst.replace('body_',''); var content = $("#content_id_"+id) editor.document.on('keydown', function(event) { away = false; var save_link = content.find(".save"); save_link.unbind("click").click(function(){ openTab.toPreserve[id] = true;save_msg(id); }); save_link.button({ disabled: false }); }); // IM Module Enabled if( window.parent.loadscript && loadscript.autoStatusIM ) { CKEDITOR.instances[inst].document.on('keydown', function(event){ loadscript.autoStatusIM; }); } if (preferences.auto_save_draft == 1) { autoSaveControl.status[id] = true; autoSaveControl.timer[id] = window.setInterval( "autoSave("+id+")" ,autosave_time); CKEDITOR.instances[inst].document.on('keydown', function(event){ autoSaveControl.status[id] = false; }) } $(".cke_editor").css("white-space", "normal"); if(typeof(preferences.font_size_editor) !== 'undefined') $(editor.document.$.body).css("font-size",preferences.font_size_editor); if(typeof(preferences.font_family_editor) !== 'undefined') $(editor.document.$.body).css("font-family",preferences.font_family_editor); RichTextEditor.editorReady = true; } } cRichTextEditor.prototype.setPlain = function (active,id){ RichTextEditor.plain[id] = active; var content = $("#content_id_"+id); var div = $("
").attr("display", "none"); if(active === true) { CKEDITOR.instances['body_'+id].destroy(); var height = document.body.scrollHeight; height -= 330; $('#body_'+id).height(height); div.html($('#body_'+id).val()); /*Remove as tags html, tabulações e quebras de linha quando for utilizado o editor de texto simples*/ div.html($.trim(div.text().replace(/[\t]+/g, '').replace(/[\n]+/g, '\n'))); /*Insere o texto sem formatação no textarea*/ $('#body_'+id).val(div.text()); $('#body_'+id).keydown(function(event) { away = false; save_link = content.find(".save")[0]; save_link.onclick = function onclick() {openTab.toPreserve[id] = true;save_msg(id);} ; $("#save_message_options_"+id).button({ disabled: false }); //save_link.className = 'message_options'; }); $("[name=textplain_rt_checkbox_"+id+"]").button({ disabled: false }); } else{ RichTextEditor.active('body_'+id, id); /*Insere somente quebras de linha para que o texto convertido não fique todo em uma linha só*/ div.html($('#body_'+id).val().replace(/[\n]+/g, '
')); $('#body_'+id).val(div.html()); } } cRichTextEditor.prototype.getData = function (inst){ var id = inst.replace('body_',''); if(RichTextEditor.plain[id] === true) return $('#'+inst).val(); else return CKEDITOR.instances[inst].getData(); } cRichTextEditor.prototype.setData = function (id,data){ if(this.plain[id.replace('body_','')] === true) $('#'+id).val(data); else CKEDITOR.instances[id].setData(data); } cRichTextEditor.prototype.setInitData = function (id,data,reply,recursion, callback){ var content = $("#content_id_"+id); if(recursion === undefined){ recursion = 1; }else{ recursion++; } if(this.plain[id] === true){ data = data.replace( new RegExp('
((.\n*)*)
'),'$1'); if($('#'+id) !== undefined){ $('#'+id).val(data); if (reply === undefined){ $('#to_'+id).focus(); } } else{ setTimeout(function() {RichTextEditor.setInitData(id,data,reply,recursion); }, 500); } } else{ if( RichTextEditor.editorReady === true && CKEDITOR.instances['body_'+id] !== undefined ){ var editor = CKEDITOR.instances['body_'+id]; var selection = editor.getSelection(); var fontSize = ''; var fontFamily = ''; if(typeof(preferences.font_size_editor) !== 'undefined') fontSize = 'font-size:' + preferences.font_size_editor; if(fontSize != '') fontFamily = ';' if(typeof(preferences.font_family_editor) !== 'undefined') fontFamily += 'font-family:' + preferences.font_family_editor + ';'; var divBr = '

'; if(selection !== undefined && selection !== null){ var selectionRanges = selection.getRanges(); } if(reply !== undefined){ if(reply == 'edit') editor.insertHtml(data); else editor.insertHtml(divBr+data); editor.focus(); } if(selection !== null){ if(selectionRanges[selectionRanges.length-1] !== undefined){ selectionRanges[selectionRanges.length-1].setStart(selectionRanges[selectionRanges.length-1].getTouchedStartNode().getParents()[1].getChild(0), 0); selectionRanges[selectionRanges.length-1].setEnd(selectionRanges[selectionRanges.length-1].getTouchedStartNode().getParents()[1].getChild(0), 0); } selection.selectRanges(selectionRanges); } if (is_webkit){ $('#cke_contents_body_'+id+'>iframe').scrollTo(':first'); } if(callback !== undefined) callback(); } else if(recursion < 20){ setTimeout(function() {RichTextEditor.setInitData(id,data,reply,recursion); }, 500); } } } cRichTextEditor.prototype.destroy = function(id) { //Remove Instancia do editor if( CKEDITOR.instances[id] !== undefined ) CKEDITOR.remove(CKEDITOR.instances[id]); } cRichTextEditor.prototype.active = function(id, just_id) { //Remove Instancia do editor caso ela exista if( CKEDITOR.instances[id] !== undefined ) CKEDITOR.remove(CKEDITOR.instances[id]); var height = document.body.scrollHeight; height -= 375; $('#'+id).ckeditor( function() { RichTextEditor.execPosInstance(id) }, { toolbar:'mail', height: height } ); //$("[name=textplain_rt_checkbox_"+just_id+"]").button({ disabled: false }); } cRichTextEditor.prototype.focus = function(id) { if(RichTextEditor.plain[id] === true) $('#body_'+id).focus(); else CKEDITOR.instances['body_'+id].focus(); } //Função reseta o atributo contentEditable para resolver bug de cursor ao trocar abas cRichTextEditor.prototype.setEditable = function(id) { if( CKEDITOR.instances['body_'+ id] === undefined ) return; var element = CKEDITOR.instances['body_'+ id].document.getBody(); element.removeAttribute('contentEditable'); element.setAttribute('contentEditable','true'); } //Build the Object RichTextEditor = new cRichTextEditor();