##// END OF EJS Templates
Setting focus to text area after reply.
Pavel Ryapolov -
r107:6af33f1b default
parent child Browse files
Show More
@@ -1,94 +1,96 b''
1 1 var image_mode = 0;
2 2 var normal_dom, table_dom;
3 3
4 4 function add_panel(after)
5 5 {
6 6 var nav_top = $(after);
7 7 if (nav_top.length === 0) return;
8 8 nav_top = nav_top[0];
9 9
10 10 var tab_bar = $('<div class="image-mode-tab" role="radiogroup" aria-label="Image mode"></div>');
11 11
12 12 var tab;
13 13
14 14 tab = $('<input type="radio" class="image-mode-normal" name="image-mode" value="0" checked="checked"/>');
15 15 tab.on("change", tab_handler);
16 16 tab = $('<label>Normal</label>').prepend(tab);
17 17 tab_bar.append(tab);
18 18
19 19 tab = $('<input type="radio" class="image-mode-table" name="image-mode" value="1"/>');
20 20 tab.on("change", tab_handler);
21 21 tab = $('<label>Gallery</label>').prepend(tab);
22 22 tab_bar.append(tab);
23 23
24 24 tab_bar.insertAfter(nav_top);
25 25 }
26 26
27 27 function tab_handler(ev)
28 28 {
29 29 var current_el = $(this);
30 30
31 31 if (!current_el.prop('checked')) return;
32 32
33 33 var new_mode = parseInt(current_el.val(), 10);
34 34 if (new_mode === image_mode) return;
35 35 image_mode = new_mode;
36 36
37 37 make_normal_dom();
38 38 make_table_dom();
39 39
40 40 switch(new_mode) {
41 41 case 0:
42 42 $('#posts-table').replaceWith(normal_dom);
43 43 break;
44 44 case 1:
45 45 $('#posts').replaceWith(table_dom);
46 46 break;
47 47 }
48 48 }
49 49
50 50 function make_normal_dom()
51 51 {
52 52 if (typeof normal_dom === 'undefined') {
53 53 normal_dom = $('#posts').clone(true);
54 54 }
55 55 }
56 56
57 57 function make_table_dom()
58 58 {
59 59 if (typeof table_dom !== 'undefined') return;
60 60
61 61 table_dom = $('<div id="posts-table"></div>');
62 62 $('#posts > .post > .image > a').each(
63 63 function(){
64 64 table_dom.append(
65 65 $(this).clone().attr('target', '_blank')
66 66 );
67 67 }
68 68 );
69 69 }
70 70
71 71 function moveCaretToEnd(el) {
72 72 if (typeof el.selectionStart == "number") {
73 73 el.selectionStart = el.selectionEnd = el.value.length;
74 74 } else if (typeof el.createTextRange != "undefined") {
75 75 el.focus();
76 76 var range = el.createTextRange();
77 77 range.collapse(false);
78 78 range.select();
79 79 }
80 80 }
81 81
82 82 function addQuickReply(postId) {
83 83 var textToAdd = '>>' + postId + '\n\n';
84 $('#id_text').val($('#id_text').val()+ textToAdd);
84 var textAreaId = '#id_text';
85 $(textAreaId).val($(textAreaId).val()+ textToAdd);
85 86
86 87 var textarea = document.getElementById('id_text');
88 $(textAreaId).focus();
87 89 moveCaretToEnd(textarea);
88 90
89 $("html, body").animate({ scrollTop: $('#id_text').offset().top }, "slow");
91 $("html, body").animate({ scrollTop: $(textAreaId).offset().top }, "slow");
90 92 }
91 93
92 94 $(document).ready(function(){
93 95 add_panel('.navigation_panel');
94 96 });
General Comments 0
You need to be logged in to leave comments. Login now