var ImageUpload = function(t, returnCB){ var events = new EventManager, hiddenInput = getHiddenInput(), result = getResult(); if(!returnCB) console.error("You must have a return callback to initialize ImageUpload.") t.appendChild(result); events.add(hiddenInput, 'change', checkFileInput); this.open = openFileInput; this.exit = exit; function Image(d, rects){ this.data = d; this.width = rects.width; this.height = rects.height; } function Rects(d){ var v = null; result.src = d; result.classList.remove('noDisplay'); setTimeout(setValue, 0); function setValue(){ v = result.getClientRects()[0]; result.classList.add('noDisplay'); result.src = ""; returnCB(new Image(d, v)); } } function getResult(){ var i = document.createElement('img'); i.className = 'noDisplay'; return i; } function openFileInput(e){ if(e && e.preventDefault) e.preventDefault(); hiddenInput.click(); } function checkFileInput(){ new FileToImageData(hiddenInput, returnFileInputData); } function returnFileInputData(a){ new Rects(a[0].result); } function exit(){ removeChild(t, result); if(!!events) events.reset(); events = hiddenInput = result = null; } };