- Author:
- Richard Zhang
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- github.com/richardzcode
- Compo:
- classic
- Demo link:
- https://js1k.com/2012-love/demo/1160
- Shortlink:
- https://js1k.com/1160
- Blog post:
- please update here!
- Bytes:
- 1018
- Chars:
- 1018
- Submission
var LS=localStorage,K='js1ktodo',S=function(){LS.setItem(K,JSON.stringify(l));draw()},L={set:function(t,i){t?l[i]=t:l[cur=l.length]=T();S(l)},del:function(){l.splice(cur,1);cur?cur--:(l.length?0:L.set(T(),0));S(l)},edit:function(c){var t=l[cur];t.s=c?(t.s+String.fromCharCode(c)):t.s.substr(0,t.s.length-1);L.set(t,cur)},mv:function(u){cur+=u?((cur==l.length-1)?0:1):(cur?-1:0);draw()}},T=function(){return{s:''}},l=JSON.parse(LS.getItem(K))||[T()],cur=l.length-1;draw=function(){a.clearRect(0,0,c.width,c.height);var i=l.length-1,j=0;for(i;i>=0;i--){drawT(l[i],20*j++,(i==cur))}};drawT=function(t,y,cur){a.beginPath();a.rect(0,y,c.width,20);a.fillStyle=cur?'#ffd':'#ff5';a.fill();a.strokeStyle=cur?'#555':'#bbb';a.stroke();a.font='14px Verdana';a.fillStyle='#000';a.fillText(t.s,8,y+14)};b.onkeydown=function(evt){var k=evt.which,m={8:L.edit,13:L.set,46:L.del,38:L.mv,40:L.mv};m[k]?m[k]((k==38)?1:0):0;(k==8)?evt.preventDefault():0};b.onkeypress=function(evt){evt.charCode?L.edit(evt.charCode):0};c.height=600;draw();
- Description
- To do list kept in local storage. So close browser don't lose items.
Enter -- create new item.
Delete -- delete item.
Backspace -- delete char. Up/Down -- move.
- Base64 encoded
dmFyIExTPWxvY2FsU3RvcmFnZSxLPSdqczFrdG9kbycsUz1mdW5jdGlvbigpe0xTLnNldEl0ZW0oSyxKU09OLnN0cmluZ2lmeShsKSk7ZHJhdygpfSxMPXtzZXQ6ZnVuY3Rpb24odCxpKXt0P2xbaV09dDpsW2N1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50RGVmYXVsdCgpOjB9O2Iub25rZXlwcmVzcz1mdW5jdGlvbihldnQpe2V2dC5jaGFyQ29kZT9MLmVkaXQoZXZ0LmNoYXJDb2RlKTowfTtjLmhlaWdodD02MDA7ZHJhdygpOw==
- Original source
var LS = localStorage
, K = 'js1ktodo'
, S = function() {
LS.setItem(K, JSON.stringify(l));
draw();
}
, L = {
set: function(t, i) { // t - null means add.
t? l[i] = t : l[cur = l.length] = T();
S(l);
}
, del: function() {
l.splice(cur, 1);
cur? cur-- : (l.length? 0 : L.set(T(), 0));
S(l);
}
, edit: function(c) {
var t = l[cur];
t.s = c? (t.s + String.fromCharCode(c)) : t.s.substr(0, t.s.length - 1);
L.set(t, cur);
}
, mv: function(u) { // u - Up or down
cur += u? ((cur == l.length - 1)? 0 : 1) : (cur? -1 : 0);
draw();
}
}
, T = function() {
return {
s: ''
};
}
, l = JSON.parse(LS.getItem(K)) || [T()]
, cur = l.length - 1;
draw = function() {
a.clearRect(0, 0, c.width, c.height);
var i = l.length - 1
, j = 0;
for (i; i >= 0; i--) {
drawT(l[i], 20*j++, (i == cur));
}
};
drawT = function(t, y, cur) {
a.beginPath();
a.rect(0, y, c.width, 20);
a.fillStyle = cur? '#ffd' : '#ff5';
a.fill();
a.strokeStyle = cur? '#555' : '#bbb';
a.stroke();
a.font = '14px Verdana';
a.fillStyle = '#000';
a.fillText(t.s, 8, y + 14);
};
b.onkeydown = function(evt) {
var k = evt.which
, m = {
8: L.edit // Backspace
, 13: L.set // Enter
, 46: L.del // Del
, 38: L.mv // Up
, 40: L.mv // Down
};
m[k]? m[k]((k == 38)? 1 : 0) : 0;
(k == 8)? evt.preventDefault() : 0;
};
b.onkeypress = function(evt) {
evt.charCode? L.edit(evt.charCode) : 0;
};
c.height = 600;
draw();