Skip to content

Commit fa8cd0d

Browse files
author
Steve Orvell
committed
* update examples with some responsiveness.
1 parent 8341190 commit fa8cd0d

File tree

2 files changed

+68
-30
lines changed

2 files changed

+68
-30
lines changed

panels/examples/app-flickr.html

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
padding: 12px 16px;
2929
background-color: #333333;
3030
}
31+
32+
.item.onyx-selected {
33+
background-color: MidnightBlue;
34+
}
35+
3136
.title {
3237
position: absolute;
3338
top: 40px;
@@ -56,10 +61,21 @@
5661
background-color: #333;
5762
}
5863
.flickr-image {
59-
max-height: 90%;
60-
max-width: 90%;
64+
min-width: 80%;
6165
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+
}
6379
}
6480
</style>
6581
</head>
@@ -68,42 +84,56 @@
6884
<script>
6985
enyo.kind({
7086
name: "App",
71-
classes: "enyo-unselectable",
72-
kind: "FittableRows",
87+
kind: "Panels",
88+
classes: "panels enyo-unselectable",
89+
realtimeFit: true,
90+
layoutKind: "SlidingArranger",
7391
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;"}
8297
]},
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}
9399
]},
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"}
98108
]}
99109
]}
100110
]},
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+
]},
101120
{kind: "FlickrSearch", onResults: "searchResults"}
102121
],
103122
rendered: function() {
104123
this.inherited(arguments);
105124
this.search();
106125
},
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+
},
107137
search: function() {
108138
this.searchText = this.$.searchInput.getValue();
109139
this.page = 0;
@@ -125,6 +155,7 @@
125155
setupItem: function(inSender, inEvent) {
126156
var i = inEvent.index;
127157
var item = this.results[i];
158+
this.$.item.addRemoveClass("onyx-selected", inSender.isSelected(inEvent.index));
128159
this.$.thumbnail.setSrc(item.thumbnail);
129160
this.$.title.setContent(item.title || "Untitled");
130161
this.$.more.canGenerate = !this.results[i+1];
@@ -135,17 +166,23 @@
135166
this.$.flickrSearch.search(this.searchText, this.page);
136167
},
137168
itemTap: function(inSender, inEvent) {
138-
if (this.getBounds().width <= 480) {
139-
this.$.panels.setIndex(1);
169+
if (this.isSmall()) {
170+
this.setIndex(1);
140171
}
141172
this.$.imageSpinner.show();
142173
var item = this.results[inEvent.index];
174+
this.$.flickrImage.hide();
143175
this.$.flickrImage.setSrc(item.original);
144176

145177
},
146178
imageLoaded: function() {
147179
this.$.flickrImage.show();
180+
var b = this.$.flickrImage.getBounds();
181+
this.$.flickrImage.addRemoveClass("tall", b.height > b.width);
148182
this.$.imageSpinner.hide();
183+
},
184+
showList: function() {
185+
this.setIndex(0);
149186
}
150187
});
151188

panels/examples/app-sliding.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
padding: 10px;
3030
}
3131

32-
@media all and (max-width: 200px) {
32+
/* be responsive */
33+
@media all and (max-width: 800px) {
3334
.panels > * {
3435
min-width: 100%;
3536
}

0 commit comments

Comments
 (0)