From: qw3rty Date: Tue, 13 Jul 2010 17:12:01 +0000 (+0000) Subject: OSQA-302 X-Git-Tag: live~609 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/268dcae115051f8d5fe9091d956a3f98b4b47e85 OSQA-302 Related questions block disappear when the user is not in the title field. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@525 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/skins/default/media/js/osqa.ask.js b/forum/skins/default/media/js/osqa.ask.js index 36da8aa..4bf05be 100644 --- a/forum/skins/default/media/js/osqa.ask.js +++ b/forum/skins/default/media/js/osqa.ask.js @@ -5,6 +5,7 @@ function changeSideBar(enabled_bar) { $(currentSideBar).fadeIn('slow'); } + $(function () { $('div#editor_side_bar').hide(); $('div#tags_side_bar').hide(); @@ -22,15 +23,19 @@ $(function() { var results_cache = {}; function reload_suggestions_box(e) { + var relatedQuestionsDiv = $('#ask-related-questions'); var q = $input.val().replace(/^\s+|\s+$/g,""); - if (q.length == 0) { - $('#ask-related-questions').html(''); + if(q.length == 0) { + close_suggestions_box(); + relatedQuestionsDiv.html(''); return false; + } else if(relatedQuestionsDiv[0].style.height == 0 || relatedQuestionsDiv[0].style.height == '0px') { + relatedQuestionsDiv.animate({'height':'150'}, 350); } if (results_cache[q] && results_cache[q] != '') { - $('#ask-related-questions').html(results_cache[q]); + relatedQuestionsDiv.html(results_cache[q]); return false; } @@ -42,6 +47,11 @@ $(function() { return; } + if(data.length == 0) { + relatedQuestionsDiv.html('

No questions like this have been found.
'); + return; + } + var html = ''; for (var i = 0; i < data.length; i++) { var item = template.replace(new RegExp('%URL%', 'g'), data[i].url) @@ -55,12 +65,30 @@ $(function() { results_cache[q] = html; - $('#ask-related-questions').html(html); + relatedQuestionsDiv.html(html); } }, 'json'); return false; } + function close_suggestions_box() { + $('#ask-related-questions').animate({'height':'0'},350, function() { + $('#ask-related-questions').html(''); + }); + } + $input.keyup(reload_suggestions_box); + $input.focus(reload_suggestions_box); + $input.blur(close_suggestions_box); + + // for chrome + $input.keydown(focus_on_question); + function focus_on_question(e) { + var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1; + + if(e.keyCode == 9 && is_chrome) { + $('#editor')[0].focus(); + } + } }); \ No newline at end of file