From e94fc0a5d07653fb0c03e3d6f820ee8b5ee2e5f7 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Mon, 26 Nov 2012 22:06:33 -0300 Subject: recovered the full text search function --- askbot/media/js/live_search.js | 34 ++++++++++++++++++------------- askbot/media/js/utils.js | 12 ++++++----- askbot/templates/meta/bottom_scripts.html | 1 + 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/askbot/media/js/live_search.js b/askbot/media/js/live_search.js index 5dffb677..5f536844 100644 --- a/askbot/media/js/live_search.js +++ b/askbot/media/js/live_search.js @@ -745,6 +745,19 @@ FullTextSearch.prototype.makeKeyDownHandler = function() { }; }; +FullTextSearch.prototype.makeFormSubmitHandler = function() { + var me = this; + var baseUrl = me._baseUrl; + return function(evt) { + // if user clicks the button the s(h)e probably wants page reload, + // so provide that experience but first update the query string + me.updateQueryString(); + var searchUrl = me.getSearchUrl(); + evt.preventDefault(); + window.location.href = baseUrl + searchUrl; + }; +}; + FullTextSearch.prototype.decorate = function(element) { this._element = element;/* this is a bit artificial we don't use _element */ this._query = element; @@ -757,6 +770,10 @@ FullTextSearch.prototype.decorate = function(element) { element.focus(); }); this._element.after(toolTip.getElement()); + //below is called after getElement, b/c element must be defined + if (this._prevText !== '') { + toolTip.hide();//hide if search query is not empty + } this._toolTip = toolTip; var dropMenu = new SearchDropMenu(); @@ -765,11 +782,8 @@ FullTextSearch.prototype.decorate = function(element) { this._dropMenu = dropMenu; element.parent().after(this._dropMenu.getElement()); - var menuCloser = function(){ - dropMenu.reset(); - }; - $(element).click(function(e){ return false }); - $(document).click(menuCloser); + $(element).click(function(e) { return false }); + $(document).click(function() { dropMenu.reset(); }); //the tag search input is optional in askbot $('#ab-tag-search').parent().before( @@ -815,13 +829,5 @@ FullTextSearch.prototype.decorate = function(element) { this.activateTagSearchInput(); - var baseUrl = this._baseUrl; - var searchUrl = this.getSearchUrl(); - $("form#searchForm").submit(function(event) { - // if user clicks the button the s(h)e probably wants page reload, - // so provide that experience but first update the query string - event.preventDefault(); - me.updateQueryString(); - window.location.href = baseUrl + searchUrl; - }); + $("form#searchForm").submit(me.makeFormSubmitHandler()); }; diff --git a/askbot/media/js/utils.js b/askbot/media/js/utils.js index 6ea23566..4340c78b 100644 --- a/askbot/media/js/utils.js +++ b/askbot/media/js/utils.js @@ -128,15 +128,16 @@ var setupButtonEventHandlers = function(button, callback){ var putCursorAtEnd = function(element){ - var el = element.get()[0]; + var el = $(element).get()[0]; + var jEl = $(el); if (el.setSelectionRange){ - var len = element.val().length * 2; + var len = jEl.val().length * 2; el.setSelectionRange(len, len); } else{ - element.val(element.val()); + jEl.val(jEl.val()); } - element.scrollTop = 999999; + jEl.scrollTop(999999); }; var setCheckBoxesIn = function(selector, value){ @@ -213,7 +214,8 @@ QSutils.patch_query_string = function (query_string, patch, remove) { var mapping = {}; if(!remove) { - mapping[patch_split[0]] = patch_split[1]; // prepopulate the patched selector if it's not meant to be removed + // prepopulate the patched selector if it's not meant to be removed + mapping[patch_split[0]] = patch_split[1]; } for (var i = 0; i < params.length; i++) { diff --git a/askbot/templates/meta/bottom_scripts.html b/askbot/templates/meta/bottom_scripts.html index 24c2ba10..9d535a2b 100644 --- a/askbot/templates/meta/bottom_scripts.html +++ b/askbot/templates/meta/bottom_scripts.html @@ -67,6 +67,7 @@ if (searchInput) { searchInput.focus(); + putCursorAtEnd(searchInput); } {% if active_tab in ('questions', 'badges', 'ask') %} -- cgit v1.2.3-1-g7c22