| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library eval_box_element; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:html'; | |
| 9 import 'observatory_element.dart'; | |
| 10 import 'package:polymer/polymer.dart'; | |
| 11 | |
| 12 | |
| 13 typedef Future evalType(String text); | |
| 14 | |
| 15 | |
| 16 @CustomTag('eval-box') | |
| 17 class EvalBoxElement extends ObservatoryElement { | |
| 18 @observable String text; | |
| 19 @observable String lineMode = "1-line"; | |
| 20 | |
| 21 @published evalType callback; | |
| 22 @observable ObservableList results = toObservable([]); | |
| 23 | |
| 24 void updateLineMode(Event e, var detail, Node target) { | |
| 25 lineMode = (e.target as InputElement).value; | |
| 26 if (lineMode == '1-line') { | |
| 27 text = text.replaceAll('\n', ' '); | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 void eval(Event e, var detail, Node target) { | |
| 32 // Prevent any form action. | |
| 33 e.preventDefault(); | |
| 34 | |
| 35 // Clear the text box. | |
| 36 var expr = text; | |
| 37 text = ''; | |
| 38 | |
| 39 // Use provided callback to eval the expression. | |
| 40 if (callback != null) { | |
| 41 var map = toObservable({}); | |
| 42 map['expr'] = expr; | |
| 43 results.insert(0, map); | |
| 44 callback(expr).then((result) { | |
| 45 map['value'] = result; | |
| 46 }); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 void selectExpr(MouseEvent e) { | |
| 51 assert(e.target is Element); | |
| 52 Element targetElement = e.target; | |
| 53 text = targetElement.getAttribute('expr'); | |
| 54 } | |
| 55 | |
| 56 EvalBoxElement.created() : super.created(); | |
| 57 } | |
| OLD | NEW |