项目作者: StevenDevooght

项目描述 :
Mention/Autocomplete plugin for tinyMCE WYSIWYG editor.
高级语言: JavaScript
项目地址: git://github.com/StevenDevooght/tinyMCE-mention.git
创建时间: 2013-06-20T15:11:02Z
项目社区:https://github.com/StevenDevooght/tinyMCE-mention

开源协议:

下载


tinyMCE mention

Travis

Mentions plugin for tinyMCE WYSIWYG editor.

preview

Browser compatibility

  • IE7+
  • Chrome
  • Safari
  • Firefox
  • Opera

Dependencies

NOTE: Use v3.x if you’re using tinyMCE v3.5.x, use v4.x if you’re using tinyMCE v4.x

Usage

Install using bower.

  1. bower install tinymce-mention

Or copy the source of the plugin to the plugins directory of your tinyMCE installation.
Add the mention plugin to your tinyMCE configuration.

  1. plugins : "advlink, paste, mention",

Add configuration options for the mention plugin. source is the only required setting.

NOTE: source can also be a function. see the options section below.

  1. mentions: {
  2. source: [
  3. { name: 'Tyra Porcelli' },
  4. { name: 'Brigid Reddish' },
  5. { name: 'Ashely Buckler' },
  6. { name: 'Teddy Whelan' }
  7. ]
  8. },

Configuration

source (required)

The source parameter can be configured as an array or a function.

array

  1. source: [
  2. { name: 'Tyra Porcelli' },
  3. { name: 'Brigid Reddish' },
  4. { name: 'Ashely Buckler' },
  5. { name: 'Teddy Whelan' }
  6. ]

function

  1. source: function (query, process, delimiter) {
  2. // Do your ajax call
  3. // When using multiple delimiters you can alter the query depending on the delimiter used
  4. if (delimiter === '@') {
  5. $.getJSON('ajax/users.json', function (data) {
  6. //call process to show the result
  7. process(data)
  8. });
  9. }
  10. }

queryBy

The name of the property used to do the lookup in the source.

Default: 'name'.

delimiter

Character that will trigger the mention plugin. Can be configured as a character or an array of characters.

character

  1. delimiter: '@'

array

  1. delimiter: ['@', '#']

Default: '@'.

delay

Delay of the lookup in milliseconds when typing a new character.

Default: 500.

items

Maximum number of items displayed in the dropdown.

Default: 10

matcher

Checks for a match in the source collection.

  1. matcher: function(item) {
  2. //only match Peter Griffin
  3. if(item[this.options.queryBy] === 'Peter Griffin') {
  4. return true;
  5. }
  6. }

highlighter

Highlights the part of the query in the matched result.

  1. highlighter: function(text) {
  2. //make matched block italic
  3. return text.replace(new RegExp('(' + this.query + ')', 'ig'), function ($1, match) {
  4. return '<i>' + match + '</i>';
  5. });
  6. }

insertFrom

Key used in the default insert implementation.

Default: queryBy value

NOTE: key can be any property defined insource option.

insert

Callback to set the content you want to insert in tinyMCE.

  1. insert: function(item) {
  2. return '<span>' + item.name + '</span>';
  3. }

NOTE: item parameter has all properties defined in the source option.

render

Callback to set the HTML of an item in the autocomplete dropdown.

  1. render: function(item) {
  2. return '<li>' +
  3. '<a href="javascript:;"><span>' + item.name + '</span></a>' +
  4. '</li>';
  5. }

NOTE: item parameter has all properties defined in the source option.

renderDropdown

Callback to set the wrapper HTML for the autocomplete dropdown.

  1. renderDropdown: function() {
  2. //add twitter bootstrap dropdown-menu class
  3. return '<ul class="rte-autocomplete dropdown-menu"></ul>';
  4. }

License

MIT licensed

Copyright (C) 2013 Cognistreamer, http://cognistreamer.com