Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.js |
— | — | @@ -144,9 +144,7 @@ |
145 | 145 | 'action': { |
146 | 146 | 'type': 'callback', |
147 | 147 | 'execute': function( context ) { |
148 | | - context.parserPlayground.parser = undefined; |
149 | | - context.parserPlayground.tree = undefined; |
150 | | - context.parserPlayground.fn.hide(); |
| 148 | + context.parserPlayground.fn.disable(); |
151 | 149 | } |
152 | 150 | } |
153 | 151 | } |
— | — | @@ -196,16 +194,39 @@ |
197 | 195 | setupInspector($target, $inspector, renderMap, treeMap); |
198 | 196 | }, renderMap); |
199 | 197 | }); |
| 198 | + |
| 199 | + context.$textarea.closest('form').submit( context.parserPlayground.fn.onSubmit ); |
| 200 | + |
200 | 201 | }, |
201 | 202 | hide: function() { |
202 | 203 | $('#pegparser-source').hide(); // it'll reshow; others won't need it |
203 | 204 | context.$iframe = undefined; |
204 | | - context.$parserContainer.remove(); |
| 205 | + if (context.$parserContainer !== undefined) { |
| 206 | + context.$parserContainer.remove(); |
| 207 | + } |
205 | 208 | context.$parserContainer = undefined; |
206 | | - context.$parserInspector.remove(); |
| 209 | + if (context.$parserInspector !== undefined) { |
| 210 | + context.$parserInspector.remove(); |
| 211 | + } |
207 | 212 | context.$parserInspector = undefined; |
208 | 213 | context.$textarea.show(); |
209 | 214 | }, |
| 215 | + disable: function() { |
| 216 | + var pp = context.parserPlayground; |
| 217 | + var finish = function() { |
| 218 | + pp.parser = undefined; |
| 219 | + pp.tree = undefined; |
| 220 | + pp.fn.hide(); |
| 221 | + }; |
| 222 | + if (pp.parser && pp.tree) { |
| 223 | + pp.parser.treeToSource( pp.tree, function( src, err ) { |
| 224 | + context.$textarea.val( src ); |
| 225 | + finish(); |
| 226 | + }); |
| 227 | + } else { |
| 228 | + finish(); |
| 229 | + } |
| 230 | + }, |
210 | 231 | toggleInspector: function() { |
211 | 232 | if (context.parserPlayground.useInspector) { |
212 | 233 | context.parserPlayground.useInspector = false; |
— | — | @@ -242,6 +263,11 @@ |
243 | 264 | return false; |
244 | 265 | } |
245 | 266 | }); |
| 267 | + }, |
| 268 | + onSubmit: function() { |
| 269 | + // @fixme if we're really doing async, this might not apply right |
| 270 | + // disable the old thingy and record the updated text before finishing submit |
| 271 | + context.parserPlayground.fn.disable(); |
246 | 272 | } |
247 | 273 | } |
248 | 274 | } |