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 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 ) { 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.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.createImage = function(){ var form = document.getElementById("attachment_window"); if (form == null){ form = document.createElement("DIV"); form.id = "attachment_window"; form.style.visibility = "hidden"; form.style.position = "absolute"; form.style.background = "#eeeeee"; form.style.left = "0px"; form.style.top = "0px"; form.style.width = "0px"; form.style.height = "0px"; document.body.appendChild(form); } var form_upload = Element('form_upload'); if (form_upload == null) form_upload = document.createElement("DIV"); form_upload.id = "form_upload"; form_upload.style.position = "absolute"; form_upload.style.top = "5px"; form_upload.style.left = "5px"; form_upload.name = get_lang("Upload File"); form_upload.style.width = "450px"; form_upload.style.height = "75px"; form_upload.innerHTML = get_lang('Select the desired image file')+':
'+ '
' + ' ' + ''; form.appendChild(form_upload); this.showWindow(form); } cRichTextEditor.prototype.showWindow = function (div){ if(! div) { return; } if(! this.emwindow[div.id]) { div.style.width = div.firstChild.style.width; div.style.height = div.firstChild.style.height; div.style.zIndex = "10000"; var title = div.firstChild.name; var wHeight = div.offsetHeight + "px"; var wWidth = div.offsetWidth + "px"; div.style.width = div.offsetWidth - 5; win = new dJSWin({ id: 'win_'+div.id, content_id: div.id, width: wWidth, height: wHeight, title_color: '#3978d6', bg_color: '#eee', title: title, title_text_color: 'white', button_x_img: '../phpgwapi/images/winclose.gif', border: true}); this.emwindow[div.id] = win; win.draw(); } else win = this.emwindow[div.id]; win.open(); } cRichTextEditor.prototype.addInputFile = function() { //Begin: Verify if the image extension is allowed. var imgExtensions = new Array("jpeg", "jpg", "gif", "png", "bmp", "xbm", "tiff", "pcx"); var inputFile = document.getElementById('inputFile_img'); if(!inputFile.value) return false; var fileExtension = inputFile.value.split("."); fileExtension = fileExtension[(fileExtension.length-1)]; var deniedExtension = true; for(var i=0; i'); save_msg(id,true); } cRichTextEditor.prototype.execPosInstance = function(inst) { if(RichTextEditor.editorReady === false) { var editor = CKEDITOR.instances[inst]; var id = inst.replace('body_',''); editor.document.on('keydown', function(event) { away = false; var save_link = Element("save_message_options_"+id); save_link.onclick = function onclick() {openTab.toPreserve[id] = true;save_msg(id);} ; $("#save_message_options_"+id).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"); RichTextEditor.editorReady = true; } } cRichTextEditor.prototype.setPlain = function (active,id){ RichTextEditor.plain[id] = active; if(active === true) { CKEDITOR.instances['body_'+id].destroy(); var height = document.body.scrollHeight; height -= 330; $('#body_'+id).height(height); $('#body_'+id).keydown(function(event) { away = false; var save_link = Element("save_message_options_"+id); 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); } 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] === true) $('#'+id).val(data); else CKEDITOR.instances[id].setData(data) } cRichTextEditor.prototype.setInitData = function (id,data,reply,recursion){ if(recursion === undefined) recursion = 1; else recursion++; if(this.plain[id] === true) { 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]; editor.insertHtml(''); var selection = editor.getSelection(); if(selection !== undefined && selection !== null) var selectionRanges = selection.getRanges(); 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(reply === undefined){ editor.on('insertHtml',function setFocus(e){ setTimeout("$('#to_"+id+"').focus()",100); editor.removeListener('insertHtml', setFocus); } ); editor.insertHtml(divBr+divBr+data); } else if(reply == 'edit') editor.insertHtml(data); else editor.insertHtml(divBr+data); if(selection !== null) selection.selectRanges(selectionRanges); //Coloca o scroll do editor no inicio if (is_webkit){ $('#cke_contents_body_'+id+'>iframe').scrollTo(':first'); } //Caso não for uma resposta votla o foco para o input to //if(reply === undefined) // setTimeout("$('#to_"+id+"').focus()",100); } 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();