1 var currentSideBar = 'div#title_side_bar';
2 function changeSideBar(enabled_bar) {
3 if (enabled_bar != currentSideBar) {
4 $(currentSideBar).hide();
5 currentSideBar = enabled_bar;
6 $(currentSideBar).fadeIn('slow');
12 $('div#editor_side_bar').hide();
13 $('div#tags_side_bar').hide();
15 $('#id_title').focus(function(){changeSideBar('div#title_side_bar')});
16 $('#editor').focus(function(){changeSideBar('div#editor_side_bar')});
17 $('#id_tags').focus(function(){changeSideBar('div#tags_side_bar')});
21 var $input = $('#id_title');
22 var $box = $('#ask-related-questions');
23 var template = $('#question-summary-template').html();
24 var $editor = $('#editor');
26 var results_cache = {};
28 function reload_suggestions_box(e) {
29 var relatedQuestionsDiv = $('#ask-related-questions');
30 var q = $input.val().replace(/^\s+|\s+$/g,"");
33 close_suggestions_box();
34 relatedQuestionsDiv.html('');
36 } else if(relatedQuestionsDiv[0].style.height == 0 || relatedQuestionsDiv[0].style.height == '0px') {
37 relatedQuestionsDiv.animate({'height':'150'}, 350);
40 if (results_cache[q] && results_cache[q] != '') {
41 relatedQuestionsDiv.html(results_cache[q]);
45 $.post(related_questions_url, {title: q}, function(data) {
47 var c = $input.val().replace(/^\s+|\s+$/g,"");
53 if(data.length == 0) {
54 relatedQuestionsDiv.html('<br /><br /><div align="center">No questions like this have been found.</div>');
59 for (var i = 0; i < data.length; i++) {
60 var item = template.replace(new RegExp('%URL%', 'g'), data[i].url)
61 .replace(new RegExp('%SCORE%', 'g'), data[i].score)
62 .replace(new RegExp('%TITLE%', 'g'), data[i].title)
63 .replace(new RegExp('%SUMMARY%', 'g'), data[i].summary);
69 results_cache[q] = html;
71 relatedQuestionsDiv.html(html);
78 function close_suggestions_box() {
79 $('#ask-related-questions').animate({'height':'0'},350, function() {
80 $('#ask-related-questions').html('');
84 $input.keyup(reload_suggestions_box);
85 $input.focus(reload_suggestions_box);
87 $editor.change(function() {
88 if ($editor.html().length > 10) {
89 close_suggestions_box();
96 $input.keydown(focus_on_question);
97 function focus_on_question(e) {
98 var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
100 if(e.keyCode == 9 && is_chrome) {
101 $('#editor')[0].focus();