|
28 | 28 | padding: 12px 16px;
|
29 | 29 | background-color: #333333;
|
30 | 30 | }
|
| 31 | + |
| 32 | + .item.onyx-selected { |
| 33 | + background-color: MidnightBlue; |
| 34 | + } |
| 35 | + |
31 | 36 | .title {
|
32 | 37 | position: absolute;
|
33 | 38 | top: 40px;
|
|
56 | 61 | background-color: #333;
|
57 | 62 | }
|
58 | 63 | .flickr-image {
|
59 |
| - max-height: 90%; |
60 |
| - max-width: 90%; |
| 64 | + min-width: 80%; |
61 | 65 | border: solid 5px #CCC;
|
62 |
| - box-shadow: 1px 1px 5px #999; |
| 66 | + box-shadow: 1px 1px 5px #999; |
| 67 | + } |
| 68 | + |
| 69 | + .flickr-image.tall { |
| 70 | + min-width: 0; |
| 71 | + min-height: 80%; |
| 72 | + } |
| 73 | + |
| 74 | + /* be responsive */ |
| 75 | + @media all and (max-width: 800px) { |
| 76 | + .panels > * { |
| 77 | + min-width: 100%; |
| 78 | + } |
63 | 79 | }
|
64 | 80 | </style>
|
65 | 81 | </head>
|
|
68 | 84 | <script>
|
69 | 85 | enyo.kind({
|
70 | 86 | name: "App",
|
71 |
| - classes: "enyo-unselectable", |
72 |
| - kind: "FittableRows", |
| 87 | + kind: "Panels", |
| 88 | + classes: "panels enyo-unselectable", |
| 89 | + realtimeFit: true, |
| 90 | + layoutKind: "SlidingArranger", |
73 | 91 | components: [
|
74 |
| - {kind: "Panels", fit: true, classes: "panels", layoutKind: "SlidingArranger", wrap: false, components: [ |
75 |
| - {layoutKind: "FittableRowsLayout", components: [ |
76 |
| - {kind: "onyx.Toolbar", components: [ |
77 |
| - {kind: "onyx.InputDecorator", components: [ |
78 |
| - {name: "searchInput", kind: "onyx.Input", value: "Japan", onchange: "search"}, |
79 |
| - {kind: "Image", src: "images/search-input-search.png"} |
80 |
| - ]}, |
81 |
| - {name: "searchSpinner", kind: "Image", src: "images/spinner.gif", showing: false} |
| 92 | + {layoutKind: "FittableRowsLayout", components: [ |
| 93 | + {kind: "onyx.Toolbar", components: [ |
| 94 | + {kind: "onyx.InputDecorator", style: "width: 90%;", layoutKind: "FittableColumnsLayout", components: [ |
| 95 | + {name: "searchInput", fit: true, kind: "onyx.Input", value: "Japan", onchange: "search"}, |
| 96 | + {kind: "Image", src: "images/search-input-search.png", style: "width: 20px; height: 20px;"} |
82 | 97 | ]},
|
83 |
| - {kind: "List", fit: true, touch: true, onSetupRow: "setupItem", components: [ |
84 |
| - {style: "padding: 10px;", classes: "item enyo-border-box", ontap: "itemTap", components: [ |
85 |
| - {name: "thumbnail", kind: "Image", classes: "thumbnail"}, |
86 |
| - {name: "title", classes: "title"} |
87 |
| - ]}, |
88 |
| - {name: "more", style: "background-color: #323232;", components: [ |
89 |
| - {kind: "onyx.Button", content: "more photos", classes: "onyx-dark more-button", ontap: "more"}, |
90 |
| - {name: "moreSpinner", kind: "Image", src: "images/spinner.gif", classes: "more-spinner"} |
91 |
| - ]} |
92 |
| - ]} |
| 98 | + {name: "searchSpinner", kind: "Image", src: "images/spinner.gif", showing: false} |
93 | 99 | ]},
|
94 |
| - {fit: true, components: [ |
95 |
| - {classes: "enyo-fit main", components: [ |
96 |
| - {name: "flickrImage", kind: "Image", classes: "enyo-fit center flickr-image", showing: false, onload: "imageLoaded", onerror: "imageLoaded"}, |
97 |
| - {name: "imageSpinner", kind: "Image", src: "images/spinner-large.gif", classes: "enyo-fit center", showing: false} |
| 100 | + {kind: "List", fit: true, touch: true, onSetupRow: "setupItem", components: [ |
| 101 | + {name: "item", style: "padding: 10px;", classes: "item enyo-border-box", ontap: "itemTap", components: [ |
| 102 | + {name: "thumbnail", kind: "Image", classes: "thumbnail"}, |
| 103 | + {name: "title", classes: "title"} |
| 104 | + ]}, |
| 105 | + {name: "more", style: "background-color: #323232;", components: [ |
| 106 | + {kind: "onyx.Button", content: "more photos", classes: "onyx-dark more-button", ontap: "more"}, |
| 107 | + {name: "moreSpinner", kind: "Image", src: "images/spinner.gif", classes: "more-spinner"} |
98 | 108 | ]}
|
99 | 109 | ]}
|
100 | 110 | ]},
|
| 111 | + {name: "pictureView", fit: true, kind: "FittableRows", classes: "enyo-fit main", components: [ |
| 112 | + {name: "backToolbar", kind: "onyx.Toolbar", showing: false, components: [ |
| 113 | + {kind: "onyx.Button", content: "Back", ontap: "showList"} |
| 114 | + ]}, |
| 115 | + {fit: true, style: "position: relative;", components: [ |
| 116 | + {name: "flickrImage", kind: "Image", classes: "enyo-fit center flickr-image", showing: false, onload: "imageLoaded", onerror: "imageLoaded"}, |
| 117 | + {name: "imageSpinner", kind: "Image", src: "images/spinner-large.gif", classes: "enyo-fit center", showing: false} |
| 118 | + ]} |
| 119 | + ]}, |
101 | 120 | {kind: "FlickrSearch", onResults: "searchResults"}
|
102 | 121 | ],
|
103 | 122 | rendered: function() {
|
104 | 123 | this.inherited(arguments);
|
105 | 124 | this.search();
|
106 | 125 | },
|
| 126 | + reflow: function() { |
| 127 | + this.inherited(arguments); |
| 128 | + var backShowing = this.$.backToolbar.showing; |
| 129 | + this.$.backToolbar.setShowing(this.isSmall()); |
| 130 | + if (this.$.backToolbar.showing != backShowing) { |
| 131 | + this.$.pictureView.resized(); |
| 132 | + } |
| 133 | + }, |
| 134 | + isSmall: function() { |
| 135 | + return window.matchMedia && window.matchMedia("all and (max-width:800px)").matches; |
| 136 | + }, |
107 | 137 | search: function() {
|
108 | 138 | this.searchText = this.$.searchInput.getValue();
|
109 | 139 | this.page = 0;
|
|
125 | 155 | setupItem: function(inSender, inEvent) {
|
126 | 156 | var i = inEvent.index;
|
127 | 157 | var item = this.results[i];
|
| 158 | + this.$.item.addRemoveClass("onyx-selected", inSender.isSelected(inEvent.index)); |
128 | 159 | this.$.thumbnail.setSrc(item.thumbnail);
|
129 | 160 | this.$.title.setContent(item.title || "Untitled");
|
130 | 161 | this.$.more.canGenerate = !this.results[i+1];
|
|
135 | 166 | this.$.flickrSearch.search(this.searchText, this.page);
|
136 | 167 | },
|
137 | 168 | itemTap: function(inSender, inEvent) {
|
138 |
| - if (this.getBounds().width <= 480) { |
139 |
| - this.$.panels.setIndex(1); |
| 169 | + if (this.isSmall()) { |
| 170 | + this.setIndex(1); |
140 | 171 | }
|
141 | 172 | this.$.imageSpinner.show();
|
142 | 173 | var item = this.results[inEvent.index];
|
| 174 | + this.$.flickrImage.hide(); |
143 | 175 | this.$.flickrImage.setSrc(item.original);
|
144 | 176 |
|
145 | 177 | },
|
146 | 178 | imageLoaded: function() {
|
147 | 179 | this.$.flickrImage.show();
|
| 180 | + var b = this.$.flickrImage.getBounds(); |
| 181 | + this.$.flickrImage.addRemoveClass("tall", b.height > b.width); |
148 | 182 | this.$.imageSpinner.hide();
|
| 183 | + }, |
| 184 | + showList: function() { |
| 185 | + this.setIndex(0); |
149 | 186 | }
|
150 | 187 | });
|
151 | 188 |
|
|
0 commit comments