Show More
@@ -55,6 +55,8 b' function showPostPreview(e) {' | |||
|
55 | 55 | |
|
56 | 56 | cln.innerHTML = 'Загрузка...'; |
|
57 | 57 | |
|
58 | var found = false; | |
|
59 | ||
|
58 | 60 | //если пост найден в дереве. |
|
59 | 61 | if($('div[id='+pNum+']').length > 0) { |
|
60 | 62 | var postdata = $('div[id='+pNum+']').html(); |
@@ -64,6 +66,8 b' function showPostPreview(e) {' | |||
|
64 | 66 | |
|
65 | 67 | //make preview |
|
66 | 68 | mkPreview(cln, postdata); |
|
69 | ||
|
70 | found = true; | |
|
67 | 71 | } |
|
68 | 72 | //ajax api |
|
69 | 73 | // else { |
@@ -86,9 +90,11 b' function showPostPreview(e) {' | |||
|
86 | 90 | |
|
87 | 91 | $del(doc.getElementById(cln.id)); |
|
88 | 92 | |
|
93 | if (found) { | |
|
89 | 94 | //add preview |
|
90 | 95 | $('body').append(cln); |
|
91 | 96 | } |
|
97 | } | |
|
92 | 98 | |
|
93 | 99 | function delPostPreview(e) { |
|
94 | 100 | var el = $x('ancestor-or-self::*[starts-with(@id,"pstprev")]', e.relatedTarget); |
@@ -98,101 +104,8 b' function delPostPreview(e) {' | |||
|
98 | 104 | else while(el.nextSibling) $del(el.nextSibling); |
|
99 | 105 | } |
|
100 | 106 | |
|
101 | ||
|
102 | ||
|
103 | ||
|
104 | ||
|
105 | ||
|
106 | 107 | function addPreview() { |
|
107 | 108 | $('.post').find('a').each(function() { |
|
108 | 109 | showPostPreview($(this)); |
|
109 | 110 | }); |
|
110 | 111 | } |
|
111 | ||
|
112 | function showPreview(node) { | |
|
113 | node.each(function() { | |
|
114 | //reflink? | |
|
115 | if($(this).text().indexOf('>>') == 0) { | |
|
116 | //add mouseover event | |
|
117 | $(this).on('mouseover', function(e) { | |
|
118 | var ref = $(this); | |
|
119 | ||
|
120 | var doc = document; | |
|
121 | //ref id | |
|
122 | var pNum = ref.text().match(/\d+/); | |
|
123 | ||
|
124 | //position | |
|
125 | var x = e.clientX + (doc.documentElement.scrollLeft || doc.body.scrollLeft) + 2; | |
|
126 | var y = e.clientY + (doc.documentElement.scrollTop || doc.body.scrollTop); | |
|
127 | ||
|
128 | //create preview block | |
|
129 | var cln = $('<div>', { | |
|
130 | id: 'pstprev_' + pNum, | |
|
131 | class: 'post_preview post' | |
|
132 | }) | |
|
133 | .css('cssText', 'top:' + y + 'px;' + (x < doc.body.clientWidth/2 ? 'left:' + x + 'px' : 'right:' + parseInt(doc.body.clientWidth - x + 1) | |
|
134 | + 'px')); | |
|
135 | ||
|
136 | ||
|
137 | var mkPreview = function(cln, html) { | |
|
138 | ||
|
139 | cln.html(html); | |
|
140 | ||
|
141 | showPreview($(cln)); | |
|
142 | //if(!$x('.//small', cln)) showRefMap(post, p_num, refMap) | |
|
143 | }; | |
|
144 | ||
|
145 | cln.html('Загрузка...'); | |
|
146 | ||
|
147 | //если пост найден в дереве. | |
|
148 | if($('div[id='+pNum+']').length > 0) { | |
|
149 | var postdata = $('div[id='+pNum+']').clone().html(); | |
|
150 | //TODO: лучше бы вынести в mkPreview | |
|
151 | //if($.localStorage('addImgPreview') > 0) showImgPreview($(postdata)); | |
|
152 | ||
|
153 | //make preview | |
|
154 | mkPreview(cln, postdata); | |
|
155 | } | |
|
156 | //ajax api | |
|
157 | // else { | |
|
158 | // $.getJSON(mayuri_cfg['board_url']+'api/single/'+pNum) | |
|
159 | // .success(function(data) { | |
|
160 | // //post templates | |
|
161 | // var postdata = makeAjaxPost(data).html(); | |
|
162 | // | |
|
163 | // //make preview | |
|
164 | // mkPreview(cln, postdata); | |
|
165 | // | |
|
166 | // })//if error | |
|
167 | // .error(function() { | |
|
168 | // cln.html('Пост не найден.'); | |
|
169 | // }); | |
|
170 | // } | |
|
171 | ||
|
172 | $del(doc.getElementById(cln.id)); | |
|
173 | ||
|
174 | //add preview | |
|
175 | $('body').append(cln); | |
|
176 | }); | |
|
177 | ||
|
178 | $(this).on('mouseout', function() { | |
|
179 | delPreview($(this)); | |
|
180 | }) | |
|
181 | } | |
|
182 | }); | |
|
183 | ||
|
184 | } | |
|
185 | ||
|
186 | function delPreview(e) { | |
|
187 | var el = e.relatedTarget; | |
|
188 | if(!el) { | |
|
189 | $(el).each(function(clone) { | |
|
190 | $del(clone) | |
|
191 | }); | |
|
192 | } | |
|
193 | { | |
|
194 | while(el.next()) | |
|
195 | $del(el.next()); | |
|
196 | } | |
|
197 | } | |
|
198 |
General Comments 0
You need to be logged in to leave comments.
Login now