JSFiddle - React, Tailwind, and code Playground
by konijn_gmail_com
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/redmond/jquery-ui.min.css">
<script src="https://jquery-elastic.googlecode.com/svn-history/r37/trunk/jquery.elastic.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script>
<h4>Tasks</h4><button id="undo">Undo</button><button id="redo">Redo</button>
<p id="info"></p>
<div id="todo_list_container">
<ul id="todo_items">
</ul>
<span id="add_todo">
<button id="add" disabled>Add</button>
<textarea id="new_todo_item" placeholder="Create new task"></textarea>
<input type="checkbox" id="star" /><label>Star</label>
</span>
</div>
CSS
html{
font-family: "Arial";
}
h4{
display: inline-block;
}
.item_content{
display: inline;
}
#undo, #redo{
text-align: right;
display: inline-block;
}
#todo_list_container{
/*border: 1px solid black;*/
min-width: 400px;
}
#todo_items{
/*border: 1px solid red;
display: inline-block;*/
}
ul
{
list-style-type: none;
}
label{
float: right;
}
.star{
float: right;
}
#add, #star, label{
vertical-align: top;
}
textarea{
width: 75%;
resize: none;
border: none;
overflow: auto;
outline: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
JavaScript
$(function(){
// check if browser supports localStorage, if not, notify and exit
checkLocalStorageBrowserSupport();
//check localStorage for existing data
checkLocalStorageExistingData();
tweakMinorUIStuff();
// todo_item class
var todo_item = {
content: "", // default content
starred: false, // default star value
addItem: function(){
// collect new item data
todo_item.content = $("#new_todo_item").val();
todo_item.starred = $("#star").prop('checked');
addItem(todo_item);
},
toggleStar: function(){
// update localStorage
// update UI
alert("working!");
},
editItem: function(){
// toggle textarea
// update localStorage
// update UI
}
}
$("#add").click(function(){ todo_item.addItem(); });
$(".star").click(function(){ todo_item.toggleStar(); });
})
function checkLocalStorageBrowserSupport(){
if(!window.localStorage) {
// notify user
$("#info").text("Your browser does not support the HTML5 feature 'localStorage'. Please use an updated browser for this application to work.");
// stop
return false;
} else
return true;
}
function checkLocalStorageExistingData(){
if(localStorage.getItem('todo_items')){
var todo_items_json = localStorage.getItem('todo_items');
var todo_items = todo_items_json ? JSON.parse(todo_items_json) : [];
todo_items.forEach(function(item){
var item_content = item[0];
var star_check = item[1];
var checked = "";
if(star_check) checked = "checked";
$("ul").append("<li><button class='done'>Done</button>"+
"<p class='item_content'>"+item_content+"</p>"+
...