|
1 | 1 | {% if S_SHOW_ATTACH_BOX and FILTERS %} |
2 | 2 | {% INCLUDECSS '@imcger_imgupload/imgupload.css' %} |
3 | 3 | <script> |
| 4 | + |
| 5 | +/** |
| 6 | + * imcger object for pphpBB. |
| 7 | + */ |
| 8 | +if (typeof imcger != 'object') { |
| 9 | + var imcger = {}; |
| 10 | +} |
| 11 | + |
4 | 12 | (function($) { // Avoid conflicts with other libraries |
5 | 13 |
|
6 | 14 | 'use strict'; |
7 | 15 |
|
8 | | - /** |
9 | | - * imcger objects for pphpBB attachment upload. |
10 | | - */ |
11 | | - if (typeof imcger != 'object') { |
12 | | - var imcger = {}; |
13 | | - } |
14 | | - |
| 16 | + // imcger object for pphpBB extension Image upload use ImageMagick |
15 | 17 | imcger.imgUpload = {}; |
16 | 18 |
|
17 | 19 | /** |
|
99 | 101 | imgOrientationIndex: [], |
100 | 102 | imgOrientationValue: [], |
101 | 103 |
|
| 104 | + /** |
| 105 | + * Subroutine from rotateRight() and rotateLeft() |
| 106 | + * |
| 107 | + * @param int attach_id attach id from image |
| 108 | + * @param int deg angle to rotated |
| 109 | + * @param bool clockwise true rotated clockwise |
| 110 | + */ |
102 | 111 | rotate: function(attach_id, deg, clockwise) { |
103 | 112 | let $image = $('#img-' + attach_id), |
104 | 113 | deg_start, deg_ziel; |
|
122 | 131 | }); |
123 | 132 | }, |
124 | 133 |
|
| 134 | + /** |
| 135 | + * Rotate the image clockwiese |
| 136 | + * |
| 137 | + * @param int attach_id attach id from attach image |
| 138 | + */ |
125 | 139 | rotateRight: function(attach_id) { |
126 | 140 | let index = 0; |
127 | 141 |
|
|
140 | 154 | this.rotate(attach_id, this.imgOrientationValue[index], true); |
141 | 155 | }, |
142 | 156 |
|
| 157 | + /** |
| 158 | + * Rotate the image anticlockwiese |
| 159 | + * |
| 160 | + * @param int attach_id attach id from attach image |
| 161 | + */ |
143 | 162 | rotateLeft: function(attach_id) { |
144 | 163 | let index = 0; |
145 | 164 |
|
|
158 | 177 |
|
159 | 178 | this.rotate(attach_id, this.imgOrientationValue[index], false); |
160 | 179 | }, |
161 | | - } |
162 | | - |
163 | | - /** |
164 | | - * Send a request to the Server to save the rotate image |
165 | | - * |
166 | | - * @param int attach_id attach id from attach image |
167 | | - * @param element button submit button |
168 | | - */ |
169 | | - imcger.imgUpload.saveImg = function(attach_id, button) { |
170 | | - let index = 0; |
171 | | - |
172 | | - if (imcger.imgUpload.image.imgOrientationIndex.includes(attach_id)) { |
173 | | - index = imcger.imgUpload.image.imgOrientationIndex.indexOf(attach_id); |
174 | | - } else { |
175 | | - return; |
176 | | - } |
177 | | - |
178 | | - if (!imcger.imgUpload.image.imgOrientationValue[index]) { |
179 | | - return; |
180 | | - } |
181 | | - |
182 | | - const url = '{{ U_IUL_SAVE_IMAGE }}', |
183 | | - requestData = 'attach_id=' + attach_id + |
184 | | - '&img_rotate_deg=' + imcger.imgUpload.image.imgOrientationValue[index] + |
185 | | - '&creation_time=' + $('input[name="creation_time"]').val() + |
186 | | - '&form_token=' + $('input[name="form_token"]').val(); |
187 | 180 |
|
188 | | - let ajaxReq = $.ajax(url, { |
189 | | - // The data to send |
190 | | - data: requestData, |
191 | | - |
192 | | - // Whether this is a POST or GET request |
193 | | - type: 'POST', |
| 181 | + /** |
| 182 | + * Send a request to the Server to save the rotate image |
| 183 | + * |
| 184 | + * @param int attach_id attach id from attach image |
| 185 | + * @param element button submit button |
| 186 | + */ |
| 187 | + saveImg: function(attach_id, button) { |
| 188 | + let index = 0; |
194 | 189 |
|
195 | | - // The type of data we expect back |
196 | | - dataType: "json", |
| 190 | + if (this.imgOrientationIndex.includes(attach_id)) { |
| 191 | + index = this.imgOrientationIndex.indexOf(attach_id); |
| 192 | + } else { |
| 193 | + return; |
| 194 | + } |
197 | 195 |
|
198 | | - // Set a timeout (in milliseconds) for the request |
199 | | - timeout: 5000, |
| 196 | + if (!this.imgOrientationValue[index]) { |
| 197 | + return; |
| 198 | + } |
200 | 199 |
|
201 | | - // Code to run before the request is send |
202 | | - beforeSend: function(xhr, settings) { |
203 | | - $(button).find('>:first-child').attr('class', 'icon fa-refresh fa-spin fa-fw'); |
204 | | - $('.imcger-iupl-button button').attr('disabled', true).css('cursor','not-allowed'); |
205 | | - }, |
206 | | - }); |
| 200 | + const url = '{{ U_IUL_SAVE_IMAGE }}', |
| 201 | + requestData = 'attach_id=' + attach_id + |
| 202 | + '&img_rotate_deg=' + this.imgOrientationValue[index] + |
| 203 | + '&creation_time=' + $('input[name="creation_time"]').val() + |
| 204 | + '&form_token=' + $('input[name="form_token"]').val(); |
| 205 | + |
| 206 | + let ajaxReq = $.ajax({ |
| 207 | + // The url of the request |
| 208 | + url: url, |
| 209 | + |
| 210 | + // The data to send |
| 211 | + data: requestData, |
| 212 | + |
| 213 | + // Whether this is a POST or GET request |
| 214 | + type: 'POST', |
| 215 | + |
| 216 | + // The type of data we expect back |
| 217 | + dataType: "json", |
| 218 | + |
| 219 | + // Set a timeout (in milliseconds) for the request |
| 220 | + timeout: 10000, |
| 221 | + |
| 222 | + // Code to run before the request is send |
| 223 | + beforeSend: function(xhr, settings) { |
| 224 | + $(button).find('>:first-child').attr('class', 'icon fa-refresh fa-spin fa-fw'); |
| 225 | + $('.imcger-iupl-button button').attr('disabled', true).css('cursor','not-allowed'); |
| 226 | + }, |
| 227 | + }); |
207 | 228 |
|
208 | | - // Code to run if the request succeeds (is done); |
209 | | - ajaxReq.done(function(json) { |
210 | | - if (json.status < 3) { |
211 | | - imcger.imgUpload.updateAttId(json.oldAttachId, json.newAttachId); |
212 | | - imcger.imgUpload.image.imgOrientationValue[index] = 0; |
213 | | - } else if (json.status == 3) { |
214 | | - window.location.assign(window.location.href.replace(window.location.hash, '')); |
215 | | - } else { |
216 | | - phpbb.alert(json.title, json.message); |
217 | | - } |
218 | | - }); |
| 229 | + // Code to run if the request succeeds (is done); |
| 230 | + ajaxReq.done(function(json) { |
| 231 | + if (json.status < 3) { |
| 232 | + imcger.imgUpload.updateAttId(json.oldAttachId, json.newAttachId); |
| 233 | + imcger.imgUpload.image.imgOrientationValue[index] = 0; |
| 234 | + } else if (json.status == 3) { |
| 235 | + window.location.assign(window.location.href.replace(window.location.hash, '')); |
| 236 | + } else { |
| 237 | + phpbb.alert(json.title, json.message); |
| 238 | + } |
| 239 | + }); |
219 | 240 |
|
220 | | - // Code to run if the request fails |
221 | | - ajaxReq.fail(function(xhr, status, errorThrown) { |
222 | | - phpbb.alert('{{ IMGUPLOAD_TITLE }}', '{{ lang("IUL_REQUEST_ERROR")|e("js") }}<br>' + |
223 | | - ' Status: ' + status + 'Error: ' + errorThrown); |
224 | | - }); |
| 241 | + // Code to run if the request fails |
| 242 | + ajaxReq.fail(function(xhr, status, errorThrown) { |
| 243 | + phpbb.alert('{{ IMGUPLOAD_TITLE }}', '{{ lang("IUL_REQUEST_ERROR")|e("js") }}<br>' + |
| 244 | + ' Status: ' + status + 'Error: ' + errorThrown); |
| 245 | + }); |
225 | 246 |
|
226 | | - // Code to run regardless of success or failure; |
227 | | - ajaxReq.always(function(xhr, status) { |
228 | | - $(button).find('>:first-child').attr('class', 'icon fa-save fa-fw'); |
229 | | - $('.imcger-iupl-button button').attr('disabled', false).css('cursor','auto'); |
230 | | - }); |
| 247 | + // Code to run regardless of success or failure; |
| 248 | + ajaxReq.always(function(xhr, status) { |
| 249 | + $(button).find('>:first-child').attr('class', 'icon fa-save fa-fw'); |
| 250 | + $('.imcger-iupl-button button').attr('disabled', false).css('cursor','auto'); |
| 251 | + }); |
| 252 | + } |
231 | 253 | } |
232 | 254 |
|
233 | 255 | /** |
|
290 | 312 | $('#file-list').on('click', '.save-image', function(e) { |
291 | 313 | let attachId = $(this).parents('.attach-row').attr('data-attach-id'); |
292 | 314 |
|
293 | | - imcger.imgUpload.saveImg(attachId, this); |
| 315 | + imcger.imgUpload.image.saveImg(attachId, this); |
294 | 316 | e.preventDefault(); |
295 | 317 | }); |
296 | 318 |
|
|
0 commit comments