Skip to content

Commit 7f48419

Browse files
author
scottjehl
committed
This adds a fallback for navbars that have one item, so they simply fill 100%. Credit for this fix and idea goes to kennedyr (Richard Kennedy), but we changed the naming around a bit. Fixes jquery-archive#1107. Thanks Richard!
1 parent 1196509 commit 7f48419

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

docs/toolbars/docs-navbar.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ <h2>Simple navbar</h2>
106106
</div><!-- /navbar -->
107107
</div><!-- /footer -->
108108

109+
<p>As a fallback, navbars with 1 item will simply render as 100%.</p>
110+
111+
<div data-role="footer">
112+
<div data-role="navbar">
113+
<ul>
114+
<li><a href="#" class="ui-btn-active">One</a></li>
115+
</ul>
116+
</div><!-- /navbar -->
117+
</div><!-- /footer -->
118+
109119
<h2>Navbars in headers</h2>
110120

111121
<p>If you want to add a navbar to the top of the page, you can still have a page title and buttons. Just add the navbar container inside the header block, right after the title and buttons in the source order.</p>

js/jquery.mobile.grid.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $.fn.grid = function(options){
1313

1414

1515
var $kids = $(this).children(),
16-
gridCols = {a: 2, b:3, c:4, d:5},
16+
gridCols = {solo:1, a:2, b:3, c:4, d:5},
1717
grid = o.grid,
1818
iterator;
1919

@@ -32,12 +32,13 @@ $.fn.grid = function(options){
3232
$(this).addClass('ui-grid-' + grid);
3333

3434
$kids.filter(':nth-child(' + iterator + 'n+1)').addClass('ui-block-a');
35-
$kids.filter(':nth-child(' + iterator + 'n+2)').addClass('ui-block-b');
36-
35+
if(iterator > 1){
36+
$kids.filter(':nth-child(' + iterator + 'n+2)').addClass('ui-block-b');
37+
}
3738
if(iterator > 2){
3839
$kids.filter(':nth-child(3n+3)').addClass('ui-block-c');
3940
}
40-
if(iterator> 3){
41+
if(iterator > 3){
4142
$kids.filter(':nth-child(4n+4)').addClass('ui-block-d');
4243
}
4344
if(iterator > 4){
@@ -46,5 +47,4 @@ $.fn.grid = function(options){
4647

4748
});
4849
};
49-
})(jQuery);
50-
50+
})(jQuery);

themes/default/jquery.mobile.grids.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
.ui-grid-a, .ui-grid-b, .ui-grid-c, .ui-grid-d { overflow: hidden; }
99
.ui-block-a, .ui-block-b, .ui-block-c, .ui-block-d, .ui-block-e { margin: 0; padding: 0; border: 0; float: left; min-height:1px;}
1010

11+
/* grid solo: 100 - single item fallback */
12+
.ui-grid-solo .ui-block-a { width: 100%; float: none; }
13+
1114
/* grid a: 50/50 */
1215
.ui-grid-a .ui-block-a, .ui-grid-a .ui-block-b { width: 50%; }
1316
.ui-grid-a .ui-block-a { clear: left; }
@@ -22,4 +25,4 @@
2225

2326
/* grid d: 20/20/20/20/20 */
2427
.ui-grid-d .ui-block-a, .ui-grid-d .ui-block-b, .ui-grid-d .ui-block-c, .ui-grid-d .ui-block-d, .ui-grid-d .ui-block-e { width: 20%; }
25-
.ui-grid-d .ui-block-a { clear: left; }
28+
.ui-grid-d .ui-block-a { clear: left; }

0 commit comments

Comments
 (0)