anyone recommend a way to autocomplete usernames when using the 'mention' function in elgg?

i use the 'mentions' plugin on my site and no-one really understands how to use it intuitively. it would be much better if an autocomplete dropdown appeared in textboxes when the @ symbol is typed, just as wiretools currently allows within the wire's add box. does anyone know of a plugin that adds this feature to blog text, discussions and comments etc?

  • If you haven't noticed yet, the master branch in the mentions repo is doing things slightly different than the 1.8 branch. Timeout for tinymce is now in the editor specific module and the keyup event is also defined differently (which might be necessary for it to work on tinymce v4 anyway).

    I also thought that it would work with requiring the extended_tinymce_init module but it is not working reliable. I'm not sure if the problem is not only with tinymce but maybe also due to other unresolved issues in the mentiones plugin. Or it might be necessary to make adjustments elsewhere in the code addtionally to get it fully working with tinymce. I just had no time to investigate in detail.

    Another way that might be possible to get it to work is customization of the tinymce plugin. Tinymce has an option to provide event handler functions on initualization. Keyboard events are also supported. I'm using this functionality to parse for certain smiley shortcuts during typing in a private version of tinymce (can't share as the code origins from a vazco plugin). It works in quite the same way as parsing for the mentions input sequences. So, instead of a specific tinymce module in the mentions plugin this code could also be added to the tinymce init function instead. Then there's likely no issue with the AMD modules not ready yet. I just can't say yet if it would work to add this code to the published version of the extended_tinymce plugin as it might fail to work without the mentions plugin being installed (or if there's any JS equivalent to elgg_is_active_plugin() to check for existence of the plugin within the tinymce init function).

  • i did see the init way of dealing with kepresses in tinyMCE when researching yes - it is the only way that i saw recommended in fact.

    it is possible to use a php check within the tinyMCE init file to see whether an elgg tinyMCE plugin is activated or not - i have done this in my theme to decide which css file to load so that i can skin the editor differently for different themes.

  • it is possible to use a php check within the tinyMCE init file to see whether an elgg tinyMCE plugin is activated or not

    Unfortunately, you can't use php code inside a AMD module. But it's possible to - for example by using a hidden input - to provide data to a module that you have fetched before requiring the module. In extended_tinymce I do this with the user language (to be used then also by tinymce). So, it should work to check for the mentions plugin being enabled or not before and then execute the keyup event function depending on the outcome. I think I'll test this out.

  • the file i am referring to is extended_tinymce/init.php.

    i was thinking that the customisation needed for thekeyup functionality would be triggered within that init.php file or a similar one - rather than within an AMD module.

  • You can pass data to AMD modules with server side AMD config hook.

  • You can pass data to AMD modules with server side AMD config hook.

    Could you point out an example where this hook is used? I fail to understand at the moment how I can make use of it.

    I've got the mentions plugin support working in Extended Tinymce (for now using a hidden input). So far, I've tested in on Elgg 2.X only and it seems to work fine both on normal textareas and also on ajax`ed textareas. I need to do some more tests (also on Elgg 1.X). On a positive outcome of the test I guesss I'll add the mentions functionality in the next release.

  • It's not fully working after all unfortunately. I have some problem with getting it to work conditionally depending on the mentions plugin installed or not. Problem here is mainly with mentions plugins not installed, i.e. the corresponding AMD module unavailable, because the require functions seems to get always executed even if nested in a if-clause checking the availability of the mentions plugin. I might have an alternative solution for that but need to implement it first to see it it works out.

    Another problem is with parsing for the mentions of username/display names. Though it might be a bug in the mentions plugin causing the parsing not to fully work as intended. I need to test this some more (also when using CKeditor) to figure out what is failing to work due to usage of tinymce and what is beyond the scope of tinymce. Right now I think I might not make a release of the Extended Tinymce plugin with mentions support included if I don't get it to work 100%.

  • maybe the issue with the JS file being included regardless of the activation status of the mentions plugin is due to caching in some way? what is the code you are using for the conditional require?

  • I've checked if mentions is active in php and used a hidden input to provide the JS part with the result. In JS I checked the hidden input and then used an if-clause

    if (mentions_active == "yes") {

        var mentions = require('mentions/autocomplete');

    }

    But require is always executed. If the mentions plugin is not installed the execution of require fails and the rest of the code is not even executed, i.e tinymce does not work anymore at all. Therefore, I think I can't use any conditional loading of the autocomplete AMD module at all. Using elgg_require_js in php to load the autocomplete module won't work either because I can't assign the module to the mentions variable and therefore can't use its methods.

    I think I will have to provide two separate AMD modules, one with mentions support and one without, and load the one fitting from php depending on the existence/absense of the mentions plugin.

    But this is only one part of the problem. As I said the identification of @<username/display name> also seems to be slightly buggy. And this might be due to bugs in the mentions plugin at least to a certain part. I need to test this much more before I can say for sure though.