Blog posts by Aleksandar Trajanovski
2015-01-27T08:48:00.0000000Z
/blogs/aleksandar-trajanovski/
Optimizely World
Creating Custom EPiServer TinyMCE Plugin
/blogs/aleksandar-trajanovski/dates/2015/1/creating-custom-episerver-tinymce-plugin/
2015-01-27T08:48:00.0000000Z
<p>I have received a request from client, to be able to add accordion in the tinymce editor with clicking only on a button in the toolbar of the editor. I said ok as always :), but subsequent questions were coming on my mind, you need to add items in the accordion and again ok :), jquery table with add rows and delete rows will do the job. That question sorted, another question came up, modal window for editing and inserting items and guess what again jquery. The body of the inserted items needs to be styled so I need to use tinymce editor for that, ok I have that. Let’s roll :).</p> <p>The html structure of the accordion is following:</p> <table cellspacing="1" cellpadding="1" border="1"><tbody> <tr> <td> <ol> <li><div class="accordion-panel-group"> </li> <li>    <h3 class="header-small linkbox-header no-border">Optional <span class="color-brand">title</span></h3> </li> <li>    <div class="panel-group" id="accordion"> </li> <li>        <div class="panel panel-default"> </li> <li>            <div class="panel-heading"> </li> <li>                <h4 class="panel-title"> </li> <li>                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne"> </li> <li>                        <!--  All exept the first header needs class="collapsed"--> </li> <li>                        <span class="plus"></span> Collapsible Group Item #1 </li> <li>                    </a> </li> <li>                </h4> </li> <li>            </div> </li> <li>            <div id="collapseOne" class="panel-collapse collapse in"> </li> <li>                <div class="panel-body"> </li> <li>                                      Body Text. </li> <li>                </div> </li> <li>            </div> </li> <li>        </div> </li> <li>        <div class="panel panel-default"> </li> <li>            <div class="panel-heading"> </li> <li>                <h4 class="panel-title"> </li> <li>                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" class="collapsed"> </li> <li>                        <span class="plus"></span> Collapsible Group Item #2 </li> <li>                    </a> </li> <li>                </h4> </li> <li>            </div> </li> <li>            <div id="collapseTwo" class="panel-collapse collapse"> </li> <li>                <div class="panel-body"> </li> <li>                   Body Text. </li> <li>                </div> </li> <li>            </div> </li> <li>        </div> </li> <li>        <div class="panel panel-default"> </li> <li>            <div class="panel-heading"> </li> <li>                <h4 class="panel-title"> </li> <li>                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree" class="collapsed"> </li> <li>                        <span class="plus"></span> Collapsible Group Item #3 </li> <li>                    </a> </li> <li>                </h4> </li> <li>            </div> </li> <li>            <div id="collapseThree" class="panel-collapse collapse"> </li> <li>                <div class="panel-body"> </li> <li>                                      Body Text. </li> <li>                </div> </li> <li>            </div> </li> <li>        </div> </li> <li>    </div> </li> <li></div> </li> </ol> </td> </tr> </tbody></table> <p>I have started from <a title="here" href="/link/47e30a76f99f49bc869b7957bfbe3719.aspx" target="_blank">here</a>. I have done the basic classes and add the basic js files.</p> <p><strong>1. AccordionPlugin.cs :</strong></p> <table border="1"><tbody> <tr> <td> <ol> <li>[TinyMCEPluginButton( </li> <li>PlugInName = "accordionplugin", ButtonName = "accordionbutton", GroupName = "misc", LanguagePath = </li> <li>"/admin/tinymce/plugins/accordionplugin/accordionbutton", </li> <li>IconUrl = "/admin/tinymce/plugins/accordionplugin/images/accordion.png")] </li> <li>public class AccordionPlugin </li> <li>{ </li> <li>} </li> </ol> </td> </tr> </tbody></table> <p>As you can see this is basic class, and here i have defined only the Icon Url on line 4.</p> <p><strong>2. editor_plugin_src.js:</strong></p> <table border="1"><tbody> <tr> <td> <ol> <li class="_mce_tagged_br">/// <reference path="AccordionSnippet.html" /> </li> <li class="_mce_tagged_br">(function (tinymce, $) { </li> <li class="_mce_tagged_br">// Load plugin specific language pack </li> <li class="_mce_tagged_br">tinymce.PluginManager.requireLangPack('accordionplugin'); </li> <li class="_mce_tagged_br">tinymce.create('tinymce.plugins.accordionplugin', { </li> <li class="_mce_tagged_br">init: function (ed, url) { </li> <li class="_mce_tagged_br">ed.addCommand('mceAccordion', function () { </li> <li class="_mce_tagged_br">var parentNode = ed.dom.getParent(ed.selection.getNode(), "div.accordion-panel-group"); </li> <li class="_mce_tagged_br">var insideAccordion = parentNode != null; </li> <li class="_mce_tagged_br">var accordionID = null; </li> <li class="_mce_tagged_br">if (insideAccordion)//if inside get accordion id </li> <li class="_mce_tagged_br">{ </li> <li class="_mce_tagged_br">if (parentNode.children[1] != null) { </li> <li class="_mce_tagged_br">accordionID = parentNode.children[1].id; </li> <li class="_mce_tagged_br">} </li> <li class="_mce_tagged_br">else { </li> <li class="_mce_tagged_br">accordionID = parentNode.children[0].id; </li> <li class="_mce_tagged_br">} </li> <li class="_mce_tagged_br">} </li> <li class="_mce_tagged_br">ed.windowManager.open({//for edit accordion </li> <li class="_mce_tagged_br">file: url + '/AccordionSnippet.html', </li> <li class="_mce_tagged_br">inline: false, </li> <li class="_mce_tagged_br">scrollbars: true, </li> <li class="_mce_tagged_br">maximizable: true </li> <li class="_mce_tagged_br">}, { </li> <li class="_mce_tagged_br">argUrl: url, // Plugin absolute URL </li> <li class="_mce_tagged_br">argParentNode: parentNode, // Accordion </li> <li class="_mce_tagged_br">argAccordionID: accordionID // Accordion ID </li> <li class="_mce_tagged_br">}); </li> <li class="_mce_tagged_br">}); </li> <li class="_mce_tagged_br">// Register infobox button </li> <li class="_mce_tagged_br">ed.addButton('accordionbutton', { </li> <li class="_mce_tagged_br">title: 'Add Accordion', </li> <li class="_mce_tagged_br">cmd: 'mceAccordion', </li> <li class="_mce_tagged_br">image: url + '/images/accordion.png', </li> <li class="_mce_tagged_br">"class": "" </li> <li class="_mce_tagged_br">}); </li> <li class="_mce_tagged_br">ed.onNodeChange.add(function (ed, cm, n, co) { </li> <li class="_mce_tagged_br">var insideAccordion = ed.dom.getParent(n, "div.accordion-panel-group") != null; </li> <li class="_mce_tagged_br">cm.setActive('accordionbutton', insideAccordion); </li> <li class="_mce_tagged_br">ed.save(); </li> <li class="_mce_tagged_br">}); </li> <li class="_mce_tagged_br">ed.onActivate.add(function (ed) { </li> <li class="_mce_tagged_br">ed.save(); </li> <li class="_mce_tagged_br">}); </li> <li class="_mce_tagged_br">ed.onChange.add(function (ed) { </li> <li class="_mce_tagged_br">ed.save(); </li> <li class="_mce_tagged_br">}); </li> <li class="_mce_tagged_br">ed.onClick.add(function (ed) { </li> <li class="_mce_tagged_br">ed.save(); </li> <li class="_mce_tagged_br">}); </li> <li class="_mce_tagged_br">  </li> <li class="_mce_tagged_br">}, </li> <li class="_mce_tagged_br">/**y </li> <li class="_mce_tagged_br">* Returns information about the plugin as a name/value array. </li> <li class="_mce_tagged_br">* </li> <li class="_mce_tagged_br">* @return {Object} Name/value array containing information about the plugin. </li> <li class="_mce_tagged_br">*/ </li> <li class="_mce_tagged_br">getInfo: function () { </li> <li class="_mce_tagged_br">return { </li> <li class="_mce_tagged_br">longname: 'Accordion plugin', </li> <li class="_mce_tagged_br">author: 'ProPeople', </li> <li class="_mce_tagged_br">authorurl: '', </li> <li class="_mce_tagged_br">infourl: '', </li> <li class="_mce_tagged_br">version: "1.0" </li> <li class="_mce_tagged_br">}; </li> <li class="_mce_tagged_br">} </li> <li class="_mce_tagged_br">}); </li> <li class="_mce_tagged_br">// Register plugin </li> <li class="_mce_tagged_br">tinymce.PluginManager.add('accordionplugin', tinymce.plugins.accordionplugin); </li> <li class="_mce_tagged_br">}(tinymce, epiJQuery)); </li> </ol> </td> </tr> </tbody></table> <p>On line 8,9 and 11 I'm requesting the parent node of my selection in the tinymce editor. The class "accordion-panel-group" is my parent node and in line 11 i'm checking to see if the selection is inside that node. If it is I'm getting the id of the accordion panel (If there is title the second child has the id-panel, if not the first child has the id). After that activate window manager of the editor with parameters. And here comes <span style="line-height: 20px">AccordionSnippet.html on line 21.</span></p> <p><span style="line-height: 20px">Thanks to this guy with his <a href="https://github.com/cellfex/TinyMCE-Insert-HTML-Snippet" target="_blank">post</a> i managed to make a popup tinymce dialog. </span></p> <p><strong><span style="line-height: 20px">4. AccordionSnippet.html:</span></strong></p> <table cellspacing="1" cellpadding="1" border="1"><tbody> <tr> <td> <ol> <li><head> </li> <li>    <title>Manage accordion</title> </li> <li>    <script src="js/jquery-1.8.3.js"></script> </li> <li>    <link href="js/jquery-ui.css" rel="stylesheet" /> </li> <li>    <script src="js/jquery-ui.js"></script> </li> <li>    <script src="../../../tinymceCustom/tiny_mce_popup.js"></script> </li> <li>    <script src="../../../tinymceCustom/tiny_mce.js"></script> </li> <li>    <script type="text/javascript" src="js/AccordionSnippet.js"></script> </li> <li>    <script src="../../../tinymceCustom/jquery.tinymce.js"></script> </li> <li>    <script type="text/javascript"> </li> <li>        $(function () {     </li> <li>            tinyMCE.init({ </li> <li>                theme: 'advanced', </li> <li>                mode: 'none', </li> <li>                theme_advanced_toolbar_location: "top" </li> <li>            }); </li> <li>        }); </li> <li>    </script> </li> <li>    <link href="js/Accordion.css" rel="stylesheet" /> </li> <li>    <script src="js/Accordion.js"></script> </li> <li></head> </li> <li><body style="overflow-y: scroll; height: 600px;"> </li> <li>    <div> </li> <li>        <div id="dialog-form" title="Add new accordion item"> </li> <li>            <p class="validateTips"> </li> <li>                All form fields are required. </li> <li>            </p> </li> <li>            <form> </li> <li>                <fieldset> </li> <li>                    <label for="titleA"> </li> <li>                        Title </li> <li>                    </label> </li> <li>                    <input type="text" name="titleA" id="titleA" value="" class="text ui-widget-content ui-corner-all" /> </li> <li>                    <label for="bodyText"> </li> <li>                        Body </li> <li>                    </label> </li> <li>                    <textarea rows="25" cols="85" name="bodyText" id="bodyText" class="text ui-widget-content ui-corner-all">Your content here</textarea> </li> <li>                </fieldset> </li> <li>            </form> </li> <li>        </div> </li> <li>        <div id="accordion-contain" class="ui-widget" style="width:680px; padding-bottom:100px"> </li> <li>            <h1>Current accordion</h1> </li> <li>            <table id="accordionItems" class="ui-widget ui-widget-content" style="width:100%;"> </li> <li>                <thead> </li> <li>                    <tr class="ui-widget-header "> </li> <li>                        <th style="width:170px;">Title </th> </li> <li>                        <th style="width:500px;">Body </th> </li> <li>                        <th style="width:5px;"></th> </li> <li>                        <th style="width:5px;"></th> </li> <li>                    </tr> </li> <li>                </thead> </li> <li>                <tbody> </li> <li>                    <!--here goes dinamically accordion items--> </li> <li>                </tbody> </li> <li>            </table> </li> <li>            <a class="createa" href="">Add new accordion item</a> </li> <li>        </div> </li> <li>        <form onsubmit="cfHtmlSnippetDialog.insert();return false;" action="#"> </li> <li>            <div id="SnippetCode" class="editablecontent" style="display:none;"> </li> <li>                <!--here goes the accordion--> </li> <li>                <div class="accordion-panel-group"> </li> <li>                    <h3 class="header-small linkbox-header no-border">Optional <span class="color-brand">title</span></h3> </li> <li>                    <div class="panel-group" id="accordion"> </li> <li>                        <!--here goes the accordion items--> </li> <li>                    </div> </li> <li>                </div> </li> <li>                <!--here goes the accordion ends--> </li> <li>            </div> </li> <li>            <div class="mceActionPanel"> </li> <li>                <div style="position: fixed; bottom: 0px; right:0px;background-color:white; width:100%"> </li> <li>                    <table style="width:100%; text-align:right"> </li> <li>                        <tr> </li> <li>                            <td> </li> <li>                                &nbsp; </li> <li>                            </td> </li> <li>                            <td style="width:5px"> </li> <li>                                <table style="width:100%; text-align:right"> </li> <li>                                    <tr> </li> <li>                                        <td> </li> <li>                                            <input type="button" id="insert" name="insert" value="{#insert}" onclick="cfHtmlSnippetDialog.insert();" /> </li> <li>                                        </td> </li> <li>                                        <td> </li> <li>                                            <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" /> </li> <li>                                        </td> </li> <li>                                    </tr> </li> <li>                                </table> </li> <li>                            </td> </li> <li>                        </tr> </li> <li>                    </table> </li> <li>                </div> </li> <li>            </div> </li> <li>        </form> </li> <li>        <script type="text/javascript"> </li> <li>            ////init configuration of the dialog////// </li> <li>            ////setting up the html in the hidden div </li> <li>            var parentNode = tinyMCEPopup.getWindowArg("argParentNode"); </li> <li>            if (parentNode != null) { </li> <li>                document.getElementById('SnippetCode').innerHTML = parentNode.innerHTML </li> <li>            } </li> <li>            var _parentNode = tinyMCEPopup.getWindowArg("argParentNode"); </li> <li>            var _accordionID = tinyMCEPopup.getWindowArg("argAccordionID"); </li> <li>            var min = 1; </li> <li>            var max = 50; </li> <li>            var random = Math.floor(Math.random() * (max - min + 1)) + min; </li> <li>            randomNumber = random; </li> <li>            if (parentNode != null) { </li> <li>                edit = true; </li> <li>                parentNode = _parentNode; </li> <li>                accordionID = _accordionID; </li> <li>            } </li> <li>            else { </li> <li>                accordionID = 'accordionID' + random; </li> <li>            } </li> <li>        </script> </li> <li>    </div> </li> <li></body> </li> <li></html> </li> </ol> </td> </tr> </tbody></table> <p>As you can see in line 6,7,9 i have included my own downloaded version of tinymce (majorVersion:"3",minorVersion:"5.11",releaseDate:"2014-05-08") downloaded from their site. Because by EPiServer on this <a href="/link/85f05074fba4407a9e8afac2af3f130a.aspx">link</a> In the last section "Using the TinyMCE editor from template pages" we can read that if we want to use TinyMCE editor in template pages as in our case AccordionSnippet.html, we need to download version from the official site and this version is not connected with the existing one on Episerver, because of that we are not able to insert local media files in body text. Line 11 is init function of tinymce. Line 24 the div is my dialog form for anoter popup where i can insert or edit items in the accordion (Title and Body text). Line 43 is the table with the conatining items displayed in table view. Line 63 is hidden accordion panel where i'm hiding the changes before the are updated on the main tinymce editor. Below i have the insert and close buttons for the snippet. </p> <p><strong>5. AccordionSnippet.js</strong></p> <table cellspacing="1" cellpadding="1" border="1"><tbody> <tr> <td> <ol> <li>tinyMCEPopup.requireLangPack(); </li> <li>var edit = false; </li> <li>var parentNode = null; </li> <li>var accordionID = null; </li> <li>var randomNumber = null; </li> <li>var cfHtmlSnippetDialog = { </li> <li>    init: function () { </li> <li>        //empty function </li> <li>    }, </li> <li>    insert: function () { </li> <li>        var sel_text = 0; </li> <li>        var ed = tinyMCEPopup.editor; </li> <li>        if (ed.selection.getContent()) { </li> <li>            content = ed.selection.getContent(); </li> <li>            sel_text = 1; </li> <li>        } else { </li> <li>            content = ed.getContent(); </li> <li>        } </li> <li>        if (edit) { </li> <li>            tinyMCEPopup.editor.dom.select('#' + accordionID)[0].innerHTML = jQuery('#' + accordionID).html(); </li> <li>            tinyMCEPopup.execCommand('mceInsertContent', false, ""); </li> <li>            tinyMCE.triggerSave(); </li> <li>        } else { </li> <li>            tinyMCEPopup.execCommand('mceInsertContent', false, "<div class='accordion-panel-group'>" + jQuery('.accordion-panel-group').html() + "</div>"); </li> <li>        } </li> <li>        tinyMCE.triggerSave(); </li> <li>        tinyMCEPopup.close(); </li> <li>       </li> <li>    } </li> <li>}; </li> <li>tinyMCEPopup.onInit.add(cfHtmlSnippetDialog.init, cfHtmlSnippetDialog); </li> </ol> </td> </tr> </tbody></table> <p>Here comes the inser fuction of the snippet where depends it is edit or new accordion.</p> <p><strong>6. Accordion.js:</strong></p> <table cellspacing="1" cellpadding="1" border="1"><tbody> <tr> <td> <ol> <li>$(document).ready(function () { </li> <li>    //change the template accordion id in the hidden div </li> <li>    jQuery('#accordion').attr("id", accordionID); </li> <li>    var parentNodeInnerHTML = $("#SnippetCode").html(); </li> <li>    var atitles = [];//get all accordion items titles </li> <li>    $("#SnippetCode").find("a.collapsed").each(function () { atitles.push($(this).text()); }); </li> <li>    var tbodies = [];//get all accordion items bodies </li> <li>    $("#SnippetCode").find(".panel-body").each(function () { tbodies.push($(this).html()); }); </li> <li>  </li> <li>    $.each(atitles, function (i, item) { </li> <li>        //fills the table with the accordion items data </li> <li>        $("#accordionItems tbody").append("<tr>" + "<td>" + $.trim(atitles[i]) + "</td>" + "<td>" + $.trim(tbodies[i]) + "</td>" + "<td><a href='' class='edit'>Edit</a></td>" + "<td><span class='delete'><a href=''>Delete</a></span></td>" + "</tr>"); </li> <li>    }); </li> <li>}); </li> <li>  </li> <li>$(function () { </li> <li>    function recreate_accordion() { </li> <li>        if ($('#' + accordionID + '').length > 0) { </li> <li>            // dostuff </li> <li>            $('#' + accordionID).empty();//removes item from the accordion </li> <li>            $('#' + accordionID).html('');//removes item from the accordion </li> <li>            $('#' + accordionID).children().remove();//removes item from the accordion </li> <li>            $('#accordionItems> tbody  > tr').each(function (ri, el) { </li> <li>                var row = $(this); </li> <li>                var _atitle = $(row.children().get(0)).text(),//accordion item title </li> <li>                     _tbody = $(row.children().get(1)).html();//accordion item body </li> <li>                var rowIndex = ri; </li> <li>                $("#" + accordionID).append(//appends item to the accordion </li> <li>                "<div class='panel panel-default'>" + </li> <li>                "   <div class='panel-heading'>" + </li> <li>                "       <h4 class='panel-title'>" + </li> <li>                "           <a data-toggle='collapse' data-parent='#" + accordionID + "' href='#collapseOne" + rowIndex + randomNumber + "' class='collapsed'>" + </li> <li>                "               <span class='plus'>&nbsp;</span>" + $.trim(_atitle) + "</a>" + </li> <li>                "       </h4>" + </li> <li>                "   </div>" + </li> <li>                "   <div id='collapseOne" + rowIndex + randomNumber + "' class='panel-collapse collapse'>" + </li> <li>                "       <div class='panel-body'>" + $.trim(_tbody) + "</div>" + </li> <li>                "   </div>" + </li> <li>                "</div>"); </li> <li>            }); </li> <li>        } </li> <li>    } </li> <li>    function addTinyMCE() { </li> <li>        $('textarea').tinymce({ </li> <li>            // Location of TinyMCE script </li> <li>            script_url: '../../../../../tiny_mce/tiny_mce.js', </li> <li>            mode: "none", </li> <li>            theme: "advanced", </li> <li>            theme_advanced_toolbar_location: "top" </li> <li>        }); </li> <li>    } </li> <li>    function removeTinyMCE() { </li> <li>        if (tinyMCE.getInstanceById('bodyText')) { </li> <li>            tinyMCE.execCommand('mceFocus', false, 'bodyText'); </li> <li>            tinyMCE.execCommand('mceRemoveControl', false, 'bodyText'); </li> <li>        } </li> <li>    } </li> <li>    var new_dialog = function (type, row) { </li> <li>        var dlg = $("#dialog-form"); </li> <li>        var atitle = dlg.find(("#titleA")), </li> <li>        tbody = dlg.find(("#bodyText")); </li> <li>        atitle.val(""); </li> <li>        tbody.val(""); </li> <li>        type = type || 'Create'; </li> <li>        var config = { </li> <li>            autoOpen: true, </li> <li>            height: 575, </li> <li>            width: 645, </li> <li>            modal: true, </li> <li>            open: addTinyMCE, </li> <li>            buttons: { </li> <li>                "Add accordion item": save_data, </li> <li>                "Cancel": function () { </li> <li>                    removeTinyMCE(); </li> <li>                    dlg.dialog("close"); </li> <li>                } </li> <li>            }, </li> <li>            close: function () { </li> <li>                removeTinyMCE(); </li> <li>                dlg.dialog("destroy"); </li> <li>            } </li> <li>        }; </li> <li>        if (type === 'Edit') { </li> <li>  </li> <li>            config.title = "Edit accordion item"; </li> <li>            get_data(); </li> <li>            delete (config.buttons['Add accordion item']); </li> <li>            config.buttons['Edit accordion item'] = function () { </li> <li>                var helpValue = tbody.val(); </li> <li>                helpValue = helpValue.replace("<p>", ""); </li> <li>                helpValue = helpValue.replace("</p>", ""); </li> <li>                tbody.val(helpValue); </li> <li>                $(row.children().get(0)).text(atitle.val()); </li> <li>                $(row.children().get(1)).html(helpValue); </li> <li>                recreate_accordion(); </li> <li>                dlg.dialog("close"); </li> <li>            }; </li> <li>        } </li> <li>        dlg.dialog(config); </li> <li>        dlg.dialog("option", "resizable", true); </li> <li>        function get_data() { </li> <li>            var _atitle = $(row.children().get(0)).text(), </li> <li>        _tbody = $(row.children().get(1)).html(); </li> <li>            atitle.val($.trim(_atitle)); </li> <li>            tbody.val($.trim(_tbody)); </li> <li>        } </li> <li>  </li> <li>        function save_data() { </li> <li>            $("#accordionItems tbody").append("<tr>" + "<td>" + atitle.val() + "</td>" + "<td>" + tbody.val() + "</td>" + "<td><a href='' class='edit'>Edit</a></td>" + "<td><span class='delete'><a href=''>Delete</a></span></td>" + "</tr>"); </li> <li>            $("#" + accordionID).append( //appends item to the accordion </li> <li>            "<div class='panel panel-default'>" + </li> <li>            "   <div class='panel-heading'>" + </li> <li>            "       <h4 class='panel-title'>" + </li> <li>            "           <a data-toggle='collapse' data-parent='#" + accordionID + "' href='#collapseOne" + ($('#accordionItems tbody tr').length + 1) + randomNumber + "' class='collapsed'>" + </li> <li>            "               <span class='plus'>&nbsp;</span>" + $.trim(atitle.val()) + "</a>" + </li> <li>            "       </h4>" + </li> <li>            "   </div>" + </li> <li>            "   <div id='collapseOne" + ($('#accordionItems tbody tr').length + 1) + randomNumber + "' class='panel-collapse collapse'>" + </li> <li>            "       <div class='panel-body'>" + $.trim(tbody.val()) + "</div>" + </li> <li>            "   </div>" + </li> <li>            "</div>"); </li> <li>  </li> <li>            dlg.dialog("close"); </li> <li>        } </li> <li>    }; </li> <li>    //delete function </li> <li>    $(document).on('click', 'span.delete', function () { </li> <li>        $(this).parents('tr:first').remove(); </li> <li>        recreate_accordion();//recreates the html of the accordion in the hidden div </li> <li>        return false; </li> <li>    }); </li> <li>    //edit function </li> <li>    $(document).on('click', 'td a.edit', function () { </li> <li>        new_dialog('Edit', $(this).parents('tr')); </li> <li>        recreate_accordion();//recreates the html of the accordion in the hidden div </li> <li>        return false; </li> <li>    }); </li> <li>    $(document).on('click', 'a.createa', function () { </li> <li>        new_dialog(); </li> <li>        return false; </li> <li>    }); </li> <li>}); </li> </ol> </td> </tr> </tbody></table> <p>In this js file in the ready function i get all the titles and body texts and fill the table with the items to diplayed it. The function recreate_accordion i used to recreate the hidden accordion (explained before) on every change so i can keep track of changes. Functions addTinyMCE and removeTinyMCE are required for init and removing of the tinymce on the textarea (thanks to this guy on this <a href="http://blog.mirthlab.com/2008/11/13/dynamically-adding-and-removing-tinymce-instances-to-a-page/" target="_blank">link</a> i have understand why). The other functions are pretty explanatory by themself.</p> <p>You can use these files as copy/paste to your project, but if before you have added the mentioned tinymce version and jquery version. The css class i have not provided them becasue you can build them by yourself or find on internet.</p> <p>I'm using the tinymce editor as plugin for the episerver tinymce editor to create styled items for the accordion and the accordion itself. The chalenge was the setup to work episerver tinymce edtor and the classic tinymce editor along with jquery and tinymce jquery together.</p> <p><strong>IMPROVEMENTS</strong></p> <p>Using the tinymce in popup window as plugin in episerver has limitations, one of that is that you cannot select local files of episerver as links in the body text. As mentioned above episerver reccomend to use downloaded version of tinymce.</p> <p>BUT some gys have tried something and they are on good direction </p> <p>1. (http://world.episerver.com/forum/developer-forum/EPiServer-7-CMS/Thread-Container/2013/11/How-well-can-TinyMCE-run-outside-of-Edit-Mode/)</p> <p>2. (http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=85047)</p> <p>3. (https://gist.github.com/mvirkkunen/10484486)</p> <p>Thanks for reading, if you have any questions or remarks please dont hesitate to write me :).</p> <p> <a href="/link/bcb2ad47423345d9bcf67530875e56ba.aspx"><img title="1" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="1" src="/link/0cf96d841ecb4cada17479d2783531f7.aspx" width="244" height="116" /></a><a href="/link/e19eb88b41bd4de4a7ab1c248f793199.aspx"><img title="2" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="2" src="/link/b0368a2472f7439e80b11b38ef816d03.aspx" width="226" height="244" /></a><a href="/link/a0cfe0367faa4441baf82a9abed36538.aspx"><img title="3" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="3" src="/link/7927fe66ba8a4ba2906cfdbdc5fc85b6.aspx" width="244" height="83" /></a><a href="/link/bd67cc3c2eba4e1f8653e2e7dde89f37.aspx"><img title="4" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="4" src="/link/4b0e1be1d71e458e81d1a523b52a3bf9.aspx" width="234" height="244" /></a><a href="/link/97b95ae713b944c7b8f719c0fcc713c1.aspx"><img title="5" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="5" src="/link/91dce1d82f4a4178a3dd216c91c6c505.aspx" width="235" height="244" /></a></p>