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

Side by Side Diff: sky/examples/city-list/city-sequence.sky

Issue 980323003: Clean up examples directory (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « sky/examples/city-list/city-list.sky ('k') | sky/examples/city-list/index.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!--
2 // Copyright 2014 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 -->
6 <script>
7 function StateHeader(state) {
8 this.state = state;
9 this.headerOrder = 1;
10 };
11
12 function LetterHeader(letter) {
13 this.letter = letter;
14 this.headerOrder = 2;
15 }
16
17 function CitySequence(cities)
18 {
19 this.items = [];
20 this.cursor = 0;
21
22 var lastState;
23 var lastLetter;
24
25 for (var i = 0; i < cities.length; i++) {
26 var city = cities[i];
27 if (!lastState || lastState.state != city.state) {
28 lastState = new StateHeader(city.state);
29 this.items.push(lastState);
30 lastLetter = undefined;
31 }
32 if (!lastLetter || lastLetter.letter != city.name[0]) {
33 lastLetter = new LetterHeader(city.name[0]);
34 this.items.push(lastLetter);
35 }
36 this.items.push(city);
37 }
38 };
39
40 CitySequence.prototype = {
41 append: function(other) {
42 var lastCity = this.items[this.items.length - 1];
43 var firstOtherCity = other.items[2];
44
45 var index = 0;
46 if (firstOtherCity.state == lastCity.state) {
47 // skip StateHeader
48 if (firstOtherCity.name[0] == lastCity.name[0]) {
49 // skip LetterHeader
50 index = 2;
51 } else {
52 index = 1;
53 }
54 }
55
56 for (; index < other.items.length; index++) {
57 this.items.push(other.items[index]);
58 }
59 }
60 };
61
62 module.exports = CitySequence;
63
64 </script>
OLDNEW
« no previous file with comments | « sky/examples/city-list/city-list.sky ('k') | sky/examples/city-list/index.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698