Commit f6dede8613d9318d78ba1bbe4e0fc0ab005b1991
- Diff rendering mode:
- inline
- side by side
twotwodo.css
(5 / 1)
|   | |||
| 132 | 132 | text-decoration: underline; | |
| 133 | 133 | cursor: help; | |
| 134 | 134 | } | |
| 135 | .cookie { | ||
| 136 | cursor: pointer; | ||
| 137 | font-style: italic; | ||
| 138 | } | ||
| 135 | 139 | .state { | |
| 136 | 140 | font-weight: bold; | |
| 137 | cursor: pointer; | ||
| 141 | cursor: crosshair; | ||
| 138 | 142 | } | |
| 139 | 143 | .todo { | |
| 140 | 144 | color: #f00; |
twotwodo.js
(37 / 14)
|   | |||
| 2 | 2 | ||
| 3 | 3 | TwoTwoDo.utils = new Object(); | |
| 4 | 4 | ||
| 5 | TwoTwoDo.utils.readCookie = function (name) { | ||
| 5 | TwoTwoDo.utils.readCookie = function () { | ||
| 6 | 6 | if (document.cookie.length > 0) { | |
| 7 | var start = document.cookie.indexOf(name+'='); | ||
| 7 | var start = document.cookie.indexOf(TwoTwoDo.data.cookie+'='); | ||
| 8 | 8 | if (start != -1) { | |
| 9 | start = start + name.length + 1; | ||
| 9 | start = start + TwoTwoDo.data.cookie.length + 1; | ||
| 10 | 10 | var end = document.cookie.indexOf(";", start); | |
| 11 | 11 | if (end == -1) { | |
| 12 | 12 | end = document.cookie.length; | |
| … | … | ||
| 17 | 17 | return null; | |
| 18 | 18 | }; | |
| 19 | 19 | ||
| 20 | TwoTwoDo.utils.writeCookie = function (name) { | ||
| 20 | TwoTwoDo.utils.writeCookie = function () { | ||
| 21 | 21 | var tasks = TwoTwoDo.data.toSource(); | |
| 22 | 22 | var expires = new Date(); | |
| 23 | 23 | 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(); | ||
| 25 | 25 | }; | |
| 26 | 26 | ||
| 27 | 27 | TwoTwoDo.utils.txt2html = function (txt) { | |
| 28 | 28 | 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, | ||
| 30 | 30 | '#<span class="memowiki">$1</span>'); | |
| 31 | html = html.replace(/@([a-zA-Z0-9_-]*)/g, | ||
| 32 | '@<span class="cookie">$1</span>'); | ||
| 31 | 33 | var tid = $('p.task input:first').attr('name'); | |
| 32 | 34 | if (tid == undefined) { | |
| 33 | 35 | tid = $('#memo textarea').attr('name'); | |
| … | … | ||
| 48 | 48 | ||
| 49 | 49 | TwoTwoDo.utils.html2txt = function (html) { | |
| 50 | 50 | 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'); | ||
| 52 | 53 | txt = txt.replace(/<span class="state (todo|started|done|canceled)" id=".*?-state-[0-9]+">:\1<\/span>/g, ':$1'); | |
| 53 | 54 | return txt; | |
| 54 | 55 | }; | |
| 55 | 56 | ||
| 57 | TwoTwoDo.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 | |||
| 56 | 69 | TwoTwoDo.data = { | |
| 70 | cookie: 'TwoTwoDo-default', | ||
| 57 | 71 | tasks: { | |
| 58 | 72 | iu: { | |
| 59 | 73 | 'iu-0': 'This is a task, click to edit', | |
| … | … | ||
| 80 | 80 | 'inu-0': 'Delete this text to remove this task' | |
| 81 | 81 | }, | |
| 82 | 82 | ninu: { | |
| 83 | 'ninu-0': 'Welcome to TwoTwoDo!', | ||
| 83 | 'ninu-0': 'Welcome to your @<span class="cookie">default</span> TwoTwoDo!', | ||
| 84 | 84 | 'ninu-1': 'The MemoWiki use hashtag: #<span class="memowiki">memo</span>' | |
| 85 | 85 | } | |
| 86 | 86 | }, | |
| 87 | 87 | cur_memo: 'memo', | |
| 88 | 88 | 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>]' | ||
| 90 | 90 | } | |
| 91 | 91 | }; | |
| 92 | 92 | ||
| … | … | ||
| 131 | 131 | TwoTwoDo.data.tasks[section][tid] = task; | |
| 132 | 132 | } | |
| 133 | 133 | ||
| 134 | TwoTwoDo.utils.writeCookie('TwoTwoDo'); | ||
| 134 | TwoTwoDo.utils.writeCookie(); | ||
| 135 | 135 | }; | |
| 136 | 136 | ||
| 137 | 137 | TwoTwoDo.task.switchState = function (tsid) { | |
| … | … | ||
| 164 | 164 | TwoTwoDo.data.memo[TwoTwoDo.data.cur_memo] = $('#memo').html(); | |
| 165 | 165 | } | |
| 166 | 166 | ||
| 167 | TwoTwoDo.utils.writeCookie('TwoTwoDo'); | ||
| 167 | TwoTwoDo.utils.writeCookie(); | ||
| 168 | 168 | }; | |
| 169 | 169 | ||
| 170 | 170 | TwoTwoDo.task.remove = function (tid) { | |
| … | … | ||
| 187 | 187 | $('#memo').html(TwoTwoDo.data.memo[memo]); | |
| 188 | 188 | TwoTwoDo.data.cur_memo = memo; | |
| 189 | 189 | ||
| 190 | TwoTwoDo.utils.writeCookie('TwoTwoDo'); | ||
| 190 | TwoTwoDo.utils.writeCookie(); | ||
| 191 | 191 | }; | |
| 192 | 192 | ||
| 193 | 193 | TwoTwoDo.memo.edit = function () { | |
| … | … | ||
| 225 | 225 | TwoTwoDo.data.memo[TwoTwoDo.data.cur_memo] = memo; | |
| 226 | 226 | } | |
| 227 | 227 | ||
| 228 | TwoTwoDo.utils.writeCookie('TwoTwoDo'); | ||
| 228 | TwoTwoDo.utils.writeCookie(); | ||
| 229 | 229 | }; | |
| 230 | 230 | ||
| 231 | 231 | TwoTwoDo.memo.remove = function () { | |
| … | … | ||
| 245 | 245 | }; | |
| 246 | 246 | ||
| 247 | 247 | TwoTwoDo.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(); | ||
| 249 | 253 | if (data != null) { | |
| 250 | 254 | TwoTwoDo.data = eval('('+data+')'); | |
| 251 | 255 | } | |
| … | … | ||
| 270 | 270 | }); | |
| 271 | 271 | $('.memowiki').live('click', function(){ | |
| 272 | 272 | TwoTwoDo.memo.show($(this).html()); | |
| 273 | }); | ||
| 274 | $('.cookie').live('click', function(){ | ||
| 275 | TwoTwoDo.utils.changeCookie($(this).html()); | ||
| 273 | 276 | }); | |
| 274 | 277 | $('.state').live('click', function(){ | |
| 275 | 278 | TwoTwoDo.task.switchState($(this).attr('id')); |

