| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library trydart.decoration; | 5 library trydart.decoration; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 | 8 |
| 9 import 'shadow_root.dart' show |
| 10 setShadowRoot; |
| 11 |
| 9 class Decoration { | 12 class Decoration { |
| 10 final String color; | 13 final String color; |
| 11 final bool bold; | 14 final bool bold; |
| 12 final bool italic; | 15 final bool italic; |
| 13 final bool stress; | 16 final bool stress; |
| 14 final bool important; | 17 final bool important; |
| 15 | 18 |
| 16 const Decoration({this.color: '#000000', | 19 const Decoration({this.color: '#000000', |
| 17 this.bold: false, | 20 this.bold: false, |
| 18 this.italic: false, | 21 this.italic: false, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 tip = error(message); | 66 tip = error(message); |
| 64 } | 67 } |
| 65 return element..append( | 68 return element..append( |
| 66 new AnchorElement() | 69 new AnchorElement() |
| 67 ..classes.add('diagnostic') | 70 ..classes.add('diagnostic') |
| 68 ..nodes.addAll(nodes) | 71 ..nodes.addAll(nodes) |
| 69 ..append(tip)); | 72 ..append(tip)); |
| 70 } | 73 } |
| 71 } | 74 } |
| 72 | 75 |
| 73 info(text) { | 76 createAlert(text, [String cls]) { |
| 74 if (text is String) { | 77 var classes = ['alert']; |
| 75 text = new Text(text); | 78 if (cls != null) { |
| 79 classes.add(cls); |
| 76 } | 80 } |
| 77 return new SpanElement() | 81 SpanElement result = new SpanElement() |
| 78 ..classes.addAll(['alert', 'alert-info']) | 82 ..classes.addAll(classes) |
| 79 ..style.opacity = '0.75' | 83 ..style.opacity = '0.75'; |
| 80 ..append(text); | 84 setShadowRoot(result, text); |
| 85 return result; |
| 81 } | 86 } |
| 82 | 87 |
| 83 error(text) { | 88 info(text) => createAlert(text, 'alert-info'); |
| 84 if (text is String) { | |
| 85 text = new Text(text); | |
| 86 } | |
| 87 return new SpanElement() | |
| 88 ..classes.addAll(['alert', 'alert-error']) | |
| 89 ..style.opacity = '0.75' | |
| 90 ..append(text); | |
| 91 } | |
| 92 | 89 |
| 93 warning(text) { | 90 error(text) => createAlert(text, 'alert-error'); |
| 94 if (text is String) { | 91 |
| 95 text = new Text(text); | 92 warning(text) => createAlert(text); |
| 96 } | |
| 97 return new SpanElement() | |
| 98 ..classes.add('alert') | |
| 99 ..style.opacity = '0.75' | |
| 100 ..append(text); | |
| 101 } | |
| 102 | 93 |
| 103 class CodeCompletionDecoration extends Decoration { | 94 class CodeCompletionDecoration extends Decoration { |
| 104 const CodeCompletionDecoration( | 95 const CodeCompletionDecoration( |
| 105 {String color: '#000000', | 96 {String color: '#000000', |
| 106 bool bold: false, | 97 bool bold: false, |
| 107 bool italic: false, | 98 bool italic: false, |
| 108 bool stress: false, | 99 bool stress: false, |
| 109 bool important: false}) | 100 bool important: false}) |
| 110 : super(color: color, bold: bold, italic: italic, stress: stress, | 101 : super(color: color, bold: bold, italic: italic, stress: stress, |
| 111 important: important); | 102 important: important); |
| 112 | 103 |
| 113 static from(Decoration decoration) { | 104 static from(Decoration decoration) { |
| 114 return new CodeCompletionDecoration( | 105 return new CodeCompletionDecoration( |
| 115 color: decoration.color, | 106 color: decoration.color, |
| 116 bold: decoration.bold, | 107 bold: decoration.bold, |
| 117 italic: decoration.italic, | 108 italic: decoration.italic, |
| 118 stress: decoration.stress, | 109 stress: decoration.stress, |
| 119 important: decoration.important); | 110 important: decoration.important); |
| 120 } | 111 } |
| 121 | 112 |
| 122 Element applyTo(text) { | 113 Element applyTo(text) { |
| 123 var codeCompletion = new DivElement() | 114 var codeCompletion = new DivElement() |
| 124 ..contentEditable = 'false' | 115 ..contentEditable = 'false' |
| 125 ..classes.add('dart-code-completion'); | 116 ..classes.add('dart-code-completion'); |
| 126 return super.applyTo(text) | 117 return super.applyTo(text) |
| 127 ..classes.add('dart-code-completion-holder') | 118 ..classes.add('dart-code-completion-holder') |
| 128 ..nodes.add(codeCompletion); | 119 ..nodes.add(codeCompletion); |
| 129 } | 120 } |
| 130 } | 121 } |
| OLD | NEW |