Show More
@@ -1,80 +1,94 | |||
|
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 | function moveCaretToEnd(el) { | |
|
72 | if (typeof el.selectionStart == "number") { | |
|
73 | el.selectionStart = el.selectionEnd = el.value.length; | |
|
74 | } else if (typeof el.createTextRange != "undefined") { | |
|
75 | el.focus(); | |
|
76 | var range = el.createTextRange(); | |
|
77 | range.collapse(false); | |
|
78 | range.select(); | |
|
79 | } | |
|
80 | } | |
|
81 | ||
|
71 | 82 | function addQuickReply(postId) { |
|
72 | 83 | var textToAdd = '>>' + postId + '\n\n'; |
|
73 | 84 | $('#id_text').val($('#id_text').val()+ textToAdd); |
|
74 | 85 | |
|
86 | var textarea = document.getElementById('id_text'); | |
|
87 | moveCaretToEnd(textarea); | |
|
88 | ||
|
75 | 89 | $("html, body").animate({ scrollTop: $('#id_text').offset().top }, "slow"); |
|
76 | 90 | } |
|
77 | 91 | |
|
78 | 92 | $(document).ready(function(){ |
|
79 | 93 | add_panel('.navigation_panel'); |
|
80 | }); No newline at end of file | |
|
94 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now