var tdList = $('.box .tdList');
var tdMask = 'tdl_';
function showItem(){
var sLocal = localStorage.length;
if (sLocal > 0){
for( var i = 0; i < sLocal; i++ ){
var key = localStorage.key(i);
if ( key.indexOf(tdMask) == 0 ){
$('<li></li>').addClass('list')
.attr('data-itemid', key)
.text(localStorage.getItem(key))
.prependTo(tdList);
}
}
}
}
showItem();
$('.box input').on('keydown', function(e){
if (e.keyCode != 13)
return;
var str = e.target.value;
e.target.value = '';
if (str.length > 0){
var nId = 0;
tdList.children().each(function(index, el){
var jeId = $(el).attr('data-itemid').slice(4);
if (jeId > nId)
nId = jeId
})
nId++;
localStorage.setItem(tdMask+nId, str);
$('<li></li>').addClass('list NEW')
.attr('data-itemid', tdMask+nId)
.text(str).prependTo(tdList);
setTimeout(function(){
$('.list').removeClass('NEW')
}, 1500);
}
});
$(document).on('click', '.list', function(e){
var jet = $(e.target);
localStorage.removeItem(jet.attr('data-itemid'));
jet.remove();
});