Git Product home page Git Product logo

trix-auto-complete's Introduction

Autocomplete plugin for Trix editor

This is a plugin that brings autocomplete to the Trix editor. This is not an official google product.

Installation Right now you need to clone this repo into your tree.

How to Use

In order to use this plugin, the Trix editor must be used and a dropdown container element must be added. The plugin can be initialized by calling the autocomplete constructor and then called by calling autoCompleteHandler() on each trix-change event. The constructor must be passed the trix editor, the editor element, the dropdown container and an array of objects. Each object must contain the following properties.

  • Trigger. Potential terms that should be completed
  • Replace. What the completed term should be.
  • Search. Potential completed terms.
  • Template. How to style each drop down menu item The following properties are optional.
  • Index.
  • Extract. How to extract the value from the drop down menu item.

An example of the strategy object

{
   index: 1,
   trigger: /\[([A-Za-z0-9]*)\],
   replace: function(data, startingPosition) {
      editor.setSelectedRange(startingPosition);
      editor.insertString(data);
   },
   search: function(term, callback) {
      let matches = _(dictionary).filter(e => e.indexOf(term) === 0);
      callback(matches.slice(0, 10).value());
   }
   template: function(value) {
      return angular.element('<a>').append(value);
   }
}

This would search for all terms that match the trigger function. Then, the term that matches the trigger function would be passed into the search function starting from the 1st index since the index is 1. The values that result from the search function would then be passed into the template function to populate the drop down menu. Finally, when a drop down item is selected, the HTML of the drop down item will be passed into the replace function and replace the term that initially triggered the drop down menu. If the user doesn't want the HTML of the drop down item, then an extract property must be defined in the strategy object.

trix-auto-complete's People

Contributors

chenmichael avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

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.