OLD | NEW |
1 <!-- | 1 <!-- |
2 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 --> | 5 --> |
6 <import src="../../framework/sky-element/sky-element.sky" as="SkyElement" /> | 6 <import src="../../framework/sky-element/sky-element.sky" as="SkyElement" /> |
7 <import src="city-data-service.sky" as="CityDataService" /> | 7 <import src="city-data-service.sky" as="CityDataService" /> |
8 <import src="city-sequence.sky" as="CitySequence" /> | 8 <import src="city-sequence.sky" as="CitySequence" /> |
9 | 9 |
| 10 <script> |
| 11 // TODO(esprehn): exports should start as the empty object. |
| 12 module.exports = {}; |
| 13 </script> |
| 14 |
| 15 <sky-element name="state-header"> |
10 <template> | 16 <template> |
11 <style> | 17 <style> |
12 div { | 18 div { |
13 font-size: 16px; | 19 font-size: 16px; |
14 color: #FFF; | 20 color: #FFF; |
15 background-color: #333; | 21 background-color: #333; |
16 padding: 4px 4px 4px 12px; | 22 padding: 4px 4px 4px 12px; |
17 display: paragraph; | 23 display: paragraph; |
18 } | 24 } |
19 </style> | 25 </style> |
20 <div>{{ state }}</div> | 26 <div>{{ state }}</div> |
21 </template> | 27 </template> |
22 <script> | 28 <script> |
23 SkyElement({ | 29 module.exports.StateHeaderElement = class extends SkyElement { |
24 name: 'state-header', | |
25 | |
26 set datum(datum) { | 30 set datum(datum) { |
27 this.state = datum.state; | 31 this.state = datum.state; |
28 } | 32 } |
29 }); | 33 }.register(); |
30 </script> | 34 </script> |
| 35 </sky-element> |
31 | 36 |
| 37 <sky-element name="letter-header"> |
32 <template> | 38 <template> |
33 <style> | 39 <style> |
34 div { | 40 div { |
35 font-size: 12px; | 41 font-size: 12px; |
36 font-weight: bold; | 42 font-weight: bold; |
37 padding: 2px 4px 4px 12px; | 43 padding: 2px 4px 4px 12px; |
38 background-color: #DDD; | 44 background-color: #DDD; |
39 display: paragraph; | 45 display: paragraph; |
40 } | 46 } |
41 </style> | 47 </style> |
42 <div>{{ letter }}</div> | 48 <div>{{ letter }}</div> |
43 </template> | 49 </template> |
44 <script> | 50 <script> |
45 SkyElement({ | 51 module.exports.LetterHeaderElement = class extends SkyElement { |
46 name: 'letter-header', | |
47 | |
48 set datum(datum) { | 52 set datum(datum) { |
49 this.letter = datum.letter; | 53 this.letter = datum.letter; |
50 } | 54 } |
51 }); | 55 }.register(); |
52 </script> | 56 </script> |
| 57 </sky-element> |
53 | 58 |
| 59 <sky-element name="city-item"> |
54 <template> | 60 <template> |
55 <style> | 61 <style> |
56 :host { | 62 :host { |
57 display: flex; | 63 display: flex; |
58 font-size: 13px; | 64 font-size: 13px; |
59 padding: 8px 4px 4px 12px; | 65 padding: 8px 4px 4px 12px; |
60 border-bottom: 1px solid #EEE; | 66 border-bottom: 1px solid #EEE; |
61 line-height: 15px; | 67 line-height: 15px; |
62 overflow: hidden; | 68 overflow: hidden; |
63 } | 69 } |
(...skipping 14 matching lines...) Expand all Loading... |
78 color: #AAA; | 84 color: #AAA; |
79 } | 85 } |
80 | 86 |
81 </style> | 87 </style> |
82 <div> | 88 <div> |
83 <span id="name">{{ name }}</span>, | 89 <span id="name">{{ name }}</span>, |
84 <span id="population">population {{ population }}</span> | 90 <span id="population">population {{ population }}</span> |
85 </div> | 91 </div> |
86 </template> | 92 </template> |
87 <script> | 93 <script> |
88 SkyElement({ | 94 module.exports.CityItemElement = class extends SkyElement { |
89 name: 'city-item', | 95 set datum(datum) { |
| 96 this.name = datum.name; |
| 97 this.population = datum.population; |
| 98 } |
| 99 }.register(); |
| 100 </script> |
| 101 </sky-element> |
90 | 102 |
91 set datum(datum) { | 103 <sky-element name="city-list"> |
92 this.name = datum.name; | |
93 this.population = datum.population; | |
94 } | |
95 }); | |
96 </script> | |
97 | |
98 <template> | 104 <template> |
99 <style> | 105 <style> |
100 | 106 |
101 :host { | 107 :host { |
102 overflow: hidden; | 108 overflow: hidden; |
103 position: absolute; | 109 position: absolute; |
104 top: 0; | 110 top: 0; |
105 right: 0; | 111 right: 0; |
106 bottom: 0; | 112 bottom: 0; |
107 left: 0; | 113 left: 0; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 display: none; | 145 display: none; |
140 } | 146 } |
141 | 147 |
142 .position { | 148 .position { |
143 position: absolute; | 149 position: absolute; |
144 left: 0; | 150 left: 0; |
145 right: 0; | 151 right: 0; |
146 } | 152 } |
147 | 153 |
148 </style> | 154 </style> |
149 | |
150 <div id="scroller" fit> | 155 <div id="scroller" fit> |
151 <div id="scrollarea"> | 156 <div id="scrollarea"> |
152 <div id="contentarea"> | 157 <div id="contentarea"> |
153 </div> | 158 </div> |
154 </div> | 159 </div> |
155 </div> | 160 </div> |
156 | |
157 </template> | 161 </template> |
158 <script> | 162 <script> |
159 | 163 |
160 (function(global) { | 164 (function(global) { |
161 "use strict"; | 165 "use strict"; |
162 | 166 |
163 var LOAD_LENGTH = 20; | 167 var LOAD_LENGTH = 20; |
164 var LOAD_BUFFER_PRE = LOAD_LENGTH * 4; | 168 var LOAD_BUFFER_PRE = LOAD_LENGTH * 4; |
165 var LOAD_BUFFER_POST = LOAD_LENGTH * 4; | 169 var LOAD_BUFFER_POST = LOAD_LENGTH * 4; |
166 | 170 |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 this.checkinTile(tiles.pop()); | 537 this.checkinTile(tiles.pop()); |
534 } | 538 } |
535 } | 539 } |
536 | 540 |
537 Tiler.prototype.reset = function() { | 541 Tiler.prototype.reset = function() { |
538 this.checkinAllTiles(); | 542 this.checkinAllTiles(); |
539 this.drawTop = 0; | 543 this.drawTop = 0; |
540 this.drawBottom = 0; | 544 this.drawBottom = 0; |
541 } | 545 } |
542 | 546 |
543 SkyElement({ | 547 module.exports.CityListElement = class extends SkyElement { |
544 name: 'city-list', | |
545 loader: null, | |
546 scroller: null, | |
547 tiler: null, | |
548 date: null, | |
549 month: null, | |
550 views: null, | |
551 | 548 |
552 attached: function() { | 549 created() { |
| 550 this.loader = null; |
| 551 this.scroller = null; |
| 552 this.tiler = null; |
| 553 this.date = null; |
| 554 this.month = null; |
| 555 this.views = null; |
| 556 } |
| 557 |
| 558 attached() { |
553 this.views = {}; | 559 this.views = {}; |
554 this.loader = new Loader(this); | 560 this.loader = new Loader(this); |
555 this.scroller = new Scroller(); | 561 this.scroller = new Scroller(); |
556 this.tiler = new Tiler( | 562 this.tiler = new Tiler( |
557 this.shadowRoot.getElementById('contentarea'), this.views, { | 563 this.shadowRoot.getElementById('contentarea'), this.views, { |
558 stateHeader: 27, | 564 stateHeader: 27, |
559 letterHeader: 18, | 565 letterHeader: 18, |
560 cityItem: 30 | 566 cityItem: 30 |
561 }); | 567 }); |
562 | 568 |
563 this.dataLoaded = this.dataLoaded.bind(this); | 569 this.dataLoaded = this.dataLoaded.bind(this); |
564 this.scrollerElement = this.shadowRoot.getElementById('scroller'); | 570 this.scrollerElement = this.shadowRoot.getElementById('scroller'); |
565 this.scrollerElement.addEventListener('scroll', | 571 this.scrollerElement.addEventListener('scroll', |
566 this.handleScroll.bind(this)); | 572 this.handleScroll.bind(this)); |
567 | 573 |
568 var self = this; | 574 var self = this; |
569 setTimeout(function() { | 575 setTimeout(function() { |
570 self.domReady(); | 576 self.domReady(); |
571 self.loader.maybeLoadMoreData(self.dataLoaded); | 577 self.loader.maybeLoadMoreData(self.dataLoaded); |
572 }); | 578 }); |
573 }, | 579 } |
574 | 580 |
575 domReady: function() { | 581 domReady() { |
576 this.scroller.setup(this.shadowRoot.getElementById('scroller'), | 582 this.scroller.setup(this.shadowRoot.getElementById('scroller'), |
577 this.shadowRoot.getElementById('scrollarea'), | 583 this.shadowRoot.getElementById('scrollarea'), |
578 this.shadowRoot.getElementById('contentarea')); | 584 this.shadowRoot.getElementById('contentarea')); |
579 var scrollFrame = this.scroller.getCurrentFrame(); | 585 var scrollFrame = this.scroller.getCurrentFrame(); |
580 this.tiler.setupViews(scrollFrame); | 586 this.tiler.setupViews(scrollFrame); |
581 }, | 587 } |
582 | 588 |
583 updateView: function(data, scrollChanged) { | 589 updateView(data, scrollChanged) { |
584 var scrollFrame = this.scroller.getCurrentFrame(); | 590 var scrollFrame = this.scroller.getCurrentFrame(); |
585 this.tiler.drawTiles(scrollFrame, data); | 591 this.tiler.drawTiles(scrollFrame, data); |
586 var datum = scrollChanged ? | 592 var datum = scrollChanged ? |
587 this.tiler.getFirstVisibleDatum(scrollFrame) : null; | 593 this.tiler.getFirstVisibleDatum(scrollFrame) : null; |
588 this.loader.maybeLoadMoreData(this.dataLoaded, datum); | 594 this.loader.maybeLoadMoreData(this.dataLoaded, datum); |
589 }, | 595 } |
590 | 596 |
591 dataLoaded: function(data, indexOffset) { | 597 dataLoaded(data, indexOffset) { |
592 var scrollFrame = this.scroller.getCurrentFrame(); | 598 var scrollFrame = this.scroller.getCurrentFrame(); |
593 this.tiler.updateFirstItem(indexOffset); | 599 this.tiler.updateFirstItem(indexOffset); |
594 this.updateView(data.items, false); | 600 this.updateView(data.items, false); |
595 }, | 601 } |
596 | 602 |
597 handleScroll: function(event) { | 603 handleScroll(event) { |
598 if (!this.scroller.captureNewFrame(event)) | 604 if (!this.scroller.captureNewFrame(event)) |
599 return; | 605 return; |
600 | 606 |
601 this.updateView(this.loader.getItems(), true); | 607 this.updateView(this.loader.getItems(), true); |
602 }, | 608 } |
603 | 609 |
604 scrollBy: function(amount) { | 610 scrollBy(amount) { |
605 this.scrollerElement.scrollTop += amount; | 611 this.scrollerElement.scrollTop += amount; |
606 this.handleScroll({ target: this.scrollerElement }); | 612 this.handleScroll({ target: this.scrollerElement }); |
607 } | 613 } |
608 }); | 614 }.register(); |
609 | 615 |
610 })(this); | 616 })(this); |
611 | |
612 </script> | 617 </script> |
613 | 618 </sky-element> |
OLD | NEW |