温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:Openlab开源综合社区系统
当前文件:
OpenLab/Add-Ons/EditorsWraper/TinyMCE/TinyMCE.cs[7K,2009-6-12 11:51:29],打开代码结构图
OpenLab/Add-Ons/EditorsWraper/TinyMCE/TinyMCE.cs[7K,2009-6-12 11:51:29],打开代码结构图1using System; 2
using System.Collections.Generic; 3
using System.Text; 4
using System.Web.UI.WebControls; 5
using Openlab.Editors; 6
using System.Web.UI; 7
using System.Collections.Specialized; 8
using System.Text.RegularExpressions; 9
using System.Collections; 10
11
namespace Openlab.AddOns.EditorsWraper 12
{ 13
14
[ParseChildren(false)] 15
public class TinyMCE : TextBox, ITextEditor 16
{ 17
private bool _enableHtmlModeEditing; 18
private NameValueCollection _tinyMCEOptions; 19
private static Regex FindStyles; 20
private bool isStyleCorrected; 21
private static Hashtable ProtectedTinyMCEOptions; 22
23
static TinyMCE() 24
{ 25
TinyMCE.ProtectedTinyMCEOptions = new Hashtable(); 26
TinyMCE.FindStyles = new Regex("style\\s*=\\s*\\\"?([^\\\"\\>]*)", RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase); 27
TinyMCE.ProtectedTinyMCEOptions.Add("mode", true); 28
TinyMCE.ProtectedTinyMCEOptions.Add("elements", true); 29
TinyMCE.ProtectedTinyMCEOptions.Add("relative_urls", true); 30
TinyMCE.ProtectedTinyMCEOptions.Add("theme_Editor_codeenabled", true); 31
} 32
33
public TinyMCE() 34
{ 35
this._enableHtmlModeEditing = true; 36
this._tinyMCEOptions = null; 37
this.isStyleCorrected = false; 38
} 39
40
protected override void AddParsedSubObject(object obj) 41
{ 42
if (obj is TinyMCEOption) 43
{ 44
TinyMCEOption option = (TinyMCEOption)obj; 45
if (TinyMCE.ProtectedTinyMCEOptions.ContainsKey(option.Name)) 46
{ 47
throw new InvalidOperationException("The TinyMCE option '" + option.Name + "' is not allowed to be modified."); 48
} 49
this.TinyMCEOptions[option.Name] = option.Value; 50
} 51
else 52
{ 53
base.AddParsedSubObject(obj); 54
} 55
} 56
57
private string GetFormattedOptions() 58
{ 59
StringBuilder options = new StringBuilder(); 60
foreach (string key in this.TinyMCEOptions.Keys) 61
{ 62
if (((key != null) && (key != string.Empty)) && !TinyMCE.ProtectedTinyMCEOptions.ContainsKey(key)) 63
{ 64
options.Append(","); 65
options.Append(key); 66
options.Append(":"); 67
options.Append(this.TinyMCEOptions[key]); 68
} 69
} 70
return options.ToString(); 71
} 72
73
protected override void OnLoad(EventArgs e) 74
{ 75
base.OnLoad(e); 76
if (this.Height != Unit.Empty) 77
{ 78
base.Style["height"] = this.Height.ToString(); 79
this.Height = Unit.Empty; 80
} 81
else 82
{ 83
base.Style["height"] = "360px;"; 84
} 85
if (this.Width != Unit.Empty) 86
{ 87
base.Style["width"] = this.Width.ToString(); 88
this.Width = Unit.Empty; 89
} 90
else 91
{ 92
base.Style["width"] = "100%"; 93
} 94
this.TextMode = TextBoxMode.MultiLine; 95
this.TinyMCEOptions["theme"] = "'advanced'"; 96
} 97
98
protected override void Render(HtmlTextWriter writer) 99
{ 100
base.Render(writer); 101
Type type = typeof(string); 102
if (!this.Page.ClientScript.IsClientScriptBlockRegistered(type, base.GetType().FullName)) 103
{ 104
this.Page.ClientScript.RegisterClientScriptBlock(type, base.GetType().FullName, ""); 105
writer.Write("<script language=\"javascript\" type=\"text/javascript\" src=\"{0}\"></script>", this.Page.Response.ApplyAppPathModifier("~/editors/tiny_mce/jscripts/tiny_mce/tiny_mce.js")); 106
} 107
108
if (!this.Page.ClientScript.IsClientScriptBlockRegistered(type, this.ClientID)) 109
{ 110
this.Page.ClientScript.RegisterStartupScript(type, this.ClientID, ""); 111
writer.Write("\r\n<script language=\"javascript\" type=\"text/javascript\">\r\ntinyMCE.init({{mode:\"exact\",elements:\"{0}\",theme_Standard_codeenabled:{1},relative_urls:false{2}}});\r\n</script>", 112
this.ClientID.ToString(), this.EnableHtmlModeEditing.ToString().ToLower(), this.GetFormattedOptions()); 113
} 114
} 115
116
public bool EnableHtmlModeEditing 117
{ 118
get 119
{ 120
return this._enableHtmlModeEditing; 121
} 122
set 123
{ 124
this._enableHtmlModeEditing = value; 125
} 126
} 127
128
public string GetClientSideMethod 129
{ 130
get 131
{ 132
return ("tinyMCE.getContent(tinyMCE.getEditorId('" + this.ClientID.ToString() + "'))"); 133
} 134
} 135
136
public bool IsRichTextCapable 137
{ 138
get 139
{ 140
return true; 141
} 142
} 143
144
public string StyleName 145
{ 146
get 147
{ 148
return base.CssClass; 149
} 150
set 151
{ 152
base.CssClass = value; 153
} 154
} 155
156
public override string Text 157
{ 158
get 159
{ 160
if (!this.isStyleCorrected) 161
{ 162
Match match = TinyMCE.FindStyles.Match(base.Text); 163
StringBuilder text = new StringBuilder(); 164
int i = 0; 165
while (match.Success) 166
{ 167
if (i != match.Index) 168
{ 169
text.Append(base.Text.Substring(i, match.Index - i)); 170
} 171
text.Append(match.Value.Replace(""", "'").Replace(""", "'").Replace("'", "'")); 172
i = match.Index + match.Length; 173
match = TinyMCE.FindStyles.Match(base.Text, i); 174
} 175
if (i < base.Text.Length) 176
{ 177
text.Append(base.Text.Substring(i)); 178
} 179
base.Text = text.ToString(); 180
this.isStyleCorrected = true; 181
} 182
return base.Text; 183
} 184
set 185
{ 186
base.Text = value; 187
this.isStyleCorrected = false; 188
} 189
} 190
191
public NameValueCollection TinyMCEOptions 192
{ 193
get 194
{ 195
if (this._tinyMCEOptions == null) 196
{ 197
this._tinyMCEOptions = new NameValueCollection(); 198
} 199
return this._tinyMCEOptions; 200
} 201
} 202
203
204
205
206
ITextEditor 成员 215
} 216
217
} 218






}
}