From d3a0d3379156f1b1552cfa1e9a81dabd95678873 Mon Sep 17 00:00:00 2001 From: scottjehl Date: Thu, 11 Nov 2010 17:33:07 -0500 Subject: [PATCH] fixed up grids and navbar again - this time to automate the column count to number of children, or 'a' when greater than 5. data-grid attribute can be set to any grid letter to trump the automated counting. --- docs/toolbars/docs-navbar.html | 10 ++++----- js/jquery.mobile.grid.js | 38 +++++++++++++++++----------------- js/jquery.mobile.navbar.js | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/docs/toolbars/docs-navbar.html b/docs/toolbars/docs-navbar.html index 7d614210..01bbb3c4 100755 --- a/docs/toolbars/docs-navbar.html +++ b/docs/toolbars/docs-navbar.html @@ -48,7 +48,7 @@

Adding a third item will automatically make each button 1/3 the width of the browser window:

-
+
  • One
  • Two
  • @@ -111,7 +111,7 @@

    I'm a header

    Options -
    +
    • One
    • Two
    • @@ -125,7 +125,7 @@

      Icons can be added to navbar items by adding the data-icon attribute specifying a standard mobile icon to each anchor.

      -
      +
      • Summary
      • Favs
      • @@ -137,7 +137,7 @@

        Icons can be stacked above the labels by adding the data-iconpos="top" attribute to each anchor.

        -
        +
        • Summary
        • Favs
        • @@ -185,7 +185,7 @@

          Navbars can be set to any theme color by data-theme attribute to the links and specifying any theme swatch.

          -
          +
          • Summary
          • Favs
          • diff --git a/js/jquery.mobile.grid.js b/js/jquery.mobile.grid.js index 3654c5c0..ed5457bb 100644 --- a/js/jquery.mobile.grid.js +++ b/js/jquery.mobile.grid.js @@ -8,31 +8,31 @@ $.fn.grid = function(options){ return $(this).each(function(){ var o = $.extend({ - grid: 'a' + grid: null },options); - - $(this).addClass('ui-grid-' + o.grid); + var $kids = $(this).children(), + gridCols = {a: 2, b:3, c:4, d:5}, + grid = o.grid, iterator; - switch( o.grid ){ - case 'a': - iterator = 2; - break; - case 'b': - iterator = 3; - break; - case 'c': - iterator = 4; - break; - case 'd': - iterator = 5; - break; + if( !grid ){ + if( $kids.length <= 5 ){ + for(var letter in gridCols){ + if(gridCols[letter] == $kids.length){ grid = letter; } + } + } + else{ + grid = 'a'; + } } - - $kids.filter(':nth-child(' + iterator + 'n+1)').addClass('ui-block-a'); - $kids.filter(':nth-child(' + iterator + 'n+2)').addClass('ui-block-b'); + iterator = gridCols[grid]; + + $(this).addClass('ui-grid-' + grid); + + $kids.filter(':nth-child(' + iterator + 'n+1)').addClass('ui-block-a'); + $kids.filter(':nth-child(' + iterator + 'n+2)').addClass('ui-block-b'); if(iterator > 2){ $kids.filter(':nth-child(3n+3)').addClass('ui-block-c'); diff --git a/js/jquery.mobile.navbar.js b/js/jquery.mobile.navbar.js index 4e7a5de7..1556a4c2 100755 --- a/js/jquery.mobile.navbar.js +++ b/js/jquery.mobile.navbar.js @@ -8,7 +8,7 @@ $.widget( "mobile.navbar", $.mobile.widget, { options: { iconpos: 'top', - grid: 'a' + grid: null }, _create: function(){ var $navbar = this.element,