##// END OF EJS Templates
Add reflink map
ritsufag -
r118:ab4d79db ritsufag/add-refl...
parent child Browse files
Show More
@@ -1,96 +1,137 b''
1 var image_mode = 0;
1 var image_mode = 0;
2 var normal_dom, table_dom;
2 var normal_dom, table_dom;
3
3
4 function add_panel(after)
4 function add_panel(after)
5 {
5 {
6 var nav_top = $(after);
6 var nav_top = $(after);
7 if (nav_top.length === 0) return;
7 if (nav_top.length === 0) return;
8 nav_top = nav_top[0];
8 nav_top = nav_top[0];
9
9
10 var tab_bar = $('<div class="image-mode-tab" role="radiogroup" aria-label="Image mode"></div>');
10 var tab_bar = $('<div class="image-mode-tab" role="radiogroup" aria-label="Image mode"></div>');
11
11
12 var tab;
12 var tab;
13
13
14 tab = $('<input type="radio" class="image-mode-normal" name="image-mode" value="0" checked="checked"/>');
14 tab = $('<input type="radio" class="image-mode-normal" name="image-mode" value="0" checked="checked"/>');
15 tab.on("change", tab_handler);
15 tab.on("change", tab_handler);
16 tab = $('<label>Normal</label>').prepend(tab);
16 tab = $('<label>Normal</label>').prepend(tab);
17 tab_bar.append(tab);
17 tab_bar.append(tab);
18
18
19 tab = $('<input type="radio" class="image-mode-table" name="image-mode" value="1"/>');
19 tab = $('<input type="radio" class="image-mode-table" name="image-mode" value="1"/>');
20 tab.on("change", tab_handler);
20 tab.on("change", tab_handler);
21 tab = $('<label>Gallery</label>').prepend(tab);
21 tab = $('<label>Gallery</label>').prepend(tab);
22 tab_bar.append(tab);
22 tab_bar.append(tab);
23
23
24 tab_bar.insertAfter(nav_top);
24 tab_bar.insertAfter(nav_top);
25 }
25 }
26
26
27 function tab_handler(ev)
27 function tab_handler(ev)
28 {
28 {
29 var current_el = $(this);
29 var current_el = $(this);
30
30
31 if (!current_el.prop('checked')) return;
31 if (!current_el.prop('checked')) return;
32
32
33 var new_mode = parseInt(current_el.val(), 10);
33 var new_mode = parseInt(current_el.val(), 10);
34 if (new_mode === image_mode) return;
34 if (new_mode === image_mode) return;
35 image_mode = new_mode;
35 image_mode = new_mode;
36
36
37 make_normal_dom();
37 make_normal_dom();
38 make_table_dom();
38 make_table_dom();
39
39
40 switch(new_mode) {
40 switch(new_mode) {
41 case 0:
41 case 0:
42 $('#posts-table').replaceWith(normal_dom);
42 $('#posts-table').replaceWith(normal_dom);
43 break;
43 break;
44 case 1:
44 case 1:
45 $('#posts').replaceWith(table_dom);
45 $('#posts').replaceWith(table_dom);
46 break;
46 break;
47 }
47 }
48 }
48 }
49
49
50 function make_normal_dom()
50 function make_normal_dom()
51 {
51 {
52 if (typeof normal_dom === 'undefined') {
52 if (typeof normal_dom === 'undefined') {
53 normal_dom = $('#posts').clone(true);
53 normal_dom = $('#posts').clone(true);
54 }
54 }
55 }
55 }
56
56
57 function make_table_dom()
57 function make_table_dom()
58 {
58 {
59 if (typeof table_dom !== 'undefined') return;
59 if (typeof table_dom !== 'undefined') return;
60
60
61 table_dom = $('<div id="posts-table"></div>');
61 table_dom = $('<div id="posts-table"></div>');
62 $('#posts > .post > .image > a').each(
62 $('#posts > .post > .image > a').each(
63 function(){
63 function(){
64 table_dom.append(
64 table_dom.append(
65 $(this).clone().attr('target', '_blank')
65 $(this).clone().attr('target', '_blank')
66 );
66 );
67 }
67 }
68 );
68 );
69 }
69 }
70
70
71 function moveCaretToEnd(el) {
71 function moveCaretToEnd(el) {
72 if (typeof el.selectionStart == "number") {
72 if (typeof el.selectionStart == "number") {
73 el.selectionStart = el.selectionEnd = el.value.length;
73 el.selectionStart = el.selectionEnd = el.value.length;
74 } else if (typeof el.createTextRange != "undefined") {
74 } else if (typeof el.createTextRange != "undefined") {
75 el.focus();
75 el.focus();
76 var range = el.createTextRange();
76 var range = el.createTextRange();
77 range.collapse(false);
77 range.collapse(false);
78 range.select();
78 range.select();
79 }
79 }
80 }
80 }
81
81
82 function addQuickReply(postId) {
82 function addQuickReply(postId) {
83 var textToAdd = '>>' + postId + '\n\n';
83 var textToAdd = '>>' + postId + '\n\n';
84 var textAreaId = '#id_text';
84 var textAreaId = '#id_text';
85 $(textAreaId).val($(textAreaId).val()+ textToAdd);
85 $(textAreaId).val($(textAreaId).val()+ textToAdd);
86
86
87 var textarea = document.getElementById('id_text');
87 var textarea = document.getElementById('id_text');
88 $(textAreaId).focus();
88 $(textAreaId).focus();
89 moveCaretToEnd(textarea);
89 moveCaretToEnd(textarea);
90
90
91 $("html, body").animate({ scrollTop: $(textAreaId).offset().top }, "slow");
91 $("html, body").animate({ scrollTop: $(textAreaId).offset().top }, "slow");
92 }
92 }
93
93
94 function addRefLinkMap() {
95 var postByNum = [], refMap = [];
96
97 $('.post').each(function() {
98 var self = $(this);
99
100 var postNum = self.attr('id');
101 //add post by id
102 postByNum[postNum] = self;
103 //add ref link
104 self.find('p').children('a').each(function() {
105 if($(this).text().indexOf('>>') == 0) {
106 var refNum = $(this).text().match(/\d+/);
107
108 if(postByNum[refNum]) {
109 if(!refMap[refNum])
110 refMap[refNum] = [];
111
112 //if !exist
113 if((',' + refMap[refNum].toString() + ',').indexOf(',' + postNum + ',') < 0) {
114 refMap[refNum].push(postNum);
115 };
116 }
117 }
118 });
119 });
120
121 for(var pNum in refMap) {
122 if(typeof refMap[pNum] === 'object') {
123 var data = 'Ответы:' + refMap[pNum].toString().replace(/(\d+)/g, ' <a href="/jump/$1/">>>$1</a>');
124
125 //append refmap panel
126 if(!$("#refmap_"+pNum).length) {
127 $('#'+pNum+'').find('.message').after($('<div class="refmap" id="refmap_'+pNum+'">'+data+'</div>'));
128 }
129 }
130 }
131 }
132
133
94 $(document).ready(function(){
134 $(document).ready(function(){
95 add_panel('.navigation_panel');
135 add_panel('.navigation_panel');
136 addRefLinkMap();
96 });
137 });
General Comments 0
You need to be logged in to leave comments. Login now