##// END OF EJS Templates
Don't show the Hide/Show option if it won't work
Bohdan Horbeshko -
r2114:1012c538 opera_mini_fix
parent child Browse files
Show More
@@ -1,363 +1,364
1 1 /*
2 2 @licstart The following is the entire license notice for the
3 3 JavaScript code in this page.
4 4
5 5
6 6 Copyright (C) 2013 neko259
7 7
8 8 The JavaScript code in this page is free software: you can
9 9 redistribute it and/or modify it under the terms of the GNU
10 10 General Public License (GNU GPL) as published by the Free Software
11 11 Foundation, either version 3 of the License, or (at your option)
12 12 any later version. The code is distributed WITHOUT ANY WARRANTY;
13 13 without even the implied warranty of MERCHANTABILITY or FITNESS
14 14 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
15 15
16 16 As additional permission under GNU GPL version 3 section 7, you
17 17 may distribute non-source (e.g., minimized or compacted) forms of
18 18 that code without the copy of the GNU GPL normally required by
19 19 section 4, provided you include this license notice and a URL
20 20 through which recipients can access the Corresponding Source.
21 21
22 22 @licend The above is the entire license notice
23 23 for the JavaScript code in this page.
24 24 */
25 25
26 26 var ITEM_VOLUME_LEVEL = 'volumeLevel';
27 27 var ITEM_HIDDEN_POSTS = 'hiddenPosts';
28 28
29 29 var IMAGE_TYPES = ['image/png', 'image/jpg', 'image/jpeg', 'image/bmp', 'image/gif'];
30 30
31 31 /**
32 32 * An email is a hidden file to prevent spam bots from posting. It has to be
33 33 * hidden.
34 34 */
35 35 function hideEmailFromForm() {
36 36 $('.form-email').parent().parent().hide();
37 37 }
38 38
39 39 /**
40 40 * Highlight code blocks with code highlighter
41 41 */
42 42 function highlightCode(node) {
43 43 node.find('pre code').each(function(i, e) {
44 44 hljs.highlightBlock(e);
45 45 });
46 46 }
47 47
48 48 function updateFavPosts(data) {
49 49 var includePostBody = $('#fav-panel').is(":visible");
50 50
51 51 var allNewPostCount = 0;
52 52
53 53 if (includePostBody) {
54 54 var favoriteThreadPanel = $('#fav-panel');
55 55 favoriteThreadPanel.empty();
56 56 }
57 57
58 58 $.each($.parseJSON(data), function (_, dict) {
59 59 var newPostCount = dict.new_post_count;
60 60 allNewPostCount += newPostCount;
61 61
62 62 if (includePostBody) {
63 63 var favThreadNode = $('<div class="post"></div>');
64 64 favThreadNode.append($(dict.post_url));
65 65 favThreadNode.append(' ');
66 66 favThreadNode.append($('<span class="title">' + dict.title + '</span>'));
67 67
68 68 if (newPostCount > 0) {
69 69 favThreadNode.append(' (<a href="' + dict.newest_post_link + '">+' + newPostCount + "</a>)");
70 70 }
71 71
72 72 favoriteThreadPanel.append(favThreadNode);
73 73
74 74 addRefLinkPreview(favThreadNode[0]);
75 75 }
76 76 });
77 77
78 78 var newPostCountNode = $('#new-fav-post-count');
79 79 if (allNewPostCount > 0) {
80 80 newPostCountNode.text('(+' + allNewPostCount + ')');
81 81 newPostCountNode.show();
82 82 } else {
83 83 newPostCountNode.hide();
84 84 }
85 85 }
86 86
87 87 function initFavPanel() {
88 88 var favPanelButton = $('#fav-panel-btn');
89 89 if (favPanelButton.length > 0 && typeof SharedWorker != 'undefined') {
90 90 var worker = new SharedWorker($('body').attr('data-update-script'));
91 91 worker.port.onmessage = function(e) {
92 92 updateFavPosts(e.data);
93 93 };
94 94 worker.onerror = function(event){
95 95 throw new Error(event.message + " (" + event.filename + ":" + event.lineno + ")");
96 96 };
97 97 worker.port.start();
98 98
99 99 $(favPanelButton).click(function() {
100 100 var favPanel = $('#fav-panel');
101 101 favPanel.toggle();
102 102
103 103 worker.port.postMessage({ includePostBody: favPanel.is(':visible')});
104 104
105 105 return false;
106 106 });
107 107
108 108 $(document).on('keyup.removepic', function(e) {
109 109 if(e.which === 27) {
110 110 $('#fav-panel').hide();
111 111 }
112 112 });
113 113 }
114 114 }
115 115
116 116 function setVolumeLevel(level) {
117 117 localStorage.setItem(ITEM_VOLUME_LEVEL, level);
118 118 }
119 119
120 120 function getVolumeLevel() {
121 121 var level = localStorage.getItem(ITEM_VOLUME_LEVEL);
122 122 if (level == null) {
123 123 level = 1.0;
124 124 }
125 125 return level
126 126 }
127 127
128 128 function processVolumeUser(node) {
129 129 if (!window.localStorage) return;
130 130 node.prop("volume", getVolumeLevel());
131 131 node.on('volumechange', function(event) {
132 132 setVolumeLevel(event.target.volume);
133 133 $("video,audio").prop("volume", getVolumeLevel());
134 134 });
135 135 }
136 136
137 137 function getHiddenPosts() {
138 138 var arr = Array();
139 139 var hiddenPosts = localStorage && localStorage.getItem(ITEM_HIDDEN_POSTS);
140 140 if (hiddenPosts) {
141 141 arr = JSON.parse(hiddenPosts);
142 142 }
143 143 return arr;
144 144 }
145 145
146 146 function processPostHiding(posts) {
147 147 if (!window.localStorage) return;
148 148 var hiddenPosts = getHiddenPosts();
149 149
150 150 $.each(posts, function(index) {
151 151 var post = $(this);
152 152 if (hiddenPosts.indexOf(post.attr("id")) > -1) {
153 153 post.toggleClass("hidden_post");
154 154 }
155 155 });
156 156 }
157 157
158 158 /**
159 159 * Add all scripts than need to work on post, when the post is added to the
160 160 * document.
161 161 */
162 162 function addScriptsToPost(post) {
163 163 addRefLinkPreview(post[0]);
164 164 highlightCode(post);
165 165 processVolumeUser(post.find("video,audio"));
166 166 processPostHiding([post]);
167 167 }
168 168
169 169 /**
170 170 * Fix compatibility issues with some rare browsers
171 171 */
172 172 function compatibilityCrutches() {
173 173 if (window.operamini) {
174 174 $('#form textarea').each(function() { this.placeholder = ''; });
175 175 }
176 176 }
177 177
178 178 function togglePostHidden(postId) {
179 179 var hiddenPosts = getHiddenPosts();
180 180
181 181 var elIndex = hiddenPosts.indexOf(postId);
182 182 if (elIndex > -1) {
183 183 hiddenPosts.splice(elIndex, 1);
184 184 } else {
185 185 hiddenPosts.push(postId);
186 186 }
187 187 localStorage.setItem(ITEM_HIDDEN_POSTS, JSON.stringify(hiddenPosts));
188 188
189 189 $('#' + postId).toggleClass("hidden_post");
190 190 }
191 191
192 192 function addContextMenu() {
193 193 $.contextMenu({
194 194 selector: '.file-menu',
195 195 trigger: 'left',
196 196
197 197 build: function($trigger, e) {
198 198 var fileSearchUrl = $trigger.data('search-url');
199 199 var isImage = IMAGE_TYPES.indexOf($trigger.data('type')) > -1;
200 200 var hasUrl = fileSearchUrl.length > 0;
201 201 var id = $trigger.data('id');
202 202 return {
203 203 items: {
204 204 duplicates: {
205 205 name: gettext('Duplicates search'),
206 206 callback: function(key, opts) {
207 207 window.location = '/feed/?image=' + $trigger.data('filename');
208 208 }
209 209 },
210 210 google: {
211 211 name: 'Google',
212 212 visible: isImage && hasUrl,
213 213 callback: function(key, opts) {
214 214 window.location = 'https://www.google.com/searchbyimage?image_url=' + fileSearchUrl;
215 215 }
216 216 },
217 217 iqdb: {
218 218 name: 'IQDB',
219 219 visible: isImage && hasUrl,
220 220 callback: function(key, opts) {
221 221 window.location = 'http://iqdb.org/?url=' + fileSearchUrl;
222 222 }
223 223 },
224 224 tineye: {
225 225 name: 'TinEye',
226 226 visible: isImage && hasUrl,
227 227 callback: function(key, opts) {
228 228 window.location = 'http://tineye.com/search?url=' + fileSearchUrl;
229 229 }
230 230 },
231 231 addAlias: {
232 232 name: gettext('Add local sticker'),
233 233 callback: function(key, opts) {
234 234 var alias = prompt(gettext('Input sticker name'));
235 235 if (alias) {
236 236 window.location = '/stickers/?action=add&name=' + alias + '&id=' + id;
237 237 }
238 238 }
239 239 }
240 240 }
241 241 };
242 242 }
243 243 });
244 244
245 245 $.contextMenu({
246 246 selector: '.post .post-menu',
247 247 trigger: 'left',
248 248 build: function($trigger, e) {
249 249 var canEditPost = PERMS['change_post'];
250 250 var canDeletePost = PERMS['delete_post'];
251 251 var canEditThread = PERMS['change_thread'];
252 252 var canDeleteThread = PERMS['delete_thread'];
253 253
254 254 var post = $trigger.parents('.post');
255 255
256 256 var isOpening = post.data('opening') === 'True';
257 257 var threadId = post.data('thread-id');
258 258 var hasGlobalId = post.data('has-global-id') === 'True';
259 259
260 260 var posterIp = $trigger.siblings('.pub_time').attr('title');
261 261 var hasIp = posterIp != null;
262 262
263 263 var postId = post.attr('id');
264 264
265 265 return {
266 266 items: {
267 267 hide: {
268 268 name: gettext('Hide/show'),
269 269 callback: function(key, opt) {
270 270 togglePostHidden(postId);
271 }
271 },
272 visible: !!localStorage
272 273 },
273 274 edit: {
274 275 name: gettext('Edit'),
275 276 callback: function(key, opt) {
276 277 window.location = '/admin/boards/post/' + postId + '/change/';
277 278 },
278 279 visible: canEditPost
279 280 },
280 281 deletePost: {
281 282 name: gettext('Delete post'),
282 283 callback: function(key, opt) {
283 284 window.location = '/admin/boards/post/' + postId + '/delete/';
284 285 },
285 286 visible: !isOpening && canDeletePost
286 287 },
287 288 editThread: {
288 289 name: gettext('Edit thread'),
289 290 callback: function(key, opt) {
290 291 window.location = '/admin/boards/thread/' + threadId + '/change/';
291 292 },
292 293 visible: isOpening && canEditThread
293 294 },
294 295 deleteThread: {
295 296 name: gettext('Delete thread'),
296 297 callback: function(key, opt) {
297 298 window.location = '/admin/boards/thread/' + threadId + '/delete/';
298 299 },
299 300 visible: isOpening && canDeleteThread
300 301 },
301 302 findByIp: {
302 303 name: 'IP = ' + posterIp,
303 304 callback: function(key, opt) {
304 305 window.location = '/feed/?ip=' + posterIp;
305 306 },
306 307 visible: canEditPost && hasIp
307 308 },
308 309 raw: {
309 310 name: 'RAW',
310 311 callback: function(key, opt) {
311 312 window.location = '/post_xml/' + postId;
312 313 },
313 314 visible: canEditPost && hasGlobalId
314 315 },
315 316 ban: {
316 317 name: gettext('Ban'),
317 318 callback: function(key, opt) {
318 319 if (confirm(gettext('Are you sure?'))) {
319 320 window.location = '/utils?method=ban&post_id=' + postId;
320 321 }
321 322 },
322 323 visible: canEditPost && hasIp
323 324 },
324 325 banAndDelete: {
325 326 name: gettext('Ban and delete'),
326 327 callback: function(key, opt) {
327 328 if (confirm(gettext('Are you sure?'))) {
328 329 window.location = '/utils?method=ban_and_delete&post_id=' + postId;
329 330 }
330 331 },
331 332 visible: hasIp && canDeletePost
332 333 }
333 334 }
334 335 };
335 336 }
336 337 });
337 338 }
338 339
339 340 $( document ).ready(function() {
340 341 hideEmailFromForm();
341 342
342 343 $("a[href='#top']").click(function() {
343 344 $("html, body").animate({ scrollTop: 0 }, "slow");
344 345 return false;
345 346 });
346 347
347 348 addImgPreview();
348 349
349 350 addRefLinkPreview();
350 351
351 352 highlightCode($(document));
352 353
353 354 initFavPanel();
354 355
355 356 var volumeUsers = $("video,audio");
356 357 processVolumeUser(volumeUsers);
357 358
358 359 addContextMenu();
359 360
360 361 compatibilityCrutches();
361 362
362 363 processPostHiding($('.post'));
363 364 });
General Comments 0
You need to be logged in to leave comments. Login now