//http://wiki.moxiecode.com/index.php/TinyMCE:Configuration // This CSS will reduce the space between (lines) paragraphs to zero. It will look more like the default line spacing in popular Word processors. // p {margin: 0px; padding: 0px;} // force BR elements on newlines instead of inserting paragraphs //force_br_newlines : true, //forced_root_block : '' // Needed for 3.x // disable/enable the creation of paragraphs on return/enter in Mozilla/Firefox. The default value of this option is true. //force_p_newlines : true // preserve white space //preformatted : true // all element cleanup will be skipped but other cleanup functionality such as URL conversion will still be executed. //verify_html : false var resetValues = {}; function resetValue(editor,option) { var text = resetValues[editor.id]; if (option=="Reset") { text = "\n" + text; editor.setContent(text); } else if (option=="Convert") { text = "\n" + text.replace(/\n/g, "
"); editor.setContent(text); } else if (option=="Revert") { tinyMCE.execCommand('mceRemoveControl', true, editor.id); var obj = document.getElementById(editor.id); obj.value = text; } } var sURLPREFIX = "/"; var sREVISIONPREFIX = ""; var sREVISIONPREFIXNOHOST = sREVISIONPREFIX.replace(sURLPREFIX,""); //var revPrefixStr = "<SUB"+" REVISIONPREFIX>"; // separate so it is not replaced by HttpHandler.subst function fitSaveCallback(id, html, body) { // make sure the user did not delete the FIT_TINY comment if (html.indexOf("")<0) { html = "" + html; } // get rid of REVISIONPREFIX (ie: smileys) as the revision number will change in future // tried using revPrefixStr, but it was putting <REVISIONPREFIX> when changing from RTF to console html = html.replace(sREVISIONPREFIX,""); html = html.replace(sREVISIONPREFIXNOHOST,""); return html; } //http://www.tinymce.com/forum/viewtopic.php?id=5090 function myCustomURLConverter(url, node, on_save) { // Do some custom URL convertion if (!url.indexOf("http")==0) { //tinyMCE.execCommand('mceRemoveNode', true, node); //alert("removed: "+url); } // Return new URL return url; } var TINYINIT = false; function tinyInit(id) { // This is where the compressor will load all components, include all components used on the page here // tinyMCE_GZ.init({ // plugins : "emotions,inlinepopups,preview,searchreplace,fullscreen", // themes : 'advanced', // languages : 'en', // disk_cache : true, // debug : false // }); tinymce.create('tinymce.plugins.FitPlugin', { createControl: function(n, cm) { switch (n) { case 'fit': var c = cm.createMenuButton('fit', { title : '', image : 'com/other/fit20.gif', icons : false }); c.onRenderMenu.add(function(c, m) { var sub; m.add({title : '', onclick : function() { resetValue(tinyMCE.activeEditor,"Reset"); }}); m.add({title : '', onclick : function() { resetValue(tinyMCE.activeEditor,"Convert"); }}); m.add({title : '', onclick : function() { resetValue(tinyMCE.activeEditor,"Revert"); }}); }); return c; } return null; } }); // Register plugin with a short name tinymce.PluginManager.add('fit', tinymce.plugins.FitPlugin); if(typeof (window.customTinyInit) == 'function') { customTinyInit(); } else { tinyMCE.init({ save_callback : "fitSaveCallback", //urlconverter_callback : "myCustomURLConverter", //mode : "textareas", //convert_urls : false, // otherwise emotions get a "../" added to them when you switch between rtf and normal modes //relative_urls : false, //remove_script_host : true, // works with relative urls, default true will remove host from url content_css : "stylesheets/TinyMce.css", theme_advanced_font_sizes: "10pt,12pt,13pt,14pt,16pt,18pt,20pt", font_size_style_values : "10pt,12pt,13pt,14pt,16pt,18pt,20pt", //force_br_newlines : true, // they warn against this but it works better with old format, as does forced_root_block //forced_root_block : '', // otherwise, converting back to regular textarea shows all the

stuff // problem with

when going back and forth //convert_newlines_to_brs : true, // otherwise, if a user from old system with newlines uses this, all newlines are lost gecko_spellcheck : true, // this keeps firefox spellcheck working paste_block_drop : true, theme : "advanced", mode : "none", language : "", height:"200", width:"100%", theme_advanced_layout_manager : "SimpleLayout", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", plugins : "-fit,advlist,advlink,emotions,inlinepopups,preview,searchreplace,fullscreen,visualblocks", theme_advanced_buttons1 : "fit,bold,italic,underline,strikethrough,fontsizeselect,forecolor,backcolor,hr,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,outdent,indent,|,link,unlink,anchor,image,charmap,emotions,|,search,replace,|,help,code,visualblocks,preview,fullscreen", theme_advanced_buttons2 : "", theme_advanced_buttons3 : "" }); } } // This is the function that moves the cursor to the end of content function moveCursorToEnd(editor_id) { inst = tinyMCE.get(editor_id); var edInst = tinyMCE.get(editor_id); ediInst.execCommand("selectall", false, null); if (tinyMCE.isMSIE) { rng = inst.getRng(); rng.collapse(false); rng.select(); } else { sel = inst.getSel(); sel.collapseToEnd(); } } function setCaretTo(obj, pos) { if(obj.createTextRange) { /* Create a TextRange, set the internal pointer to a specified position and show the cursor at this position */ var range = obj.createTextRange(); range.move("character", pos); range.select(); } else if(obj.selectionStart) { /* Gecko is a little bit shorter on that. Simply focus the element and set the selection to a specified position */ alert(obj.selectionStart); obj.focus(); obj.setSelectionRange(pos, pos); } } function toggleEditor(id) { if (typeof tinyMCE !== 'undefined') { if (TINYINIT==false) { tinyInit(); TINYINIT=true; } var obj = document.getElementById(id); if (!tinyMCE.get(id)) { resetValues[id] = obj.value; if (obj.value.indexOf("")<0) { // make sure field starts with tag if (obj.value.indexOf('\n') > -1) { var q2 = confirm("You have existing text which does not appear to be from the RTF editor ("+id+"). All newlines will be removed by this editor.\n\nIf you do not like the result, use the custom ATS options (first icon) to convert your original text!\n\nContinue ?"); if (q2==false) { return false; } } obj.value = "" + obj.value; //setCaretTo(obj,16); //does not seem to work on Firefox } tinyMCE.execCommand('mceAddControl', true, id); //window.setTimeout("tinyMCE.execCommand('mceFocus', false, id)", 1); tinyMCE.execCommand('JustifyLeft',false,id); // get rid of missing cursor } else { tinyMCE.execCommand('mceRemoveControl', true, id); if (!checkValidRtfContent(obj.value)) { obj.value=""; // otherwise, nothing there - don't want to see FIT_TINY tag in regular console } } } } function checkRtfTags() { for(i=0; i<document.entry_form.elements.length; i++) { var element = document.entry_form.elements[i]; if (element.tagName=='TEXTAREA') { if (tinyMCE.get(element.id)) { var obj = document.getElementById(element.id); if (obj && obj.value.indexOf("<!-- FIT_TINY -->")<0) { obj.value = "" + obj.value; } } } } } // initialize any that need it function initTiny() { //var count; for(i=0; i<document.entry_form.elements.length; i++) { var element = document.entry_form.elements[i]; if (element.tagName=='TEXTAREA') { var def = element.id; var index = def.indexOf("field"); if (index>0) { // testspec stuff prefixes with tc1, tr2, .. def = def.substr(index); } if (rtfDefaultFields.indexOf(def)>=0) { // defaults to rtf through settings //setTimeout("toggleEditor('"+element.id+"');",10*count++); var obj = document.getElementById(element.id); if (obj.value.length == 0 || obj.value.indexOf("") >= 0) { //only enable editor if field is blank or contains rich text toggleEditor(element.id); } } else if (element.id.length>0) { var obj = document.getElementById(element.id); if (obj && obj.value.indexOf("")>=0) { // defaults to rtf cause data was edited there before toggleEditor(element.id); } } } } } function rtfCheckLinks() { var warning = ""; for(i=0; i<document.entry_form.elements.length; i++) { var element = document.entry_form.elements[i]; if (element.tagName=='TEXTAREA') { //var obj = document.getElementById(element.id); //if (obj && obj.value.indexOf("<!-- FIT_TINY -->")>=0) { //alert("i: "+element.id + " : "+element.value); //} var inst = tinyMCE.get(element.id); if (inst) { var imgNodes = inst.getDoc().getElementsByTagName("img"); var n=0; for (n==0; n<imgNodes.length; n++) { var src = imgNodes[n].src; if (src.indexOf("http")<0 && src.indexOf("www")<0) { // appears to be invalid, check if it was already there if (typeof resetValues[element.id]!='undefined') { if (resetValues[element.id].indexOf(src)<0) { warning+=">"+src + "\n"; } } } } } } } if (warning.length>0) { warning=""+ warning + "\n\n"; if (!confirm(warning)) { return false; } } return true; }