MCPcopy Create free account
hub / github.com/devforth/painterro / handleOpen

Method handleOpen

js/inserter.js:199–243  ·  view source on GitHub ↗
(src, mimetype)

Source from the content-addressed store, hash-verified

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) {

Callers 2

initEventHandlersMethod · 0.80
loadImageMethod · 0.80

Calls 2

startLoadingMethod · 0.95
imgToDataURLFunction · 0.90

Tested by

no test coverage detected