Skip to content

Commit

Permalink
Add max_cols setting
Browse files Browse the repository at this point in the history
Right now the number of columns is calculated by dividing the available
space by the necessary space. I want to have an option to limit the
number of calculated columns, without changing the width of the div my
grid lives in.

In order to limit the number of calculated columns max_cols is set to a
number. To have 'unlimited' columns set the value of max_cols to -1 (as
ids done in the default settings). This provides the arbitrary useful
functionality to set the max number of columns to 0. Any sideeffect
caused by this are mitigated by checking that the max_cols is larger
than the min_cols setting.
  • Loading branch information
tuvokki committed Apr 11, 2013
1 parent b58f145 commit 5569caa
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/jquery.gridster.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
extra_rows: 0,
extra_cols: 0,
min_cols: 1,
max_cols: -1,
min_rows: 15,
max_size_x: 6,
autogenerate_stylesheet: true,
Expand Down Expand Up @@ -55,6 +56,8 @@
* @param {Number} [options.extra_rows] Add more rows in addition to
* those that have been calculated.
* @param {Number} [options.min_cols] The minimum required columns.
* @param {Number} [options.max_cols] The maximum columns possible (set to -1
* for no maximum).
* @param {Number} [options.min_rows] The minimum required rows.
* @param {Number} [options.max_size_x] The maximum number of columns
* that a widget can span.
Expand Down Expand Up @@ -2509,6 +2512,12 @@
});

this.cols = Math.max(min_cols, cols, this.options.min_cols);
var max_cols = this.options.max_cols;
if (max_cols >= -1 && max_cols >= min_cols) {
if (max_cols < this.cols) {
this.cols = max_cols;
}
}
this.rows = Math.max(max_rows, this.options.min_rows);

this.baseX = ($(window).width() - aw) / 2;
Expand Down

0 comments on commit 5569caa

Please sign in to comment.