Merge remote-tracking branch 'eric/master'

Grunt changes
  Add an optional final parameter to add_widget.
  Bumping to v0.5.7
  Grunt
  Fix Widget Right Edge Collission Detection
  re-name model_id parameter
  add model_id parameter to add_widget method in order to create a relationship between widget and backbone model
  Fix the memory leak that was incorrectly iterating rows and columns
  Cache $(window) and $(this) selectors for performance
  fix (Gridster.js):  destroy  resize_api
This commit is contained in:
David Morse
2015-04-07 13:50:05 -06:00
9 changed files with 160 additions and 100 deletions
+3
View File
@@ -55,6 +55,9 @@
* **gridster:** make grid responsive ([a3913043](http://github.com/DecksterTeam/gridster.js/commit/a3913043579bae9f5ef28e34524ad7a8ae7dcafd))
<a name="v0.5.7"></a>
### v0.5.7 (2015-02-17)
<a name="v0.5.6"></a>
### v0.5.6 (2014-09-25)
+51 -32
View File
@@ -63,8 +63,13 @@
var d = this.data;
typeof d.left === 'undefined' && (d.left = d.x1);
typeof d.top === 'undefined' && (d.top = d.y1);
if ( d.left === undefined ) {
d.left = d.x1;
}
if ( d.top === undefined ) {
d.top = d.y1;
}
this.coords.x1 = d.left;
this.coords.y1 = d.top;
@@ -283,20 +288,22 @@
var area_coords = self.calculate_overlapped_area_coords(
player_coords, collider_coords);
var area = self.calculate_overlapped_area(area_coords);
var collider_data = {
area: area,
area_coords : area_coords,
region: region,
coords: collider_coords,
player_coords: player_coords,
el: $collider
};
if ( 0 != area ) {
var collider_data = {
area: area,
area_coords : area_coords,
region: region,
coords: collider_coords,
player_coords: player_coords,
el: $collider
};
if (self.options.on_overlap) {
self.options.on_overlap.call(this, collider_data);
if (self.options.on_overlap) {
self.options.on_overlap.call(this, collider_data);
}
colliders_coords.push($collider_coords_ins);
colliders_data.push(collider_data);
}
colliders_coords.push($collider_coords_ins);
colliders_data.push(collider_data);
}
}
@@ -520,7 +527,7 @@
this.disabled = false;
this.events();
$(window).bind(this.nsEvent('resize'),
$window.bind(this.nsEvent('resize'),
throttle($.proxy(this.calculate_dimensions, this), 200));
};
@@ -578,9 +585,9 @@
var diff_y = Math.round(mouse_actual_pos.top - this.mouse_init_pos.top);
var left = Math.round(this.el_init_offset.left +
diff_x - this.baseX + $(window).scrollLeft() - this.win_offset_x);
diff_x - this.baseX + $window.scrollLeft() - this.win_offset_x);
var top = Math.round(this.el_init_offset.top +
diff_y - this.baseY + $(window).scrollTop() - this.win_offset_y);
diff_y - this.baseY + $window.scrollTop() - this.win_offset_y);
if (this.options.limit) {
if (left > this.player_max_left) {
@@ -598,8 +605,8 @@
pointer: {
left: mouse_actual_pos.left,
top: mouse_actual_pos.top,
diff_left: diff_x + ($(window).scrollLeft() - this.win_offset_x),
diff_top: diff_y + ($(window).scrollTop() - this.win_offset_y)
diff_left: diff_x + ($window.scrollLeft() - this.win_offset_x),
diff_top: diff_y + ($window.scrollTop() - this.win_offset_y)
}
};
};
@@ -747,8 +754,8 @@
this.helper = false;
}
this.win_offset_y = $(window).scrollTop();
this.win_offset_x = $(window).scrollLeft();
this.win_offset_y = $window.scrollTop();
this.win_offset_x = $window.scrollLeft();
this.scroll_offset_y = 0;
this.scroll_offset_x = 0;
this.el_init_offset = this.$player.offset();
@@ -827,7 +834,7 @@
this.$container.off(this.ns);
this.$document.off(this.ns);
$(window).off(this.ns);
$window.off(this.ns);
$.removeData(this.$container, 'drag');
};
@@ -864,7 +871,8 @@
}(this, function($, Draggable, Collision) {
var defaults = {
var $window = $( window ),
defaults = {
namespace: '',
widget_selector: 'li',
widget_margins: [10, 10],
@@ -972,7 +980,7 @@
* `[min_cols_occupied, min_rows_occupied]`
* @param {Function} [options.resize.start] Function executed
* when resizing starts.
* @param {Function} [otions.resize.resize] Function executed
* @param {Function} [options.resize.resize] Function executed
* during the resizing.
* @param {Function} [options.resize.stop] Function executed
* when resizing stops.
@@ -1112,7 +1120,7 @@
}, this), 0);
}
$(window).bind('resize.gridster', throttle(
$window.bind('resize.gridster', throttle(
$.proxy(this.recalculate_faux_grid, this), 200));
};
@@ -1235,6 +1243,7 @@
}
return $w.fadeIn({complete: function () { if(callback) callback.call(this); }});
};
@@ -1704,10 +1713,11 @@
});
$nexts.not($exclude).each($.proxy(function(i, w) {
var wgd = $(w).coords().grid;
var $w = $( w ),
wgd = $w.coords().grid;
if ( !(wgd.row <= (row + size_y - 1))) { return; }
var diff = (row + size_y) - wgd.row;
this.move_widget_down($(w), diff);
this.move_widget_down($w, diff);
}, this));
this.set_dom_grid_height();
@@ -4185,6 +4195,8 @@
* @return {Object} Returns the instance of the Gridster class.
*/
fn.add_faux_rows = function(rows) {
rows = window.parseInt( rows, 10 );
var actual_rows = this.rows;
var max_rows = actual_rows + (rows || 1);
@@ -4211,6 +4223,8 @@
* @return {Object} Returns the instance of the Gridster class.
*/
fn.add_faux_cols = function(cols) {
cols = window.parseInt( cols, 10 );
var actual_cols = this.cols;
var max_cols = actual_cols + (cols || 1);
max_cols = Math.min(max_cols, this.options.max_cols);
@@ -4240,7 +4254,7 @@
*/
fn.recalculate_faux_grid = function() {
var aw = this.$wrapper.width();
this.baseX = ($(window).width() - aw) / 2;
this.baseX = ($window.width() - aw) / 2;
this.baseY = this.$wrapper.offset().top;
$.each(this.faux_grid, $.proxy(function(i, coords) {
@@ -4371,7 +4385,7 @@
this.rows = Math.max(max_rows, this.options.min_rows);
this.baseX = ($(window).width() - aw) / 2;
this.baseX = ($window.width() - aw) / 2;
this.baseY = this.$wrapper.offset().top;
if (this.options.autogenerate_stylesheet) {
@@ -4392,12 +4406,16 @@
this.$el.removeData('gridster');
// remove bound callback on window resize
$(window).unbind('.gridster');
$window.unbind('.gridster');
if (this.drag_api) {
this.drag_api.destroy();
}
if (this.resize_api) {
this.resize_api.destroy();
}
this.remove_style_tags();
remove && this.$el.remove();
@@ -4409,8 +4427,9 @@
//jQuery adapter
$.fn.gridster = function(options) {
return this.each(function() {
if (! $(this).data('gridster')) {
$(this).data('gridster', new Gridster( this, options ));
var $this = $( this );
if (! $this.data('gridster')) {
$this.data('gridster', new Gridster( this, options ));
}
});
};
+2 -2
View File
File diff suppressed because one or more lines are too long
+51 -32
View File
@@ -63,8 +63,13 @@
var d = this.data;
typeof d.left === 'undefined' && (d.left = d.x1);
typeof d.top === 'undefined' && (d.top = d.y1);
if ( d.left === undefined ) {
d.left = d.x1;
}
if ( d.top === undefined ) {
d.top = d.y1;
}
this.coords.x1 = d.left;
this.coords.y1 = d.top;
@@ -283,20 +288,22 @@
var area_coords = self.calculate_overlapped_area_coords(
player_coords, collider_coords);
var area = self.calculate_overlapped_area(area_coords);
var collider_data = {
area: area,
area_coords : area_coords,
region: region,
coords: collider_coords,
player_coords: player_coords,
el: $collider
};
if ( 0 != area ) {
var collider_data = {
area: area,
area_coords : area_coords,
region: region,
coords: collider_coords,
player_coords: player_coords,
el: $collider
};
if (self.options.on_overlap) {
self.options.on_overlap.call(this, collider_data);
if (self.options.on_overlap) {
self.options.on_overlap.call(this, collider_data);
}
colliders_coords.push($collider_coords_ins);
colliders_data.push(collider_data);
}
colliders_coords.push($collider_coords_ins);
colliders_data.push(collider_data);
}
}
@@ -520,7 +527,7 @@
this.disabled = false;
this.events();
$(window).bind(this.nsEvent('resize'),
$window.bind(this.nsEvent('resize'),
throttle($.proxy(this.calculate_dimensions, this), 200));
};
@@ -578,9 +585,9 @@
var diff_y = Math.round(mouse_actual_pos.top - this.mouse_init_pos.top);
var left = Math.round(this.el_init_offset.left +
diff_x - this.baseX + $(window).scrollLeft() - this.win_offset_x);
diff_x - this.baseX + $window.scrollLeft() - this.win_offset_x);
var top = Math.round(this.el_init_offset.top +
diff_y - this.baseY + $(window).scrollTop() - this.win_offset_y);
diff_y - this.baseY + $window.scrollTop() - this.win_offset_y);
if (this.options.limit) {
if (left > this.player_max_left) {
@@ -598,8 +605,8 @@
pointer: {
left: mouse_actual_pos.left,
top: mouse_actual_pos.top,
diff_left: diff_x + ($(window).scrollLeft() - this.win_offset_x),
diff_top: diff_y + ($(window).scrollTop() - this.win_offset_y)
diff_left: diff_x + ($window.scrollLeft() - this.win_offset_x),
diff_top: diff_y + ($window.scrollTop() - this.win_offset_y)
}
};
};
@@ -747,8 +754,8 @@
this.helper = false;
}
this.win_offset_y = $(window).scrollTop();
this.win_offset_x = $(window).scrollLeft();
this.win_offset_y = $window.scrollTop();
this.win_offset_x = $window.scrollLeft();
this.scroll_offset_y = 0;
this.scroll_offset_x = 0;
this.el_init_offset = this.$player.offset();
@@ -827,7 +834,7 @@
this.$container.off(this.ns);
this.$document.off(this.ns);
$(window).off(this.ns);
$window.off(this.ns);
$.removeData(this.$container, 'drag');
};
@@ -864,7 +871,8 @@
}(this, function($, Draggable, Collision) {
var defaults = {
var $window = $( window ),
defaults = {
namespace: '',
widget_selector: 'li',
widget_margins: [10, 10],
@@ -972,7 +980,7 @@
* `[min_cols_occupied, min_rows_occupied]`
* @param {Function} [options.resize.start] Function executed
* when resizing starts.
* @param {Function} [otions.resize.resize] Function executed
* @param {Function} [options.resize.resize] Function executed
* during the resizing.
* @param {Function} [options.resize.stop] Function executed
* when resizing stops.
@@ -1112,7 +1120,7 @@
}, this), 0);
}
$(window).bind('resize.gridster', throttle(
$window.bind('resize.gridster', throttle(
$.proxy(this.recalculate_faux_grid, this), 200));
};
@@ -1235,6 +1243,7 @@
}
return $w.fadeIn({complete: function () { if(callback) callback.call(this); }});
};
@@ -1704,10 +1713,11 @@
});
$nexts.not($exclude).each($.proxy(function(i, w) {
var wgd = $(w).coords().grid;
var $w = $( w ),
wgd = $w.coords().grid;
if ( !(wgd.row <= (row + size_y - 1))) { return; }
var diff = (row + size_y) - wgd.row;
this.move_widget_down($(w), diff);
this.move_widget_down($w, diff);
}, this));
this.set_dom_grid_height();
@@ -4185,6 +4195,8 @@
* @return {Object} Returns the instance of the Gridster class.
*/
fn.add_faux_rows = function(rows) {
rows = window.parseInt( rows, 10 );
var actual_rows = this.rows;
var max_rows = actual_rows + (rows || 1);
@@ -4211,6 +4223,8 @@
* @return {Object} Returns the instance of the Gridster class.
*/
fn.add_faux_cols = function(cols) {
cols = window.parseInt( cols, 10 );
var actual_cols = this.cols;
var max_cols = actual_cols + (cols || 1);
max_cols = Math.min(max_cols, this.options.max_cols);
@@ -4240,7 +4254,7 @@
*/
fn.recalculate_faux_grid = function() {
var aw = this.$wrapper.width();
this.baseX = ($(window).width() - aw) / 2;
this.baseX = ($window.width() - aw) / 2;
this.baseY = this.$wrapper.offset().top;
$.each(this.faux_grid, $.proxy(function(i, coords) {
@@ -4371,7 +4385,7 @@
this.rows = Math.max(max_rows, this.options.min_rows);
this.baseX = ($(window).width() - aw) / 2;
this.baseX = ($window.width() - aw) / 2;
this.baseY = this.$wrapper.offset().top;
if (this.options.autogenerate_stylesheet) {
@@ -4392,12 +4406,16 @@
this.$el.removeData('gridster');
// remove bound callback on window resize
$(window).unbind('.gridster');
$window.unbind('.gridster');
if (this.drag_api) {
this.drag_api.destroy();
}
if (this.resize_api) {
this.resize_api.destroy();
}
this.remove_style_tags();
remove && this.$el.remove();
@@ -4409,8 +4427,9 @@
//jQuery adapter
$.fn.gridster = function(options) {
return this.each(function() {
if (! $(this).data('gridster')) {
$(this).data('gridster', new Gridster( this, options ));
var $this = $( this );
if (! $this.data('gridster')) {
$this.data('gridster', new Gridster( this, options ));
}
});
};
File diff suppressed because one or more lines are too long
+14 -12
View File
@@ -169,20 +169,22 @@
var area_coords = self.calculate_overlapped_area_coords(
player_coords, collider_coords);
var area = self.calculate_overlapped_area(area_coords);
var collider_data = {
area: area,
area_coords : area_coords,
region: region,
coords: collider_coords,
player_coords: player_coords,
el: $collider
};
if ( 0 != area ) {
var collider_data = {
area: area,
area_coords : area_coords,
region: region,
coords: collider_coords,
player_coords: player_coords,
el: $collider
};
if (self.options.on_overlap) {
self.options.on_overlap.call(this, collider_data);
if (self.options.on_overlap) {
self.options.on_overlap.call(this, collider_data);
}
colliders_coords.push($collider_coords_ins);
colliders_data.push(collider_data);
}
colliders_coords.push($collider_coords_ins);
colliders_data.push(collider_data);
}
}
+7 -2
View File
@@ -67,8 +67,13 @@
var d = this.data;
typeof d.left === 'undefined' && (d.left = d.x1);
typeof d.top === 'undefined' && (d.top = d.y1);
if ( d.left === undefined ) {
d.left = d.x1;
}
if ( d.top === undefined ) {
d.top = d.y1;
}
this.coords.x1 = d.left;
this.coords.y1 = d.top;
+8 -8
View File
@@ -98,7 +98,7 @@
this.disabled = false;
this.events();
$(window).bind(this.nsEvent('resize'),
$window.bind(this.nsEvent('resize'),
throttle($.proxy(this.calculate_dimensions, this), 200));
};
@@ -156,9 +156,9 @@
var diff_y = Math.round(mouse_actual_pos.top - this.mouse_init_pos.top);
var left = Math.round(this.el_init_offset.left +
diff_x - this.baseX + $(window).scrollLeft() - this.win_offset_x);
diff_x - this.baseX + $window.scrollLeft() - this.win_offset_x);
var top = Math.round(this.el_init_offset.top +
diff_y - this.baseY + $(window).scrollTop() - this.win_offset_y);
diff_y - this.baseY + $window.scrollTop() - this.win_offset_y);
if (this.options.limit) {
if (left > this.player_max_left) {
@@ -176,8 +176,8 @@
pointer: {
left: mouse_actual_pos.left,
top: mouse_actual_pos.top,
diff_left: diff_x + ($(window).scrollLeft() - this.win_offset_x),
diff_top: diff_y + ($(window).scrollTop() - this.win_offset_y)
diff_left: diff_x + ($window.scrollLeft() - this.win_offset_x),
diff_top: diff_y + ($window.scrollTop() - this.win_offset_y)
}
};
};
@@ -325,8 +325,8 @@
this.helper = false;
}
this.win_offset_y = $(window).scrollTop();
this.win_offset_x = $(window).scrollLeft();
this.win_offset_y = $window.scrollTop();
this.win_offset_x = $window.scrollLeft();
this.scroll_offset_y = 0;
this.scroll_offset_x = 0;
this.el_init_offset = this.$player.offset();
@@ -405,7 +405,7 @@
this.$container.off(this.ns);
this.$document.off(this.ns);
$(window).off(this.ns);
$window.off(this.ns);
$.removeData(this.$container, 'drag');
};
+22 -10
View File
@@ -17,7 +17,8 @@
}(this, function($, Draggable, Collision) {
var defaults = {
var $window = $( window ),
defaults = {
namespace: '',
widget_selector: 'li',
widget_margins: [10, 10],
@@ -125,7 +126,7 @@
* `[min_cols_occupied, min_rows_occupied]`
* @param {Function} [options.resize.start] Function executed
* when resizing starts.
* @param {Function} [otions.resize.resize] Function executed
* @param {Function} [options.resize.resize] Function executed
* during the resizing.
* @param {Function} [options.resize.stop] Function executed
* when resizing stops.
@@ -265,7 +266,7 @@
}, this), 0);
}
$(window).bind('resize.gridster', throttle(
$window.bind('resize.gridster', throttle(
$.proxy(this.recalculate_faux_grid, this), 200));
};
@@ -388,6 +389,7 @@
}
return $w.fadeIn({complete: function () { if(callback) callback.call(this); }});
};
@@ -857,10 +859,11 @@
});
$nexts.not($exclude).each($.proxy(function(i, w) {
var wgd = $(w).coords().grid;
var $w = $( w ),
wgd = $w.coords().grid;
if ( !(wgd.row <= (row + size_y - 1))) { return; }
var diff = (row + size_y) - wgd.row;
this.move_widget_down($(w), diff);
this.move_widget_down($w, diff);
}, this));
this.set_dom_grid_height();
@@ -3338,6 +3341,8 @@
* @return {Object} Returns the instance of the Gridster class.
*/
fn.add_faux_rows = function(rows) {
rows = window.parseInt( rows, 10 );
var actual_rows = this.rows;
var max_rows = actual_rows + (rows || 1);
@@ -3364,6 +3369,8 @@
* @return {Object} Returns the instance of the Gridster class.
*/
fn.add_faux_cols = function(cols) {
cols = window.parseInt( cols, 10 );
var actual_cols = this.cols;
var max_cols = actual_cols + (cols || 1);
max_cols = Math.min(max_cols, this.options.max_cols);
@@ -3393,7 +3400,7 @@
*/
fn.recalculate_faux_grid = function() {
var aw = this.$wrapper.width();
this.baseX = ($(window).width() - aw) / 2;
this.baseX = ($window.width() - aw) / 2;
this.baseY = this.$wrapper.offset().top;
$.each(this.faux_grid, $.proxy(function(i, coords) {
@@ -3524,7 +3531,7 @@
this.rows = Math.max(max_rows, this.options.min_rows);
this.baseX = ($(window).width() - aw) / 2;
this.baseX = ($window.width() - aw) / 2;
this.baseY = this.$wrapper.offset().top;
if (this.options.autogenerate_stylesheet) {
@@ -3545,12 +3552,16 @@
this.$el.removeData('gridster');
// remove bound callback on window resize
$(window).unbind('.gridster');
$window.unbind('.gridster');
if (this.drag_api) {
this.drag_api.destroy();
}
if (this.resize_api) {
this.resize_api.destroy();
}
this.remove_style_tags();
remove && this.$el.remove();
@@ -3562,8 +3573,9 @@
//jQuery adapter
$.fn.gridster = function(options) {
return this.each(function() {
if (! $(this).data('gridster')) {
$(this).data('gridster', new Gridster( this, options ));
var $this = $( this );
if (! $this.data('gridster')) {
$this.data('gridster', new Gridster( this, options ));
}
});
};