Giter Club home page Giter Club logo

tinymce-autocomplete-plugin's Introduction

This fork merged all other known forks into one. Then all noticed bugs were fixed to work with recent JQuery (1.8.2).

This plugin now has: Ajax and all words completion support (not only the ones preceding with '@' or some other character).

Example code for .NET MVC 3 controller method for getting Ajax autocompletion words list:

		public JsonResult GetWordCompletion(string q)
		{
				var jsonObj = new
				{
					ok = 1,
					DATA = new List<object>
						{
							new { name = "autocomplete item 1" },
							new { name = "autocomplete item 2" },
							new { name = "autocomplete item 3" }
						},
					ERRORS = new int[0]
				};

			return Json(jsonObj, JsonRequestBehavior.AllowGet);
		}

Below you can find original readme...

AJAX AutoComplete for TinyMCE provides inline autocomplete in a style similar to Twitter or Facebook. The text you type in tinyMCE is checked against a list of specified options; if there is a match then you will see them appear in a list underneath the caret. This plugin was originally designed for PriorityCentre, a task and meeting management application developed by Mijura (https://mijura.com).

This fork has been updated to provide generation of autocomplete list on-the-fly with AJAX. Use at your own risk. Also you can visit my page: http://www.sib.li :-)

Server should return data in this format:

{
	"ok":1,
	"DATA":
	[
		{"name":"autocomplete item 1"},
		{"name":"autocomplete item 2"},
		{"name":"autocomplete item 3"}
	],
	"ERRORS":[]
}

To configure use autocomplete_options_url setting (without autocomplete_options):

autocomplete_options_url: "/path/to/my/ajax.php",

This plugin has been tested in Firefox, Chrome, Safari and Internet Explorer 9. It currently does not support IE7/8.

Screenshot

Screenshot of the tinymce autocomplete plugin

Requirements

Autocomplete requires TinyMCE with the jQuery package, available for download here: http://www.tinymce.com/download/download.php

Autocomplete options

There are four parameters that need to be specified in your tinyMCE config:

  1. autocomplete_delimiters - A CSV list of delimiters (ASCII codes) on which to split text entered into tinyMCE. In most cases you will want to split text by spaces, in which case you would specify '160,32'. 32 is a normal space and 160 is &nbsp; (which is commonly used by tinyMCE). Whichever delimiter you specify first will be inserted after you select an option. The default is '160,32' for spaces.
  2. autocomplete_options - A CSV list OR Javascript Object "options".
    1. A CSV List like "john,jane,william"
    2. JSON-like "options" array of objects havaing a key and a description ( both visible to user key and description, key is only used for autocomplete features ) "options": [ { "key": "Attila", "description": "- The Great Hun" } ]
  3. autocomplete_trigger - You can specify a trigger character that must be type immediately before searching for options. The default trigger is '@'
  4. autocomplete_end_option - Any text that you want to be added after the option. The caret will be placed between the option and this ending text. For example, you could specify 'end', in which case selecting an autocomplete option would insert: '@jane @end' with the caret placed in between (and including the trigger before the end option).
  5. autocomplete_min_length - The minimum number of characters a word needs to have before the autocomplete activates. Only active when autocomplete_trigger is ''. The default is 3.
  6. autocomplete_on_select - A function to call after an option is selected. The default is false.
  7. autocomplete_on_match - A function to call when text entered match only one option. The default is false.

Configuration with TinyMCE

Copy the autocomplete folder (in src) to the plugins directory of your TinyMCE installation.

Include the autocomplete plugin in your TinyMCE configuration, this might look like:

plugins : "autolink,lists,pagebreak,style,layer,advlink,emotions,advlist,autocomplete",

Add the configuration options for the autocomplete plugin, e.g.:

// Required
autocomplete_options: "john,jane,william", 

OR (if you prefer showing description along the keys)

autocomplete_options: {
						"options": [
							{
								"key": "Attila",
								"description": "- The <i>Great</i> Hun <hr /> <iframe src=\"http://farm4.staticflickr.com/3451/3233621766_e4f6db7a22_m.jpg\"></iframe>"
							},
							{
								"key": "Kattila",
								"description": "/ The Great B<b>um</b>"
							},
							{
								"key": "JustKey",
								"description": "* Just a <a href=\"http://twitter.com/enersizetech\">link</a>"
							}
						]
 					  },
// Optional
autocomplete_delimiters: "160,32",		// Optional and this is the default 
autocomplete_trigger: "@",			// Optional and this is the default
autocomplete_end_option: "end",			// Optional and by default no ending text is inserted

Include (and customize) the CSS in src/styles/autocomplete.css on the page with your TinyMCE installation.

Support

You are welcome to use this plugin at your own risk. It is currently being maintained on GitHub where you can submit issues / feature requests.

License

Open Source Initiative OSI - The MIT License (MIT):Licensing

The MIT License (MIT) Copyright (c) 2012 Mijura Pty. Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

tinymce-autocomplete-plugin's People

Contributors

abrimo avatar santeriv avatar siberex avatar wnasich avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

tinymce-autocomplete-plugin's Issues

Auto Complete Plugin

where can i get the plugin.min.js file for this plugin. because when i tried this plugin it said plugin.min.js not found.

example configuration

Hi, it would be nice to have some example configuration
This should contain a test server which delivers a simple completion list.
And a more detailed instruction how and where to set some options would be nice as well.

I tried to configure and get it running in the wordpress editor, but I failed,
So I also would appreciate to have some instructions how to integrate in wordpress.

Suggestion list won't display

Hi, I cannot get the suggestion list to display. I have imported the javascript and stylesheet files.

It seems that the trigger character should be removed in getCurrentWords().
if (autocomplete_data.trigger == '') {
if (word.length >= autocomplete_data.minLength) {
retWord = word;
}
} else {
if (word.length > 0 && word.charAt(0).toString() == autocomplete_data.trigger) {
retWord = word;
}
}

Below is my config:

$('.tinymce').tinymce({
mode : "textareas",
theme : "advanced",
plugins : "autolink,lists,advimage,inlinepopups,paste,fullscreen,noneditable,autocomplete",
theme_advanced_buttons1 : "fontselect,fontsizeselect,formatselect,bold,italic,underline,strikethrough,bullist,numlist,outdent,indent,justifyleft,justifycenter,justifyright,justifyfull,forecolor,backcolor,link,code,pasteword,image,fullscreen",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "none",
autocomplete_options: "john,jane,william"
});

Add z-index to auto-list

So happy to have found this script, thank you for putting this on github! I placed this inside a WordPress editor and noticed that in Full Screen mode (a WP feature) the auto list doesn't display without an appropriate z-index value. For people integrating this into WordPress, you might want to set the z-index to something like z-index: 1000000; for full screen mode support.

Improve calculating the suggestion list's position

Hi. The current method for calculating the suggestion list's position does not work in IE. The problem is that editor.selection.getRng().getClientRects() always returns an empty array. I have just found out that it can be fixed by making a Range with positive length. Here is the new code:

    var range = ed.selection.getRng();
    var rangeStart = range.startOffset;
    range.setStart(range.startContainer, range.startOffset - 1);
    var rects = range.getClientRects();
    range.setStart(range.startContainer, rangeStart);
    if (rects.length > 0) {
      var rect = rects[0];
      textareaTop = rect.top + rect.height;
      textareaLeft = rect.left;
    }

Display Problem of Completion Box

As you can see on the image below. I've got a problem with the Completion box.
It is not displayed inside the box and the style is not correct.
I've got this problems in Firefox, Chrome and Internet Explorer (Windows 7).
I'm not sure wheter I configured the css correctly ( I just copied it into contents.css)
Please have a look at my configuration here http://pcai042.informatik.uni-leipzig.de/~swp11-6/tinymce.zip (tinymce 3.5.7 , configuration in examples folder)
Is my configuration wrong or does that problem occur in new version of tinymce?

problem

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.