private void SetupScripts() { if (BasePath.Contains("tiny_mce")) { this.Page.ClientScript.RegisterClientScriptBlock( this.GetType(), "tinymcemain", "<script type=\"text/javascript\" src=\"" + ResolveUrl(this.BasePath + "tiny_mce.js") + "\"></script>"); } else { this.Page.ClientScript.RegisterClientScriptBlock( this.GetType(), "tinymcemain", "<script type=\"text/javascript\" src=\"" + ResolveUrl(this.BasePath + "tinymce.min.js") + "\"></script>"); } StringBuilder setupScript = new StringBuilder(); setupScript.Append("function mojoTinyMCEOnChangeHandler(inst) {"); //setupScript.Append("hookupGoodbyePrompt(\"" + Page.Server.HtmlEncode(Resource.UnSavedChangesPrompt) + "\"); "); setupScript.Append("hookupGoodbyePrompt(\"" + Resource.UnSavedChangesPrompt.HtmlEscapeQuotes().RemoveLineBreaks() + "\"); "); setupScript.Append("} "); Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "tinymceExitPrompt", "\n<script type=\"text/javascript\">\n" + setupScript.ToString() + "\n</script>"); setupScript = new StringBuilder(); setupScript.Append("\n<script type=\"text/javascript\">"); //this older approach did not work inside tabs // so we switched to use the editor constructor //setupScript.Append("tinyMCE.init({"); //setupScript.Append("mode :\"specific_textareas\" "); //setupScript.Append(", editor_selector : \"mceEditor\" "); //if (BasePath.Contains("tiny_mce")) //{ setupScript.Append(" var ed" + this.ClientID + " = new tinymce.Editor('" + this.ClientID + "', { "); //} //else //{ // setupScript.Append("tinyMCE.init({"); // setupScript.Append("selector: 'textarea#" + this.ClientID + "',"); // setupScript.Append("theme: 'modern',"); //} setupScript.Append("accessibility_focus : true "); //waiting for the 3.5 branch of TinyMCE to comeout of beta // it has more support for html 5 setupScript.Append(", schema :'" + WebConfigSettings.TinyMceSchema + "' "); //http://www.tinymce.com/tryit/html5_formats.php // setupScript.Append(",style_formats :[{title : 'section', block : 'section', wrapper: true, merge_siblings: false},"); // setupScript.Append("{title : 'article', block : 'article', wrapper: true, merge_siblings: false},"); // setupScript.Append("{title : 'aside', block : 'aside', wrapper: true},"); // setupScript.Append("{title : 'figure', block : 'figure', wrapper: true}]"); //if (!AccessibilityFocus) // true is default //{ // setupScript.Append(", accessibility_focus : false "); //} if (!AccessibilityWarnings) { setupScript.Append(", accessibility_warnings : false "); } setupScript.Append(", browsers : \"" + this.Browsers + "\""); setupScript.Append(",forced_root_block:'" + forcedRootBlock + "'"); if (!CustomShortcuts) { setupScript.Append(", custom_shortcuts : false "); } if (!convertUrls) { setupScript.Append(", convert_urls : false "); } // added 2009-12-15 previously TinyMCE was encoding German chars and this made it not find matches in search index setupScript.Append(", entity_encoding : 'raw' "); //setupScript.Append(",encoding :'xml'"); setupScript.Append(", dialog_type : \"" + this.DialogType + "\""); CultureInfo culture; if (WebConfigSettings.UseCultureOverride) { culture = SiteUtils.GetDefaultUICulture(); } else { culture = CultureInfo.CurrentUICulture; } setupScript.Append(",language:'" + culture.TwoLetterISOLanguageName + "'"); if (culture.TextInfo.IsRightToLeft) { textDirection = "rtl"; } if (extendedValidElements.Length > 0) { setupScript.Append(",extended_valid_elements:\"" + extendedValidElements + "\""); } //extended_valid_elements setupScript.Append(",directionality:\"" + this.TextDirection + "\""); setupScript.Append(",editor_deselector:\"" + this.DeSelectorCSSClass + "\""); if (spellCheckerUrl.Length > 0) { setupScript.Append(", spellchecker_rpc_url:\"" + spellCheckerUrl + "\""); } else { if (EnableGeckoSpellCheck) { setupScript.Append(",gecko_spellcheck : true "); } } if ((plugins.Contains("spellchecker")) && (SpellCheckerLanguages.Length > 0)) { setupScript.Append(",spellchecker_languages:\"" + SpellCheckerLanguages + "\""); } //setupScript.Append(", language : \"" + this.Language + "\""); setupScript.Append(",body_class:'" + editorBodyCssClass + "'"); if (!EnableObjectResizing) { setupScript.Append(", object_resizing : false "); } if (Plugins.Length > 0) { setupScript.Append(", plugins : \"" + this.Plugins + "\""); if (Plugins.Contains("preview")) { setupScript.Append(",plugin_preview_width:'850'"); setupScript.Append(",plugin_preview_height:'900'"); } //TODO: populate from style templates for a element //http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advlink //This option should contain a semicolon separated list of class titles and class names separated by = //advlink_styles : “Code=code;Excel=excel;Flash=flash;Sound=sound;Office=office;PDF=pdf;Image=image;PowerPoint=powerpoint;Word=word;Video=video” //advlink_styles //setupScript.Append(",media_strict:false"); } //setupScript.Append(",apply_source_formatting:true"); //if (UseStrictLoadingMode) //{ // setupScript.Append(", strict_loading_mode : true "); //} setupScript.Append(", theme : \"" + this.Theme + "\""); if (!EnableUndoRedo) { setupScript.Append(", custom_undo_redo : false "); } if (EnableUndoRedo) { setupScript.Append(", custom_undo_redo_levels : " + this.UnDoLevels.ToString()); } if (Theme == "advanced") { setupScript.Append(", layout_manager : \"" + this.AdvancedLayoutManager + "\""); setupScript.Append(", theme_advanced_blockformats : \"" + this.AdvancedBlockFormats + "\""); if (AdvancedStyles.Length > 0) { setupScript.Append(", theme_advanced_styles : \"" + this.AdvancedStyles + "\""); } setupScript.Append(", theme_advanced_source_editor_width : \"" + this.AdvancedSourceEditorWidth + "\""); setupScript.Append(", theme_advanced_source_editor_height : \"" + this.AdvancedSourceEditorHeight + "\""); if (!AdvancedSourceEditorWrap) { setupScript.Append(", theme_advanced_source_editor_wrap : false "); } if (AdvancedLayoutManager == "SimpleLayout") { setupScript.Append(", theme_advanced_toolbar_location : \"" + this.AdvancedToolbarLocation + "\""); setupScript.Append(", theme_advanced_toolbar_align : \"" + this.AdvancedToolbarAlign + "\""); setupScript.Append(", theme_advanced_statusbar_location : \"" + this.AdvancedStatusBarLocation + "\""); setupScript.Append(", theme_advanced_buttons1 : \"" + this.AdvancedRow1Buttons + "\""); setupScript.Append(", theme_advanced_buttons2 : \"" + this.AdvancedRow2Buttons + "\""); setupScript.Append(", theme_advanced_buttons3 : \"" + this.AdvancedRow3Buttons + "\""); //setupScript.Append(", theme_advanced_buttons1_add : \"pastetext,pasteword,selectall\""); setupScript.Append(",theme_advanced_resizing : true "); } //advanced theme has 2 skins default and o2k7 // o2k7 also supports skin_variant with default, silver and black as options // so basically we have // default // o2k7default // o2k7silver // o2k7black switch (skin) { case "o2k7default": setupScript.Append(",skin :'o2k7'"); break; case "o2k7silver": setupScript.Append(",skin :'o2k7'"); setupScript.Append(",skin_variant :'silver'"); break; case "o2k7black": setupScript.Append(",skin :'o2k7'"); setupScript.Append(",skin_variant :'black'"); break; case "default": default: //do nothing break; } if (templatesUrl.Length > 0) { setupScript.Append(",template_external_list_url: \"" + this.templatesUrl + "\""); } if (!Cleanup) { setupScript.Append(", cleanup : false "); } if (CleanupOnStart) { setupScript.Append(", cleanup_on_startup : true "); } //setupScript.Append(",convert_newlines_to_brs : true "); if (!InlineStyles) { setupScript.Append(", inline_styles : false "); } if (EditorAreaCSS.Length > 0) { setupScript.Append(", content_css : \"" + this.EditorAreaCSS + "\""); } if (emotionsBaseUrl.Length > 0) { setupScript.Append(",emotions_images_url : '" + emotionsBaseUrl + "'"); } if (AutoFocus) { setupScript.Append(", auto_focus : \"" + this.ClientID + "\" "); } if ((enableFileBrowser) && (fileManagerUrl.Length > 0)) { setupScript.Append(",file_browser_callback : 'myFileBrowser' "); } setupScript.Append(",onchange_callback : 'mojoTinyMCEOnChangeHandler' "); if (forcePasteAsPlainText) { //setupScript.Append(",oninit:'setPlainText'"); setupScript.Append(",paste_text_sticky:true"); setupScript.Append(",setup : function(ed) {"); setupScript.Append("ed.onInit.add(function(ed) {"); setupScript.Append("ed.pasteAsPlainText = true;"); setupScript.Append("});}"); } } setupScript.Append("}); "); if (plugins.Contains("fullpage")) { StringBuilder supScript = new StringBuilder(); supScript.Append("\n<script type=\"text/javascript\">"); supScript.Append("var editorContentFilter = {"); supScript.Append("setContent: function(originalContent) {"); supScript.Append(" var headMatch = originalContent.match(/<head>(.|\\n|\\r)*?<\\/head>/i);"); supScript.Append("if (headMatch) {"); supScript.Append("var headText = headMatch[0];"); supScript.Append("var stylesMatch = headText.match(/<style(.|\\n|\\r)*?>(.|\\n|\\r)*?<\\/style>/ig);"); supScript.Append("if (stylesMatch) {"); supScript.Append("var styleText = \"\";"); supScript.Append("for (var i = 0; i < stylesMatch.length; i++) {"); supScript.Append("styleText += stylesMatch[i];"); supScript.Append("}"); supScript.Append("originalContent = originalContent.replace(/<body((.|\\n|\\r)*?)>/gi, \"<body$1><!--style begin-->\" + styleText + \"<!--style end-->\");"); supScript.Append("}"); supScript.Append("}"); supScript.Append("return originalContent;"); supScript.Append("},"); supScript.Append("getContent: function(originalContent) {"); supScript.Append(" return originalContent.replace(/<!--style begin-->(.|\\n|\\r)*?<!--style end-->/g, '');"); supScript.Append("}"); supScript.Append("};"); supScript.Append("</script>"); this.Page.ClientScript.RegisterClientScriptBlock( typeof(Page), "tmcfpfix", supScript.ToString()); setupScript.Append("ed" + this.ClientID + ".onBeforeSetContent.add(function(ed, o) {"); setupScript.Append("o.content = editorContentFilter.setContent(o.content);"); setupScript.Append(" });"); setupScript.Append("ed" + this.ClientID + ".onGetContent.add(function(ed, o) {"); setupScript.Append("o.content = editorContentFilter.getContent(o.content);"); setupScript.Append(" });"); } setupScript.Append("ed" + this.ClientID + ".render(); "); //if (forcePasteAsPlainText) //{ // setupScript.Append("ed" + this.ClientID + ".onPaste.add( function(ed, e, o){ "); // setupScript.Append("ed.execCommand('mcePasteText', true); "); // setupScript.Append("ed.execCommand('mceAddUndoLevel');"); // setupScript.Append("return tinymce.dom.Event.cancel(e); "); // setupScript.Append("});"); //} setupScript.Append("</script>"); this.Page.ClientScript.RegisterStartupScript( this.GetType(), this.UniqueID, setupScript.ToString()); if ((enableFileBrowser) && (fileManagerUrl.Length > 0)) { SetupFileBrowserScript(); } //string submitScript = " tinyMCE.triggerSave(false,true); "; ////submitScript = " alert(tinyMCE.getContent('" + this.ClientID + "')); return false; "; //this.Page.ClientScript.RegisterOnSubmitStatement( // this.GetType(), "tmsubmit", submitScript); }