|
101 | 101 | * @param {Array} [options.resize.max_size] Limit widget dimensions
|
102 | 102 | * when resizing. Array values should be integers:
|
103 | 103 | * `[max_cols_occupied, max_rows_occupied]`
|
| 104 | + * @param {Array} [options.resize.min_size] Limit widget dimensions |
| 105 | + * when resizing. Array values should be integers: |
| 106 | + * `[min_cols_occupied, min_rows_occupied]` |
104 | 107 | * @param {Function} [options.resize.start] Function executed
|
105 | 108 | * when resizing starts.
|
106 | 109 | * @param {Function} [otions.resize.resize] Function executed
|
|
211 | 214 | * @param {Number} [col] The column the widget should start in.
|
212 | 215 | * @param {Number} [row] The row the widget should start in.
|
213 | 216 | * @param {Array} [max_size] max_size Maximun size (in units) for width and height.
|
| 217 | + * @param {Array} [min_size] min_size Minimum size (in units) for width and height. |
214 | 218 | * @return {HTMLElement} Returns the jQuery wrapped HTMLElement representing.
|
215 | 219 | * the widget that was just created.
|
216 | 220 | */
|
217 |
| - fn.add_widget = function(html, size_x, size_y, col, row, max_size) { |
| 221 | + fn.add_widget = function(html, size_x, size_y, col, row, max_size, min_size) { |
218 | 222 | var pos;
|
219 | 223 | size_x || (size_x = 1);
|
220 | 224 | size_y || (size_y = 1);
|
|
248 | 252 | this.set_widget_max_size($w, max_size);
|
249 | 253 | }
|
250 | 254 |
|
| 255 | + if (min_size) { |
| 256 | + this.set_widget_min_size($w, min_size); |
| 257 | + } |
| 258 | + |
251 | 259 | this.set_dom_grid_height();
|
252 | 260 |
|
253 | 261 | return $w.fadeIn();
|
254 | 262 | };
|
255 | 263 |
|
256 | 264 |
|
| 265 | + /** |
| 266 | + * Change widget size limits. |
| 267 | + * |
| 268 | + * @method set_widget_min_size |
| 269 | + * @param {HTMLElement|Number} $widget The jQuery wrapped HTMLElement |
| 270 | + * representing the widget or an index representing the desired widget. |
| 271 | + * @param {Array} min_size Minimum size (in units) for width and height. |
| 272 | + * @return {HTMLElement} Returns instance of gridster Class. |
| 273 | + */ |
| 274 | + fn.set_widget_min_size = function($widget, min_size) { |
| 275 | + $widget = typeof $widget === 'number' ? |
| 276 | + this.$widgets.eq($widget) : $widget; |
| 277 | + |
| 278 | + if (!$widget.length) { return this; } |
| 279 | + |
| 280 | + var wgd = $widget.data('coords').grid; |
| 281 | + wgd.min_size_x = min_size[0]; |
| 282 | + wgd.min_size_y = min_size[1]; |
| 283 | + |
| 284 | + return this; |
| 285 | + }; |
| 286 | + |
| 287 | + |
257 | 288 | /**
|
258 | 289 | * Change widget size limits.
|
259 | 290 | *
|
|
681 | 712 | 'size_y': parseInt($el.attr('data-sizey'), 10),
|
682 | 713 | 'max_size_x': parseInt($el.attr('data-max-sizex'), 10) || false,
|
683 | 714 | 'max_size_y': parseInt($el.attr('data-max-sizey'), 10) || false,
|
| 715 | + 'min_size_x': parseInt($el.attr('data-min-sizex'), 10) || false, |
| 716 | + 'min_size_y': parseInt($el.attr('data-min-sizey'), 10) || false, |
684 | 717 | 'el': $el
|
685 | 718 | };
|
686 | 719 |
|
|
1061 | 1094 | this.options.max_cols - this.resize_initial_col + 1);
|
1062 | 1095 | this.resize_max_size_y = this.resize_wgd.max_size_y ||
|
1063 | 1096 | this.options.resize.max_size[1];
|
| 1097 | + |
| 1098 | + this.resize_min_size_x = (this.resize_wgd.min_size_x || |
| 1099 | + this.options.resize.min_size[0] || 1); |
| 1100 | + this.resize_min_size_y = (this.resize_wgd.min_size_y || |
| 1101 | + this.options.resize.min_size[1] || 1); |
| 1102 | + |
1064 | 1103 | this.resize_initial_last_col = this.get_highest_occupied_cell().col;
|
1065 | 1104 |
|
1066 | 1105 | this.resize_dir = {
|
|
1153 | 1192 | var size_x = Math.max(1, this.resize_initial_sizex + inc_units_x);
|
1154 | 1193 | var size_y = Math.max(1, this.resize_initial_sizey + inc_units_y);
|
1155 | 1194 |
|
1156 |
| - size_x = Math.min(size_x, this.resize_max_size_x); |
| 1195 | + size_x = Math.max(Math.min(size_x, this.resize_max_size_x), this.resize_min_size_x); |
1157 | 1196 | max_width = (this.resize_max_size_x * wbd_x) +
|
1158 | 1197 | ((size_x - 1) * this.options.widget_margins[0] * 2);
|
| 1198 | + min_width = (this.resize_min_size_x * wbd_x) + |
| 1199 | + ((size_x - 1) * this.options.widget_margins[0] * 2); |
1159 | 1200 |
|
1160 |
| - size_y = Math.min(size_y, this.resize_max_size_y); |
| 1201 | + size_y = Math.max(Math.min(size_y, this.resize_max_size_y), this.resize_min_size_y); |
1161 | 1202 | max_height = (this.resize_max_size_y * wbd_y) +
|
1162 | 1203 | ((size_y - 1) * this.options.widget_margins[1] * 2);
|
1163 |
| - |
| 1204 | + min_height = (this.resize_min_size_y * wbd_y) + |
| 1205 | + ((size_y - 1) * this.options.widget_margins[1] * 2); |
1164 | 1206 |
|
1165 | 1207 | if (this.resize_dir.right) {
|
1166 | 1208 | size_y = this.resize_initial_sizey;
|
|
1183 | 1225 |
|
1184 | 1226 |
|
1185 | 1227 | var css_props = {};
|
1186 |
| - !this.resize_dir.bottom && (css_props.width = Math.min( |
1187 |
| - this.resize_initial_width + rel_x, max_width)); |
1188 |
| - !this.resize_dir.right && (css_props.height = Math.min( |
1189 |
| - this.resize_initial_height + rel_y, max_height)); |
| 1228 | + !this.resize_dir.bottom && (css_props.width = Math.max(Math.min( |
| 1229 | + this.resize_initial_width + rel_x, max_width), min_width)); |
| 1230 | + !this.resize_dir.right && (css_props.height = Math.max(Math.min( |
| 1231 | + this.resize_initial_height + rel_y, max_height), min_height)); |
1190 | 1232 |
|
1191 | 1233 | this.$resized_widget.css(css_props);
|
1192 | 1234 |
|
|
0 commit comments