Commit ffa7160026374366e06bca79815de2124e153880

  • avatar
  • p4bl0 <pablo.rauzy @gm…l.com>
  • Wed Jun 24 04:16:09 CEST 2009
added tasks state marker (todo/started/done)
twotwodo.css
(12 / 0)
  
113113.memowiki {
114114 text-decoration: underline;
115115}
116.state {
117 font-weight: bold;
118}
119.todo {
120 color: #f00;
121}
122.started {
123 color: #fa0;
124}
125.done {
126 color: #9c3;
127}
twotwodo.js
(72 / 12)
  
2424
2525TwoTwoDo.txt2html = function (txt) {
2626 var html = txt.replace(/\n/g, '<br />');
27 html = html.replace(/\#([a-zA-Z0-9]*)/g, '#<span class="memowiki">$1</span>');
27 html = html.replace(/#([a-zA-Z0-9]*)/g,
28 '#<span class="memowiki">$1</span>');
29 var tid = $('p.task input:first').attr('name');
30 if (tid == undefined) {
31 tid = $('#memo textarea').attr('name');
32 }
33 var i = 0, tmp1, tmp2 = html;
34 do {
35 tmp1 = tmp2; i++;
36 tmp2 = tmp1.replace(/(^|[^>]):(todo|started|done)/,
37 '$1<span class="state $2" id="'+tid+'-state-'+i+'">:$2</span>');
38 } while (tmp1 != tmp2);
39 html = tmp2;
40
2841 return html;
2942};
3043
3144TwoTwoDo.html2txt = function (html) {
3245 var txt = html.replace(/<br( \/)?>/g, '\n');
33 txt = txt.replace(/\#<span class="memowiki">([a-zA-Z0-9]*)<\/span>/g, '#$1');
46 txt = txt.replace(/#<span class="memowiki">([a-zA-Z0-9]*)<\/span>/g, '#$1');
47 txt = txt.replace(/<span class="state (todo|started|done)" id=".*?-state-[0-9]+">:\1<\/span>/g, ':$1');
3448 return txt;
3549};
3650
3751TwoTwoDo.data = {
3852 tasks: {
39 iu: {'iu-0': 'This is a task, click to edit'},
40 niu: {'niu-0': 'Double click in a section to add a new task'},
41 inu: {'inu-0': 'Delete this text to remove this task'},
42 ninu: {'ninu-0': 'Welcome to TwoTwoDo!', 'ninu-1': 'The MemoWiki use hashtag: #<span class="memowiki">default</span>'}
53 iu: {
54 'iu-0': 'This is a task, click to edit',
55 'iu-1': 'Click on this task\'s state marker twice <span class="state todo" id="iu-1-state-0">:todo</span>'
56 },
57 niu: {
58 'niu-0': 'Double click in a section to add a new task'
59 },
60 inu: {
61 'inu-0': 'Delete this text to remove this task'
62 },
63 ninu: {
64 'ninu-0': 'Welcome to TwoTwoDo!',
65 'ninu-1': 'The MemoWiki use hashtag: #<span class="memowiki">default</span>'
66 }
4367 },
4468 cur_memo: 'default',
4569 memo: {'default': 'This is the wiki content for the \'default\' hashtag :-)'}
8484
8585TwoTwoDo.task.edit = function (tid) {
8686 $('p.task input').blur();
87
8788 var task = TwoTwoDo.html2txt($('#'+tid).html());
8889 $('#'+tid).unbind('click')
8990 .addClass('edit')
90 .html('<input type="text" value="'+task+'" />');
91 .html('<input type="text" name="'+tid+'" value="'+task+'" />');
9192 $('#'+tid+' input').focus().blur(function(){
9293 TwoTwoDo.task.save(tid);
9394 });
113113 TwoTwoDo.writeCookie('TwoTwoDo');
114114};
115115
116TwoTwoDo.task.switchState = function (tsid) {
117 $('p.task input').blur();
118 $('#memo textarea').blur();
119
120 var state = $('#'+tsid).html().substr(1);
121 var newState;
122 switch (state) {
123 case 'todo':
124 newState = 'started'; break;
125 case 'started':
126 newState = 'done'; break;
127 default:
128 newState = 'todo';
129 }
130 $('#'+tsid).removeClass(state)
131 .addClass(newState)
132 .html(':'+newState);
133
134 var tmp = tsid.split(/-/);
135 if (tmp.length == 4) {
136 var section = tmp[0];
137 var tid = tsid.substr(0, tsid.indexOf('-state'));
138 TwoTwoDo.data.tasks[section][tid] = $('#'+tid).html();
139 }
140 else {
141 TwoTwoDo.data.memo[TwoTwoDo.data.cur_memo] = $('#memo').html();
142 }
143
144 TwoTwoDo.writeCookie('TwoTwoDo');
145};
146
116147TwoTwoDo.task.remove = function (tid) {
117148 $('#'+tid).remove();
118149 var section = tid.split(/-/)[0];
155155
156156TwoTwoDo.memo.show = function (memo) {
157157 $('p.task input').blur();
158 $('#memo textarea').blur();
158159
159160 if (TwoTwoDo.data.memo[memo] == undefined) {
160161 TwoTwoDo.data.memo[memo] = 'New memo';
175175
176176 $('#memo').unbind('click')
177177 .addClass('edit')
178 .html('<textarea>'+memo+'</textarea>');
178 .html('<textarea name="'+TwoTwoDo.data.cur_memo+'">'+memo+'</textarea>');
179179 $('#memo textarea').attr('rows', r)
180180 .focus()
181181 .blur(function(){
188188
189189TwoTwoDo.memo.save = function () {
190190 var memo = TwoTwoDo.txt2html($('#memo textarea').val());
191
191
192192 $('#memo').removeClass('edit')
193193 .html(memo)
194194 .click(function(){
241241 $('#memo').click(function(){
242242 TwoTwoDo.memo.edit();
243243 });
244 $('span.memowiki').live('click', function(){
245 TwoTwoDo.memo.show($(this).html());
246 });
244 $('.memowiki').live('click', function(){
245 TwoTwoDo.memo.show($(this).html());
246 });
247 $('.state').live('click', function(){
248 TwoTwoDo.task.switchState($(this).attr('id'));
249 });
247250};
248251
249252$(document).ready(function(){