Skip to content

Commit

Permalink
Added option to configure autocomplete widget. Closes ivirabyan#38
Browse files Browse the repository at this point in the history
  • Loading branch information
ivirabyan committed Jul 16, 2015
1 parent 3cd58bb commit c911f76
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,16 @@ Don't use textarea value directly, because it contains special characters, used
Data source for the autocomplete. See [jQuery Autocomplete API](http://api.jqueryui.com/autocomplete/#option-source) for available values.

Source data is an array of objects with `uid` and `value` properties: `[{uid: '123', value: 'Alex'}, ...]`. If you want to display an icon in dropdown list, you can add an `image` property to objects in the array.

#### delay
Delay for autocomplete to start searching. Default value is 0. More info in [jQuery Autocomplete API](http://api.jqueryui.com/autocomplete/#option-delay)

#### trigger
Char which trigger autocomplete, default value is '@'

#### autoFocus
If this is true, first item is automatically focused in the dropdown. Default is true.

#### widget
Name of the autocomplete widget to use. May be useful when you want to somehow customize appearance of autocomplete widget, for example add headers to items list. You must inherit from widget, used internally (`ui.areacomplete` when you use textarea, and `ui.editablecomplete` when you use div with `contenteditable=true`).

#### autocomplete
Options to pass to jQuery Autocomplete widget. Default is `{delay: 0, autoFocus: true}`.

## Methods

#### getValue()
Expand Down
34 changes: 19 additions & 15 deletions jquery.mentions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ class MentionsInput extends MentionsBase

constructor: (@input, options) ->
@settings =
delay: 0
trigger: '@',
autoFocus: true,
widget: 'areacomplete'
widget: 'areacomplete',
autocomplete: {
autoFocus: true,
delay: 0
}

super @input, options

Expand All @@ -181,14 +183,13 @@ class MentionsInput extends MentionsBase
@highlighter.removeClass('focus')
)

@autocomplete = @input[@options.widget](
options = $.extend(
matcher: @_getMatcher(),
select: @_onSelect,
source: @options.source,
delay: @options.delay,
appendTo: @input.parent(),
autoFocus: @options.autoFocus
)
appendTo: @input.parent()
, @options.autocomplete)
@autocomplete = @input[@options.widget](options)

@_setValue(@input.val())
@_initEvents()
Expand Down Expand Up @@ -353,21 +354,24 @@ class MentionsContenteditable extends MentionsBase

constructor: (@input, options) ->
@settings =
delay: 0
trigger: '@',
autoFocus: true,
widget: 'editablecomplete'
widget: 'editablecomplete',
autocomplete: {
autoFocus: true,
delay: 0
}

super @input, options
@autocomplete = @input[@options.widget](

options = $.extend(
matcher: @_getMatcher(),
suffix: @marker,
select: @_onSelect,
source: @options.source,
delay: @options.delay,
autoFocus: @options.autoFocus,
showAtCaret: @options.showAtCaret
)
, @options.autocomplete)
@autocomplete = @input[@options.widget](options)

@_setValue(@input.html())
@_initEvents()

Expand Down
32 changes: 17 additions & 15 deletions jquery.mentions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c911f76

Please sign in to comment.