Mercurial > repos > tabletprog
comparison editor.js @ 131:8285784f5ff5
Implement previous and next buttons
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 07 Aug 2013 10:01:28 -0700 |
parents | 2b25d0ce2946 |
children | a503a329acfa |
comparison
equal
deleted
inserted
replaced
130:6a1a716bb8c6 | 131:8285784f5ff5 |
---|---|
14 for (var i in this.messages) { | 14 for (var i in this.messages) { |
15 this.messages[i].toHTML(el, this); | 15 this.messages[i].toHTML(el, this); |
16 } | 16 } |
17 }; | 17 }; |
18 | 18 |
19 object.prototype.getNext = function(curNode) { | |
20 for (var i = 0; i < this.messages.length-1; i++) { | |
21 if (this.messages[i] == curNode) { | |
22 return this.messages[i+1]; | |
23 } | |
24 } | |
25 return this.up.getNext(this); | |
26 }; | |
27 | |
28 object.prototype.getPrev = function(curNode) { | |
29 for (var i = 1; i < this.messages.length; i++) { | |
30 if (this.messages[i] == curNode) { | |
31 return this.messages[i - 1]; | |
32 } | |
33 } | |
34 return this.up.getPrev(this); | |
35 }; | |
36 | |
19 lambda.prototype.toHTML = function(node, up) { | 37 lambda.prototype.toHTML = function(node, up) { |
20 this.up = up | 38 this.up = up |
21 var astNode = this; | 39 var astNode = this; |
22 var el = newEl('div', { | 40 var el = newEl('div', { |
23 className: 'lambda', | 41 className: 'lambda', |
39 this.expressions[i].toHTML(body, this); | 57 this.expressions[i].toHTML(body, this); |
40 } | 58 } |
41 el.appendChild(args); | 59 el.appendChild(args); |
42 el.appendChild(body); | 60 el.appendChild(body); |
43 node.appendChild(el); | 61 node.appendChild(el); |
62 }; | |
63 | |
64 lambda.prototype.getNext = function(curNode) { | |
65 for (var i = 0; i < this.args.length; i++) { | |
66 if (this.args[i] == curNode) { | |
67 if ((i + 1) < this.args.length) { | |
68 return this.args[i+1]; | |
69 } else if(this.expressions.length) { | |
70 return this.expressions[0]; | |
71 } else { | |
72 break; | |
73 } | |
74 } | |
75 } | |
76 for (var i = 0; i < this.expressions.length-1; i++) { | |
77 if (this.expressions[i] == curNode) { | |
78 return this.expressions[i+1]; | |
79 } | |
80 } | |
81 return this.up.getNext(this); | |
82 }; | |
83 | |
84 lambda.prototype.getPrev = function(curNode) { | |
85 for (var i = 0; i < this.args.length; i++) { | |
86 if (this.args[i] == curNode) { | |
87 if (i > 0) { | |
88 return this.args[i-1]; | |
89 } else { | |
90 return this.up.getPrev(this); | |
91 } | |
92 } | |
93 } | |
94 for (var i = 0; i < this.expressions.length; i++) { | |
95 if (this.expressions[i] == curNode) { | |
96 if (i > 0) { | |
97 return this.expressions[i-1]; | |
98 } else if(this.args.length) { | |
99 return this.args[this.args.length-1]; | |
100 } else { | |
101 break; | |
102 } | |
103 } | |
104 } | |
105 return this.up.getPrev(this); | |
44 }; | 106 }; |
45 | 107 |
46 assignment.prototype.toHTML = function(node, up) { | 108 assignment.prototype.toHTML = function(node, up) { |
47 this.up = up; | 109 this.up = up; |
48 var astNode = this; | 110 var astNode = this; |
58 }); | 120 }); |
59 this.domNode = base; | 121 this.domNode = base; |
60 base.appendChild(varName); | 122 base.appendChild(varName); |
61 node.appendChild(base); | 123 node.appendChild(base); |
62 this.expression.toHTML(base, this); | 124 this.expression.toHTML(base, this); |
125 }; | |
126 | |
127 assignment.prototype.getNext = function(curNode) { | |
128 return this.up.getNext(this); | |
129 }; | |
130 | |
131 assignment.prototype.getPrev = function(curNode) { | |
132 return this; | |
63 }; | 133 }; |
64 | 134 |
65 op.prototype.toHTML = function(node, up) { | 135 op.prototype.toHTML = function(node, up) { |
66 this.up = up; | 136 this.up = up; |
67 var astNode = this; | 137 var astNode = this; |
83 this.right.toHTML(base, this); | 153 this.right.toHTML(base, this); |
84 } | 154 } |
85 node.appendChild(base); | 155 node.appendChild(base); |
86 }; | 156 }; |
87 | 157 |
158 op.prototype.getNext = function(curNode) { | |
159 if (this.left == curNode) { | |
160 return this.right; | |
161 } | |
162 return this.up.getNext(this); | |
163 }; | |
164 | |
165 op.prototype.getPrev = function(curNode) { | |
166 if (this.right == curNode) { | |
167 return this.left; | |
168 } | |
169 return this.up.getPrev(this); | |
170 }; | |
171 | |
88 intlit.prototype.toHTML = function(node, up) { | 172 intlit.prototype.toHTML = function(node, up) { |
89 this.up = up; | 173 this.up = up; |
90 var astNode = this; | 174 var astNode = this; |
91 this.domNode = newEl('span', { | 175 this.domNode = newEl('span', { |
92 className: 'integer', | 176 className: 'integer', |
132 }); | 216 }); |
133 for (var i = 0; i < this.val.length; i++) { | 217 for (var i = 0; i < this.val.length; i++) { |
134 this.val[i].toHTML(this.domNode, this); | 218 this.val[i].toHTML(this.domNode, this); |
135 } | 219 } |
136 node.appendChild(this.domNode); | 220 node.appendChild(this.domNode); |
221 }; | |
222 | |
223 listlit.prototype.getNext = arraylit.prototype.getNext = function(curNode) { | |
224 for (var i = 0; i < this.val.length; i++) { | |
225 if (this.val[i] == curNode) { | |
226 if ((i + 1) < this.val.length) { | |
227 return this.val[i+1]; | |
228 } else { | |
229 break; | |
230 } | |
231 } | |
232 } | |
233 return this.up.getNext(this); | |
234 }; | |
235 | |
236 listlit.prototype.getPrev = arraylit.prototype.getPrev = function(curNode) { | |
237 for (var i = 0; i < this.val.length; i++) { | |
238 if (this.val[i] == curNode) { | |
239 if (i > 0) { | |
240 return this.val[i-1]; | |
241 } else { | |
242 break; | |
243 } | |
244 } | |
245 } | |
246 return this.up.getPrev(this); | |
137 }; | 247 }; |
138 | 248 |
139 arraylit.prototype.toHTML = function(node, up) { | 249 arraylit.prototype.toHTML = function(node, up) { |
140 this.up = up; | 250 this.up = up; |
141 this.domNode = newEl('span', { | 251 this.domNode = newEl('span', { |
176 this.args[i].toHTML(base, this); | 286 this.args[i].toHTML(base, this); |
177 } | 287 } |
178 node.appendChild(base); | 288 node.appendChild(base); |
179 }; | 289 }; |
180 | 290 |
291 funcall.prototype.getNext = function(curNode) { | |
292 if (this.receiver == curNode && this.args.length) { | |
293 return this.args[0]; | |
294 } | |
295 for (var i = 0; i < this.args.length-1; i++) { | |
296 if (this.args[i] == curNode) { | |
297 return this.args[i+1]; | |
298 } | |
299 } | |
300 return this.up.getNext(this); | |
301 }; | |
302 | |
303 funcall.prototype.getPrev = function(curNode) { | |
304 for (var i = 0; i < this.args.length; i++) { | |
305 if (this.args[i] == curNode) { | |
306 if (i > 0) { | |
307 return this.args[i-1]; | |
308 } else if (this.receiver) { | |
309 return this.receiver; | |
310 } else { | |
311 break; | |
312 } | |
313 } | |
314 } | |
315 return this.up.getPrev(this); | |
316 }; | |
317 | |
181 symbol.prototype.toHTML = function(node, up) { | 318 symbol.prototype.toHTML = function(node, up) { |
182 this.up = up; | 319 this.up = up; |
183 var astNode = this; | 320 var astNode = this; |
184 this.domNode = newEl('span', { | 321 this.domNode = newEl('span', { |
185 className: 'symbol', | 322 className: 'symbol', |