|
15 | 15 |
|
16 | 16 | ns.GifExportController.prototype.init = function () { |
17 | 17 | this.uploadStatusContainerEl = document.querySelector('.gif-upload-status'); |
18 | | - this.previewContainerEl = document.querySelector('.gif-export-preview'); |
19 | | - this.uploadButton = document.querySelector('.gif-upload-button'); |
20 | 18 | this.downloadButton = document.querySelector('.gif-download-button'); |
21 | 19 | this.repeatCheckbox = document.querySelector('.gif-repeat-checkbox'); |
22 | 20 |
|
23 | 21 | // Initialize repeatCheckbox state |
24 | 22 | this.repeatCheckbox.checked = this.getRepeatSetting_(); |
25 | 23 |
|
26 | | - this.addEventListener(this.uploadButton, 'click', this.onUploadButtonClick_); |
27 | 24 | this.addEventListener(this.downloadButton, 'click', this.onDownloadButtonClick_); |
28 | 25 | this.addEventListener(this.repeatCheckbox, 'change', this.onRepeatCheckboxChange_); |
29 | 26 |
|
|
36 | 33 | return this.exportController.getExportZoom(); |
37 | 34 | }; |
38 | 35 |
|
39 | | - ns.GifExportController.prototype.onUploadButtonClick_ = function (evt) { |
40 | | - evt.preventDefault(); |
41 | | - var zoom = this.getZoom_(); |
42 | | - var fps = this.piskelController.getFPS(); |
43 | | - |
44 | | - this.renderAsImageDataAnimatedGIF(zoom, fps, this.uploadImageData_.bind(this)); |
45 | | - }; |
46 | | - |
47 | 36 | ns.GifExportController.prototype.onDownloadButtonClick_ = function (evt) { |
48 | 37 | var zoom = this.getZoom_(); |
49 | 38 | var fps = this.piskelController.getFPS(); |
|
58 | 47 | }); |
59 | 48 | }; |
60 | 49 |
|
61 | | - ns.GifExportController.prototype.uploadImageData_ = function (imageData) { |
62 | | - this.updatePreview_(imageData); |
63 | | - this.previewContainerEl.classList.add('preview-upload-ongoing'); |
64 | | - |
65 | | - pskl.app.imageUploadService.upload(imageData, |
66 | | - this.onImageUploadCompleted_.bind(this), |
67 | | - this.onImageUploadFailed_.bind(this)); |
68 | | - }; |
69 | | - |
70 | | - ns.GifExportController.prototype.onImageUploadCompleted_ = function (imageUrl) { |
71 | | - this.updatePreview_(imageUrl); |
72 | | - this.updateStatus_(imageUrl); |
73 | | - this.previewContainerEl.classList.remove('preview-upload-ongoing'); |
74 | | - }; |
75 | | - |
76 | | - ns.GifExportController.prototype.onImageUploadFailed_ = function (event, xhr) { |
77 | | - if (xhr.status === 500) { |
78 | | - $.publish(Events.SHOW_NOTIFICATION, [{ |
79 | | - 'content': 'Upload failed : ' + xhr.responseText, |
80 | | - 'hideDelay' : 5000 |
81 | | - }]); |
82 | | - } |
83 | | - }; |
84 | | - |
85 | 50 | ns.GifExportController.prototype.updatePreview_ = function (src) { |
86 | 51 | this.previewContainerEl.innerHTML = '<div><img style="max-width:32px;" src="' + src + '"/></div>'; |
87 | 52 | }; |
|
166 | 131 | ns.GifExportController.prototype.getRepeatSetting_ = function () { |
167 | 132 | return pskl.UserSettings.get(pskl.UserSettings.EXPORT_GIF_REPEAT); |
168 | 133 | }; |
169 | | - |
170 | | - ns.GifExportController.prototype.updateStatus_ = function (imageUrl, error) { |
171 | | - if (imageUrl) { |
172 | | - var linkTpl = '<a class="highlight" href="{{link}}" target="_blank">{{shortLink}}</a>'; |
173 | | - var linkHtml = pskl.utils.Template.replace(linkTpl, { |
174 | | - link : imageUrl, |
175 | | - shortLink : this.shorten_(imageUrl, URL_MAX_LENGTH, '...') |
176 | | - }); |
177 | | - this.uploadStatusContainerEl.innerHTML = 'Your image is now available at : ' + linkHtml; |
178 | | - } else { |
179 | | - // FIXME : Should display error message instead |
180 | | - } |
181 | | - }; |
182 | | - |
183 | | - ns.GifExportController.prototype.shorten_ = function (url, maxLength, suffix) { |
184 | | - if (url.length > maxLength) { |
185 | | - var index = Math.round((maxLength - suffix.length) / 2); |
186 | | - var part1 = url.substring(0, index); |
187 | | - var part2 = url.substring(url.length - index, url.length); |
188 | | - url = part1 + suffix + part2; |
189 | | - } |
190 | | - return url; |
191 | | - }; |
192 | 134 | })(); |
0 commit comments