Skip to content

Commit 244e1e5

Browse files
author
Jake Harding
committed
0.9.3
1 parent 91d2b25 commit 244e1e5

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

component.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typeahead.js",
3-
"version": "0.9.2",
3+
"version": "0.9.3",
44
"main": [
55
"dist/typeahead.js"
66
],

dist/typeahead.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*!
2-
* typeahead.js 0.9.2
2+
* typeahead.js 0.9.3
33
* https://github.com/twitter/typeahead
44
* Copyright 2013 Twitter, Inc. and other contributors; Licensed MIT
55
*/
66

77
(function($) {
8-
var VERSION = "0.9.2";
8+
var VERSION = "0.9.3";
99
var utils = {
1010
isMsie: function() {
1111
var match = /(msie) ([\w.]+)/i.exec(navigator.userAgent);
@@ -190,6 +190,8 @@
190190
var ls, methods;
191191
try {
192192
ls = window.localStorage;
193+
ls.setItem("~~~", "!");
194+
ls.removeItem("~~~");
193195
} catch (err) {
194196
ls = null;
195197
}
@@ -744,11 +746,20 @@
744746
nextIndex = $suggestions.length - 1;
745747
}
746748
$underCursor = $suggestions.eq(nextIndex).addClass("tt-is-under-cursor");
749+
this._ensureVisibility($underCursor);
747750
this.trigger("cursorMoved", extractSuggestion($underCursor));
748751
},
749752
_getSuggestions: function() {
750753
return this.$menu.find(".tt-suggestions > .tt-suggestion");
751754
},
755+
_ensureVisibility: function($el) {
756+
var menuHeight = this.$menu.height() + parseInt(this.$menu.css("paddingTop"), 10) + parseInt(this.$menu.css("paddingBottom"), 10), menuScrollTop = this.$menu.scrollTop(), elTop = $el.position().top, elBottom = elTop + $el.outerHeight(true);
757+
if (elTop < 0) {
758+
this.$menu.scrollTop(menuScrollTop + elTop);
759+
} else if (menuHeight < elBottom) {
760+
this.$menu.scrollTop(menuScrollTop + (elBottom - menuHeight));
761+
}
762+
},
752763
destroy: function() {
753764
this.$menu.off(".tt");
754765
this.$menu = null;
@@ -764,6 +775,7 @@
764775
close: function() {
765776
if (this.isOpen) {
766777
this.isOpen = false;
778+
this.isMouseOverDropdown = false;
767779
this._hide();
768780
this.$menu.find(".tt-suggestions > .tt-suggestion").removeClass("tt-is-under-cursor");
769781
this.trigger("closed");
@@ -812,6 +824,7 @@
812824
elBuilder = document.createElement("div");
813825
fragment = document.createDocumentFragment();
814826
utils.each(suggestions, function(i, suggestion) {
827+
suggestion.dataset = dataset.name;
815828
compiledHtml = dataset.template(suggestion.datum);
816829
elBuilder.innerHTML = wrapper.replace("%body", compiledHtml);
817830
$el = $(elBuilder.firstChild).css(css.suggestion).data("suggestion", suggestion);
@@ -901,7 +914,7 @@
901914
this.inputView = new InputView({
902915
input: $input,
903916
hint: $hint
904-
}).on("focused", this._openDropdown).on("blured", this._closeDropdown).on("blured", this._setInputValueToQuery).on("enterKeyed", this._handleSelection).on("queryChanged", this._clearHint).on("queryChanged", this._clearSuggestions).on("queryChanged", this._getSuggestions).on("whitespaceChanged", this._updateHint).on("queryChanged whitespaceChanged", this._openDropdown).on("queryChanged whitespaceChanged", this._setLanguageDirection).on("escKeyed", this._closeDropdown).on("escKeyed", this._setInputValueToQuery).on("tabKeyed upKeyed downKeyed", this._managePreventDefault).on("upKeyed downKeyed", this._moveDropdownCursor).on("upKeyed downKeyed", this._openDropdown).on("tabKeyed leftKeyed rightKeyed", this._autocomplete);
917+
}).on("focused", this._openDropdown).on("blured", this._closeDropdown).on("blured", this._setInputValueToQuery).on("enterKeyed tabKeyed", this._handleSelection).on("queryChanged", this._clearHint).on("queryChanged", this._clearSuggestions).on("queryChanged", this._getSuggestions).on("whitespaceChanged", this._updateHint).on("queryChanged whitespaceChanged", this._openDropdown).on("queryChanged whitespaceChanged", this._setLanguageDirection).on("escKeyed", this._closeDropdown).on("escKeyed", this._setInputValueToQuery).on("tabKeyed upKeyed downKeyed", this._managePreventDefault).on("upKeyed downKeyed", this._moveDropdownCursor).on("upKeyed downKeyed", this._openDropdown).on("tabKeyed leftKeyed rightKeyed", this._autocomplete);
905918
}
906919
utils.mixin(TypeaheadView.prototype, EventTarget, {
907920
_managePreventDefault: function(e) {
@@ -970,7 +983,7 @@
970983
this.inputView.setInputValue(suggestion.value);
971984
byClick ? this.inputView.focus() : e.data.preventDefault();
972985
byClick && utils.isMsie() ? utils.defer(this.dropdownView.close) : this.dropdownView.close();
973-
this.eventBus.trigger("selected", suggestion.datum);
986+
this.eventBus.trigger("selected", suggestion.datum, suggestion.dataset);
974987
}
975988
},
976989
_getSuggestions: function() {
@@ -1000,7 +1013,7 @@
10001013
if (hint !== "" && query !== hint) {
10011014
suggestion = this.dropdownView.getFirstSuggestion();
10021015
this.inputView.setInputValue(suggestion.value);
1003-
this.eventBus.trigger("autocompleted", suggestion.datum);
1016+
this.eventBus.trigger("autocompleted", suggestion.datum, suggestion.dataset);
10041017
}
10051018
},
10061019
_propagateEvent: function(e) {

0 commit comments

Comments
 (0)