Commit ffa7160026374366e06bca79815de2124e153880
- Diff rendering mode:
- inline
- side by side
twotwodo.css
(12 / 0)
|   | |||
| 113 | 113 | .memowiki { | |
| 114 | 114 | text-decoration: underline; | |
| 115 | 115 | } | |
| 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)
|   | |||
| 24 | 24 | ||
| 25 | 25 | TwoTwoDo.txt2html = function (txt) { | |
| 26 | 26 | 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 | |||
| 28 | 41 | return html; | |
| 29 | 42 | }; | |
| 30 | 43 | ||
| 31 | 44 | TwoTwoDo.html2txt = function (html) { | |
| 32 | 45 | 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'); | ||
| 34 | 48 | return txt; | |
| 35 | 49 | }; | |
| 36 | 50 | ||
| 37 | 51 | TwoTwoDo.data = { | |
| 38 | 52 | 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 | } | ||
| 43 | 67 | }, | |
| 44 | 68 | cur_memo: 'default', | |
| 45 | 69 | memo: {'default': 'This is the wiki content for the \'default\' hashtag :-)'} | |
| … | … | ||
| 84 | 84 | ||
| 85 | 85 | TwoTwoDo.task.edit = function (tid) { | |
| 86 | 86 | $('p.task input').blur(); | |
| 87 | |||
| 87 | 88 | var task = TwoTwoDo.html2txt($('#'+tid).html()); | |
| 88 | 89 | $('#'+tid).unbind('click') | |
| 89 | 90 | .addClass('edit') | |
| 90 | .html('<input type="text" value="'+task+'" />'); | ||
| 91 | .html('<input type="text" name="'+tid+'" value="'+task+'" />'); | ||
| 91 | 92 | $('#'+tid+' input').focus().blur(function(){ | |
| 92 | 93 | TwoTwoDo.task.save(tid); | |
| 93 | 94 | }); | |
| … | … | ||
| 113 | 113 | TwoTwoDo.writeCookie('TwoTwoDo'); | |
| 114 | 114 | }; | |
| 115 | 115 | ||
| 116 | TwoTwoDo.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 | |||
| 116 | 147 | TwoTwoDo.task.remove = function (tid) { | |
| 117 | 148 | $('#'+tid).remove(); | |
| 118 | 149 | var section = tid.split(/-/)[0]; | |
| … | … | ||
| 155 | 155 | ||
| 156 | 156 | TwoTwoDo.memo.show = function (memo) { | |
| 157 | 157 | $('p.task input').blur(); | |
| 158 | $('#memo textarea').blur(); | ||
| 158 | 159 | ||
| 159 | 160 | if (TwoTwoDo.data.memo[memo] == undefined) { | |
| 160 | 161 | TwoTwoDo.data.memo[memo] = 'New memo'; | |
| … | … | ||
| 175 | 175 | ||
| 176 | 176 | $('#memo').unbind('click') | |
| 177 | 177 | .addClass('edit') | |
| 178 | .html('<textarea>'+memo+'</textarea>'); | ||
| 178 | .html('<textarea name="'+TwoTwoDo.data.cur_memo+'">'+memo+'</textarea>'); | ||
| 179 | 179 | $('#memo textarea').attr('rows', r) | |
| 180 | 180 | .focus() | |
| 181 | 181 | .blur(function(){ | |
| … | … | ||
| 188 | 188 | ||
| 189 | 189 | TwoTwoDo.memo.save = function () { | |
| 190 | 190 | var memo = TwoTwoDo.txt2html($('#memo textarea').val()); | |
| 191 | |||
| 191 | |||
| 192 | 192 | $('#memo').removeClass('edit') | |
| 193 | 193 | .html(memo) | |
| 194 | 194 | .click(function(){ | |
| … | … | ||
| 241 | 241 | $('#memo').click(function(){ | |
| 242 | 242 | TwoTwoDo.memo.edit(); | |
| 243 | 243 | }); | |
| 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 | }); | ||
| 247 | 250 | }; | |
| 248 | 251 | ||
| 249 | 252 | $(document).ready(function(){ |

