I am in the process of creating a drop down list with contains a list of classes so my users can apply them to link, paragraphs etc. I have read in a lot of places now that the advanced
theme supports this out of the box but I can't find out where to download this theme.
I suspect the advanced theme is Wordpress only at this point as I found it included in the wordpress download but not in a format that would allow me to use it.
Am I missing something?
OK, I found out where the confusion lies.
TinyMCE versions 3.x contain the advanced
theme but it is not shipped with 4.0 which I am using. I did download 3.x and try the advanced theme with 4.0 but it isn't compatible. Wordpress it seems ships with 3.x which is why I thought it was a wordpress only option.
For more info (hoping it helps someone else):
It seems now that you have to use the format_styles
and custom_formats
options against the TinyMCE editor to give users the ability to select styles. I have written some code that parses my CSS file, looks for all H2, 2 etc
, P
and A
classes and populates those options. It's the long way round but it works very well. It' just a shame there is no out of the box routine.
I ended up using CssParser with the following code (C# - Copy pasting this won't work but it should give a good guide on what to do):
//Declared so we can deserialise into JSON
public class CustomFormat
{
public string title;
public string selector;
public string classes;
}
private void BuildTinyMCECSS()
{
List<string> AllowedTags = new List<string> { "p", "a", "h1", "h2", "h3", "h4", "h5", "h6" };
CssParser StyleSheet = new CssParser();
StyleSheet.AddStyleSheet("MyPath/Styles.css");
//1: Only in our allowed tags. 2: Isn't a pseudo class. 3: Is a class of one of the allowed tags.
foreach (KeyValuePair<string, StyleClass> Style in StyleSheet.Styles.Where(n => AllowedTags.Any(a => n.Key.StartsWith(a) && !n.Key.Contains(':') && n.Key.Contains('.'))))
{
CustomFormat CF = new CustomFormat();
CF.title = Style.Key;
CF.selector = Style.Key.Substring(0, Str.IndexOf('.'));
CF.classes = Style.Key.Substring(Style.Key.IndexOf('.') + 1);
//Note: CCUtils is a static class I use for utilities. Any code to deserialise will work
string JS = String.Format("{1},", Style.Key, CCUtils.SerializeToStringJSON(CF, typeof(CustomFormat)));
Session["JS"] += JS;
}
//Remove the spare comma at the end (ie won't like it)
Session["JS"] = Session["JS"].ToString().Substring(0, Session["JS"].ToString().LastIndexOf(','));
}
My init code for style_formats
looks like this (note, I have to re-add the default options as adding anything into style_format
clears it's existing list.
style_formats:
[{
title: "Headers",
items: [{title: "Header 1",format: "h1"}, {title: "Header 2",format: "h2"}, {title: "Header 3",format: "h3"}, {title: "Header 4",format: "h4"}, {title: "Header 5",format: "h5"}, {title: "Header 6",format: "h6"}]},
{title: "Inline",items: [{title: "Bold",icon: "bold",format: "bold"}, {title: "Italic",icon: "italic",format: "italic"},
{title: "Underline",icon: "underline",format: "underline"}, {title: "Strikethrough",icon: "strikethrough",format: "strikethrough"}, {title: "Superscript",icon: "superscript",format: "superscript"}, {title: "Subscript",icon: "subscript",format: "subscript"}, {title: "Code",icon: "code",format: "code"}]},
{title: "Blocks",items: [{title: "Paragraph",format: "p"}, {title: "Blockquote",format: "blockquote"}, {title: "Div",format: "div"}, {title: "Pre",format: "pre"}]},
{title: "Alignment",items: [{title: "Left",icon: "alignleft",format: "alignleft"}, {title: "Center",icon: "aligncenter",format: "aligncenter"}, {title: "Right",icon: "alignright",format: "alignright"}, {title: "Justify",icon: "alignjustify",format: "alignjustify"}]},
{
title: "Classes", items: [<%= Session["JS"] %>]
}]
More information on the style_formats
option can be found here: TinyMCE Style Formats
来源:https://stackoverflow.com/questions/17197339/tinymce-advanced-theme-where-is-it