From 0f2dc303750f3ddd88e911b0e4af9a497774036d Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Wed, 29 May 2013 04:38:51 -0400 Subject: fixed the folded editor option on the ask page and allowed to go to a specific question by hitting enter when selection in the dropdown is made --- askbot/media/js/live_search.js | 42 +++++++++++++++++++++++++++++++--- askbot/templates/widgets/ask_form.html | 1 + 2 files changed, 40 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; diff --git a/askbot/templates/widgets/ask_form.html b/askbot/templates/widgets/ask_form.html index 3ddb07dd..1d5029f1 100644 --- a/askbot/templates/widgets/ask_form.html +++ b/askbot/templates/widgets/ask_form.html @@ -13,6 +13,7 @@ {% set editor_is_folded = ( + settings.QUESTION_BODY_EDITOR_MODE == 'folded' and settings.MIN_QUESTION_BODY_LENGTH == 0 and form.text.value()|is_empty_editor_value() ) -- cgit v1.2.3-1-g7c22