<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">Blog posts by Russell Mercer</title><link href="https://world.optimizely.com/blogs/russell-mercer/" /><updated>2017-07-31T06:06:46.0000000Z</updated><id>https://world.optimizely.com/blogs/russell-mercer/</id><generator uri="https://world.optimizely.com/blogs/russell-mercer/" version="2.0">Optimizely World</generator><entry><title>Using Adobe Typekit in EpiServer</title><link href="https://world.optimizely.com/blogs/russell-mercer/dates/2017/7/using-adobe-typekit-in-episerver/" /><id>https://world.optimizely.com/blogs/russell-mercer/dates/2017/7/using-adobe-typekit-in-episerver/</id><published>2017-07-31T06:06:46.0000000Z</published><updated>2017-07-31T06:06:46.0000000Z</updated><author><name>russell@gurudigital.nz</name></author><category term="Blog post" /><summary type="html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p&gt;Typekit provides embed code to load fonts&lt;/p&gt;
&lt;p&gt;&lt;a href="https://typekit.com/"&gt;https://typekit.com/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The problem is that you want those same fonts to be present in the TinyMCE editor.&lt;/p&gt;
&lt;p&gt;I decided to use a TinyMCE plugin to load the TypeKit.&lt;/p&gt;
&lt;p&gt;&lt;a href="/link/617e0a5265a44c5e997820f4380dee78.aspx"&gt;https://world.episerver.com/documentation/developer-guides/CMS/editing/Customizing-the-TinyMCE-editor/&lt;/a&gt;&amp;nbsp;-&amp;nbsp;Adding a TinyMCE plug-in&lt;/p&gt;
&lt;p&gt;I chose the option of creating a Util folder as per&lt;/p&gt;
&lt;p&gt;&lt;a href="/link/df61a51597354c7d8c3e61fc541848fe.aspx"&gt;https://world.episerver.com/globalassets/sdkdocuments/developers-guide1/episerver-cms/75/editing/tinymce_add_javascript.png&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I only needed&amp;nbsp;editor_plugin.js under a folder that I named typekitplugin&lt;/p&gt;
&lt;p&gt;I created a class decorated with the TinyMCEPluginNonVisual attribute&lt;/p&gt;
&lt;p&gt;[TinyMCEPluginNonVisual(LanguagePath = "/admin/tinymce/plugins/typekitplugin", PlugInName = "typekitplugin")]&lt;br /&gt; public class TinyMCETypeKitPlugin&lt;br /&gt; {&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;Once that is done you need to activate it in the editor settings&lt;/p&gt;
&lt;p&gt;I.e. Admin - Config - Edit Custom Property Types -&amp;nbsp;XhtmlString &amp;gt; 255 - Plugins without a button&lt;/p&gt;
&lt;p&gt;You will find that it is missing a langauge entry&amp;nbsp;which you can fix by adding TinyMCE.xml under Resources/LanguageFiles&lt;/p&gt;
&lt;p&gt;=========================================&lt;/p&gt;
&lt;p&gt;&lt;span&gt;TinyMCE.xml&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;========================================&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;&lt;br /&gt;&amp;lt;languages&amp;gt;&lt;br /&gt; &amp;lt;language name="English" id="en"&amp;gt;&lt;br /&gt; &amp;lt;tinymce&amp;gt;&lt;br /&gt; &amp;lt;typekitplugin&amp;gt;&lt;br /&gt; &amp;lt;typekitplugin_desc&amp;gt;&lt;br /&gt; Typekit Plugin&lt;br /&gt; &amp;lt;/typekitplugin_desc&amp;gt;&lt;br /&gt; &amp;lt;/typekitplugin&amp;gt;&lt;br /&gt; &amp;lt;/tinymce&amp;gt;&lt;br /&gt; &amp;lt;/language&amp;gt;&lt;br /&gt;&amp;lt;/languages&amp;gt;&lt;/p&gt;
&lt;p&gt;=========================================&lt;/p&gt;
&lt;p&gt;&lt;span&gt;editor_plugin.js&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You will need to change "xxxxxxx" to the ID of the TypeKit&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Change the GetInfo function as appropriate&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;========================================&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;(function () {&lt;/p&gt;
&lt;p&gt;tinymce.create('tinymce.plugins.typekitplugin', {&lt;br /&gt; /**&lt;br /&gt; * Initializes the plugin, this will be executed after the plugin has been created.&lt;br /&gt; * This call is done before the editor instance has finished it's initialization so use the onInit event&lt;br /&gt; * of the editor instance to intercept that event.&lt;br /&gt; *&lt;br /&gt; * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.&lt;br /&gt; * @param {string} url Absolute URL to where the plugin is located.&lt;br /&gt; */&lt;br /&gt; init: function (ed, url) {&lt;br /&gt; ed.onPreInit.add(function (ed) {&lt;/p&gt;
&lt;p&gt;// Get the DOM document object for the IFRAME&lt;br /&gt; var doc = ed.getDoc();&lt;/p&gt;
&lt;p&gt;// Create the script we will add to the header asynchronously&lt;br /&gt; var jscript = "(function() {\n\&lt;br /&gt; var config = {\n\&lt;br /&gt; kitId: '&lt;span&gt;xxxxxxx&lt;/span&gt;'\n\&lt;br /&gt; };\n\&lt;br /&gt; var d = false;\n\&lt;br /&gt; var tk = document.createElement('script');\n\&lt;br /&gt; tk.src = '//use.typekit.net/' + config.kitId + '.js';\n\&lt;br /&gt; tk.type = 'text/javascript';\n\&lt;br /&gt; tk.async = 'true';\n\&lt;br /&gt; tk.onload = tk.onreadystatechange = function() {\n\&lt;br /&gt; var rs = this.readyState;\n\&lt;br /&gt; if (d || rs &amp;amp;&amp;amp; rs != 'complete' &amp;amp;&amp;amp; rs != 'loaded') return;\n\&lt;br /&gt; d = true;\n\&lt;br /&gt; try { Typekit.load(config); } catch (e) {}\n\&lt;br /&gt; };\n\&lt;br /&gt; var s = document.getElementsByTagName('script')[0];\n\&lt;br /&gt; s.parentNode.insertBefore(tk, s);\n\&lt;br /&gt; })();";&lt;/p&gt;
&lt;p&gt;// Create a script element and insert the TypeKit code into it&lt;br /&gt; var script = doc.createElement("script");&lt;br /&gt; script.type = "text/javascript";&lt;br /&gt; script.appendChild(doc.createTextNode(jscript));&lt;/p&gt;
&lt;p&gt;// Add the script to the header&lt;br /&gt; doc.getElementsByTagName('head')[0].appendChild(script);&lt;br /&gt; });&lt;br /&gt; },&lt;/p&gt;
&lt;p&gt;/**&lt;br /&gt; * Returns information about the plugin as a name/value array.&lt;br /&gt; * The current keys are longname, author, authorurl, infourl and version.&lt;br /&gt; *&lt;br /&gt; * @return {Object} Name/value array containing information about the plugin.&lt;br /&gt; */&lt;br /&gt; getInfo: function () {&lt;br /&gt; return {&lt;br /&gt; longname: 'TypeKit plugin for HaurikiPHO',&lt;br /&gt; author: 'Guru Digital',&lt;br /&gt; authorurl: 'http://gurudigital.nz',&lt;br /&gt; infourl: 'http://gurudigital.nz',&lt;br /&gt; version: "1.0"&lt;br /&gt; };&lt;br /&gt; }&lt;br /&gt; });&lt;/p&gt;
&lt;p&gt;// Register plugin&lt;br /&gt; tinymce.PluginManager.add('typekitplugin', tinymce.plugins.typekitplugin);&lt;br /&gt;})();&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</summary></entry><entry><title>CheckboxList using Enum</title><link href="https://world.optimizely.com/blogs/russell-mercer/dates/2015/1/post-title/" /><id>https://world.optimizely.com/blogs/russell-mercer/dates/2015/1/post-title/</id><published>2015-01-26T23:12:43.0000000Z</published><updated>2015-01-26T23:17:20.6600000Z</updated><author><name>russell@gurudigital.nz</name></author><category term="Blog post" /><summary type="html">I recently implemented a checkboxlist using Enum  &lt;br /&gt;References:  &lt;br /&gt;  &lt;ul&gt;   &lt;li&gt;http://joelabrahamsson.com/enum-properties-with-episerver/ &lt;/li&gt;   &lt;li&gt;http://world.episerver.com/blogs/Linus-Ekstrom/Dates/2013/12/SingleMultiple-selection-in-EPiServer-75/&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;My Code&lt;/p&gt;  &lt;pre&gt;

public class EnumMultipleSelectionFactory&amp;lt;TEnum&amp;gt; : ISelectionFactory
{
    public IEnumerable&amp;lt;ISelectItem&amp;gt; GetSelections(
            ExtendedMetadata metadata)
    {
        var values = Enum.GetValues(typeof(TEnum));
        List&amp;lt;ISelectItem&amp;gt; items = new List&amp;lt;ISelectItem&amp;gt;();
        foreach (var value in values)
        {
            items.Add(new SelectItem { Text = GetValueName(value), Value = value.ToString() });
        }
                return items;
    }

    private string GetValueName(object value)
    {
        var staticName = Enum.GetName(typeof(TEnum), value);

        string localizationPath = string.Format(
            &amp;quot;/property/enum/{0}/{1}&amp;quot;,
            typeof(TEnum).Name.ToLowerInvariant(),
            staticName.ToLowerInvariant());

        string localizedName;
        if (LocalizationService.Current.TryGetString(
            localizationPath,
            out localizedName))
        {
            return localizedName;
        }

        return staticName;
    }
}



public class EventItemPage : SitePageData
{
    public enum EventCategoryValues
    {
        Arts,
        Business,
        Community,
        Festivals,
        Kids,
        Recreation,
        Sports
    }

    [Display(
        GroupName = SystemTabNames.Content,
        Order = 1030)]
    [SelectMany(SelectionFactoryType = typeof(EnumMultipleSelectionFactory&amp;lt;EventCategoryValues&amp;gt;))]
    public virtual string EventCategories { get; set; }

}


&lt;/pre&gt;</summary></entry></feed>