|
261 | 261 | this.set_dom_grid_width(); |
262 | 262 | this.set_dom_grid_height(); |
263 | 263 |
|
264 | | - this.drag_api.set_limits(this.container_width); |
| 264 | + this.drag_api.set_limits(this.cols * this.min_widget_width); |
265 | 265 |
|
266 | 266 | return $w.fadeIn(); |
267 | 267 | }; |
|
816 | 816 | var draggable_options = $.extend(true, {}, this.options.draggable, { |
817 | 817 | offset_left: this.options.widget_margins[0], |
818 | 818 | offset_top: this.options.widget_margins[1], |
819 | | - container_width: this.container_width, |
| 819 | + container_width: this.cols * this.min_widget_width, |
820 | 820 | limit: true, |
821 | 821 | ignore_dragging: ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON', |
822 | 822 | '.' + this.options.resize.handle_class], |
|
910 | 910 | this.placeholder_grid_data = $.extend({}, this.player_grid_data); |
911 | 911 |
|
912 | 912 | this.set_dom_grid_height(this.$el.height() + |
913 | | - (this.player_grid_data.size_y * this.min_widget_height)); |
| 913 | + (this.player_grid_data.size_y * this.min_widget_height)); |
914 | 914 |
|
915 | | - this.set_dom_grid_width(this.highest_col + 1); |
| 915 | + this.set_dom_grid_width(this.cols); |
916 | 916 |
|
917 | | - // auto grow cols |
| 917 | + var pgd_sizex = this.player_grid_data.size_x; |
918 | 918 | var cols_diff = this.cols - this.highest_col; |
919 | | - if (cols_diff < this.player_grid_data.size_x) { |
920 | | - this.add_faux_cols(this.player_grid_data.size_x - cols_diff); |
| 919 | + |
| 920 | + if (this.options.autogrow_cols && cols_diff <= pgd_sizex) { |
| 921 | + this.add_faux_cols(Math.min(pgd_sizex - cols_diff, 1)); |
921 | 922 | } |
922 | 923 |
|
923 | 924 | var colliders = this.faux_grid; |
|
969 | 970 | top: ui.position.top + this.baseY |
970 | 971 | }; |
971 | 972 |
|
| 973 | + // auto grow cols |
| 974 | + if (this.options.autogrow_cols) { |
| 975 | + var prcol = this.placeholder_grid_data.col + |
| 976 | + this.placeholder_grid_data.size_x - 1; |
| 977 | + |
| 978 | + // "- 1" due to adding at least 1 column in on_start_drag |
| 979 | + if (prcol >= this.cols - 1 && this.options.max_cols >= this.cols + 1) { |
| 980 | + this.add_faux_cols(1); |
| 981 | + this.set_dom_grid_width(this.cols + 1); |
| 982 | + this.drag_api.set_limits(this.container_width); |
| 983 | + } |
| 984 | + |
| 985 | + this.collision_api.set_colliders(this.faux_grid); |
| 986 | + } |
| 987 | + |
972 | 988 | this.colliders_data = this.collision_api.get_closest_colliders( |
973 | 989 | abs_offset); |
974 | 990 |
|
975 | 991 | this.on_overlapped_column_change( |
976 | | - this.on_start_overlapping_column, |
977 | | - this.on_stop_overlapping_column |
978 | | - ); |
| 992 | + this.on_start_overlapping_column, this.on_stop_overlapping_column); |
979 | 993 |
|
980 | 994 | this.on_overlapped_row_change( |
981 | | - this.on_start_overlapping_row, |
982 | | - this.on_stop_overlapping_row |
983 | | - ); |
| 995 | + this.on_start_overlapping_row, this.on_stop_overlapping_row); |
984 | 996 |
|
985 | | - //auto grow cols |
986 | | - if (this.options.autogrow_cols) { |
987 | | - var prcol = this.placeholder_grid_data.col + |
988 | | - this.placeholder_grid_data.size_x - 1; |
989 | | - if (prcol === this.highest_col) { |
990 | | - if (prcol < this.cols) { |
991 | | - this.set_dom_grid_width(prcol + 1); |
992 | | - } |
993 | | - this.highest_col = prcol + 1; |
994 | | - this.drag_api.set_limits(this.container_width); |
995 | | - } |
996 | | - } |
997 | 997 |
|
998 | 998 | if (this.helper && this.$player) { |
999 | 999 | this.$player.css({ |
|
1069 | 1069 | this.set_dom_grid_width(); |
1070 | 1070 |
|
1071 | 1071 | if (this.options.autogrow_cols) { |
1072 | | - this.drag_api.set_limits(this.container_width); |
| 1072 | + this.drag_api.set_limits(this.cols * this.min_widget_width); |
1073 | 1073 | } |
1074 | 1074 | }; |
1075 | 1075 |
|
|
1107 | 1107 |
|
1108 | 1108 | this.resize_initial_last_col = this.get_highest_occupied_cell().col; |
1109 | 1109 |
|
| 1110 | + this.set_dom_grid_width(this.cols); |
| 1111 | + |
1110 | 1112 | this.resize_dir = { |
1111 | 1113 | right: ui.$player.is('.' + this.resize_handle_class + '-x'), |
1112 | 1114 | bottom: ui.$player.is('.' + this.resize_handle_class + '-y') |
|
1165 | 1167 | this.set_dom_grid_width(); |
1166 | 1168 |
|
1167 | 1169 | if (this.options.autogrow_cols) { |
1168 | | - this.drag_api.set_limits(this.container_width); |
| 1170 | + this.drag_api.set_limits(this.cols * this.min_widget_width); |
1169 | 1171 | } |
1170 | 1172 |
|
1171 | 1173 | if (this.options.resize.stop) { |
|
1187 | 1189 | var rel_y = (ui.pointer.diff_top); |
1188 | 1190 | var wbd_x = this.options.widget_base_dimensions[0]; |
1189 | 1191 | var wbd_y = this.options.widget_base_dimensions[1]; |
| 1192 | + var margin_x = this.options.widget_margins[0]; |
| 1193 | + var margin_y = this.options.widget_margins[1]; |
| 1194 | + var max_size_x = this.resize_max_size_x; |
| 1195 | + var min_size_x = this.resize_min_size_x; |
| 1196 | + var max_size_y = this.resize_max_size_y; |
| 1197 | + var min_size_y = this.resize_min_size_y; |
| 1198 | + var autogrow = this.options.autogrow_cols; |
| 1199 | + var width; |
1190 | 1200 | var max_width = Infinity; |
1191 | 1201 | var max_height = Infinity; |
1192 | 1202 |
|
1193 | | - var inc_units_x = Math.ceil((rel_x / |
1194 | | - (this.options.widget_base_dimensions[0] + |
1195 | | - this.options.widget_margins[0] * 2)) - 0.2); |
1196 | | - |
1197 | | - var inc_units_y = Math.ceil((rel_y / |
1198 | | - (this.options.widget_base_dimensions[1] + |
1199 | | - this.options.widget_margins[1] * 2)) - 0.2); |
| 1203 | + var inc_units_x = Math.ceil((rel_x / (wbd_x + margin_x * 2)) - 0.2); |
| 1204 | + var inc_units_y = Math.ceil((rel_y / (wbd_y + margin_y * 2)) - 0.2); |
1200 | 1205 |
|
1201 | 1206 | var size_x = Math.max(1, this.resize_initial_sizex + inc_units_x); |
1202 | 1207 | var size_y = Math.max(1, this.resize_initial_sizey + inc_units_y); |
1203 | 1208 |
|
1204 | | - size_x = Math.max(Math.min(size_x, this.resize_max_size_x), this.resize_min_size_x); |
1205 | | - max_width = (this.resize_max_size_x * wbd_x) + |
1206 | | - ((size_x - 1) * this.options.widget_margins[0] * 2); |
1207 | | - min_width = (this.resize_min_size_x * wbd_x) + |
1208 | | - ((size_x - 1) * this.options.widget_margins[0] * 2); |
| 1209 | + var max_cols = (this.container_width / this.min_widget_width) - |
| 1210 | + this.resize_initial_col + 1; |
| 1211 | + var limit_width = ((max_cols * this.min_widget_width) - margin_x * 2); |
| 1212 | + |
| 1213 | + size_x = Math.max(Math.min(size_x, max_size_x), min_size_x); |
| 1214 | + size_x = Math.min(max_cols, size_x); |
| 1215 | + width = (max_size_x * wbd_x) + ((size_x - 1) * margin_x * 2); |
| 1216 | + max_width = Math.min(width, limit_width); |
| 1217 | + min_width = (min_size_x * wbd_x) + ((size_x - 1) * margin_x * 2); |
1209 | 1218 |
|
1210 | | - size_y = Math.max(Math.min(size_y, this.resize_max_size_y), this.resize_min_size_y); |
1211 | | - max_height = (this.resize_max_size_y * wbd_y) + |
1212 | | - ((size_y - 1) * this.options.widget_margins[1] * 2); |
1213 | | - min_height = (this.resize_min_size_y * wbd_y) + |
1214 | | - ((size_y - 1) * this.options.widget_margins[1] * 2); |
| 1219 | + size_y = Math.max(Math.min(size_y, max_size_y), min_size_y); |
| 1220 | + max_height = (max_size_y * wbd_y) + ((size_y - 1) * margin_y * 2); |
| 1221 | + min_height = (min_size_y * wbd_y) + ((size_y - 1) * margin_y * 2); |
1215 | 1222 |
|
1216 | 1223 | if (this.resize_dir.right) { |
1217 | 1224 | size_y = this.resize_initial_sizey; |
1218 | 1225 | } else if (this.resize_dir.bottom) { |
1219 | 1226 | size_x = this.resize_initial_sizex; |
1220 | 1227 | } |
1221 | 1228 |
|
1222 | | - |
1223 | | - if (this.options.autogrow_cols) { |
1224 | | - // auto grow cols |
| 1229 | + if (autogrow) { |
1225 | 1230 | var last_widget_col = this.resize_initial_col + size_x - 1; |
1226 | | - if (this.options.autogrow_cols && this.resize_initial_last_col <= last_widget_col) { |
1227 | | - this.set_dom_grid_width(last_widget_col + 1); |
| 1231 | + if (autogrow && this.resize_initial_last_col <= last_widget_col) { |
| 1232 | + this.set_dom_grid_width(Math.max(last_widget_col + 1, this.cols)); |
1228 | 1233 |
|
1229 | 1234 | if (this.cols < last_widget_col) { |
1230 | 1235 | this.add_faux_cols(last_widget_col - this.cols); |
1231 | 1236 | } |
1232 | 1237 | } |
1233 | 1238 | } |
1234 | 1239 |
|
1235 | | - |
1236 | 1240 | var css_props = {}; |
1237 | 1241 | !this.resize_dir.bottom && (css_props.width = Math.max(Math.min( |
1238 | 1242 | this.resize_initial_width + rel_x, max_width), min_width)); |
|
1245 | 1249 | size_y !== this.resize_last_sizey) { |
1246 | 1250 |
|
1247 | 1251 | this.resize_widget(this.$resized_widget, size_x, size_y); |
| 1252 | + this.set_dom_grid_width(this.cols); |
1248 | 1253 |
|
1249 | 1254 | this.$resize_preview_holder.css({ |
1250 | 1255 | 'width': '', |
|
2710 | 2715 | * @return {Object} Returns the instance of the Gridster class. |
2711 | 2716 | */ |
2712 | 2717 | fn.set_dom_grid_width = function(cols) { |
2713 | | - var width; |
2714 | | - |
2715 | 2718 | if (typeof cols === 'undefined') { |
2716 | 2719 | cols = this.get_highest_occupied_cell().col; |
2717 | 2720 | } |
2718 | 2721 |
|
2719 | | - cols = Math.min(this.options.max_cols, |
2720 | | - Math.max(cols, this.options.min_cols)); |
| 2722 | + var max_cols = (this.options.autogrow_cols ? this.options.max_cols : |
| 2723 | + this.cols); |
| 2724 | + |
| 2725 | + cols = Math.min(max_cols, Math.max(cols, this.options.min_cols)); |
2721 | 2726 | this.container_width = cols * this.min_widget_width; |
2722 | 2727 | this.$el.css('width', this.container_width); |
2723 | 2728 | return this; |
|
0 commit comments