Zimbra SkillZ: Social Justice Zimlet

Hello Zimbra Customers, Partners & Friends,

Today’s new Zimlet from Barry de Graaff, Channel Evangelist for Zimbra Synacor, is the Social Justice Zimlet. While you write an email, this Zimlet suggests alternative words when appropriate. For example: master ldap > primary ldap.

This post shows you how to write a Zimlet that uses a keyup event, so you can write Zimlets that interact with the Zimbra composer while the user types. The Social Justice Zimlet is an example of using keyup. This blog also shows you how to use the selection object to do advanced tricks.

For all the relevant files, click here: https://github.com/Zimbra/zimbra-zimlet-social-justice

 The Social Justice Zimlet.

Zimlets for Advanced Uses of Composer

The Zimbra composer is based on TinyMCE. You can use the browser’s native selection object and combine it with TinyMCE’s comprehensive API to do advanced tasks.

This code snippet shows how to add an onkeyup event handler and get the last typed word:

export default class MoreMenu extends Component {
    constructor(props) {
        this.zimletContext = props.children.context;

        this.props.getComposer().on('keyup', function (e) {
                var selRng = this.props.getComposer().selection.getRng();
                let content = this.props.getComposer().selection;
                let contentText = content.getSel().focusNode.data;
                try {
                    let contentTillCaret = contentText.substring(0, selRng.startOffset);
                    let lastTypedWord = this.lastWord(contentTillCaret);
                    //do something here
                } catch (err) { console.log(err) };

This code snippet shows how to replace the last typed word:

    replaceWord = (myNewWord) => {  
        this.props.getComposer().selection.getSel().modify('extend', 'backward', 'word');

Enjoy the new Social Justice Zimlet,

Your Zimbra Friends & Colleagues

, , , ,

Comments are closed.

Copyright © 2022 Zimbra, Inc. All rights reserved.

All information contained in this blog is intended for informational purposes only. Synacor, Inc. is not responsible or liable in any manner for the use or misuse of any technical content provided herein. No specific or implied warranty is provided in association with the information or application of the information provided herein, including, but not limited to, use, misuse or distribution of such information by any user. The user assumes any and all risk pertaining to the use or distribution in any form of any subject matter contained in this blog.

Legal Information | Privacy Policy | Do Not Sell My Personal Information | CCPA Disclosures