Skip to content

Instantly share code, notes, and snippets.

@rominirani
Created August 16, 2013 08:04
Show Gist options
  • Save rominirani/6248133 to your computer and use it in GitHub Desktop.
Save rominirani/6248133 to your computer and use it in GitHub Desktop.
Episode #9 : Firefox OS Tutorial : Device Storage : app.js
function listContents(storagename) {
//Clear up the list first
$('#results').html("");
var files = navigator.getDeviceStorage(storagename);
var cursor = files.enumerate();
cursor.onsuccess = function () {
//alert("Got something");
var file = this.result;
if (file != null) {
var imageElement = $('<img height="100" width="75">');
imageElement.attr('src', window.URL.createObjectURL(file));
$("<p>" + file.name + "," + file.lastModifiedDate + "," + file.type + "," + file.size + "</p>").appendTo('#results');
imageElement.appendTo("#results");
this.done = false;
}
else {
this.done = true;
}
if (!this.done) {
this.continue();
}
}
}
$(document).ready(function(){
$("#browseSDCard").click(function(){
listContents('sdcard');
});
$("#browseVideos").click(function(){
listContents('videos');
});
$("#browseMusic").click(function(){
listContents('music');
});
$("#browsePictures").click(function(){
listContents('pictures');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment