|
1 |
| -/*! gridster.js - v0.6.4 - 2015-03-19 |
| 1 | +/*! gridster.js - v0.6.4 - 2015-04-06 |
2 | 2 | * http://gridster.net/
|
3 | 3 | * Copyright (c) 2015 decksterteam; Licensed */
|
4 | 4 |
|
|
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 |
|
|
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) {
|
|
1470 | 1491 | * @method center_widgets
|
1471 | 1492 | */
|
1472 | 1493 | fn.center_widgets = debounce(function () {
|
1473 |
| - var window_width = $(window).width(); |
| 1494 | + var wrapper_width = this.$wrapper.width(); |
1474 | 1495 | 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; |
| 1496 | + var col_count = Math.floor(Math.max(Math.floor(wrapper_width / col_size), this.min_col_count) / 2) * 2; |
1476 | 1497 |
|
1477 | 1498 | this.options.min_cols = col_count;
|
1478 | 1499 | this.options.max_cols = col_count;
|
1479 | 1500 | this.options.extra_cols = 0;
|
1480 | 1501 | this.options.max_size_x = col_count;
|
1481 | 1502 | this.set_dom_grid_width(col_count);
|
| 1503 | + this.cols = col_count; |
1482 | 1504 |
|
1483 | 1505 | var col_dif = (col_count - this.prev_col_count) / 2;
|
1484 | 1506 |
|
|
1515 | 1537 |
|
1516 | 1538 |
|
1517 | 1539 | 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; |
| 1540 | + return Math.min.apply(Math, this.$widgets.map($.proxy(function (key, widget) { |
| 1541 | + return this.get_cells_occupied($(widget).coords().grid).cols; |
| 1542 | + }, this)).get()); |
1525 | 1543 | };
|
1526 | 1544 |
|
1527 | 1545 |
|
1528 | 1546 | fn.shift_cols = function (col_dif) {
|
1529 |
| - this.$widgets.each($.proxy(function(i, widget) { |
1530 |
| - var $widget = $(widget); |
| 1547 | + var widgets_coords = this.$widgets.map($.proxy(function(i, widget) { |
| 1548 | + var $w = $(widget); |
| 1549 | + return this.dom_to_coords($w); |
| 1550 | + }, this)); |
| 1551 | + widgets_coords = Gridster.sort_by_row_and_col_asc(widgets_coords); |
| 1552 | + |
| 1553 | + widgets_coords.each($.proxy(function(i, widget) { |
| 1554 | + var $widget = $(widget.el); |
1531 | 1555 | var wgd = $widget.coords().grid;
|
1532 |
| - var value = parseInt($widget.attr("data-col")); |
| 1556 | + var col = parseInt($widget.attr("data-col")); |
| 1557 | + |
1533 | 1558 | var new_grid_data = {
|
1534 |
| - col: Math.round(value + col_dif), |
| 1559 | + col: col + col_dif, |
1535 | 1560 | row: wgd.row,
|
1536 | 1561 | size_x: wgd.size_x,
|
1537 | 1562 | size_y: wgd.size_y
|
1538 | 1563 | };
|
1539 |
| - |
1540 | 1564 | setTimeout($.proxy(function () {
|
1541 | 1565 | this.mutate_widget_in_gridmap($widget, wgd, new_grid_data);
|
1542 | 1566 | }, this), 0);
|
|
1925 | 1949 |
|
1926 | 1950 | this.options.resize.enabled && this.add_resize_handle($el);
|
1927 | 1951 |
|
1928 |
| - if (this.options.center_widgets) { |
1929 |
| - setTimeout($.proxy(function () { |
1930 |
| - this.center_widgets(); |
1931 |
| - }, this), 0); |
1932 |
| - } |
1933 |
| - |
1934 | 1952 | return posChanged;
|
1935 | 1953 | };
|
1936 | 1954 |
|
|
2066 | 2084 | }, 60)
|
2067 | 2085 | });
|
2068 | 2086 |
|
2069 |
| - this.drag_api = this.$el.drag(draggable_options); |
| 2087 | + this.drag_api = this.$el.gridDraggable(draggable_options); |
2070 | 2088 | return this;
|
2071 | 2089 | };
|
2072 | 2090 |
|
|
2078 | 2096 | * @return {Class} Returns instance of gridster Class.
|
2079 | 2097 | */
|
2080 | 2098 | fn.resizable = function() {
|
2081 |
| - this.resize_api = this.$el.drag({ |
| 2099 | + this.resize_api = this.$el.gridDraggable({ |
2082 | 2100 | items: '.' + this.options.resize.handle_class,
|
2083 | 2101 | offset_left: this.options.widget_margins[0],
|
2084 | 2102 | container_width: this.container_width,
|
|
2480 | 2498 | if (size_x !== this.resize_last_sizex ||
|
2481 | 2499 | size_y !== this.resize_last_sizey) {
|
2482 | 2500 |
|
2483 |
| - this.resize_widget(this.$resized_widget, size_x, size_y); |
| 2501 | + this.resize_widget(this.$resized_widget, size_x, size_y, false); |
2484 | 2502 | this.set_dom_grid_width(this.cols);
|
2485 | 2503 |
|
2486 | 2504 | this.$resize_preview_holder.css({
|
|
3974 | 3992 | opts.widget_base_dimensions ||
|
3975 | 3993 | (opts.widget_base_dimensions = this.options.widget_base_dimensions);
|
3976 | 3994 |
|
| 3995 | + opts.widget_margins || (opts.widget_margins = this.options.widget_margins); |
3977 | 3996 |
|
3978 | 3997 | if(this.is_responsive()) {
|
3979 |
| - opts.widget_base_dimensions = [this.get_responsive_col_width(), opts.widget_base_dimensions[1]]; |
| 3998 | + opts.widget_base_dimensions = [this.get_responsive_col_width(), opts.widget_base_dimensions[1]]; |
| 3999 | + this.toggle_collapsed_grid(full_width, opts); |
3980 | 4000 | }
|
3981 | 4001 |
|
3982 |
| - opts.widget_margins || (opts.widget_margins = this.options.widget_margins); |
3983 |
| - |
3984 |
| - |
3985 |
| - this.toggle_collapsed_grid(full_width, opts); |
3986 |
| - |
3987 | 4002 | // don't duplicate stylesheets for the same configuration
|
3988 | 4003 | var serialized_opts = $.param(opts);
|
3989 | 4004 | if ($.inArray(serialized_opts, Gridster.generated_stylesheets) >= 0) {
|
|
4268 | 4283 | *
|
4269 | 4284 | * @param wrapper
|
4270 | 4285 | */
|
4271 |
| - fn.set_num_columns = function (wrapper) { |
| 4286 | + fn.set_num_columns = function (wrapper_width) { |
4272 | 4287 |
|
4273 | 4288 | var max_cols = this.options.max_cols;
|
4274 | 4289 |
|
4275 |
| - var cols = Math.floor(wrapper / (this.min_widget_width + this.options.widget_margins[0])) + |
| 4290 | + var cols = Math.floor(wrapper_width / (this.min_widget_width + this.options.widget_margins[0])) + |
4276 | 4291 | this.options.extra_cols;
|
4277 | 4292 |
|
4278 | 4293 | var actual_cols = this.$widgets.map(function() {
|
|
0 commit comments