Last active
December 13, 2015 18:29
-
-
Save digitarald/4956057 to your computer and use it in GitHub Desktop.
Image selection via Web Activity on Firefox OS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ('MozActivity' in window) { | |
document.getElementById('my-file-input').addEventListener('click', function(evt) { | |
evt.preventDefault(); | |
var picking = new MozActivity({ | |
name: 'pick', | |
data: { | |
type: 'image/jpg' | |
} | |
}); | |
picking.onsuccess = function() { | |
// this.result.blob holds the File reference | |
// Blob and XMLHttpRequest2 | |
// https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/Sending_and_Receiving_Binary_Data | |
// Getting the image data | |
var img = new Image(); | |
img.onload = function() { | |
// Draw image to canvas for resizing or similar | |
} | |
img.src = URL.createObjectURL(this.result.blob); | |
}; | |
picking.onerror = function () { | |
console.log('No image!'); | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment