From 21d24a087cf4ee3ea4a01923514cbe47839ce6c1 Mon Sep 17 00:00:00 2001 From: Jack Lukic Date: Sun, 15 May 2016 13:56:21 -0400 Subject: [PATCH] #3856 #3870 - Fixed issue where onSelect event would not prevent bubbled close event on blur. --- RELEASE-NOTES.md | 1 + src/definitions/modules/search.js | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index a8c3c93ec..27767f0b3 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -36,6 +36,7 @@ - **Form Validation** - Revalidating a field `on: blur` could cause fields not yet interacted with to be validated #3606 - **Rail** - Fixed incorrect width for `close rail` and `very close rail` caused by variable addition with mixed units `px` + `em` #3835 - **Search** - A previous unfinished XHR query aborting would cause the next query to fail #2779 +- **Search** - Fixed an issue where `onResult` returning `false` would not prevent the search menu from hiding. Clicking on an empty results message will also no longer close the search results. #3856 #3870 - **Video** - Fixed issue with `change` behavior not working properly when correctly to change videos. **Bugs** diff --git a/src/definitions/modules/search.js b/src/definitions/modules/search.js index c33d772cd..775cd2183 100644 --- a/src/definitions/modules/search.js +++ b/src/definitions/modules/search.js @@ -61,6 +61,8 @@ $.fn.search = function(parameters) { element = this, instance = $module.data(moduleNamespace), + disabledBubbled = false, + module ; @@ -168,8 +170,13 @@ $.fn.search = function(parameters) { if(module.resultsClicked) { module.debug('Determining if user action caused search to close'); $module - .one('click', selector.results, function(event) { - if( !module.is.animating() && !module.is.hidden() ) { + .one('click.close' + eventNamespace, selector.results, function(event) { + if(module.is.inMessage(event) || disabledBubbled) { + $prompt.focus(); + return; + } + disabledBubbled = false; + if( !module.is.animating() && !module.is.hidden()) { callback(); } }) @@ -209,6 +216,7 @@ $.fn.search = function(parameters) { if( $.isFunction(settings.onSelect) ) { if(settings.onSelect.call(element, result, results) === false) { module.debug('Custom onSelect callback cancelled default select action'); + disabledBubbled = true; return; } } @@ -356,6 +364,9 @@ $.fn.search = function(parameters) { hidden: function() { return $results.hasClass(className.hidden); }, + inMessage: function(event) { + return (event.target && $(event.target).closest(selector.message).length > 0); + }, empty: function() { return ($results.html() === ''); }, @@ -1223,6 +1234,7 @@ $.fn.search.settings = { prompt : '.prompt', searchButton : '.search.button', results : '.results', + message : '.results > .message', category : '.category', result : '.result', title : '.title, .name'