For proper complete article and live demo visitjquery mobile Iphone app
I recently added article about web storage and demonstrated how to use local storage and session storage. So i thought to go further and create a application based on html5 web storage so that me and you all can better understand how web storage works and how it can be coded.
Terms of Agreement:
By using this article, you agree to the following terms...
You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
You may link to this article from another website, but ONLY if it is not wrapped in a frame.
You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
So here we are creating jquery mobile Iphone/Ipad application which is simple Todo app for iphone ipad using jquery mobile and web storage, where you can list your todo’s and once its completed you delete it from list. For this app i am using local storage so if you create a list and then come back after few days it will be there as it is, so you can use this app for your daily tasks management.
TODO App
<SCRIPT src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
<SCRIPT src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js">
var i = localStorage.length;
function onBodyLoad(){
var todo = "";
create_new_list();
$("#clear").click(function(){
localStorage.clear();
$("#todo_list li").fadeOut(function(){
$(this).html("");
});
});
$("#remove").live("click",function(e){
var index = $(this).closest("li").attr("id");
$(this).closest("li").slideUp(function(){
// remove the selected item
localStorage.removeItem('names_'+index);
// rearrange localstorage array
for(i=0; i < localStorage.length; i++) {
if( !localStorage.getItem("names_"+i)) {
localStorage.setItem("names_"+i, localStorage.getItem('names_' + (i+1) ) );
localStorage.removeItem('names_'+ (i+1) );
}
}
// clear existing list UI
$("#todo_list").html("");
// create new list
create_new_list();
});
});
}
function create_new_list(){
for (var i = 0; i < localStorage.length; i++){
todo = localStorage.getItem('names_'+i);
$("#todo_list").append('
');
}
// Refresh list so jquery mobile can apply iphone look to the list
$("#todo_list").listview();
$("#todo_list").listview("refresh");
}
function save_todo(){
var todo = $("#textinput1").val();
if(todo.length){
// store item in local storage
localStorage['names_'+i] = todo;
// Update todo list
$("#todo_list").append('
');
// Refresh list so jquery mobile can apply iphone look to the list
$("#todo_list").listview();
$("#todo_list").listview("refresh");
i++;
}
}
Report Bad Submission
Your Vote
Other User Comments
There are no comments on this submission.
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)