📄 tinymce.cs
字号:
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetFocus.Web.Core;
namespace NetFocus.Web.Applications.Forum
{
[ParseChildren(false)]
public class TinyMCE : TextBox, ITextEditor
{
private NameValueCollection _tinyMCEOptions;
private static Regex FindStyles;
private bool isStyleCorrected;
private static Hashtable ProtectedTinyMCEOptions;
static TinyMCE()
{
TinyMCE.ProtectedTinyMCEOptions = new Hashtable();
TinyMCE.FindStyles = new Regex("style\\s*=\\s*\\\"?([^\\\"\\>]*)", RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
TinyMCE.ProtectedTinyMCEOptions.Add("mode", true);
TinyMCE.ProtectedTinyMCEOptions.Add("elements", true);
TinyMCE.ProtectedTinyMCEOptions.Add("relative_urls", true);
TinyMCE.ProtectedTinyMCEOptions.Add("theme_communityserver_codeenabled", true);
}
public TinyMCE()
{
this._tinyMCEOptions = null;
this.isStyleCorrected = false;
}
protected override void AddParsedSubObject(object obj)
{
if (obj is TinyMCEOption)
{
TinyMCEOption option1 = (TinyMCEOption)obj;
if (TinyMCE.ProtectedTinyMCEOptions.ContainsKey(option1.Name))
{
throw new InvalidOperationException("The TinyMCE option '" + option1.Name + "' is not allowed to be modified.");
}
this.TinyMCEOptions[option1.Name] = option1.Value;
}
else
{
base.AddParsedSubObject(obj);
}
}
private string GetFormattedOptions()
{
StringBuilder builder1 = new StringBuilder();
foreach (string text1 in this.TinyMCEOptions.Keys)
{
if (((text1 != null) && (text1 != string.Empty)) && !TinyMCE.ProtectedTinyMCEOptions.ContainsKey(text1))
{
builder1.Append(",");
builder1.Append(text1);
builder1.Append(":");
builder1.Append(this.TinyMCEOptions[text1]);
}
}
return builder1.ToString();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.Height != Unit.Empty)
{
base.Style["height"] = this.Height.ToString();
}
if (this.Width != Unit.Empty)
{
base.Style["width"] = this.Width.ToString();
}
this.TextMode = TextBoxMode.MultiLine;
this.TinyMCEOptions["theme"] = "'CommunityServer'";
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
if (!this.Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), base.GetType().FullName))
{
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), base.GetType().FullName, "");
writer.Write("<script language=\"javascript\" type=\"text/javascript\" src=\"{0}\"></script>", this.Page.Response.ApplyAppPathModifier("~/utility/tiny_mce/tiny_mce.js"));
}
if (!this.Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), base.GetType().FullName + "_CommunityServerOptions"))
{
StringBuilder builder1 = new StringBuilder();
//if (CSContext.Current.SiteSettings.EnableEmoticons)
//{
// foreach (Smiley smiley1 in Smilies.GetSmilies(true))
// {
// if (builder1.Length > 0)
// {
// builder1.Append(",");
// }
// builder1.Append("['");
// builder1.Append(smiley1.SmileyText.Replace("'", @"\'"));
// builder1.Append("','[");
// builder1.Append(smiley1.SmileyCode.Replace("'", @"\'"));
// builder1.Append("]','");
// builder1.Append(Globals.GetSiteUrls().Emoticon.Replace("'", @"\'"));
// builder1.Append(smiley1.SmileyUrl.Replace("'", @"\'"));
// builder1.Append("']");
// }
//}
this.Page.ClientScript.RegisterStartupScript(this.GetType(), base.GetType().FullName + "_CommunityServerOptions", "");
writer.Write("\r\n<script language=\"javascript\" type=\"text/javascript\">\r\ntinyMCE_CommunityServerOptions = {{ContentSelectorEnabled:{0},ContentSelectorOpenFunction:new Function(\"{1}\"),Smilies:[{2}]}}\r\n</script>", "true", GetOpenScript("TinyMCE_ContentSelectorPlugin._addContent(content);").Replace("\"", "\\\""), builder1.ToString());
}
if (!this.Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), this.ClientID))
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, "");
writer.Write("\r\n<script language=\"javascript\" type=\"text/javascript\">\r\ntinyMCE.init({{mode:\"exact\",elements:\"{0}\",theme_communityserver_codeenabled:{1},relative_urls:false{2}}});\r\n</script>", this.ClientID.ToString(), "true", this.GetFormattedOptions());
}
}
public string GetOpenScript(string setContentScript)
{
return GetOpenScript("", setContentScript);
}
public string GetOpenScript(string initializeScript, string setContentScript)
{
return string.Empty;
//return "window.ContentSelectorCallbackFunction = new Function('content', '" + setContentScript.Replace("'", "\\'") + "');" + initializeScript + "; Telligent_Modal.Open('" + SiteUrls.Instance().ContentSelectorModal + "', 600, 420, null);";
}
public override string Text
{
get
{
if (!this.isStyleCorrected)
{
//Match match1 = TinyMCE.FindStyles.Match(base.Text);
//StringBuilder builder1 = new StringBuilder();
//int num1 = 0;
//while (match1.Success)
//{
// if (num1 != match1.Index)
// {
// builder1.Append(base.Text.Substring(num1, match1.Index - num1));
// }
// builder1.Append(match1.Value.Replace(""", "'").Replace(""", "'").Replace("'", "'"));
// num1 = match1.Index + match1.Length;
// match1 = TinyMCE.FindStyles.Match(base.Text, num1);
//}
//if (num1 < base.Text.Length)
//{
// builder1.Append(base.Text.Substring(num1));
//}
//base.Text = builder1.ToString();
this.isStyleCorrected = true;
}
return base.Text;
}
set
{
base.Text = value;
this.isStyleCorrected = false;
}
}
public NameValueCollection TinyMCEOptions
{
get
{
if (this._tinyMCEOptions == null)
{
this._tinyMCEOptions = new NameValueCollection();
}
return this._tinyMCEOptions;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -