From 3d755fd793e7e74cbdc56d9a86143f4ebf779a98 Mon Sep 17 00:00:00 2001 From: vieron Date: Wed, 1 May 2013 21:14:27 +0200 Subject: [PATCH] Pass container width to draggable instance. Relative to 5569caa687 --- src/jquery.draggable.js | 7 +++++-- src/jquery.gridster.js | 18 +++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/jquery.draggable.js b/src/jquery.draggable.js index 7c758a270..afc9dccb8 100644 --- a/src/jquery.draggable.js +++ b/src/jquery.draggable.js @@ -15,7 +15,8 @@ offset_left: 0, autoscroll: true, ignore_dragging: ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'], - handle: null + handle: null, + container_width: 0 // 0 == auto // drag: function(e){}, // start : function(e, ui){}, // stop : function(e){} @@ -247,7 +248,9 @@ this.el_init_offset = this.$player.offset(); this.player_width = this.$player.width(); this.player_height = this.$player.height(); - this.player_max_left = (this.$container.width() - this.player_width + + + var container_width = this.options.container_width || this.$container.width(); + this.player_max_left = (container_width - this.player_width + this.options.offset_left); if (this.options.start) { diff --git a/src/jquery.gridster.js b/src/jquery.gridster.js index df5f84ead..c47835c06 100644 --- a/src/jquery.gridster.js +++ b/src/jquery.gridster.js @@ -642,6 +642,7 @@ var self = this; var draggable_options = $.extend(true, {}, this.options.draggable, { offset_left: this.options.widget_margins[0], + container_width: this.container_width, start: function(event, ui) { self.$widgets.filter('.player-revert') .removeClass('player-revert'); @@ -2502,14 +2503,15 @@ fn.generate_grid_and_stylesheet = function() { var aw = this.$wrapper.width(); var ah = this.$wrapper.height(); + var max_cols = this.options.max_cols; var cols = Math.floor(aw / this.min_widget_width) + this.options.extra_cols; var actual_cols = this.$widgets.map(function() { return $(this).attr('data-col'); - }); - actual_cols = Array.prototype.slice.call(actual_cols, 0); + }).get(); + //needed to pass tests with phantomjs actual_cols.length || (actual_cols = [0]); @@ -2522,17 +2524,19 @@ }); 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; - } + + if (max_cols > -1 && max_cols >= min_cols && max_cols < this.cols) { + this.cols = max_cols; } + this.rows = Math.max(max_rows, this.options.min_rows); this.baseX = ($(window).width() - aw) / 2; this.baseY = this.$wrapper.offset().top; + this.container_width = (this.cols * this.options.widget_base_dimensions[0]) + + (this.cols * this.options.widget_margins[0]) + this.options.widget_margins[0]; + if (this.options.autogenerate_stylesheet) { this.generate_stylesheet(); }