Try our conversational search powered by Generative AI!

TinyMCE custom plugin label is empty

Vote:
 

Hi,

I am currently trying to implement a custom TinyMce plugin to episerver.
I've done the following so far

Added The Class to Util/Editor/TinyMCE/Plugins/wordlength/wordlength.cs

using EPiServer.Editor.TinyMCE;

namespace MyEpiServerWebsite.Util.Editor.tinymce.plugins.wordlength
{
    [TinyMCEPluginNonVisual(
        DisplayName = "wordlength",
        Description = "wordlength",
        PlugInName = "wordlength")]
    public class wordlength
    {
        
    }
        
    
}


Added The JS to Util/Editor/TinyMCE/Plugins/wordlength/editor_plugin.js

(function() {
    tinymce.create('tinymce.plugins.wordlength', {
		block : 0,
		id : null,
		countre : null,
		cleanre : null,

		init : function(ed, url) {
			var t = this, last = 0, VK = tinymce.VK;

            t.countre = ed.getParam('wordlength_countregex', /[\w\u2019\u00co-\u00ff^\uc397^u00f7\'-]+/g); // u2019 == ’ u00c0-u00ff extended latin chars with diacritical marks. exclude uc397 multiplication & u00f7 division
            t.cleanre = ed.getParam('wordlength_cleanregex', /[0-9.(),;:!?%#$?\'\"_+=\\\/-]*/g);
            t.update_rate = ed.getParam('wordlength_update_rate', 2000);
            t.update_on_delete = ed.getParam('wordlength_update_on_delete', false);
			t.id = ed.id + '-word-length';

			ed.onPostRender.add(function(ed, cm) {
				var row, id;

				// Add it to the specified id or the theme advanced path
                id = ed.getParam('wordlength_target_id');
				if (!id) {
					row = tinymce.DOM.get(ed.id + '_path_row');

					if (row)
                        tinymce.DOM.add(row.parentNode, 'div', { 'style': 'float: right' }, ed.getLang('wordlength.words', 'Estimated to Read: ') + '0' + " seconds - ");
				} else {
					tinymce.DOM.add(id, 'span', {}, '0');
				}
			});

			ed.onInit.add(function(ed) {
				ed.selection.onSetContent.add(function() {
					t._count(ed);
				});

				t._count(ed);
			});

			ed.onSetContent.add(function(ed) {
				t._count(ed);
			});

			function checkKeys(key) {
				return key !== last && (key === VK.ENTER || last === VK.SPACEBAR || checkDelOrBksp(last));
			}

			function checkDelOrBksp(key) {
				return key === VK.DELETE || key === VK.BACKSPACE;
			}

			ed.onKeyUp.add(function(ed, e) {
				if (checkKeys(e.keyCode) || t.update_on_delete && checkDelOrBksp(e.keyCode)) {
					t._count(ed);
				}

				last = e.keyCode;
			});
		},

		_getCount : function(ed) {
			var tc = 0;
			var tx = ed.getContent({ format: 'raw' });

			if (tx) {
					tx = tx.replace(/\.\.\./g, ' '); // convert ellipses to spaces
					tx = tx.replace(/<.[^><>]*?>/g, ' ').replace(/ | /gi, ' '); // remove html tags and space chars

					// deal with html entities
					tx = tx.replace(/(\w+)(&.+?;)+(\w+)/, "$1$3").replace(/&.+?;/g, ' ');
					tx = tx.replace(this.cleanre, ''); // remove numbers and punctuation

					var wordArray = tx.match(this.countre);
					if (wordArray) {
							tc = wordArray.length;
					}
			}

			return tc;
		},

		_count : function(ed) {
			var t = this;

			// Keep multiple calls from happening at the same time
			if (t.block)
				return;

			t.block = 1;

			setTimeout(function() {
				if (!ed.destroyed) {
					var tc = t._getCount(ed);
                    tinymce.DOM.setHTML(t.id, Math.round((tc/250) * 60 ));
					setTimeout(function() {t.block = 0;}, t.update_rate);
				}
			}, 1);
		},

		getInfo: function() {
			return {
                longname: 'wordlength plugin',
				author : 'Moxiecode Systems AB',
				authorurl : 'http://tinymce.moxiecode.com',
                infourl: 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/wordlength',
				version : tinymce.majorVersion + "." + tinymce.minorVersion
			};
		}
	});

    tinymce.PluginManager.add('wordlength', tinymce.plugins.wordlength);
})();




The plugin is working in the editor of the CMS and is visible in the pluginmanager as you can see below.

Plugin manager

On the propertypage the plugin is showing as a checkbox and the label is left empty

Plugin Manager

How can I get my label to say wordlength? Why is it not working?

I'm looking forward hearing from you guys!

#185674
Edited, Nov 29, 2017 16:16
Vote:
 

Hi,

Presumably you're following the Customizing the TinyMCE editor guide?

If so, I'm fairly certain you're just missing the translation (Step 3: Handling translations), you just need to add something like the following to your language files:

<?xml version="1.0" encoding="utf-8"?>
<languages>
    <language name="English" id="en">
        <tinymce>
            <wordlength>
                <wordlength_desc>Word Length</wordlength_desc>
            </wordlength>
        </tinymce>
    </language>
</languages>
#185690
Nov 30, 2017 0:06
Vote:
 

Hi there,

Thanks for your reply. I am indeed following that guide. I also looked for the language files but i couldnt find them. Where can i find these language files? What do i put as a language path? I was unable to figure this out. 

#185691
Edited, Nov 30, 2017 0:12
Vote:
 

That depends on your solution laughing

But it's probably something like /Resources/LanguageFiles. In your web.config you'll find the path specified under <episerver.framework> (more details here).

My example above is a translation for the TinyMCE editor - where you are missing one. The languagepath is so you can apply localization in Episerver, right now your example will always be called "wordlength" regardless of editor language.

/Jake

#185692
Nov 30, 2017 0:38
Vote:
 

This was indeed the solution to my problem! I had to add the virtual path to the web.config and create the language file according to the location of the path. After that I added the LanguagePath attribute to the class and everything is working fine now!

Thanks for your help!

#185995
Dec 08, 2017 11:24
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.