diff --git a/js/redactor-plugins.js b/js/redactor-plugins.js index 929a9feafb209605657553253f9f679a65c23ed0..182aa0ba651f855ab4297d7516290129b2832bda 100644 --- a/js/redactor-plugins.js +++ b/js/redactor-plugins.js @@ -1691,7 +1691,9 @@ RedactorPlugins.contexttypeahead = function() { return (this.query.match(/\./g) || []).length == (item.match(/\./g) || []).length; }, - onselect: this.contexttypeahead.select.bind(this) + onselect: this.contexttypeahead.select.bind(this), + scroll: true, + items: 100 }); } diff --git a/scp/css/typeahead.css b/scp/css/typeahead.css index 03f5091d9a218baa337c0707c9f765120981d949..2e4e4d6ccd71853ecbf21973f302272476fe8dc3 100644 --- a/scp/css/typeahead.css +++ b/scp/css/typeahead.css @@ -32,6 +32,12 @@ right: 0; left: auto; } +.dropdown-menu.scroll { + max-height: 180px; + height: auto; + overflow-y: auto; + padding: 0; +} .dropdown-menu .divider { height: 1px; margin: 8px 1px; diff --git a/scp/js/bootstrap-typeahead.js b/scp/js/bootstrap-typeahead.js index 2bdf1a2227a6a881fe7dff4c22a6accf96d7d338..6c8238ad132a24178d565420083d6ccd0cd27cff 100644 --- a/scp/js/bootstrap-typeahead.js +++ b/scp/js/bootstrap-typeahead.js @@ -28,6 +28,8 @@ this.sorter = this.options.sorter || this.sorter this.highlighter = this.options.highlighter || this.highlighter this.$menu = $(this.options.menu).appendTo('body') + if (this.options.scroll) + this.$menu.addClass('scroll'); this.source = this.options.source this.onselect = this.options.onselect this.strings = true @@ -174,6 +176,16 @@ return this } + , adjustScroll: function(next) { + var top = this.$menu.scrollTop(), + bottom = top + this.$menu.height(), + pos = next.position(); + if (pos.top < 0) + this.$menu.scrollTop(top + pos.top - 10); + else if (next.height() + top + pos.top > bottom) + this.$menu.scrollTop(top + pos.top - this.$menu.height() + next.height() + 10); + } + , next: function (event) { var active = this.$menu.find('.active').removeClass('active') , next = active.next() @@ -183,6 +195,10 @@ } next.addClass('active') + + if (this.options.scroll) { + this.adjustScroll(next); + } } , prev: function (event) { @@ -194,6 +210,10 @@ } prev.addClass('active') + + if (this.options.scroll) { + this.adjustScroll(prev); + } } , listen: function () { @@ -315,6 +335,7 @@ , property: 'value' , render: 'info' , minLength: 1 + , scroll: false } $.fn.typeahead.Constructor = Typeahead