1 var currentSideBar = 'div#title_side_bar';
2 function changeSideBar(enabled_bar) {
3 $(currentSideBar).hide();
4 currentSideBar = enabled_bar;
5 $(currentSideBar).fadeIn('slow');
10 $('div#editor_side_bar').hide();
11 $('div#tags_side_bar').hide();
13 $('#id_title').focus(function(){changeSideBar('div#title_side_bar')});
14 $('#editor').focus(function(){changeSideBar('div#editor_side_bar')});
15 $('#id_tags').focus(function(){changeSideBar('div#tags_side_bar')});
19 var $input = $('#id_title');
20 var $box = $('#ask-related-questions');
21 var template = $('#question-summary-template').html();
23 var results_cache = {};
25 function reload_suggestions_box(e) {
26 var relatedQuestionsDiv = $('#ask-related-questions');
27 var q = $input.val().replace(/^\s+|\s+$/g,"");
30 close_suggestions_box();
31 relatedQuestionsDiv.html('');
33 } else if(relatedQuestionsDiv[0].style.height == 0 || relatedQuestionsDiv[0].style.height == '0px') {
34 relatedQuestionsDiv.animate({'height':'150'}, 350);
37 if (results_cache[q] && results_cache[q] != '') {
38 relatedQuestionsDiv.html(results_cache[q]);
42 $.post(related_questions_url, {title: q}, function(data) {
44 var c = $input.val().replace(/^\s+|\s+$/g,"");
50 if(data.length == 0) {
51 relatedQuestionsDiv.html('<br /><br /><div align="center">No questions like this have been found.</div>');
56 for (var i = 0; i < data.length; i++) {
57 var item = template.replace(new RegExp('%URL%', 'g'), data[i].url)
58 .replace(new RegExp('%SCORE%', 'g'), data[i].score)
59 .replace(new RegExp('%TITLE%', 'g'), data[i].title)
60 .replace(new RegExp('%SUMMARY%', 'g'), data[i].summary);
66 results_cache[q] = html;
68 relatedQuestionsDiv.html(html);
75 function close_suggestions_box() {
76 $('#ask-related-questions').animate({'height':'0'},350, function() {
77 $('#ask-related-questions').html('');
81 $input.keyup(reload_suggestions_box);
82 $input.focus(reload_suggestions_box);
83 $input.blur(close_suggestions_box);
86 $input.keydown(focus_on_question);
87 function focus_on_question(e) {
88 var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
90 if(e.keyCode == 9 && is_chrome) {
91 $('#editor')[0].focus();