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

Method handleIt

js/inserter.js:201–229  ·  view source on GitHub ↗
(source)

Source from the content-addressed store, hash-verified

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,

Callers

nothing calls this directly

Calls 4

loadedMethod · 0.95
finishLoadingMethod · 0.95
getAvailableOptionsMethod · 0.95
fitImageMethod · 0.80

Tested by

no test coverage detected