(src, mimetype)
| 197 | } |
| 198 | |
| 199 | handleOpen(src, mimetype) { |
| 200 | this.startLoading(); |
| 201 | const handleIt = (source) => { |
| 202 | const img = new Image(); |
| 203 | const empty = this.main.worklog.clean; |
| 204 | const replaceAllImmediately = empty && this.main.params.replaceAllOnEmptyBackground; |
| 205 | img.onload = () => { |
| 206 | if (replaceAllImmediately) { |
| 207 | this.main.fitImage(img, mimetype); |
| 208 | } else { |
| 209 | this.loaded(img, mimetype); |
| 210 | } |
| 211 | this.finishLoading(); |
| 212 | }; |
| 213 | img.onerror = () => { |
| 214 | if (typeof this.main.params.onImageFailedOpen === 'function') { |
| 215 | this.main.params.onImageFailedOpen(); |
| 216 | } |
| 217 | }; |
| 218 | // img.crossOrigin = '*'; TODO: try to identify CORS issues earlier? |
| 219 | img.src = source; |
| 220 | if (!replaceAllImmediately) { |
| 221 | const availableOptions = this.getAvailableOptions(); |
| 222 | if (availableOptions.length !== 1) { |
| 223 | this.selector.removeAttribute('hidden'); |
| 224 | this.waitChoice = true; |
| 225 | } else { |
| 226 | this.doLater = this.activeOption[availableOptions[0]].handle; |
| 227 | } |
| 228 | } |
| 229 | }; |
| 230 | |
| 231 | if (src.indexOf('data') !== 0) { |
| 232 | imgToDataURL(src, (dataUrl) => { // if CORS will not allow, |
| 233 | // better see error in console than have different canvas mode |
| 234 | handleIt(dataUrl); |
| 235 | }, () => { |
| 236 | if (typeof this.main.params.onImageFailedOpen === 'function') { |
| 237 | this.main.params.onImageFailedOpen(); |
| 238 | } |
| 239 | }); |
| 240 | } else { |
| 241 | handleIt(src); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | handleKeyDown(evt) { |
| 246 | if (this.waitChoice && evt.keyCode === KEYS.esc) { |
no test coverage detected