diff options
Diffstat (limited to 'askbot/media/js')
-rw-r--r-- | askbot/media/js/live_search.js | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/askbot/media/js/live_search.js b/askbot/media/js/live_search.js index b812070c..2cb62b2b 100644 --- a/askbot/media/js/live_search.js +++ b/askbot/media/js/live_search.js @@ -14,6 +14,14 @@ SearchDropMenu.prototype.setAskHandler = function(handler) { this._askHandler = handler; }; +SearchDropMenu.prototype.setSearchWidget = function(widget) { + this._searchWidget = widget; +}; + +SearchDropMenu.prototype.getSearchWidget = function() { + return this._searchWidget; +}; + SearchDropMenu.prototype.setAskButtonEnabled = function(isEnabled) { this._askButtonEnabled = isEnabled; }; @@ -42,6 +50,11 @@ SearchDropMenu.prototype.render = function() { } }; +SearchDropMenu.prototype.clearSelectedItem = function() { + this._selectedItemIndex = 0; + this._resultsList.find('li').removeClass('selected'); +} + /** * @param {number} idx position of item starting from 1 for the topmost * Selects item inentified by position. @@ -126,7 +139,17 @@ SearchDropMenu.prototype.makeKeyHandler = function() { return false; } } - me.selectItem(curItem); + + var widget = me.getSearchWidget(); + if (curItem === 0) { + //activate key handlers on input box + widget.setFullTextSearchEnabled(true); + me.clearSelectedItem(); + } else { + //deactivate key handlers on input box + widget.setFullTextSearchEnabled(false); + me.selectItem(curItem); + } return false } }; @@ -772,6 +795,14 @@ FullTextSearch.prototype.updateToolTip = function() { } }; +FullTextSearch.prototype.setFullTextSearchEnabled = function(enabled) { + this._fullTextSearchEnabled = enabled; +}; + +FullTextSearch.prototype.getFullTextSearchEnabled = function() { + return this._fullTextSearchEnabled; +}; + /** * keydown handler operates on the tooltip and the X button * also opens and closes drop menu according to the min search word threshold @@ -793,8 +824,12 @@ FullTextSearch.prototype.makeKeyDownHandler = function() { return false; } } else if (keyCode === 13) { - formSubmitHandler(e); - return false; + if (me.getFullTextSearchEnabled()) { + formSubmitHandler(e); + return false; + } else { + return true; + } } var query = me.getSearchQuery(); @@ -856,6 +891,7 @@ FullTextSearch.prototype.decorate = function(element) { this._toolTip = toolTip; var dropMenu = new SearchDropMenu(); + dropMenu.setSearchWidget(this); dropMenu.setAskHandler(this.makeAskHandler()); dropMenu.setAskButtonEnabled(this._askButtonEnabled); this._dropMenu = dropMenu; |