|
21 | 21 | allowRepeat : false, //Allow repeat mentions
|
22 | 22 | showAvatars : true, //Show the avatars
|
23 | 23 | elastic : true, //Grow the textarea automatically
|
| 24 | + onCaret : false, |
24 | 25 | classes : {
|
25 | 26 | autoCompleteItemActive : "active" //Classes to apply in each item
|
26 | 27 | },
|
|
221 | 222 | function getInputBoxValue() {
|
222 | 223 | return $.trim(elmInputBox.val());
|
223 | 224 | }
|
| 225 | + |
| 226 | + // This is taken straight from live (as of Sep 2012) GitHub code. The |
| 227 | + // technique is known around the web. Just google it. Github's is quite |
| 228 | + // succint though. NOTE: relies on selectionEnd, which as far as IE is concerned, |
| 229 | + // it'll only work on 9+. Good news is nothing will happen if the browser |
| 230 | + // doesn't support it. |
| 231 | + function textareaSelectionPosition($el) { |
| 232 | + var a, b, c, d, e, f, g, h, i, j, k; |
| 233 | + if (!(i = $el[0])) return; |
| 234 | + if (!$(i).is("textarea")) return; |
| 235 | + if (i.selectionEnd == null) return; |
| 236 | + g = { |
| 237 | + position: "absolute", |
| 238 | + overflow: "auto", |
| 239 | + whiteSpace: "pre-wrap", |
| 240 | + wordWrap: "break-word", |
| 241 | + boxSizing: "content-box", |
| 242 | + top: 0, |
| 243 | + left: -9999 |
| 244 | + }, h = ["boxSizing", "fontFamily", "fontSize", "fontStyle", "fontVariant", "fontWeight", "height", "letterSpacing", "lineHeight", "paddingBottom", "paddingLeft", "paddingRight", "paddingTop", "textDecoration", "textIndent", "textTransform", "width", "word-spacing"]; |
| 245 | + for (j = 0, k = h.length; j < k; j++) e = h[j], g[e] = $(i).css(e); |
| 246 | + return c = document.createElement("div"), $(c).css(g), $(i).after(c), b = document.createTextNode(i.value.substring(0, i.selectionEnd)), a = document.createTextNode(i.value.substring(i.selectionEnd)), d = document.createElement("span"), d.innerHTML = " ", c.appendChild(b), c.appendChild(d), c.appendChild(a), c.scrollTop = i.scrollTop, f = $(d).position(), $(c).remove(), f |
| 247 | + } |
224 | 248 |
|
225 | 249 | //Scrolls back to the input after autocomplete if the window has scrolled past the input
|
226 | 250 | function scrollToInput() {
|
|
384 | 408 | 'id' : utils.htmlEncode(item.id),
|
385 | 409 | 'display' : utils.htmlEncode(item.name),
|
386 | 410 | 'type' : utils.htmlEncode(item.type),
|
387 |
| - 'content' : utils.highlightTerm(utils.htmlEncode((item.name)), query) |
| 411 | + 'content' : utils.highlightTerm(utils.htmlEncode((item.display ? item.display : item.name)), query) |
388 | 412 | })).attr('data-uid', itemUid); //Inserts the new item to list
|
389 | 413 |
|
390 | 414 | //If the index is 0
|
|
408 | 432 | });
|
409 | 433 |
|
410 | 434 | elmAutocompleteList.show(); //Shows the elmAutocompleteList div
|
411 |
| - elmDropDownList.show(); //Shows the elmDropDownList |
| 435 | + if (settings.onCaret) { |
| 436 | + positionAutocomplete(elmAutocompleteList, elmInputBox); |
| 437 | + } |
| 438 | + elmDropDownList.show(); //Shows the elmDropDownList |
412 | 439 | }
|
413 | 440 |
|
414 | 441 | //Search into data list passed as parameter
|
|
423 | 450 | hideAutoComplete(); //Hide the autocompletelist
|
424 | 451 | }
|
425 | 452 | }
|
| 453 | + |
| 454 | + function positionAutocomplete(elmAutocompleteList, elmInputBox) { |
| 455 | + var position = textareaSelectionPosition(elmInputBox), |
| 456 | + lineHeight = parseInt(elmInputBox.css('line-height'), 10) || 18; |
| 457 | + elmAutocompleteList.css('width', '15em'); // Sort of a guess |
| 458 | + elmAutocompleteList.css('left', position.left); |
| 459 | + elmAutocompleteList.css('top', lineHeight + position.top); |
| 460 | + } |
426 | 461 |
|
427 | 462 | //Resets the text area
|
428 | 463 | function resetInput() {
|
|
0 commit comments