|
1 | | -/*! gridster.js - v0.6.4 - 2015-04-04 |
2 | | -* http://gridster.net/ |
3 | | -* Copyright (c) 2015 decksterteam; Licensed */ |
4 | | - |
| 1 | +/*! gridster.js - v0.6.5 - 2015-04-06 |
| 2 | +* http://gridster.net/ |
| 3 | +* Copyright (c) 2015 decksterteam; Licensed */ |
| 4 | + |
5 | 5 | ;(function(root, factory) { |
6 | 6 |
|
7 | 7 | if (typeof define === 'function' && define.amd) { |
|
119 | 119 | return Coords; |
120 | 120 |
|
121 | 121 | })); |
122 | | - |
| 122 | + |
123 | 123 | ;(function(root, factory) { |
124 | 124 |
|
125 | 125 | if (typeof define === 'function' && define.amd) { |
|
354 | 354 | return Collision; |
355 | 355 |
|
356 | 356 | })); |
357 | | - |
| 357 | + |
358 | 358 | ;(function(window, undefined) { |
359 | 359 |
|
360 | 360 | /* Delay, debounce and throttle functions taken from underscore.js |
|
427 | 427 | }; |
428 | 428 |
|
429 | 429 | })(window); |
430 | | - |
| 430 | + |
431 | 431 | ;(function(root, factory) { |
432 | 432 |
|
433 | 433 | if (typeof define === 'function' && define.amd) { |
|
845 | 845 | }; |
846 | 846 |
|
847 | 847 | //jQuery adapter |
848 | | - $.fn.drag = function ( options ) { |
| 848 | + $.fn.gridDraggable = function ( options ) { |
849 | 849 | return new Draggable(this, options); |
850 | 850 | }; |
851 | 851 |
|
852 | 852 | return Draggable; |
853 | 853 |
|
854 | 854 | })); |
855 | | - |
| 855 | + |
856 | 856 | ;(function(root, factory) { |
857 | 857 |
|
858 | 858 | if (typeof define === 'function' && define.amd) { |
|
1106 | 1106 | this.draggable(); |
1107 | 1107 | this.options.resize.enabled && this.resizable(); |
1108 | 1108 |
|
| 1109 | + if (this.options.center_widgets) { |
| 1110 | + setTimeout($.proxy(function () { |
| 1111 | + this.center_widgets(); |
| 1112 | + }, this), 0); |
| 1113 | + } |
| 1114 | + |
1109 | 1115 | $(window).bind('resize.gridster', throttle( |
1110 | 1116 | $.proxy(this.recalculate_faux_grid, this), 200)); |
1111 | 1117 | }; |
|
1222 | 1228 |
|
1223 | 1229 | this.drag_api.set_limits((this.cols * this.min_widget_width) + ((this.cols + 1) * this.options.widget_margins[0])); |
1224 | 1230 |
|
| 1231 | + if (this.options.center_widgets) { |
| 1232 | + setTimeout($.proxy(function () { |
| 1233 | + this.center_widgets(); |
| 1234 | + }, this), 0); |
| 1235 | + } |
| 1236 | + |
1225 | 1237 | return $w.fadeIn({complete: function () { if(callback) callback.call(this); }}); |
1226 | 1238 | }; |
1227 | 1239 |
|
|
1297 | 1309 | * @param {Number} size_x The number of columns that will occupy the widget. |
1298 | 1310 | * By default <code>size_x</code> is limited to the space available from |
1299 | 1311 | * the column where the widget begins, until the last column to the right. |
| 1312 | + * @param {Boolean} [reposition] Set to false to not move the widget to |
| 1313 | + * the left if there is insufficient space on the right. |
1300 | 1314 | * @param {Number} size_y The number of rows that will occupy the widget. |
1301 | 1315 | * @param {Function} [callback] Function executed when the widget is removed. |
1302 | 1316 | * @return {HTMLElement} Returns $widget. |
1303 | 1317 | */ |
1304 | | - fn.resize_widget = function($widget, size_x, size_y, callback) { |
| 1318 | + fn.resize_widget = function($widget, size_x, size_y, reposition, callback) { |
1305 | 1319 | var wgd = $widget.coords().grid; |
1306 | 1320 | var col = wgd.col; |
1307 | 1321 | var max_cols = this.options.max_cols; |
| 1322 | + reposition !== false && (reposition = true); |
1308 | 1323 | var old_size_y = wgd.size_y; |
1309 | 1324 | var old_col = wgd.col; |
1310 | 1325 | var new_col = old_col; |
1311 | 1326 |
|
1312 | 1327 | size_x || (size_x = wgd.size_x); |
1313 | 1328 | size_y || (size_y = wgd.size_y); |
1314 | 1329 |
|
1315 | | - if (max_cols !== Infinity) { |
1316 | | - size_x = Math.min(size_x, max_cols - col + 1); |
| 1330 | + //if (max_cols !== Infinity) { |
| 1331 | + // size_x = Math.min(size_x, max_cols - col + 1); |
| 1332 | + //} |
| 1333 | + |
| 1334 | + if (reposition && old_col + size_x - 1 > this.cols) { |
| 1335 | + var diff = old_col + (size_x - 1) - this.cols; |
| 1336 | + var c = old_col - diff; |
| 1337 | + new_col = Math.max(1, c); |
1317 | 1338 | } |
1318 | 1339 |
|
1319 | 1340 | if (size_y > old_size_y) { |
|
1352 | 1373 | * representing the widget. |
1353 | 1374 | * @param {Number} size_x The number of cols that will occupy the widget. |
1354 | 1375 | * @param {Number} size_y The number of rows that will occupy the widget. |
| 1376 | + * @param {Number} col The column to resize the widget from. |
1355 | 1377 | * @param {Function} [callback] Function executed when the widget is expanded. |
1356 | 1378 | * @return {HTMLElement} Returns $widget. |
1357 | 1379 | */ |
1358 | | - fn.expand_widget = function($widget, size_x, size_y, callback) { |
| 1380 | + fn.expand_widget = function($widget, size_x, size_y, col, callback) { |
1359 | 1381 | var wgd = $widget.coords().grid; |
1360 | 1382 | var max_size_x = Math.floor(($(window).width() - this.options.widget_margins[0] * 2) / this.min_widget_width); |
1361 | 1383 | size_x = size_x || Math.min(max_size_x, this.cols); |
|
1365 | 1387 | $widget.attr('pre_expand_col', wgd.col); |
1366 | 1388 | $widget.attr('pre_expand_sizex', wgd.size_x); |
1367 | 1389 | $widget.attr('pre_expand_sizey', wgd.size_y); |
1368 | | - var new_col = 1; |
| 1390 | + var new_col = col || 1; |
1369 | 1391 |
|
1370 | 1392 | if (size_y > old_size_y) { |
1371 | 1393 | this.add_faux_rows(Math.max(size_y - old_size_y, 0)); |
|
1470 | 1492 | * @method center_widgets |
1471 | 1493 | */ |
1472 | 1494 | fn.center_widgets = debounce(function () { |
1473 | | - var window_width = $(window).width(); |
| 1495 | + var wrapper_width = this.$wrapper.width(); |
1474 | 1496 | var col_size = this.options.widget_base_dimensions[0] + (2 * this.options.widget_margins[0]); |
1475 | | - var col_count = Math.floor(Math.max(Math.floor(window_width / col_size), this.min_col_count) / 2) * 2; |
| 1497 | + var col_count = Math.floor(Math.max(Math.floor(wrapper_width / col_size), this.min_col_count) / 2) * 2; |
1476 | 1498 |
|
1477 | 1499 | this.options.min_cols = col_count; |
1478 | 1500 | this.options.max_cols = col_count; |
1479 | 1501 | this.options.extra_cols = 0; |
1480 | 1502 | this.options.max_size_x = col_count; |
1481 | 1503 | this.set_dom_grid_width(col_count); |
| 1504 | + this.cols = col_count; |
1482 | 1505 |
|
1483 | 1506 | var col_dif = (col_count - this.prev_col_count) / 2; |
1484 | 1507 |
|
|
1515 | 1538 |
|
1516 | 1539 |
|
1517 | 1540 | fn.get_min_col = function () { |
1518 | | - var min_col = this.min_col_count; |
1519 | | - this.$widgets.each($.proxy(function(i, widget) { |
1520 | | - var $widget = $(widget); |
1521 | | - var value = parseInt($widget.attr("data-col")); |
1522 | | - min_col = Math.min(min_col, value); |
1523 | | - }, this)); |
1524 | | - return min_col; |
| 1541 | + return Math.min.apply(Math, this.$widgets.map($.proxy(function (key, widget) { |
| 1542 | + return this.get_cells_occupied($(widget).coords().grid).cols; |
| 1543 | + }, this)).get()); |
1525 | 1544 | }; |
1526 | 1545 |
|
1527 | 1546 |
|
1528 | 1547 | fn.shift_cols = function (col_dif) { |
1529 | | - this.$widgets.each($.proxy(function(i, widget) { |
1530 | | - var $widget = $(widget); |
| 1548 | + var widgets_coords = this.$widgets.map($.proxy(function(i, widget) { |
| 1549 | + var $w = $(widget); |
| 1550 | + return this.dom_to_coords($w); |
| 1551 | + }, this)); |
| 1552 | + widgets_coords = Gridster.sort_by_row_and_col_asc(widgets_coords); |
| 1553 | + |
| 1554 | + widgets_coords.each($.proxy(function(i, widget) { |
| 1555 | + var $widget = $(widget.el); |
1531 | 1556 | var wgd = $widget.coords().grid; |
1532 | | - var value = parseInt($widget.attr("data-col")); |
| 1557 | + var col = parseInt($widget.attr("data-col")); |
| 1558 | + |
1533 | 1559 | var new_grid_data = { |
1534 | | - col: Math.round(value + col_dif), |
| 1560 | + col: col + col_dif, |
1535 | 1561 | row: wgd.row, |
1536 | 1562 | size_x: wgd.size_x, |
1537 | 1563 | size_y: wgd.size_y |
1538 | 1564 | }; |
1539 | | - |
1540 | 1565 | setTimeout($.proxy(function () { |
1541 | 1566 | this.mutate_widget_in_gridmap($widget, wgd, new_grid_data); |
1542 | 1567 | }, this), 0); |
|
1925 | 1950 |
|
1926 | 1951 | this.options.resize.enabled && this.add_resize_handle($el); |
1927 | 1952 |
|
1928 | | - if (this.options.center_widgets) { |
1929 | | - setTimeout($.proxy(function () { |
1930 | | - this.center_widgets(); |
1931 | | - }, this), 0); |
1932 | | - } |
1933 | | - |
1934 | 1953 | return posChanged; |
1935 | 1954 | }; |
1936 | 1955 |
|
|
2066 | 2085 | }, 60) |
2067 | 2086 | }); |
2068 | 2087 |
|
2069 | | - this.drag_api = this.$el.drag(draggable_options); |
| 2088 | + this.drag_api = this.$el.gridDraggable(draggable_options); |
2070 | 2089 | return this; |
2071 | 2090 | }; |
2072 | 2091 |
|
|
2078 | 2097 | * @return {Class} Returns instance of gridster Class. |
2079 | 2098 | */ |
2080 | 2099 | fn.resizable = function() { |
2081 | | - this.resize_api = this.$el.drag({ |
| 2100 | + this.resize_api = this.$el.gridDraggable({ |
2082 | 2101 | items: '.' + this.options.resize.handle_class, |
2083 | 2102 | offset_left: this.options.widget_margins[0], |
2084 | 2103 | container_width: this.container_width, |
|
2480 | 2499 | if (size_x !== this.resize_last_sizex || |
2481 | 2500 | size_y !== this.resize_last_sizey) { |
2482 | 2501 |
|
2483 | | - this.resize_widget(this.$resized_widget, size_x, size_y); |
| 2502 | + this.resize_widget(this.$resized_widget, size_x, size_y, false); |
2484 | 2503 | this.set_dom_grid_width(this.cols); |
2485 | 2504 |
|
2486 | 2505 | this.$resize_preview_holder.css({ |
|
3866 | 3885 | cols = this.get_highest_occupied_cell().col; |
3867 | 3886 | } |
3868 | 3887 |
|
3869 | | - var max_cols = (this.options.autogrow_cols ? this.options.max_cols : this.cols); |
| 3888 | + var max_cols = (this.options.autogrow_cols ? this.options.max_cols : |
| 3889 | + this.cols); |
3870 | 3890 |
|
3871 | 3891 | cols = Math.min(max_cols, Math.max(cols, this.options.min_cols)); |
3872 | 3892 | this.container_width = ((cols + 1) * this.options.widget_margins[0]) + (cols * this.min_widget_width); |
3873 | | - if(this.is_responsive()) { |
3874 | | - this.$el.css({'min-width': '100%', 'max-width': '100%'}); |
3875 | | - return this; //if we are responsive exit before setting the width of $el |
3876 | | - } |
3877 | 3893 | this.$el.css('width', this.container_width); |
3878 | 3894 |
|
| 3895 | + if(this.is_responsive()) { |
| 3896 | + this.$el.css({'min-width': '100%', 'max-width': '100%'}); |
| 3897 | + return this; |
| 3898 | + } |
3879 | 3899 | return this; |
3880 | 3900 | }; |
3881 | 3901 |
|
|
3973 | 3993 | opts.widget_base_dimensions || |
3974 | 3994 | (opts.widget_base_dimensions = this.options.widget_base_dimensions); |
3975 | 3995 |
|
| 3996 | + opts.widget_margins || (opts.widget_margins = this.options.widget_margins); |
3976 | 3997 |
|
3977 | 3998 | if(this.is_responsive()) { |
3978 | | - opts.widget_base_dimensions = [this.get_responsive_col_width(), opts.widget_base_dimensions[1]]; |
| 3999 | + opts.widget_base_dimensions = [this.get_responsive_col_width(), opts.widget_base_dimensions[1]]; |
| 4000 | + this.toggle_collapsed_grid(full_width, opts); |
3979 | 4001 | } |
3980 | 4002 |
|
3981 | | - opts.widget_margins || (opts.widget_margins = this.options.widget_margins); |
3982 | | - |
3983 | | - |
3984 | | - this.toggle_collapsed_grid(full_width, opts); |
3985 | | - |
3986 | 4003 | // don't duplicate stylesheets for the same configuration |
3987 | 4004 | var serialized_opts = $.param(opts); |
3988 | 4005 | if ($.inArray(serialized_opts, Gridster.generated_stylesheets) >= 0) { |
|
4267 | 4284 | * |
4268 | 4285 | * @param wrapper |
4269 | 4286 | */ |
4270 | | - fn.set_num_columns = function (wrapper) { |
| 4287 | + fn.set_num_columns = function (wrapper_width) { |
4271 | 4288 |
|
4272 | 4289 | var max_cols = this.options.max_cols; |
4273 | 4290 |
|
4274 | | - var cols = Math.floor(wrapper / (this.min_widget_width + this.options.widget_margins[0])) + |
| 4291 | + var cols = Math.floor(wrapper_width / (this.min_widget_width + this.options.widget_margins[0])) + |
4275 | 4292 | this.options.extra_cols; |
4276 | 4293 |
|
4277 | 4294 | var actual_cols = this.$widgets.map(function() { |
|
0 commit comments