From 45d3d18dd931535f6dc61d946874a4529ed64564 Mon Sep 17 00:00:00 2001 From: worldofsites Date: Wed, 26 Apr 2017 10:23:55 +0700 Subject: [PATCH 1/3] Update search in select options Updating search behavior in select options. --- src/jquery.selectric.js | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/jquery.selectric.js b/src/jquery.selectric.js index e500fda..332ef04 100644 --- a/src/jquery.selectric.js +++ b/src/jquery.selectric.js @@ -624,14 +624,39 @@ _this.elements.input.val(''); }, _this.options.keySearchTimeout); - if ( val.length ) { - // Search in select options - $.each(_this.items, function(i, elm) { - if ( !elm.disabled && searchRegExp.test(elm.text) || searchRegExp.test(elm.slug) ) { - _this.highlight(i); - return; - } - }); + if (val.length) { + var suitableIndexes = []; + $.each(_this.items, function (i, elm) { + if (!elm.disabled && (searchRegExp.test(elm.text) || searchRegExp.test(elm.slug))) { + suitableIndexes.push(i); + } + }); + + var alreadyHighlighted = $.inArray(_this.state.highlightedIdx, suitableIndexes) > -1; + + var lastItem = suitableIndexes.slice(-1).pop(); + + $.each(suitableIndexes, function (i, elm) { + if (alreadyHighlighted) { + if (elm === _this.state.highlightedIdx) { + //do nothing + } else if (elm < _this.state.highlightedIdx) { + if (lastItem && lastItem === _this.state.highlightedIdx) { + _this.highlight(elm); + return false; + } else { + //do nothing + } + } else if (elm > _this.state.highlightedIdx) { + _this.highlight(elm); + return false; + } + + } else { + _this.highlight(elm); + return false; + } + }); } }); } From 0bb47f6c766b7d6a767854db790eba23bac0043d Mon Sep 17 00:00:00 2001 From: worldofsites Date: Wed, 26 Apr 2017 10:52:48 +0700 Subject: [PATCH 2/3] Add ability to search for selects with optgroups Add ability to search for selects with optgroups --- src/jquery.selectric.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/jquery.selectric.js b/src/jquery.selectric.js index 332ef04..9093c89 100644 --- a/src/jquery.selectric.js +++ b/src/jquery.selectric.js @@ -627,8 +627,16 @@ if (val.length) { var suitableIndexes = []; $.each(_this.items, function (i, elm) { - if (!elm.disabled && (searchRegExp.test(elm.text) || searchRegExp.test(elm.slug))) { - suitableIndexes.push(i); + if (elm.element.is('optgroup')) { + $.each(elm.items, function (k, subElm) { + if (!subElm.disabled && (searchRegExp.test(subElm.text) || searchRegExp.test(subElm.slug))) { + suitableIndexes.push(subElm.index); + } + }); + } else { + if (!elm.disabled && (searchRegExp.test(elm.text) || searchRegExp.test(elm.slug))) { + suitableIndexes.push(elm.index); + } } }); From 0a0da704c9370ef9527ef8f0eb8574e4d2aaa8c6 Mon Sep 17 00:00:00 2001 From: worldofsites Date: Fri, 5 May 2017 18:12:06 +0700 Subject: [PATCH 3/3] updates for travis CI build failed rows --- src/jquery.selectric.js | 71 ++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/src/jquery.selectric.js b/src/jquery.selectric.js index 9093c89..e0c3753 100644 --- a/src/jquery.selectric.js +++ b/src/jquery.selectric.js @@ -625,46 +625,37 @@ }, _this.options.keySearchTimeout); if (val.length) { - var suitableIndexes = []; - $.each(_this.items, function (i, elm) { - if (elm.element.is('optgroup')) { - $.each(elm.items, function (k, subElm) { - if (!subElm.disabled && (searchRegExp.test(subElm.text) || searchRegExp.test(subElm.slug))) { - suitableIndexes.push(subElm.index); - } - }); - } else { - if (!elm.disabled && (searchRegExp.test(elm.text) || searchRegExp.test(elm.slug))) { - suitableIndexes.push(elm.index); - } - } - }); - - var alreadyHighlighted = $.inArray(_this.state.highlightedIdx, suitableIndexes) > -1; - - var lastItem = suitableIndexes.slice(-1).pop(); - - $.each(suitableIndexes, function (i, elm) { - if (alreadyHighlighted) { - if (elm === _this.state.highlightedIdx) { - //do nothing - } else if (elm < _this.state.highlightedIdx) { - if (lastItem && lastItem === _this.state.highlightedIdx) { - _this.highlight(elm); - return false; - } else { - //do nothing - } - } else if (elm > _this.state.highlightedIdx) { - _this.highlight(elm); - return false; - } - - } else { - _this.highlight(elm); - return false; - } - }); + var suitableIndexes = []; + $.each(_this.items, function (i, elm) { + if (elm.element.is('optgroup')) { + $.each(elm.items, function (k, subElm) { + if (!subElm.disabled && (searchRegExp.test(subElm.text) || searchRegExp.test(subElm.slug))) { + suitableIndexes.push(subElm.index); + } + }); + } else if (!elm.disabled && (searchRegExp.test(elm.text) || searchRegExp.test(elm.slug))) { + suitableIndexes.push(elm.index); + } + }); + var alreadyHighlighted = $.inArray(_this.state.highlightedIdx, suitableIndexes) > -1; + var lastItem = suitableIndexes.slice(-1).pop(); + $.each(suitableIndexes, function (i, elm) { + if (alreadyHighlighted) { + if (elm < _this.state.highlightedIdx) { + if (lastItem && lastItem === _this.state.highlightedIdx) { + _this.highlight(elm); + return false; + } + } else if (elm > _this.state.highlightedIdx) { + _this.highlight(elm); + return false; + } + + } else { + _this.highlight(elm); + return false; + } + }); } }); }