Skip to content

Commit 5700a3f

Browse files
andy4711andy4711
andy4711
authored and
andy4711
committed
I've programed some configuration options for ckeditor. My intention was to give the advanced users flexible configuration options and user who don't want to deal with custom config.js files some simple options.
First, i changed ckeditor to 4.1.3-full, because i had problems with the ckeditor.js (https://n2cms.codeplex.com/discussions/450462) And to full edition because of the toolbar configuration ooption (see EditableFreeTextAreaAttribute) I've tried to include most of the configuration options as ckeditor inpage configuration. First because of ckeditor updates and second i hohope i makes the usage of own ckeditor config.js files easier. New features 1. Editor Mode I've integrated three predefined Editor Modes, they modify the ckeditor toolbars. Standard=Same toolbar configuration as before. Basic = Copy/Paste, Undo/Redo, FOrmatting (Bold,Underline/Italic) Full=All Features available - The Editor mode is configurable as EditableFreeTextAreaAttribute. - Defaultmode = Standard - Moved the toolbar configuration from config.js to inpage We have projects with different areas, in some areas the user is allowed to change styles or format the text free. And in other areas he should be restricted to simple formating. So with this options we are flexible. 2. Custom config.js configuration element I've programed the inpage configration for a custom config.js file I had to rename the predefined configuration property, because i couldn't compile the code. I always got an configuration element is not allowed to use reserved prefix config or locked error. Example: <ckeditor ckConfigJsPath="/scripts/ckconfig.js" /> 3. Format dropdown I've moved the default configuration of the format dropdown from config.cs to inpage configuration. Then i added a configuration element overwriteFormatTags. This option overwrites the predefined format values. And the EditableFreeTextArea also has a property AdditionalFormats. If specified, the given formats will be added in addtiotin to the default values to the format dropdown. So you can set common format's with web.config and however have the flexibility to set special format values on a page. Example: In web.config <ckeditor overwriteFormatTags="p;h1" /> AdditionalFormats:="h2;h3" Default option for all dropdowns are h1;p and for the EditableFreeTextAre with set AdditionalFormats h1;h2;h3p 4. advancedMenues I've moved the advanced menues as inpage configuration. I'ts not important, but i think so there some logic in the configuration 5. Custon contents.css I've aded a configuration element which let's you specify the path to a custom contents.css file. Example: <ckeditor contentsCssPath="/scripts/contents.css" /> 5. Custom Styles To fill custom styles into the styles dropdown you have to integrate a custom config.js file. In this file you could add your own stylesets, it's not limited to one. I've interated a sample into config.js and comented it out. So copy the original config.js file to your own location, uncoment the block which adds the custom styles. Add your own styleset(s). Like before i've integrated a default option in web.config which points ckeditor to the custom style. But you can also overide this option with an EditableFreeTextArea Property for special pages. This example asumes the style i put as sample into config.js and copied into my own location <ckeditor ckConfigJsPath="/scripts/ckconfig.js" overwriteStylesSet="my_styles" /> With this configuration options and the custom config.js file all editors are using the Styleset my_styles Now you can integrate a second styleset named styles_productspage into /scripts/ckconfig.js and set UseStylesSet:=productspage in EditableFreeTextAre So i hope this covers the most configuration tasks and provides a bigger configuration flexibility through the global configurtion options in web.config and special options as EditableFreeTextArea Property. https://n2cms.codeplex.com/discussions/445836
1 parent 6a5e47c commit 5700a3f

File tree

153 files changed

+2663
-1670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+2663
-1670
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Disable LF normalization for all files
2+
* -text

docs/n2cms.configuration.xsd

+5-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,11 @@
552552
</xs:element>
553553
<xs:element name="ckeditor" minOccurs="0" maxOccurs="1">
554554
<xs:complexType>
555-
<xs:attribute name="configJsPath" type="xs:string" use="optional" default="~/N2/Resources/ckeditor/config.js" />
555+
<xs:attribute name="ckConfigJsPath" type="xs:string" use="optional" default="~/N2/Resources/ckeditor/config.js" />
556+
<xs:attribute name="overwriteStylesSet" type="xs:string" use="optional" default="default" />
557+
<xs:attribute name="overwriteFormatTags" type="xs:string" use="optional" default="p;h1;h2;h3;pre" />
558+
<xs:attribute name="contentsCssPath" type="xs:string" use="optional" default="~/N2/Resources/ckeditor/contents.css" />
559+
<xs:attribute name="advancedMenues" type="xs:boolean" use="optional" default="false" />
556560
</xs:complexType>
557561
</xs:element>
558562
<xs:element name="tinyMCE" minOccurs="0">

src/Framework/N2/Configuration/CkEditorElement.cs

+32-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,39 @@ namespace N2.Configuration
1111
/// </summary>
1212
public class CkEditorElement : ConfigurationElement
1313
{
14-
[ConfigurationProperty("configJsPath")]
14+
[ConfigurationProperty("ckConfigJsPath")]
1515
public string ConfigJsPath
1616
{
17-
get { return (string)base["configJsPath"]; }
18-
set { base["configJsPath"] = value; }
19-
}
17+
get { return (string)base["ckConfigJsPath"]; }
18+
set { base["ckConfigJsPath"] = value; }
19+
}
20+
21+
[ConfigurationProperty("overwriteStylesSet")]
22+
public string OverwriteStylesSet
23+
{
24+
get { return (string)base["overwriteStylesSet"]; }
25+
set { base["overwriteStylesSet"] = value; }
26+
}
27+
28+
[ConfigurationProperty("overwriteFormatTags")]
29+
public string OverwriteFormatTags
30+
{
31+
get { return (string)base["overwriteFormatTags"]; }
32+
set { base["overwriteFormatTags"] = value; }
33+
}
34+
35+
[ConfigurationProperty("contentsCssPath")]
36+
public string ContentsCssPath
37+
{
38+
get { return (string)base["contentsCssPath"]; }
39+
set { base["contentsCssPath"] = value; }
40+
}
41+
42+
[ConfigurationProperty("advancedMenues")]
43+
public bool AdvancedMenues
44+
{
45+
get { return (bool)base["advancedMenues"]; }
46+
set { base["advancedMenues"] = value; }
47+
}
2048
}
2149
}

src/Framework/N2/Details/EditableFreeTextAreaAttribute.cs

+43-69
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,37 @@
1212

1313
namespace N2.Details
1414
{
15-
/// <summary>
16-
/// Rich text editor settings set (toolbars, features).
17-
/// </summary>
18-
public enum FreeTextAreaSettingsSet
19-
{
20-
/// <summary>Setting set is defined by configuration, DEFAULT by default.</summary>
21-
Undefined,
22-
/// <summary>Fixed rich text editor toolbar, basic features, no additional toolbars.</summary>
23-
[Obsolete]
24-
Fixed,
25-
/// <summary>Single line toolbar, no additional toolbars.</summary>
26-
Minimal,
27-
/// <summary>Single line tooolbar, all other toolbars shown by toogle icon.</summary>
28-
Simple,
29-
/// <summary>Extended toolbar with all features, less frequently used toolbars shown by toogle icon.</summary>
30-
Extended
31-
}
3215

3316

3417
/// <summary>Attribute used to mark properties as editable. This attribute is predefined to use the <see cref="N2.Web.UI.WebControls.FreeTextArea"/> web control as editor.</summary>
35-
/// <example>
18+
/// <example>
19+
/// Editor with standard toolbars:
3620
/// [N2.Details.EditableFreeTextArea("Text", 110)]
3721
/// public virtual string Text { get; set; }
38-
///
39-
/// Setting set with full features:
40-
/// [N2.Details.EditableFreeTextArea("Text", 110, FreeTextAreaSettingsSet.Extended)]
22+
///
23+
/// Editor with full toolbars:
24+
/// [N2.Details.EditableFreeTextArea("Text", 110, FreeTextArea.EditorModeSetting.Full)]
25+
///
26+
/// Editor with reduced toolbars:
27+
/// [N2.Details.EditableFreeTextArea("Text", 110, FreeTextArea.EditorModeSetting.Basic)]
4128
///
4229
/// Default toolbar mode can be set in Web.config, e.g.
4330
/// <![CDATA[
4431
/// <n2>
4532
/// <edit>
4633
/// <tinyMCE cssUrl="/Content/myrichtext.css">
47-
/// <settings>
48-
/// <add key="settings_set" value="Extended" />
49-
/// </settings>
5034
/// </edit>
5135
/// </n2>
5236
/// ]]>
5337
///
54-
/// Notes:
55-
/// settings_set property is nonstantard.
56-
/// See also standard TinyMCE settings at http://tinymce.moxiecode.com/wiki.php/Configuration
57-
/// Toogle toolbars: see PWD plugin at http://www.neele.name/pdw_toggle_toolbars/
5838
/// </example>
5939
[AttributeUsage(AttributeTargets.Property)]
6040
public class EditableFreeTextAreaAttribute : EditableTextBoxAttribute, IRelativityTransformer
61-
{
41+
{
42+
private FreeTextArea.EditorModeSetting editorMode = FreeTextArea.EditorModeSetting.Standard;
43+
private string additionalFormats = string.Empty;
44+
private string useStylesSet = string.Empty;
45+
6246
public EditableFreeTextAreaAttribute()
6347
: base(null, 100)
6448
{
@@ -67,20 +51,27 @@ public EditableFreeTextAreaAttribute()
6751
public EditableFreeTextAreaAttribute(string title, int sortOrder)
6852
: base(title, sortOrder)
6953
{
54+
}
55+
56+
57+
public FreeTextArea.EditorModeSetting EditorMode
58+
{
59+
set { editorMode = value; }
60+
}
61+
62+
public string AdditionalFormats
63+
{
64+
set { additionalFormats = value; }
65+
}
66+
67+
public string UseStylesSet
68+
{
69+
set { useStylesSet = value; }
7070
}
7171

72-
public EditableFreeTextAreaAttribute(string title, int sortOrder, FreeTextAreaSettingsSet toolbars)
73-
: base(title, sortOrder)
74-
{
75-
Toolbars = toolbars;
76-
}
77-
78-
/// <summary> Current rich text editor setting set (e.g. basic features with simple toolbar, extended etc) </summary>
79-
public FreeTextAreaSettingsSet Toolbars { get; set; }
80-
8172
protected override void ModifyEditor(TextBox tb)
8273
{
83-
// set width and height to control the size of the tinyMCE editor
74+
// set width and height to control the size of the ckeditor
8475
// 1 column is evaluated to 10px
8576
// 1 row is evaluated to 20px
8677
if (Columns > 0)
@@ -90,8 +81,14 @@ protected override void ModifyEditor(TextBox tb)
9081
}
9182

9283
protected override TextBox CreateEditor()
93-
{
94-
return new FreeTextArea();
84+
{
85+
FreeTextArea fta = new FreeTextArea();
86+
87+
fta.EditorMode = editorMode;
88+
fta.AdditionalFormats = additionalFormats;
89+
fta.UseStylesSet = useStylesSet;
90+
91+
return fta;
9592
}
9693

9794
protected override Control AddRequiredFieldValidator(Control container, Control editor)
@@ -105,40 +102,17 @@ public override void UpdateEditor(ContentItem item, Control editor)
105102
{
106103
base.UpdateEditor(item, editor);
107104

108-
FreeTextArea fta = (FreeTextArea)editor;
105+
FreeTextArea fta = (FreeTextArea)editor;
106+
107+
fta.EditorMode = editorMode;
108+
fta.AdditionalFormats = additionalFormats;
109+
fta.UseStylesSet = useStylesSet;
109110

110111
if (item is IDocumentBaseSource)
111112
fta.DocumentBaseUrl = (item as IDocumentBaseSource).BaseUrl;
112113

113-
string rt_mode = GetSettingsSetString(Toolbars);
114-
if (!string.IsNullOrEmpty(rt_mode))
115-
fta.CustomOverrides["settings_set"] = rt_mode;
116-
117-
string content_css = GetCssFiles(string.Empty);
118-
if (!string.IsNullOrEmpty(content_css))
119-
{
120-
fta.CustomOverrides["content_css"] = content_css;
121-
}
122114
}
123115

124-
/// <summary>Stringify current settingset mode.</summary>
125-
/// <remarks>Extended class might implement extended logics,
126-
/// e.g. check current site StartPage properties when UNDEFINED.
127-
/// When defined will override default config. value.
128-
/// </remarks>
129-
protected virtual string GetSettingsSetString(FreeTextAreaSettingsSet settingsSet)
130-
{
131-
return settingsSet.ToString();
132-
}
133-
134-
/// <summary> Comma separated list of CSS file Urls to be used by TinyMCE, defined by application, default empty (unset) </summary>
135-
/// <remarks> Extended class might implement extended logics, e.g. to check current site StartPage properties to set site specific styling.
136-
/// When defined will override default config. value.
137-
/// </remarks>
138-
protected virtual string GetCssFiles(string cssFiles)
139-
{
140-
return cssFiles;
141-
}
142116

143117
public override string GetIndexableText(ContentItem item)
144118
{

0 commit comments

Comments
 (0)