Show More
@@ -1,220 +1,220 b'' | |||
|
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 | var IMAGE_TYPES = ['png', 'jpg', 'jpeg', 'bmp', 'gif']; | |
|
27 | var IMAGE_TYPES = ['image/png', 'image/jpg', 'image/jpeg', 'image/bmp', 'image/gif']; | |
|
28 | 28 | |
|
29 | 29 | /** |
|
30 | 30 | * An email is a hidden file to prevent spam bots from posting. It has to be |
|
31 | 31 | * hidden. |
|
32 | 32 | */ |
|
33 | 33 | function hideEmailFromForm() { |
|
34 | 34 | $('.form-email').parent().parent().hide(); |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | /** |
|
38 | 38 | * Highlight code blocks with code highlighter |
|
39 | 39 | */ |
|
40 | 40 | function highlightCode(node) { |
|
41 | 41 | node.find('pre code').each(function(i, e) { |
|
42 | 42 | hljs.highlightBlock(e); |
|
43 | 43 | }); |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | function updateFavPosts(data) { |
|
47 | 47 | var includePostBody = $('#fav-panel').is(":visible"); |
|
48 | 48 | |
|
49 | 49 | var allNewPostCount = 0; |
|
50 | 50 | |
|
51 | 51 | if (includePostBody) { |
|
52 | 52 | var favoriteThreadPanel = $('#fav-panel'); |
|
53 | 53 | favoriteThreadPanel.empty(); |
|
54 | 54 | } |
|
55 | 55 | |
|
56 | 56 | $.each($.parseJSON(data), function (_, dict) { |
|
57 | 57 | var newPostCount = dict.new_post_count; |
|
58 | 58 | allNewPostCount += newPostCount; |
|
59 | 59 | |
|
60 | 60 | if (includePostBody) { |
|
61 | 61 | var favThreadNode = $('<div class="post"></div>'); |
|
62 | 62 | favThreadNode.append($(dict.post_url)); |
|
63 | 63 | favThreadNode.append(' '); |
|
64 | 64 | favThreadNode.append($('<span class="title">' + dict.title + '</span>')); |
|
65 | 65 | |
|
66 | 66 | if (newPostCount > 0) { |
|
67 | 67 | favThreadNode.append(' (<a href="' + dict.newest_post_link + '">+' + newPostCount + "</a>)"); |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | favoriteThreadPanel.append(favThreadNode); |
|
71 | 71 | |
|
72 | 72 | addRefLinkPreview(favThreadNode[0]); |
|
73 | 73 | } |
|
74 | 74 | }); |
|
75 | 75 | |
|
76 | 76 | var newPostCountNode = $('#new-fav-post-count'); |
|
77 | 77 | if (allNewPostCount > 0) { |
|
78 | 78 | newPostCountNode.text('(+' + allNewPostCount + ')'); |
|
79 | 79 | newPostCountNode.show(); |
|
80 | 80 | } else { |
|
81 | 81 | newPostCountNode.hide(); |
|
82 | 82 | } |
|
83 | 83 | } |
|
84 | 84 | |
|
85 | 85 | function initFavPanel() { |
|
86 | 86 | var favPanelButton = $('#fav-panel-btn'); |
|
87 | 87 | if (favPanelButton.length > 0 && typeof SharedWorker != 'undefined') { |
|
88 | 88 | var worker = new SharedWorker($('body').attr('data-update-script')); |
|
89 | 89 | worker.port.onmessage = function(e) { |
|
90 | 90 | updateFavPosts(e.data); |
|
91 | 91 | }; |
|
92 | 92 | worker.onerror = function(event){ |
|
93 | 93 | throw new Error(event.message + " (" + event.filename + ":" + event.lineno + ")"); |
|
94 | 94 | }; |
|
95 | 95 | worker.port.start(); |
|
96 | 96 | |
|
97 | 97 | $(favPanelButton).click(function() { |
|
98 | 98 | var favPanel = $('#fav-panel'); |
|
99 | 99 | favPanel.toggle(); |
|
100 | 100 | |
|
101 | 101 | worker.port.postMessage({ includePostBody: favPanel.is(':visible')}); |
|
102 | 102 | |
|
103 | 103 | return false; |
|
104 | 104 | }); |
|
105 | 105 | |
|
106 | 106 | $(document).on('keyup.removepic', function(e) { |
|
107 | 107 | if(e.which === 27) { |
|
108 | 108 | $('#fav-panel').hide(); |
|
109 | 109 | } |
|
110 | 110 | }); |
|
111 | 111 | } |
|
112 | 112 | } |
|
113 | 113 | |
|
114 | 114 | function setVolumeLevel(level) { |
|
115 | 115 | localStorage.setItem(ITEM_VOLUME_LEVEL, level); |
|
116 | 116 | } |
|
117 | 117 | |
|
118 | 118 | function getVolumeLevel() { |
|
119 | 119 | var level = localStorage.getItem(ITEM_VOLUME_LEVEL); |
|
120 | 120 | if (level == null) { |
|
121 | 121 | level = 1.0; |
|
122 | 122 | } |
|
123 | 123 | return level |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | function processVolumeUser(node) { |
|
127 | 127 | if (!window.localStorage) return; |
|
128 | 128 | node.prop("volume", getVolumeLevel()); |
|
129 | 129 | node.on('volumechange', function(event) { |
|
130 | 130 | setVolumeLevel(event.target.volume); |
|
131 | 131 | $("video,audio").prop("volume", getVolumeLevel()); |
|
132 | 132 | }); |
|
133 | 133 | } |
|
134 | 134 | |
|
135 | 135 | /** |
|
136 | 136 | * Add all scripts than need to work on post, when the post is added to the |
|
137 | 137 | * document. |
|
138 | 138 | */ |
|
139 | 139 | function addScriptsToPost(post) { |
|
140 | 140 | addRefLinkPreview(post[0]); |
|
141 | 141 | highlightCode(post); |
|
142 | 142 | processVolumeUser(post.find("video,audio")); |
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | /** |
|
146 | 146 | * Fix compatibility issues with some rare browsers |
|
147 | 147 | */ |
|
148 | 148 | function compatibilityCrutches() { |
|
149 | 149 | if (window.operamini) { |
|
150 | 150 | $('#form textarea').each(function() { this.placeholder = ''; }); |
|
151 | 151 | } |
|
152 | 152 | } |
|
153 | 153 | |
|
154 | 154 | function addContextMenu() { |
|
155 | 155 | $.contextMenu({ |
|
156 | 156 | selector: '.file-menu', |
|
157 | 157 | trigger: 'left', |
|
158 | 158 | |
|
159 | 159 | build: function($trigger, e) { |
|
160 | 160 | var fileSearchUrl = $trigger.data('search-url'); |
|
161 | 161 | var isImage = IMAGE_TYPES.indexOf($trigger.data('type')) > -1; |
|
162 | 162 | var hasUrl = fileSearchUrl.length > 0; |
|
163 | 163 | return { |
|
164 | 164 | items: { |
|
165 | 165 | duplicates: { |
|
166 | 166 | name: gettext('Duplicates search'), |
|
167 | 167 | callback: function(key, opts) { |
|
168 | 168 | window.location = '/feed/?image=' + $trigger.data('filename'); |
|
169 | 169 | } |
|
170 | 170 | }, |
|
171 | 171 | google: { |
|
172 | 172 | name: 'Google', |
|
173 | 173 | visible: isImage && hasUrl, |
|
174 | 174 | callback: function(key, opts) { |
|
175 | 175 | window.location = 'https://www.google.com/searchbyimage?image_url=' + fileSearchUrl; |
|
176 | 176 | } |
|
177 | 177 | }, |
|
178 | 178 | iqdb: { |
|
179 | 179 | name: 'IQDB', |
|
180 | 180 | visible: isImage && hasUrl, |
|
181 | 181 | callback: function(key, opts) { |
|
182 | 182 | window.location = 'http://iqdb.org/?url=' + fileSearchUrl; |
|
183 | 183 | } |
|
184 | 184 | }, |
|
185 | 185 | tineye: { |
|
186 | 186 | name: 'TinEye', |
|
187 | 187 | visible: isImage && hasUrl, |
|
188 | 188 | callback: function(key, opts) { |
|
189 | 189 | window.location = 'http://tineye.com/search?url=' + fileSearchUrl; |
|
190 | 190 | } |
|
191 | 191 | } |
|
192 | 192 | }, |
|
193 | 193 | }; |
|
194 | 194 | } |
|
195 | 195 | }); |
|
196 | 196 | } |
|
197 | 197 | |
|
198 | 198 | $( document ).ready(function() { |
|
199 | 199 | hideEmailFromForm(); |
|
200 | 200 | |
|
201 | 201 | $("a[href='#top']").click(function() { |
|
202 | 202 | $("html, body").animate({ scrollTop: 0 }, "slow"); |
|
203 | 203 | return false; |
|
204 | 204 | }); |
|
205 | 205 | |
|
206 | 206 | addImgPreview(); |
|
207 | 207 | |
|
208 | 208 | addRefLinkPreview(); |
|
209 | 209 | |
|
210 | 210 | highlightCode($(document)); |
|
211 | 211 | |
|
212 | 212 | initFavPanel(); |
|
213 | 213 | |
|
214 | 214 | var volumeUsers = $("video,audio"); |
|
215 | 215 | processVolumeUser(volumeUsers); |
|
216 | 216 | |
|
217 | 217 | addContextMenu(); |
|
218 | 218 | |
|
219 | 219 | compatibilityCrutches(); |
|
220 | 220 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now