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