terminal42 / contao-notification_center

The most popular notification configuration extension for the Contao Open Source CMS!
64 stars 38 forks source link

Simple-Token autocomplete not working in TinyMCE (HTML) #270

Closed contaoacademy closed 2 years ago

contaoacademy commented 2 years ago

If I type ## in the RAW text-window, then autocomplete comes up automatically for me. If I enable text and HTML and try to do the same in TinyMCE, then autocomplete does not show up.

Currently, I could only reproduce the problem under Contao 4.13 because under Contao 4.9 it still works as expected.

screen-20220720_4R2U26GF

cliffparnitzky commented 2 years ago

Can confirm. The developer console throws an error.

contaoacademy commented 2 years ago

Maybe the same issue as #262

philvdb commented 2 years ago

@contaoacademy possibly, but the behavior is slightly different. TinyMCE does not load for me at all when I use Contao 4.13.

philvdb commented 2 years ago

Now that my tinyMCE is showing again I was able to look into the autosuggester problem. I'm not familiar with tinyMCE at all but the problem seems to be in assets/autosuggester.js:164:


        // Add the events to tinyMCE
        if (this.tinyMCE) {

            if (window.tinyMCE.majorVersion == '4') {
                this.tinyMCE.on('keyUp', function(event) {
                   this.eventKeyUp.call(this, event);
                }.bind(this));

window.tinyMCE is not defined, this.tinyMCE is. However, this.tinyMCE does not have a property called majorVersion or version at all at least in my installation. This means that the check for version 4 fails and the nonexistent property onKeyUp causes the error in our developer consoles.

Knowing virtually nothing about tinyMCE I don't know if this is the proper solution. However at least in my installation, instead of looking for the version number checking for the existence of the on function leads to the autosuggester working again:

        // Add the events to tinyMCE
        if (this.tinyMCE) {

            if (typeof this.tinyMCE.on === 'function') {
                this.tinyMCE.on('keyUp', function(event) {
                   this.eventKeyUp.call(this, event);
                }.bind(this));

Let me know if this is the right approach I could try creating a pull request .. would have to figure out how to minify the Javascript properly though :clown_face: . If switching out the line and minifying the JS is something that comes easy in your development workflow I will be happy if anyone else wants to do it.

philvdb commented 2 years ago

@contaoacademy , @cliffparnitzky feel free to try out https://github.com/philvdb/contao-notification_center to see whether it solves the problem for you as well and report back here.

contaoacademy commented 2 years ago

@philvdb Looks great! Works for me. Thank you.