#TinyMCE: Plugin DDL with Popup

Recently I had a story asking for some advanced functionality for a new TinyMCE button. I broke down the requirements to the following.  I created a JSFiddle to show it working.

  • Custom TinyMCE drop down menu
  • When a menu item is selected it should insert the menu value into the editor at the cursor
  • Last item on the menu will show a popup
  • On the popup have a text box for entering custom text
  • When Insert is clicked insert the text into the editor at the cursor
Core plugin code – Javascript
$('#Insert').click(function () {
    var text = $('#added-token').val();
    tinyMCE.activeEditor.execCommand('mceInsertContent', false, "{Added Text:" + text + "}");
    return false;
tinymce.PluginManager.add('tokens', function (editor, url) {
    editor.addButton('inserttoken', {
        title: "Insert Token",
        type: 'menubutton',
        text: 'Tokens',
        icon: false,
        onselect: function (e) {
          if (e.control.settings.value != '{MenuItemPopup}') {
          } else {
            $('#token-modal').modal({ show: true });
        menu: [
            { text: 'Menu Item 1', value: '{MenuItem1}' },
            { text: 'Menu Item 2', value: '{MenuItem2}' },
            { text: 'Menu Item 3', value: '{MenuItem3}' },
            { text: 'Menu Item 4', value: '{MenuItem4}' },                     
            { text: 'Menu Item with Popup', value: '{MenuItemPopup}' }                        
        onPostRender: function () {
    selector: "textarea",
	width:      '100%',
	height:     270,
    plugins:    [ "anchor link tokens" ],
    statusbar:  false,
	menubar:    false,
    toolbar:    "inserttoken anchor | alignleft aligncenter alignright alignjustify",
	rel_list:   [ { title: 'Lightbox', value: 'lightbox' } ]
Core plugin code – HTML
<div id="token-modal" class="modal hide fade" >
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Modal header</h3>
    <div class="modal-body">
        <input type="text" name="group" id="added-token"  />
    <div class="modal-footer">
        <button data-dismiss="modal">Close</button>
        <button id="Insert">Insert</button>

JIRA: Show @Mentions Feed

During the regular process of working on tickets people will use @mention to alert me when there is a question or something I need to know.  I get emails with this in it but was looking for a way to use JIRA to find them.  I found the following two articles that when combined together gave me the basics of what I need.

First JIRA Advanced Search capabilities are very strong.  I used this article to set up a new filter for the mentions.

Then in this article I got the following query that works fairly good to get a list of the mentions.  It shows me all tickets updated in the last 7 days that I have ever been mentioned in.

(text ~ currentUser()) AND updatedDate >= -7d ORDER BY updated DESC

So I tweaked it to only show tickets with new comments added in the last 7 days instead. This article got me this query.

text ~ currentUser() AND issueFunction in commented("after -7d") ORDER BY updated DESC

It still isn’t exactly what I want but is closer to what I need. It will do for now.



#TinyMCE: Disable/Enable Brute Force Solution

tinymceI spent a good chunk of yesterday trying to figure out how to change the state of the TinyMCE textbox from readonly to edit mode.  Or to set the values to enable and disable the box properly.  After much trial, error, and research I found this post which links to this post that explains that it is just not possible to do it cleanly.  These posts are a few years old but in the rest of my research I couldn’t find anything that contradicted them.  I tried many different workarounds suggested by other people and each one had something that just didn’t work quite right.  Here is the brute force solution that I came up with:

I created two TinyMCE editors one that is readonly and one that is not.  Then I show and hide them via a button click.

Another problem that I came across is properly showing and hiding the editors.  When I tried to use the built in options they would not show properly when toggling. I had problems with the textareas being set to visible.   To solve this problem I wrapped the original textarea inside a div and I show and hide the divs instead of the actual text area.

I like so many things about the TinyMCE editor but these problems were very frustrating and took up far too much of my time.

#TinyMCE: Validation with MVC

Today I am trying to figure out how to do validation with TinyMCE editors while using MVC’ s unobtrusive validation.  I did a google search and came up with a large number of results that all said the same thing.  I couldn’t get any of them to work.  While testing I found the following solution.  It isn’t perfect but is pretty close to what I need.

Here is the solution I came up with. I didn’t need to add any other additional code to the page.

      $('form button[type=submit]').not('.cancel').click(function () {
        var form = $('#FormName');
        var isValid = form.valid();
        var istinymceValid = $('#ContentField').valid();
        if (!isValid || !istinymceValid) {
          return false;
        return true;

Bootstrap3 Dialog


One of the great things about programming in the world today is that so much of the basic functionality I need can be found somewhere on the Web, as long as you know the correct search string.

I spent a good chunk of time looking for a quick and easy way to use Bootstrap modals without having a ton of ugly code on each page that isn’t really necessary.  Especially for modals that are repeated throughout the software.

This time I was looking for a Bootstrap modal that could be easily used for Alert and Confirmation boxes.  I couldn’t find one out there, even though I knew it should exist, so I built my own.  Then I plugged in a different search string and found exactly what I needed.

Bootstrap3 Dialog (Git Hub)is a nice clean simple solution that meets all our needs.  The code is well laid out and I was able to make some minor modifications that met our custom needs.

#VisualStudio Shortcut Keys – Open File in Solution Explorer

Solution-ExplorerWhen working in an application as complex as Visual Studio it becomes necessary to learn the shortcut keys.  Some of them are used so much that the keys get hit with no thought at all.  Then there are those few that are necessary for doing things, like efficient navigation of large projects, but are used so rarely that they are easily forgotten.  One of these is the “Sync With Active Document” (Ctrl+[, S) command.  Opens the Solution Explorer and navigates directly to the file that you are looking at.