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