Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: recipes/web/html/replacing.html

Issue 14109034: Recipes for using CSS Selectors with dart:html (Closed) Base URL: https://github.com/dart-lang/cookbook.git@master
Patch Set: Incorporated changes recommended by Seth Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2
3 <html>
4 <body>
5
6 <ul>
7 <li>Get crazy startup idea</li>
8 <li>Set up company
9 <ul>
10 <li>Build something</li>
11 <li>Raise money</li>
12 <li>Get users</li>
13 </ul>
14 <li>Profit!!!</li>
15 </ul>
16
17 <script type="application/dart">
18
19 import 'dart:html';
20
21 void main() {
22
23
24 var span = new Element.html("<span>You can edit this.&nbsp;</span>");
25 var link = new Element.html("<a href='#'>Edit</a>");
26 var input = new Element.html(
27 "<input type='text' value='${span.innerHtml}' />");
28
29 document.body.children.addAll([span, link]);
30 bool editing = false;
31
32 link.onClick.listen((event) {
33 editing = !editing;
34 if (editing) {
35 span.replaceWith(input);
36 link.innerHtml = 'Done';
37 } else {
38 input.replaceWith(span);
39 link.innerHtml = 'Edit';
40 }
41
42 event.preventDefault();
43 event.stopPropagation();
44 });
45
46 queryAll('ul').forEach((item) {
47 var ol = new Element.tag('ol');
48 ol.children.addAll(item.children);
49 item.replaceWith(ol);
50 });
51 }
52 </script>
53
54 <script src="packages/browser/dart.js"></script>
55 </body>
56 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698