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

Unified Diff: recipes/web/html/traversing_from_current_position.html

Issue 14109034: Recipes for using CSS Selectors with dart:html (Closed) Base URL: https://github.com/dart-lang/cookbook.git@master
Patch Set: Removed unwanted file. Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: recipes/web/html/traversing_from_current_position.html
diff --git a/recipes/web/html/traversing_from_current_position.html b/recipes/web/html/traversing_from_current_position.html
new file mode 100644
index 0000000000000000000000000000000000000000..dbe8e4dbb1f82d0f050ef12606307d71f499312a
--- /dev/null
+++ b/recipes/web/html/traversing_from_current_position.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+
+<html>
+ <ul>
+ <li>Head</li>
+ <li>Shoulders</li>
+ <li>Knees</li>
+ <li>Toes</li>
+ </ul>
+
+ <body>
+ <script type="application/dart">
+ import 'dart:html';
+
+ nextSiblings(item) {
+ Element nextElement = item.nextElementSibling;
+ return item.parent.children.skipWhile((i) => i != nextElement).toList();
+ }
+
+ previousSiblings(item) {
+ return item.parent.children.takeWhile((i) => i != item).toList();
+ }
+
+ List prevAll(item) {
+ var results = [];
+ var children = item.parent.children;
+
+ for (var i = 0; i < children.length; i++) {
+ if (children[i] == item) break;
+ results.add(children[i]);
+ }
+ return results;
+ }
+
+ void main() {
+ LIElement knees = query('ul > li:nth-child(3)');
+ assert(knees.nextElementSibling.innerHtml == 'Toes');
+ assert(knees.previousElementSibling.innerHtml == 'Shoulders');
+ assert(knees.parent.tagName == 'UL');
+ assert(knees.parent.children.length == 4);
+ List<Element> prev = previousSiblings(knees);
+ assert(prev.first.innerHtml == 'Head');
+ assert(prev.last.innerHtml == 'Shoulders');
+ assert(nextSiblings(knees).first.innerHtml == 'Toes');
+ }
+ </script>
+ <script src="packages/browser/dart.js"></script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698