Commit f6dede8613d9318d78ba1bbe4e0fc0ab005b1991

  • avatar
  • p4bl0 <pablo.rauzy @gm…l.com>
  • Wed Jun 24 18:37:22 CEST 2009
added possibility to have other TwoTwoDo list (i.e. use another cookie) using @listName
  
132132 text-decoration: underline;
133133 cursor: help;
134134}
135.cookie {
136 cursor: pointer;
137 font-style: italic;
138}
135139.state {
136140 font-weight: bold;
137 cursor: pointer;
141 cursor: crosshair;
138142}
139143.todo {
140144 color: #f00;
twotwodo.js
(37 / 14)
  
22
33TwoTwoDo.utils = new Object();
44
5TwoTwoDo.utils.readCookie = function (name) {
5TwoTwoDo.utils.readCookie = function () {
66 if (document.cookie.length > 0) {
7 var start = document.cookie.indexOf(name+'=');
7 var start = document.cookie.indexOf(TwoTwoDo.data.cookie+'=');
88 if (start != -1) {
9 start = start + name.length + 1;
9 start = start + TwoTwoDo.data.cookie.length + 1;
1010 var end = document.cookie.indexOf(";", start);
1111 if (end == -1) {
1212 end = document.cookie.length;
1717 return null;
1818};
1919
20TwoTwoDo.utils.writeCookie = function (name) {
20TwoTwoDo.utils.writeCookie = function () {
2121 var tasks = TwoTwoDo.data.toSource();
2222 var expires = new Date();
2323 expires.setDate(expires.getDate()+365);
24 document.cookie = name+'='+escape(tasks)+';expires='+expires.toGMTString();
24 document.cookie = TwoTwoDo.data.cookie+'='+escape(tasks)+';expires='+expires.toGMTString();
2525};
2626
2727TwoTwoDo.utils.txt2html = function (txt) {
2828 var html = txt.replace(/\n/g, '<br />');
29 html = html.replace(/#([a-zA-Z0-9]*)/g,
29 html = html.replace(/#([a-zA-Z0-9_-]*)/g,
3030 '#<span class="memowiki">$1</span>');
31 html = html.replace(/@([a-zA-Z0-9_-]*)/g,
32 '@<span class="cookie">$1</span>');
3133 var tid = $('p.task input:first').attr('name');
3234 if (tid == undefined) {
3335 tid = $('#memo textarea').attr('name');
4848
4949TwoTwoDo.utils.html2txt = function (html) {
5050 var txt = html.replace(/<br( \/)?>/g, '\n');
51 txt = txt.replace(/#<span class="memowiki">([a-zA-Z0-9]*)<\/span>/g, '#$1');
51 txt = txt.replace(/#<span class="memowiki">([a-zA-Z0-9_-]*)<\/span>/g, '#$1');
52 txt = txt.replace(/@<span class="cookie">([a-zA-Z0-9_-]*)<\/span>/g, '@$1');
5253 txt = txt.replace(/<span class="state (todo|started|done|canceled)" id=".*?-state-[0-9]+">:\1<\/span>/g, ':$1');
5354 return txt;
5455};
5556
57TwoTwoDo.utils.changeCookie = function (cookie) {
58 $('p.task input').blur();
59 $('#memo textarea').blur();
60
61 var url = document.location.toString();
62 if (url.indexOf('?') != -1) {
63 url = url.substring(0, url.indexOf('?'));
64 }
65
66 document.location = url+'?'+cookie;
67};
68
5669TwoTwoDo.data = {
70 cookie: 'TwoTwoDo-default',
5771 tasks: {
5872 iu: {
5973 'iu-0': 'This is a task, click to edit',
8080 'inu-0': 'Delete this text to remove this task'
8181 },
8282 ninu: {
83 'ninu-0': 'Welcome to TwoTwoDo!',
83 'ninu-0': 'Welcome to your @<span class="cookie">default</span> TwoTwoDo!',
8484 'ninu-1': 'The MemoWiki use hashtag: #<span class="memowiki">memo</span>'
8585 }
8686 },
8787 cur_memo: 'memo',
8888 memo: {
89 'memo': 'This is the MemoWiki content for the \'memo\' hashtag :-)<br />Like tasks, memo can contains state markers and hashtag links to other memo.<br /><br />Write #<span class="memowiki">another</span> memo [<span class="state todo" id="memo-state-0">:todo</span>]'
89 'memo': 'This is the MemoWiki content for the \'memo\' hashtag :-)<br />Like tasks, memo can contains state markers and hashtag links to other memo.<br /><br />Write #<span class="memowiki">another</span> memo [<span class="state todo" id="memo-state-0">:todo</span>]<br />Start a new TwoTwoDo for your @<span class="cookie">work</span> for instance [<span class="state todo" id="memo-state-0">:todo</span>]'
9090 }
9191};
9292
131131 TwoTwoDo.data.tasks[section][tid] = task;
132132 }
133133
134 TwoTwoDo.utils.writeCookie('TwoTwoDo');
134 TwoTwoDo.utils.writeCookie();
135135};
136136
137137TwoTwoDo.task.switchState = function (tsid) {
164164 TwoTwoDo.data.memo[TwoTwoDo.data.cur_memo] = $('#memo').html();
165165 }
166166
167 TwoTwoDo.utils.writeCookie('TwoTwoDo');
167 TwoTwoDo.utils.writeCookie();
168168};
169169
170170TwoTwoDo.task.remove = function (tid) {
187187 $('#memo').html(TwoTwoDo.data.memo[memo]);
188188 TwoTwoDo.data.cur_memo = memo;
189189
190 TwoTwoDo.utils.writeCookie('TwoTwoDo');
190 TwoTwoDo.utils.writeCookie();
191191};
192192
193193TwoTwoDo.memo.edit = function () {
225225 TwoTwoDo.data.memo[TwoTwoDo.data.cur_memo] = memo;
226226 }
227227
228 TwoTwoDo.utils.writeCookie('TwoTwoDo');
228 TwoTwoDo.utils.writeCookie();
229229};
230230
231231TwoTwoDo.memo.remove = function () {
245245};
246246
247247TwoTwoDo.init = function () {
248 var data = TwoTwoDo.utils.readCookie('TwoTwoDo');
248 var url = document.location.toString();
249 if (url.indexOf('?') != -1) {
250 TwoTwoDo.data.cookie = 'TwoTwoDo-'+url.substr(url.indexOf('?')+1);
251 }
252 var data = TwoTwoDo.utils.readCookie();
249253 if (data != null) {
250254 TwoTwoDo.data = eval('('+data+')');
251255 }
270270 });
271271 $('.memowiki').live('click', function(){
272272 TwoTwoDo.memo.show($(this).html());
273 });
274 $('.cookie').live('click', function(){
275 TwoTwoDo.utils.changeCookie($(this).html());
273276 });
274277 $('.state').live('click', function(){
275278 TwoTwoDo.task.switchState($(this).attr('id'));