Git Product home page Git Product logo

tinymce-suggestions's Introduction

TinyMCE suggestions

TinyMCE suggestions is a an auto-complete plugin.

This plugin doesn't need a special char to trigger the suggestion function and doesn't popup a list of suggestions. Instead this plugin is only triggered by typing.

To retrieve the suggested word completion, this plugin searches from a list of words, or through a user defined function, for example to search from an API.

The completion function can be triggered by pressing the Tab key in the keyboard.

TinyMCE suggestions screenshot

Example

tinymce.init({
    selector: "#textarea",  // change this value according to your HTML
    plugins: "suggestions"
});

Options

These options affect the execution of the suggestions of the suggestions plugin.

terms_list

This option is an array containing a list of string terms where the plugin will search to complete the typed word.

tinymce.init({
    selector: "#textarea",  // change this value according to your HTML
    plugins: "suggestions",
    terms_list: [
        'Afghanistan',
        'Albania',
        'Algeria',
        'Andorra'
    ]
});

min_search_length

This option is an integer which represent the minimum word length before triggering the suggestion function. The default value is 3.

tinymce.init({
    selector: "#textarea",  // change this value according to your HTML
    plugins: "suggestions",
    min_search_length: 3
});

suggestion_node_id

This option is the id of the TinyMCE DOM node containing the suggestion. The default value is suggestionNodeId

tinymce.init({
    selector: "#textarea",  // change this value according to your HTML
    plugins: "suggestions",
    suggestion_node_id: "suggestionNodeId"
});

suggestion_text_color

This option defines the html hex color of the suggestion completion text. The default value is #dee7f1.

tinymce.init({
    selector: "#textarea",  // change this value according to your HTML
    plugins: "suggestions",
    suggestion_text_color: "#dee7f1"
});

debounce_time

This option is an integer which defines the delay in milliseconds which the plugin waits when you type before triggering the suggestion function. The default value is 250 ms.

tinymce.init({
    selector: "#textarea",  // change this value according to your HTML
    plugins: "suggestions",
    debounce_time: 250
});

search_function

This option is a user defined async function which is used to get the suggested word. The return value is a string or an array of strings. The keyword argument of the function represents the word already typed in TinyMCE editor. The default value is null.

tinymce.init({
    selector: "#textarea",  // change this value according to your HTML
    plugins: "suggestions",
    search_function: async ( keyword ) => {
        const response = await fetch(`https://example.com/api/?keyword=${keyword}`);
        
        if(response.ok){
            const jsonResponse = await response.json();
            return jsonResponse;
        }else{
           throw new Error("ERR")
        }
    }
});

tinymce-suggestions's People

Contributors

shmox75 avatar richard-muvirimi avatar

Stargazers

 avatar  avatar Keram Yasin avatar Dzung Do avatar

Watchers

 avatar

tinymce-suggestions's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.