From 3087690d89ff994138a2563dc4763e868c3d52d7 Mon Sep 17 00:00:00 2001 From: rolux Date: Fri, 20 May 2011 08:19:55 +0200 Subject: [PATCH] allow limit for autocomplete menu length --- source/Ox.UI/js/Form/Ox.Input.js | 43 ++++++++++++++----------- source/Ox.UI/js/Video/Ox.VideoEditor.js | 1 + 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/source/Ox.UI/js/Form/Ox.Input.js b/source/Ox.UI/js/Form/Ox.Input.js index beced278..9b5f739a 100644 --- a/source/Ox.UI/js/Form/Ox.Input.js +++ b/source/Ox.UI/js/Form/Ox.Input.js @@ -69,6 +69,7 @@ Ox.Input = function(options, self) { autocompleteReplaceCorrect: false, autocompleteSelect: false, autocompleteSelectHighlight: false, + autocompleteSelectMax: 0, autocompleteSelectSubmit: false, autovalidate: null, changeOnKeypress: false, @@ -274,14 +275,15 @@ Ox.Input = function(options, self) { Ox.print('autocomplete', oldValue, oldCursor) if (self.options.value || self.options.autocompleteReplaceCorrect) { - if(Ox.isFunction(self.options.autocomplete)) { - if(self.options.key) { - self.options.autocomplete(self.options.key, - self.options.value, - autocompleteCallback) + if (Ox.isFunction(self.options.autocomplete)) { + if (self.options.key) { + self.options.autocomplete( + self.options.key, self.options.value, autocompleteCallback + ); } else { - self.options.autocomplete(self.options.value, - autocompleteCallback) + self.options.autocomplete( + self.options.value, autocompleteCallback + ); } } else { autocompleteCallback(autocompleteFunction(self.options.value)); @@ -334,17 +336,22 @@ Ox.Input = function(options, self) { self.oldCursor = cursor(); self.oldValue = self.options.value; self.$autocompleteMenu.options({ - items: $.map(values, function(v, i) { - if (value == v.toLowerCase()) { - selected = i; + items: Ox.map(values, function(v, i) { + var ret = null; + if ( + !self.options.autocompleteSelectMax || + i < self.options.autocompleteSelectMax + ) { + if (value == v.toLowerCase()) { + selected = i; + } + ret = { + id: v.toLowerCase().replace(/ /g, '_'), // fixme: need function to do lowercase, underscores etc? + title: self.options.autocompleteSelectHighlight ? + Ox.highlight(v, value, 'OxHighlight') : v + }; } - return { - id: v.toLowerCase().replace(/ /g, '_'), // fixme: need function to do lowercase, underscores etc? - title: self.options.autocompleteSelectHighlight ? v.replace( - new RegExp('(' + value + ')', 'ig'), - '$1' - ) : v - }; + return ret; }), selected: selected }).showMenu(); @@ -404,7 +411,7 @@ Ox.Input = function(options, self) { ); } } else if (Ox.isRegExp(self.options.autovalidate)) { - autovalidateCallback(autovalidateFunction(self.options.value)); + autovalidateCallback(autovalidateFunction(self.options.value)); } else { autovalidateTypeFunction(self.options.type, self.options.value); } diff --git a/source/Ox.UI/js/Video/Ox.VideoEditor.js b/source/Ox.UI/js/Video/Ox.VideoEditor.js index 23befced..79f23681 100644 --- a/source/Ox.UI/js/Video/Ox.VideoEditor.js +++ b/source/Ox.UI/js/Video/Ox.VideoEditor.js @@ -462,6 +462,7 @@ Ox.VideoEditor = function(options, self) { autocomplete: self.words, autocompleteSelect: true, autocompleteSelectHighlight: true, + autocompleteSelectMax: 10, autocompleteSelectSubmit: true, changeOnKeypress: true, placeholder: 'Find...',