mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-16 22:10:25 +00:00
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
|
|
//>>description: Applies classes for grid styling.
|
|
//>>label: CSS Grid Tool
|
|
|
|
define( [ "jquery" ], function( $ ) {
|
|
//>>excludeEnd("jqmBuildExclude");
|
|
(function( $, undefined ) {
|
|
|
|
$.fn.grid = function( options ) {
|
|
return this.each(function() {
|
|
|
|
var $this = $( this ),
|
|
o = $.extend({
|
|
grid: null
|
|
},options),
|
|
$kids = $this.children(),
|
|
gridCols = {solo:1, a:2, b:3, c:4, d:5},
|
|
grid = o.grid,
|
|
iterator;
|
|
|
|
if ( !grid ) {
|
|
if ( $kids.length <= 5 ) {
|
|
for ( var letter in gridCols ) {
|
|
if ( gridCols[ letter ] === $kids.length ) {
|
|
grid = letter;
|
|
}
|
|
}
|
|
} else {
|
|
grid = "a";
|
|
}
|
|
}
|
|
iterator = gridCols[grid];
|
|
|
|
$this.addClass( "ui-grid-" + grid );
|
|
|
|
$kids.filter( ":nth-child(" + iterator + "n+1)" ).addClass( "ui-block-a" );
|
|
|
|
if ( iterator > 1 ) {
|
|
$kids.filter( ":nth-child(" + iterator + "n+2)" ).addClass( "ui-block-b" );
|
|
}
|
|
if ( iterator > 2 ) {
|
|
$kids.filter( ":nth-child(3n+3)" ).addClass( "ui-block-c" );
|
|
}
|
|
if ( iterator > 3 ) {
|
|
$kids.filter( ":nth-child(4n+4)" ).addClass( "ui-block-d" );
|
|
}
|
|
if ( iterator > 4 ) {
|
|
$kids.filter( ":nth-child(5n+5)" ).addClass( "ui-block-e" );
|
|
}
|
|
});
|
|
};
|
|
})( jQuery );
|
|
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
|
|
});
|
|
//>>excludeEnd("jqmBuildExclude");
|