[third] Don't move typeahead popups when the body scrolls.

Trac #1479

All our typeaheads use this, but I made it an option that must be enabled
explicitly since it is not default bootstrap behavior.

(imported from commit 97852dc407d1f6dbe46b5fdd2c56d3ed8c6718d2)
This commit is contained in:
Kevin Mehall
2013-08-21 11:37:54 -04:00
parent 834ff7d750
commit f944a8ed0e
3 changed files with 20 additions and 1 deletions

View File

@@ -214,6 +214,7 @@ exports.initialize = function () {
return stream_data.subscribed_streams(); return stream_data.subscribed_streams();
}, },
items: 3, items: 3,
fixed: true,
highlighter: function (item) { highlighter: function (item) {
var query = this.query; var query = this.query;
return typeahead_helper.highlight_query_in_phrase(query, item); return typeahead_helper.highlight_query_in_phrase(query, item);
@@ -232,6 +233,7 @@ exports.initialize = function () {
return exports.topics_seen_for(stream_name); return exports.topics_seen_for(stream_name);
}, },
items: 3, items: 3,
fixed: true,
highlighter: composebox_typeahead_highlighter, highlighter: composebox_typeahead_highlighter,
sorter: function (items) { sorter: function (items) {
var sorted = typeahead_helper.sorter(this.query, items, function (x){return x;}); var sorted = typeahead_helper.sorter(this.query, items, function (x){return x;});
@@ -246,6 +248,7 @@ exports.initialize = function () {
source: page_params.people_list, source: page_params.people_list,
items: 5, items: 5,
dropup: true, dropup: true,
fixed: true,
highlighter: function (item) { highlighter: function (item) {
var query = get_last_recipient_in_pm(this.query); var query = get_last_recipient_in_pm(this.query);
var item_formatted = typeahead_helper.render_person(item); var item_formatted = typeahead_helper.render_person(item);
@@ -339,6 +342,7 @@ exports.initialize = function () {
} }
}, },
dropup: true, dropup: true,
fixed: true,
matcher: function (item) { matcher: function (item) {
if (this.completing === 'emoji') { if (this.completing === 'emoji') {
return query_matches_emoji(this.token, item); return query_matches_emoji(this.token, item);

View File

@@ -52,6 +52,7 @@ exports.initialize = function () {
search_object = suggestions.lookup_table; search_object = suggestions.lookup_table;
return suggestions.strings; return suggestions.strings;
}, },
fixed: true,
items: 30, items: 30,
helpOnEmptyStrings: true, helpOnEmptyStrings: true,
naturalSearch: true, naturalSearch: true,

View File

@@ -1826,6 +1826,11 @@
this.source = this.options.source this.source = this.options.source
this.shown = false this.shown = false
this.dropup = this.options.dropup this.dropup = this.options.dropup
this.fixed = this.options.fixed || false;
if (this.fixed) {
this.$menu.css('position', 'fixed');
}
// The naturalSearch option causes arrow keys to immediately // The naturalSearch option causes arrow keys to immediately
// update the search box with the underlying values from the // update the search box with the underlying values from the
// search suggestions. // search suggestions.
@@ -1854,7 +1859,16 @@
} }
, show: function () { , show: function () {
var pos = $.extend({}, this.$element.offset(), { var pos;
if (this.fixed) {
// Relative to screen instead of to page
pos = this.$element[0].getBoundingClientRect();
} else {
pos = this.$element.offset();
}
pos = $.extend({}, pos, {
height: this.$element[0].offsetHeight height: this.$element[0].offsetHeight
}) })