diff --git a/CHANGELOG.md b/CHANGELOG.md
index e69de29bb..fbb225fef 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -0,0 +1,25 @@
+
+## v0.2.0 (2013-10-26)
+
+
+#### Bug Fixes
+
+* fixes and improvements in widget-resizing. ([ae02b32b](http://github.com/ducksboard/gridster.js/commit/ae02b32b9210c6328f4acc339e215ae50c134f77), closes [#32](http://github.com/ducksboard/gridster.js/issues/32))
+* **gridster:**
+ * the preview holder should not always use `li` ([1ade74e2](http://github.com/ducksboard/gridster.js/commit/1ade74e239485b07e870fca44e1eafb3ff1ae283))
+ * overlapping widget problem ([31fd8d6b](http://github.com/ducksboard/gridster.js/commit/31fd8d6ba893e4c39b91ba30d429e37f3da30b24))
+ * Orphan preview holder when dragging is interrupted ([1b13617d](http://github.com/ducksboard/gridster.js/commit/1b13617df2ce53235bdf3a1e38f1555f529663c3))
+ * remove_widget Returns the instance of the Gridster Class ([5bfbc5c0](http://github.com/ducksboard/gridster.js/commit/5bfbc5c0b5ab49c2a7c651327ce2e0f30f594985))
+
+
+#### Features
+
+* **draggable:**
+ * new config option to move or not the dragged element ([4d9b2a84](http://github.com/ducksboard/gridster.js/commit/4d9b2a84f11cb7cb2ddad51c158d92b82e7bc447))
+ * CSS selectors support in `ignore_dragging` config opt ([0f956249](http://github.com/ducksboard/gridster.js/commit/0f95624925be97aee7a8450707e04e887e4dac58))
+ * pass previous position to the drag callback ([055cc0e4](http://github.com/ducksboard/gridster.js/commit/055cc0e4f6f9de5721986515656ac894855f9e02))
+ * Don't start new drag if previous one hasn't stopped ([91ca6572](http://github.com/ducksboard/gridster.js/commit/91ca65721c2eb32b5dec82cdc5e5e7f81dac329e))
+ * pass useful data to all drag callbacks ([8dda2410](http://github.com/ducksboard/gridster.js/commit/8dda2410f300592706985c05141ca6b702977dc0))
+* **gridster:** drag-and-drop widget resizing ([e1924053](http://github.com/ducksboard/gridster.js/commit/e19240532de0bad35ffe6e5fc63934819390adc5))
+* **utils:** add delay helper to utils ([faa6c5db](http://github.com/ducksboard/gridster.js/commit/faa6c5db0002feccf681e9f919ed583eef152773))
+
diff --git a/dist/jquery.gridster.css b/dist/jquery.gridster.css
index 219f6a83b..4218e1f37 100644
--- a/dist/jquery.gridster.css
+++ b/dist/jquery.gridster.css
@@ -1,4 +1,4 @@
-/*! gridster.js - v0.1.0 - 2013-06-14
+/*! gridster.js - v0.2.0 - 2013-10-26
* http://gridster.net/
* Copyright (c) 2013 ducksboard; Licensed MIT */
@@ -15,19 +15,20 @@
transition: height .4s;
}
-.gridster .gs_w{
+.gridster .gs-w {
z-index: 2;
position: absolute;
}
-.ready .gs_w:not(.preview-holder) {
+.ready .gs-w:not(.preview-holder) {
-webkit-transition: opacity .3s, left .3s, top .3s;
-moz-transition: opacity .3s, left .3s, top .3s;
-o-transition: opacity .3s, left .3s, top .3s;
transition: opacity .3s, left .3s, top .3s;
}
-.ready .gs_w:not(.preview-holder) {
+.ready .gs-w:not(.preview-holder),
+.ready .resize-preview-holder {
-webkit-transition: opacity .3s, left .3s, top .3s, width .3s, height .3s;
-moz-transition: opacity .3s, left .3s, top .3s, width .3s, height .3s;
-o-transition: opacity .3s, left .3s, top .3s, width .3s, height .3s;
@@ -50,7 +51,8 @@
transition: left .3s, top .3s!important;
}
-.gridster .dragging {
+.gridster .dragging,
+.gridster .resizing {
z-index: 10!important;
-webkit-transition: all 0s !important;
-moz-transition: all 0s !important;
@@ -58,7 +60,62 @@
transition: all 0s !important;
}
+
+.gs-resize-handle {
+ position: absolute;
+ z-index: 1;
+}
+
+.gs-resize-handle-both {
+ width: 20px;
+ height: 20px;
+ bottom: -8px;
+ right: -8px;
+ background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pg08IS0tIEdlbmVyYXRvcjogQWRvYmUgRmlyZXdvcmtzIENTNiwgRXhwb3J0IFNWRyBFeHRlbnNpb24gYnkgQWFyb24gQmVhbGwgKGh0dHA6Ly9maXJld29ya3MuYWJlYWxsLmNvbSkgLiBWZXJzaW9uOiAwLjYuMSAgLS0+DTwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DTxzdmcgaWQ9IlVudGl0bGVkLVBhZ2UlMjAxIiB2aWV3Qm94PSIwIDAgNiA2IiBzdHlsZT0iYmFja2dyb3VuZC1jb2xvcjojZmZmZmZmMDAiIHZlcnNpb249IjEuMSINCXhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbDpzcGFjZT0icHJlc2VydmUiDQl4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjZweCIgaGVpZ2h0PSI2cHgiDT4NCTxnIG9wYWNpdHk9IjAuMzAyIj4NCQk8cGF0aCBkPSJNIDYgNiBMIDAgNiBMIDAgNC4yIEwgNCA0LjIgTCA0LjIgNC4yIEwgNC4yIDAgTCA2IDAgTCA2IDYgTCA2IDYgWiIgZmlsbD0iIzAwMDAwMCIvPg0JPC9nPg08L3N2Zz4=');
+ background-position: top left;
+ background-repeat: no-repeat;
+ cursor: se-resize;
+ z-index: 20;
+}
+
+.gs-resize-handle-x {
+ top: 0;
+ bottom: 13px;
+ right: -5px;
+ width: 10px;
+ cursor: e-resize;
+}
+
+.gs-resize-handle-y {
+ left: 0;
+ right: 13px;
+ bottom: -5px;
+ height: 10px;
+ cursor: s-resize;
+}
+
+.gs-w:hover .gs-resize-handle,
+.resizing .gs-resize-handle {
+ opacity: 1;
+}
+
+.gs-resize-handle,
+.gs-w.dragging .gs-resize-handle {
+ opacity: 0;
+}
+
+.gs-resize-disabled .gs-resize-handle {
+ display: none!important;
+}
+
+[data-max-sizex="1"] .gs-resize-handle-x,
+[data-max-sizey="1"] .gs-resize-handle-y,
+[data-max-sizey="1"][data-max-sizex="1"] .gs-resize-handle {
+ display: none !important;
+}
+
/* Uncomment this if you set helper : "clone" in draggable options */
/*.gridster .player {
opacity:0;
-}*/
+}
+*/
\ No newline at end of file
diff --git a/dist/jquery.gridster.js b/dist/jquery.gridster.js
index 95e034869..ca8ef46ca 100644
--- a/dist/jquery.gridster.js
+++ b/dist/jquery.gridster.js
@@ -1,4 +1,4 @@
-/*! gridster.js - v0.1.0 - 2013-06-14
+/*! gridster.js - v0.2.0 - 2013-10-26
* http://gridster.net/
* Copyright (c) 2013 ducksboard; Licensed MIT */
@@ -317,6 +317,14 @@
}(jQuery, window, document));
;(function(window, undefined) {
+
+
+ window.delay = function(func, wait) {
+ var args = Array.prototype.slice.call(arguments, 2);
+ return setTimeout(function(){ return func.apply(null, args); }, wait);
+ };
+
+
/* Debounce and throttle functions taken from underscore.js */
window.debounce = function(func, wait, immediate) {
var timeout;
@@ -358,20 +366,22 @@
})(window);
-;(function($, window, document, undefined){
+;(function($, window, document, undefined) {
var defaults = {
- items: '.gs_w',
+ items: 'li',
distance: 1,
limit: true,
offset_left: 0,
autoscroll: true,
ignore_dragging: ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'],
handle: null,
- container_width: 0 // 0 == auto
- // drag: function(e){},
- // start : function(e, ui){},
- // stop : function(e){}
+ container_width: 0, // 0 == auto
+ move_element: true,
+ helper: false // or 'clone'
+ // drag: function(e) {},
+ // start : function(e, ui) {},
+ // stop : function(e) {}
};
var $window = $(window);
@@ -480,21 +490,36 @@
if (this.options.limit) {
if (left > this.player_max_left) {
left = this.player_max_left;
- }else if(left < this.player_min_left) {
+ } else if(left < this.player_min_left) {
left = this.player_min_left;
}
}
return {
- left: left,
- top: top,
- mouse_left: mouse_actual_pos.left,
- mouse_top: mouse_actual_pos.top
+ position: {
+ left: left,
+ top: top
+ },
+ pointer: {
+ left: mouse_actual_pos.left,
+ top: mouse_actual_pos.top,
+ diff_left: diff_x,
+ diff_top: diff_y + this.scrollOffset
+ }
};
};
- fn.manage_scroll = function(offset) {
+ fn.get_drag_data = function(e) {
+ var offset = this.get_offset(e);
+ offset.$player = this.$player;
+ offset.$helper = this.helper ? this.$helper : this.$player;
+
+ return offset;
+ };
+
+
+ fn.manage_scroll = function(data) {
/* scroll document */
var nextScrollTop;
var scrollTop = $window.scrollTop();
@@ -504,8 +529,8 @@
var mouse_down_zone = max_window_y - 50;
var mouse_up_zone = min_window_y + 50;
- var abs_mouse_left = offset.mouse_left;
- var abs_mouse_top = min_window_y + offset.mouse_top;
+ var abs_mouse_left = data.pointer.left;
+ var abs_mouse_top = min_window_y + data.pointer.top;
var max_player_y = (this.doc_height - this.window_height +
this.player_height);
@@ -551,7 +576,7 @@
this.mouse_init_pos = this.get_mouse_pos(e);
this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top;
- this.$body.on(pointer_events.move, function(mme){
+ this.$body.on(pointer_events.move, function(mme) {
var mouse_actual_pos = self.get_mouse_pos(mme);
var diff_x = Math.abs(
mouse_actual_pos.left - self.mouse_init_pos.left);
@@ -582,8 +607,10 @@
fn.on_dragstart = function(e) {
e.preventDefault();
- this.drag_start = true;
- this.is_dragging = true;
+
+ if (this.is_dragging) { return this; }
+
+ this.drag_start = this.is_dragging = true;
var offset = this.$container.offset();
this.baseX = Math.round(offset.left);
this.baseY = Math.round(offset.top);
@@ -593,9 +620,10 @@
this.$helper = this.$player.clone()
.appendTo(this.$container).addClass('helper');
this.helper = true;
- }else{
+ } else {
this.helper = false;
}
+
this.scrollOffset = 0;
this.el_init_offset = this.$player.offset();
this.player_width = this.$player.width();
@@ -606,52 +634,43 @@
this.options.offset_left);
if (this.options.start) {
- this.options.start.call(this.$player, e, {
- helper: this.helper ? this.$helper : this.$player
- });
+ this.options.start.call(this.$player, e, this.get_drag_data(e));
}
return false;
};
fn.on_dragmove = function(e) {
- var offset = this.get_offset(e);
+ var data = this.get_drag_data(e);
- this.options.autoscroll && this.manage_scroll(offset);
+ this.options.autoscroll && this.manage_scroll(data);
- (this.helper ? this.$helper : this.$player).css({
- 'position': 'absolute',
- 'left' : offset.left,
- 'top' : offset.top
- });
+ if (this.options.move_element) {
+ (this.helper ? this.$helper : this.$player).css({
+ 'position': 'absolute',
+ 'left' : data.position.left,
+ 'top' : data.position.top
+ });
+ }
- var ui = {
- 'position': {
- 'left': offset.left,
- 'top': offset.top
- }
- };
+ var last_position = this.last_position || data.position;
+ data.prev_position = last_position;
if (this.options.drag) {
- this.options.drag.call(this.$player, e, ui);
+ this.options.drag.call(this.$player, e, data);
}
+
+ this.last_position = data.position;
return false;
};
fn.on_dragstop = function(e) {
- var offset = this.get_offset(e);
+ var data = this.get_drag_data(e);
this.drag_start = false;
- var ui = {
- 'position': {
- 'left': offset.left,
- 'top': offset.top
- }
- };
-
if (this.options.stop) {
- this.options.stop.call(this.$player, e, ui);
+ this.options.stop.call(this.$player, e, data);
}
if (this.helper) {
@@ -679,8 +698,7 @@
this.disabled = true;
};
-
- fn.destroy = function(){
+ fn.destroy = function() {
this.disable();
this.$container.off('.gridster-draggable');
@@ -695,16 +713,12 @@
return !$(event.target).is(this.options.handle);
}
- return $.inArray(event.target.nodeName, this.options.ignore_dragging) >= 0;
+ return $(event.target).is(this.options.ignore_dragging.join(', '));
};
//jQuery adapter
$.fn.drag = function ( options ) {
- return this.each(function () {
- if (!$.data(this, 'drag')) {
- $.data(this, 'drag', new Draggable( this, options ));
- }
- });
+ return new Draggable(this, options);
};
@@ -722,7 +736,7 @@
min_cols: 1,
max_cols: null,
min_rows: 15,
- max_size_x: 6,
+ max_size_x: false,
autogenerate_stylesheet: true,
avoid_overlapped_widgets: true,
serialize_params: function($w, wgd) {
@@ -735,7 +749,15 @@
},
collision: {},
draggable: {
+ items: '.gs-w',
distance: 4
+ },
+ resize: {
+ enabled: false,
+ axes: ['x', 'y', 'both'],
+ handle_append_to: '',
+ handle_class: 'gs-resize-handle',
+ max_size: [Infinity, Infinity]
}
};
@@ -784,6 +806,19 @@
* @param {Object} [options.draggable] An Object with all options for
* Draggable class you want to overwrite. See Draggable docs for more
* info.
+ * @param {Object} [options.resize] An Object with resize config
+ * options.
+ * @param {Boolean} [options.resize.enabled] Set to true to enable
+ * resizing.
+ * @param {Array} [options.resize.axes] Axes in which widgets can be
+ * resized. Possible values: ['x', 'y', 'both'].
+ * @param {String} [options.resize.handle_append_to] Set a valid CSS
+ * selector to append resize handles to.
+ * @param {String} [options.resize.handle_class] CSS class name used
+ * by resize handles.
+ * @param {Array} [options.resize.max_size] Limit widget dimensions
+ * when resizing. Array values should be integers:
+ * `[max_cols_occupied, max_rows_occupied]`
*
* @constructor
*/
@@ -791,7 +826,8 @@
this.options = $.extend(true, defaults, options);
this.$el = $(el);
this.$wrapper = this.$el.parent();
- this.$widgets = this.$el.children(this.options.widget_selector).addClass('gs_w');
+ this.$widgets = this.$el.children(
+ this.options.widget_selector).addClass('gs-w');
this.widgets = [];
this.$changed = $([]);
this.wrapper_width = this.$wrapper.width();
@@ -810,13 +846,16 @@
var fn = Gridster.prototype;
fn.init = function() {
+ this.options.resize.enabled && this.setup_resize();
this.generate_grid_and_stylesheet();
this.get_widgets_from_DOM();
this.set_dom_grid_height();
this.$wrapper.addClass('ready');
this.draggable();
+ this.options.resize.enabled && this.resizable();
- $(window).bind('resize.gridster', throttle($.proxy(this.recalculate_faux_grid, this), 200));
+ $(window).bind('resize.gridster', throttle(
+ $.proxy(this.recalculate_faux_grid, this), 200));
};
@@ -845,6 +884,33 @@
};
+
+ /**
+ * Disables drag-and-drop widget resizing.
+ *
+ * @method disable
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.disable_resize = function() {
+ this.$el.addClass('gs-resize-disabled');
+ this.resize_api.disable();
+ return this;
+ };
+
+
+ /**
+ * Enables drag-and-drop widget resizing.
+ *
+ * @method enable
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.enable_resize = function() {
+ this.$el.removeClass('gs-resize-disabled');
+ this.resize_api.enable();
+ return this;
+ };
+
+
/**
* Add a new widget to the grid.
*
@@ -855,10 +921,11 @@
* @param {Number} [size_y] The nÂș of columns the widget occupies vertically.
* @param {Number} [col] The column the widget should start in.
* @param {Number} [row] The row the widget should start in.
+ * @param {Array} [max_size] max_size Maximun size (in units) for width and height.
* @return {HTMLElement} Returns the jQuery wrapped HTMLElement representing.
* the widget that was just created.
*/
- fn.add_widget = function(html, size_x, size_y, col, row) {
+ fn.add_widget = function(html, size_x, size_y, col, row, max_size) {
var pos;
size_x || (size_x = 1);
size_y || (size_y = 1);
@@ -879,7 +946,7 @@
'data-row': pos.row,
'data-sizex' : size_x,
'data-sizey' : size_y
- }).addClass('gs_w').appendTo(this.$el).hide();
+ }).addClass('gs-w').appendTo(this.$el).hide();
this.$widgets = this.$widgets.add($w);
@@ -888,26 +955,73 @@
this.add_faux_rows(pos.size_y);
//this.add_faux_cols(pos.size_x);
+ if (max_size) {
+ this.set_widget_max_size($w, max_size);
+ }
+
this.set_dom_grid_height();
return $w.fadeIn();
};
+ /**
+ * Change widget size limits.
+ *
+ * @method set_widget_max_size
+ * @param {HTMLElement|Number} $widget The jQuery wrapped HTMLElement
+ * representing the widget or an index representing the desired widget.
+ * @param {Array} max_size Maximun size (in units) for width and height.
+ * @return {HTMLElement} Returns instance of gridster Class.
+ */
+ fn.set_widget_max_size = function($widget, max_size) {
+ $widget = typeof $widget === 'number' ?
+ this.$widgets.eq($widget) : $widget;
- /**
- * Change the size of a widget.
+ if (!$widget.length) { return this; }
+
+ var wgd = $widget.data('coords').grid;
+ wgd.max_size_x = max_size[0];
+ wgd.max_size_y = max_size[1];
+
+ return this;
+ };
+
+
+ /**
+ * Append the resize handle into a widget.
+ *
+ * @method add_resize_handle
+ * @param {HTMLElement} $widget The jQuery wrapped HTMLElement
+ * representing the widget.
+ * @return {HTMLElement} Returns instance of gridster Class.
+ */
+ fn.add_resize_handle = function($w) {
+ var append_to = this.options.resize.handle_append_to;
+ $(this.resize_handle_tpl).appendTo( append_to ? $(append_to, $w) : $w);
+
+ return this;
+ };
+
+
+ /**
+ * Change the size of a widget. Width is limited to the current grid width.
*
* @method resize_widget
* @param {HTMLElement} $widget The jQuery wrapped HTMLElement
* representing the widget.
* @param {Number} size_x The number of columns that will occupy the widget.
* @param {Number} size_y The number of rows that will occupy the widget.
- * @param {Function} callback Function executed when the widget is removed.
+ * @param {Boolean} [reposition] Set to false to not move the widget to
+ * the left if there is insufficient space on the right.
+ * By default size_x is limited to the space available from
+ * the column where the widget begins, until the last column to the right.
+ * @param {Function} [callback] Function executed when the widget is removed.
* @return {HTMLElement} Returns $widget.
*/
- fn.resize_widget = function($widget, size_x, size_y, callback) {
+ fn.resize_widget = function($widget, size_x, size_y, reposition, callback) {
var wgd = $widget.coords().grid;
+ reposition !== false && (reposition = true);
size_x || (size_x = wgd.size_x);
size_y || (size_y = wgd.size_y);
@@ -915,20 +1029,20 @@
size_x = this.cols;
}
- var old_cells_occupied = this.get_cells_occupied(wgd);
- var old_size_x = wgd.size_x;
var old_size_y = wgd.size_y;
var old_col = wgd.col;
var new_col = old_col;
- var wider = size_x > old_size_x;
- var taller = size_y > old_size_y;
- if (old_col + size_x - 1 > this.cols) {
+ if (reposition && old_col + size_x - 1 > this.cols) {
var diff = old_col + (size_x - 1) - this.cols;
var c = old_col - diff;
new_col = Math.max(1, c);
}
+ if (size_y > old_size_y) {
+ this.add_faux_rows(Math.max(size_y - old_size_y, 0));
+ }
+
var new_grid_data = {
col: new_col,
row: wgd.row,
@@ -936,7 +1050,34 @@
size_y: size_y
};
- var new_cells_occupied = this.get_cells_occupied(new_grid_data);
+ this.mutate_widget_in_gridmap($widget, wgd, new_grid_data);
+
+ this.set_dom_grid_height();
+
+ if (callback) {
+ callback.call(this, new_grid_data.size_x, new_grid_data.size_y);
+ }
+
+ return $widget;
+ };
+
+
+ /**
+ * Mutate widget dimensions and position in the grid map.
+ *
+ * @method mutate_widget_in_gridmap
+ * @param {HTMLElement} $widget The jQuery wrapped HTMLElement
+ * representing the widget to mutate.
+ * @param {Object} wgd Current widget grid data (col, row, size_x, size_y).
+ * @param {Object} new_wgd New widget grid data.
+ * @return {HTMLElement} Returns instance of gridster Class.
+ */
+ fn.mutate_widget_in_gridmap = function($widget, wgd, new_wgd) {
+ var old_size_x = wgd.size_x;
+ var old_size_y = wgd.size_y;
+
+ var old_cells_occupied = this.get_cells_occupied(wgd);
+ var new_cells_occupied = this.get_cells_occupied(new_wgd);
var empty_cols = [];
$.each(old_cells_occupied.cols, function(i, col) {
@@ -970,48 +1111,46 @@
if (occupied_cols.length) {
var cols_to_empty = [
- new_col, wgd.row, size_x, Math.min(old_size_y, size_y), $widget
+ new_wgd.col, new_wgd.row, new_wgd.size_x, Math.min(old_size_y, new_wgd.size_y), $widget
];
this.empty_cells.apply(this, cols_to_empty);
}
if (occupied_rows.length) {
- var rows_to_empty = [new_col, wgd.row, size_x, size_y, $widget];
+ var rows_to_empty = [new_wgd.col, new_wgd.row, new_wgd.size_x, new_wgd.size_y, $widget];
this.empty_cells.apply(this, rows_to_empty);
}
- wgd.col = new_col;
- wgd.size_x = size_x;
- wgd.size_y = size_y;
- this.add_to_gridmap(new_grid_data, $widget);
+ // not the same that wgd = new_wgd;
+ wgd.col = new_wgd.col;
+ wgd.row = new_wgd.row;
+ wgd.size_x = new_wgd.size_x;
+ wgd.size_y = new_wgd.size_y;
+
+ this.add_to_gridmap(new_wgd, $widget);
+
+ $widget.removeClass('player-revert');
//update coords instance attributes
$widget.data('coords').update({
- width: (size_x * this.options.widget_base_dimensions[0] +
- ((size_x - 1) * this.options.widget_margins[0]) * 2),
- height: (size_y * this.options.widget_base_dimensions[1] +
- ((size_y - 1) * this.options.widget_margins[1]) * 2)
+ width: (new_wgd.size_x * this.options.widget_base_dimensions[0] +
+ ((new_wgd.size_x - 1) * this.options.widget_margins[0]) * 2),
+ height: (new_wgd.size_y * this.options.widget_base_dimensions[1] +
+ ((new_wgd.size_y - 1) * this.options.widget_margins[1]) * 2)
});
- if (size_y > old_size_y) {
- this.add_faux_rows(size_y - old_size_y);
- }
-
- if (size_x > old_size_x) {
- this.add_faux_cols(size_x - old_size_x);
- }
-
$widget.attr({
- 'data-col': new_col,
- 'data-sizex': size_x,
- 'data-sizey': size_y
+ 'data-col': new_wgd.col,
+ 'data-row': new_wgd.row,
+ 'data-sizex': new_wgd.size_x,
+ 'data-sizey': new_wgd.size_y
});
if (empty_cols.length) {
var cols_to_remove_holes = [
- empty_cols[0], wgd.row,
+ empty_cols[0], new_wgd.row,
empty_cols.length,
- Math.min(old_size_y, size_y),
+ Math.min(old_size_y, new_wgd.size_y),
$widget
];
@@ -1020,18 +1159,17 @@
if (empty_rows.length) {
var rows_to_remove_holes = [
- new_col, wgd.row, size_x, size_y, $widget
+ new_wgd.col, new_wgd.row, new_wgd.size_x, new_wgd.size_y, $widget
];
this.remove_empty_cells.apply(this, rows_to_remove_holes);
}
- if (callback) {
- callback.call(this, size_x, size_y);
- }
+ this.move_widget_up($widget);
- return $widget;
+ return this;
};
+
/**
* Move down widgets in cells represented by the arguments col, row, size_x,
* size_y
@@ -1184,6 +1322,8 @@
callback.call(this, el);
}
}, this));
+
+ return this;
};
@@ -1246,12 +1386,13 @@
* @return {Array} Returns the instance of the Gridster class.
*/
fn.register_widget = function($el) {
-
var wgd = {
'col': parseInt($el.attr('data-col'), 10),
'row': parseInt($el.attr('data-row'), 10),
'size_x': parseInt($el.attr('data-sizex'), 10),
'size_y': parseInt($el.attr('data-sizey'), 10),
+ 'max_size_x': parseInt($el.attr('data-max-sizex'), 10) || false,
+ 'max_size_y': parseInt($el.attr('data-max-sizey'), 10) || false,
'el': $el
};
@@ -1259,8 +1400,7 @@
!this.can_move_to(
{size_x: wgd.size_x, size_y: wgd.size_y}, wgd.col, wgd.row)
) {
- wgd = this.next_position(wgd.size_x, wgd.size_y);
- wgd.el = $el;
+ $.extend(wgd, this.next_position(wgd.size_x, wgd.size_y));
$el.attr({
'data-col': wgd.col,
'data-row': wgd.row,
@@ -1271,12 +1411,13 @@
// attach Coord object to player data-coord attribute
$el.data('coords', $el.coords());
-
// Extend Coord object with grid position info
$el.data('coords').grid = wgd;
this.add_to_gridmap(wgd, $el);
+ this.options.resize.enabled && this.add_resize_handle($el);
+
return this;
};
@@ -1349,13 +1490,15 @@
var draggable_options = $.extend(true, {}, this.options.draggable, {
offset_left: this.options.widget_margins[0],
container_width: this.container_width,
+ ignore_dragging: ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON',
+ '.' + this.options.resize.handle_class],
start: function(event, ui) {
self.$widgets.filter('.player-revert')
.removeClass('player-revert');
self.$player = $(this);
- self.$helper = self.options.draggable.helper === 'clone' ?
- $(ui.helper) : self.$player;
+ self.$helper = $(ui.$helper);
+
self.helper = !self.$helper.is(self.$player);
self.on_start_drag.call(self, event, ui);
@@ -1371,7 +1514,51 @@
}, 60)
});
- this.drag_api = this.$el.drag(draggable_options).data('drag');
+ this.drag_api = this.$el.drag(draggable_options);
+ return this;
+ };
+
+
+ /**
+ * Bind resize events to get resize working.
+ *
+ * @method resizable
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.resizable = function() {
+ this.resize_api = this.$el.drag({
+ items: '.' + this.options.resize.handle_class,
+ offset_left: this.options.widget_margins[0],
+ container_width: this.container_width,
+ move_element: false,
+ start: $.proxy(this.on_start_resize, this),
+ stop: $.proxy(function(event, ui) {
+ delay($.proxy(function() {
+ this.on_stop_resize(event, ui);
+ }, this), 120);
+ }, this),
+ drag: throttle($.proxy(this.on_resize, this), 60)
+ });
+
+ return this;
+ };
+
+
+ /**
+ * Setup things required for resizing. Like build templates for drag handles.
+ *
+ * @method setup_resize
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.setup_resize = function() {
+ this.resize_handle_class = this.options.resize.handle_class;
+ var axes = this.options.resize.axes;
+ var handle_tpl = '';
+
+ this.resize_handle_tpl = $.map(axes, function(type) {
+ return handle_tpl.replace('{type}', type);
+ }).join('');
return this;
};
@@ -1381,10 +1568,9 @@
*
* @method on_start_drag
* @param {Event} event The original browser event
- * @param {Object} ui A prepared ui object.
+ * @param {Object} ui A prepared ui object with useful drag-related data
*/
fn.on_start_drag = function(event, ui) {
-
this.$helper.add(this.$player).add(this.$wrapper).addClass('dragging');
this.$player.addClass('player');
@@ -1406,12 +1592,11 @@
this.last_cols = [];
this.last_rows = [];
-
// see jquery.collision.js
this.collision_api = this.$helper.collision(
colliders, this.options.collision);
- this.$preview_holder = $('
', {
+ this.$preview_holder = $('<' + this.$player.get(0).tagName + ' />', {
'class': 'preview-holder',
'data-row': this.$player.attr('data-row'),
'data-col': this.$player.attr('data-col'),
@@ -1432,7 +1617,7 @@
*
* @method on_drag
* @param {Event} event The original browser event
- * @param {Object} ui A prepared ui object.
+ * @param {Object} ui A prepared ui object with useful drag-related data
*/
fn.on_drag = function(event, ui) {
//break if dragstop has been fired
@@ -1475,7 +1660,7 @@
*
* @method on_stop_drag
* @param {Event} event The original browser event
- * @param {Object} ui A prepared ui object.
+ * @param {Object} ui A prepared ui object with useful drag-related data
*/
fn.on_stop_drag = function(event, ui) {
this.$helper.add(this.$player).add(this.$wrapper)
@@ -1483,7 +1668,8 @@
ui.position.left = ui.position.left + this.baseX;
ui.position.top = ui.position.top + this.baseY;
- this.colliders_data = this.collision_api.get_closest_colliders(ui.position);
+ this.colliders_data = this.collision_api.get_closest_colliders(
+ ui.position);
this.on_overlapped_column_change(
this.on_start_overlapping_column,
@@ -1531,6 +1717,148 @@
};
+
+ /**
+ * This function is executed every time a widget starts to be resized.
+ *
+ * @method on_start_resize
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_start_resize = function(event, ui) {
+ this.$resized_widget = ui.$player.closest('.gs-w');
+ this.resize_coords = this.$resized_widget.coords();
+ this.resize_wgd = this.resize_coords.grid;
+ this.resize_initial_width = this.resize_coords.coords.width;
+ this.resize_initial_height = this.resize_coords.coords.height;
+ this.resize_initial_sizex = this.resize_coords.grid.size_x;
+ this.resize_initial_sizey = this.resize_coords.grid.size_y;
+ this.resize_last_sizex = this.resize_initial_sizex;
+ this.resize_last_sizey = this.resize_initial_sizey;
+ this.resize_max_size_x = Math.min(this.resize_wgd.max_size_x ||
+ this.options.resize.max_size[0], this.cols - this.resize_wgd.col + 1);
+ this.resize_max_size_y = this.resize_wgd.max_size_y ||
+ this.options.resize.max_size[1];
+
+ this.resize_dir = {
+ right: ui.$player.is('.' + this.resize_handle_class + '-x'),
+ bottom: ui.$player.is('.' + this.resize_handle_class + '-y')
+ };
+
+ this.$resized_widget.css({
+ 'min-width': this.options.widget_base_dimensions[0],
+ 'min-height': this.options.widget_base_dimensions[1]
+ });
+
+ var nodeName = this.$resized_widget.get(0).tagName;
+ this.$resize_preview_holder = $('<' + nodeName + ' />', {
+ 'class': 'preview-holder resize-preview-holder',
+ 'data-row': this.$resized_widget.attr('data-row'),
+ 'data-col': this.$resized_widget.attr('data-col'),
+ 'css': {
+ 'width': this.resize_initial_width,
+ 'height': this.resize_initial_height
+ }
+ }).appendTo(this.$el);
+
+ this.$resized_widget.addClass('resizing');
+ };
+
+
+ /**
+ * This function is executed every time a widget stops being resized.
+ *
+ * @method on_stop_resize
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_stop_resize = function(event, ui) {
+ this.$resized_widget
+ .removeClass('resizing')
+ .css({
+ 'width': '',
+ 'height': ''
+ });
+
+ delay($.proxy(function() {
+ this.$resize_preview_holder
+ .remove()
+ .css({
+ 'min-width': '',
+ 'min-height': ''
+ });
+ }, this), 300);
+ };
+
+ /**
+ * This function is executed when a widget is being resized.
+ *
+ * @method on_resize
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_resize = function(event, ui) {
+ var rel_x = (ui.pointer.diff_left);
+ var rel_y = (ui.pointer.diff_top);
+ var wbd_x = this.options.widget_base_dimensions[0];
+ var wbd_y = this.options.widget_base_dimensions[1];
+ var max_width = Infinity;
+ var max_height = Infinity;
+
+ var inc_units_x = Math.ceil((rel_x /
+ (this.options.widget_base_dimensions[0] +
+ this.options.widget_margins[0] * 2)) - 0.2);
+
+ var inc_units_y = Math.ceil((rel_y /
+ (this.options.widget_base_dimensions[1] +
+ this.options.widget_margins[1] * 2)) - 0.2);
+
+ var size_x = Math.max(1, this.resize_initial_sizex + inc_units_x);
+ var size_y = Math.max(1, this.resize_initial_sizey + inc_units_y);
+
+ size_x = Math.min(size_x, this.resize_max_size_x);
+ max_width = (this.resize_max_size_x * wbd_x) +
+ ((size_x - 1) * this.options.widget_margins[0] * 2);
+
+ size_y = Math.min(size_y, this.resize_max_size_y);
+ max_height = (this.resize_max_size_y * wbd_y) +
+ ((size_y - 1) * this.options.widget_margins[1] * 2);
+
+
+ if (this.resize_dir.right) {
+ size_y = this.resize_initial_sizey;
+ } else if (this.resize_dir.bottom) {
+ size_x = this.resize_initial_sizex;
+ }
+
+ var css_props = {};
+ !this.resize_dir.bottom && (css_props.width = Math.min(
+ this.resize_initial_width + rel_x, max_width));
+ !this.resize_dir.right && (css_props.height = Math.min(
+ this.resize_initial_height + rel_y, max_height));
+
+ this.$resized_widget.css(css_props);
+
+ if (size_x !== this.resize_last_sizex ||
+ size_y !== this.resize_last_sizey) {
+
+ this.resize_widget(this.$resized_widget, size_x, size_y, false);
+
+ this.$resize_preview_holder.css({
+ 'width': '',
+ 'height': ''
+ }).attr({
+ 'data-row': this.$resized_widget.attr('data-row'),
+ 'data-sizex': size_x,
+ 'data-sizey': size_y
+ });
+ }
+
+ this.resize_last_sizex = size_x;
+ this.resize_last_sizey = size_y;
+ };
+
+
/**
* Executes the callbacks passed as arguments when a column begins to be
* overlapped or stops being overlapped.
@@ -2036,8 +2364,9 @@
}, this));
}
+ var $widgets_under_ph = this.get_widgets_under_player(
+ this.cells_occupied_by_placeholder);
- var $widgets_under_ph = this.get_widgets_under_player(this.cells_occupied_by_placeholder);
if ($widgets_under_ph.length) {
$widgets_under_ph.each($.proxy(function(i, widget) {
var $w = $(widget);
@@ -2429,10 +2758,14 @@
* @return {Class} Returns the instance of the Gridster Class.
*/
fn.move_widget_down = function($widget, y_units) {
- var el_grid_data = $widget.coords().grid;
- var actual_row = el_grid_data.row;
- var moved = [];
- var y_diff = y_units;
+ var el_grid_data, actual_row, moved, y_diff;
+
+ if (y_units <= 0) { return false; }
+
+ el_grid_data = $widget.coords().grid;
+ actual_row = el_grid_data.row;
+ moved = [];
+ y_diff = y_units;
if (!$widget) { return false; }
@@ -2971,7 +3304,7 @@
*/
fn.generate_stylesheet = function(opts) {
var styles = '';
- var max_size_x = this.options.max_size_x;
+ var max_size_x = this.options.max_size_x || this.cols;
var max_rows = 0;
var max_cols = 0;
var i;
@@ -3003,7 +3336,7 @@
styles += (opts.namespace + ' [data-col="'+ (i + 1) + '"] { left:' +
((i * opts.widget_base_dimensions[0]) +
(i * opts.widget_margins[0]) +
- ((i + 1) * opts.widget_margins[0])) + 'px;} ');
+ ((i + 1) * opts.widget_margins[0])) + 'px; }\n');
}
/* generate CSS styles for rows */
@@ -3011,19 +3344,19 @@
styles += (opts.namespace + ' [data-row="' + (i + 1) + '"] { top:' +
((i * opts.widget_base_dimensions[1]) +
(i * opts.widget_margins[1]) +
- ((i + 1) * opts.widget_margins[1]) ) + 'px;} ');
+ ((i + 1) * opts.widget_margins[1]) ) + 'px; }\n');
}
for (var y = 1; y <= opts.rows; y++) {
styles += (opts.namespace + ' [data-sizey="' + y + '"] { height:' +
(y * opts.widget_base_dimensions[1] +
- (y - 1) * (opts.widget_margins[1] * 2)) + 'px;}');
+ (y - 1) * (opts.widget_margins[1] * 2)) + 'px; }\n');
}
for (var x = 1; x <= max_size_x; x++) {
styles += (opts.namespace + ' [data-sizex="' + x + '"] { width:' +
(x * opts.widget_base_dimensions[0] +
- (x - 1) * (opts.widget_margins[0] * 2)) + 'px;}');
+ (x - 1) * (opts.widget_margins[0] * 2)) + 'px; }\n');
}
return this.add_style_tag(styles);
diff --git a/dist/jquery.gridster.min.css b/dist/jquery.gridster.min.css
index b1e3cdfce..b28c6c791 100644
--- a/dist/jquery.gridster.min.css
+++ b/dist/jquery.gridster.min.css
@@ -1,2 +1,2 @@
-/*! gridster.js - v0.1.0 - 2013-06-14 - * http://gridster.net/ - Copyright (c) 2013 ducksboard; Licensed MIT */
-.gridster{position:relative}.gridster>*{margin:0 auto;-webkit-transition:height .4s;-moz-transition:height .4s;-o-transition:height .4s;-ms-transition:height .4s;transition:height .4s}.gridster .gs_w{z-index:2;position:absolute}.ready .gs_w:not(.preview-holder){-webkit-transition:opacity .3s,left .3s,top .3s;-moz-transition:opacity .3s,left .3s,top .3s;-o-transition:opacity .3s,left .3s,top .3s;transition:opacity .3s,left .3s,top .3s}.ready .gs_w:not(.preview-holder){-webkit-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;-moz-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;-o-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;transition:opacity .3s,left .3s,top .3s,width .3s,height .3s}.gridster .preview-holder{z-index:1;position:absolute;background-color:#fff;border-color:#fff;opacity:.3}.gridster .player-revert{z-index:10!important;-webkit-transition:left .3s,top .3s!important;-moz-transition:left .3s,top .3s!important;-o-transition:left .3s,top .3s!important;transition:left .3s,top .3s!important}.gridster .dragging{z-index:10!important;-webkit-transition:all 0s!important;-moz-transition:all 0s!important;-o-transition:all 0s!important;transition:all 0s!important}
\ No newline at end of file
+/*! gridster.js - v0.2.0 - 2013-10-26 - * http://gridster.net/ - Copyright (c) 2013 ducksboard; Licensed MIT */
+.gridster{position:relative}.gridster>*{margin:0 auto;-webkit-transition:height .4s;-moz-transition:height .4s;-o-transition:height .4s;-ms-transition:height .4s;transition:height .4s}.gridster .gs-w{z-index:2;position:absolute}.ready .gs-w:not(.preview-holder){-webkit-transition:opacity .3s,left .3s,top .3s;-moz-transition:opacity .3s,left .3s,top .3s;-o-transition:opacity .3s,left .3s,top .3s;transition:opacity .3s,left .3s,top .3s}.ready .gs-w:not(.preview-holder),.ready .resize-preview-holder{-webkit-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;-moz-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;-o-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;transition:opacity .3s,left .3s,top .3s,width .3s,height .3s}.gridster .preview-holder{z-index:1;position:absolute;background-color:#fff;border-color:#fff;opacity:.3}.gridster .player-revert{z-index:10!important;-webkit-transition:left .3s,top .3s!important;-moz-transition:left .3s,top .3s!important;-o-transition:left .3s,top .3s!important;transition:left .3s,top .3s!important}.gridster .dragging,.gridster .resizing{z-index:10!important;-webkit-transition:all 0s!important;-moz-transition:all 0s!important;-o-transition:all 0s!important;transition:all 0s!important}.gs-resize-handle{position:absolute;z-index:1}.gs-resize-handle-both{width:20px;height:20px;bottom:-8px;right:-8px;background-image:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pg08IS0tIEdlbmVyYXRvcjogQWRvYmUgRmlyZXdvcmtzIENTNiwgRXhwb3J0IFNWRyBFeHRlbnNpb24gYnkgQWFyb24gQmVhbGwgKGh0dHA6Ly9maXJld29ya3MuYWJlYWxsLmNvbSkgLiBWZXJzaW9uOiAwLjYuMSAgLS0+DTwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DTxzdmcgaWQ9IlVudGl0bGVkLVBhZ2UlMjAxIiB2aWV3Qm94PSIwIDAgNiA2IiBzdHlsZT0iYmFja2dyb3VuZC1jb2xvcjojZmZmZmZmMDAiIHZlcnNpb249IjEuMSINCXhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbDpzcGFjZT0icHJlc2VydmUiDQl4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjZweCIgaGVpZ2h0PSI2cHgiDT4NCTxnIG9wYWNpdHk9IjAuMzAyIj4NCQk8cGF0aCBkPSJNIDYgNiBMIDAgNiBMIDAgNC4yIEwgNCA0LjIgTCA0LjIgNC4yIEwgNC4yIDAgTCA2IDAgTCA2IDYgTCA2IDYgWiIgZmlsbD0iIzAwMDAwMCIvPg0JPC9nPg08L3N2Zz4=);background-position:top left;background-repeat:no-repeat;cursor:se-resize;z-index:20}.gs-resize-handle-x{top:0;bottom:13px;right:-5px;width:10px;cursor:e-resize}.gs-resize-handle-y{left:0;right:13px;bottom:-5px;height:10px;cursor:s-resize}.gs-w:hover .gs-resize-handle,.resizing .gs-resize-handle{opacity:1}.gs-resize-handle,.gs-w.dragging .gs-resize-handle{opacity:0}.gs-resize-disabled .gs-resize-handle{display:none!important}[data-max-sizex="1"] .gs-resize-handle-x,[data-max-sizey="1"] .gs-resize-handle-y,[data-max-sizey="1"][data-max-sizex="1"] .gs-resize-handle{display:none!important}
\ No newline at end of file
diff --git a/dist/jquery.gridster.min.js b/dist/jquery.gridster.min.js
index 4b1733c92..8ce71112a 100644
--- a/dist/jquery.gridster.min.js
+++ b/dist/jquery.gridster.min.js
@@ -1,2 +1,2 @@
-/*! gridster.js - v0.1.0 - 2013-06-14 - * http://gridster.net/ - Copyright (c) 2013 ducksboard; Licensed MIT */ (function(t){function i(i){return i[0]&&t.isPlainObject(i[0])?this.data=i[0]:this.el=i,this.isCoords=!0,this.coords={},this.init(),this}var e=i.prototype;e.init=function(){this.set(),this.original_coords=this.get()},e.set=function(t,i){var e=this.el;if(e&&!t&&(this.data=e.offset(),this.data.width=e.width(),this.data.height=e.height()),e&&t&&!i){var s=e.offset();this.data.top=s.top,this.data.left=s.left}var r=this.data;return this.coords.x1=r.left,this.coords.y1=r.top,this.coords.x2=r.left+r.width,this.coords.y2=r.top+r.height,this.coords.cx=r.left+r.width/2,this.coords.cy=r.top+r.height/2,this.coords.width=r.width,this.coords.height=r.height,this.coords.el=e||!1,this},e.update=function(i){if(!i&&!this.el)return this;if(i){var e=t.extend({},this.data,i);return this.data=e,this.set(!0,!0)}return this.set(!0),this},e.get=function(){return this.coords},t.fn.coords=function(){if(this.data("coords"))return this.data("coords");var t=new i(this,arguments[0]);return this.data("coords",t),t}})(jQuery,window,document),function(t,i,e){function s(i,e,s){this.options=t.extend(r,s),this.$element=i,this.last_colliders=[],this.last_colliders_coords=[],"string"==typeof e||e instanceof jQuery?this.$colliders=t(e,this.options.colliders_context).not(this.$element):this.colliders=t(e),this.init()}var r={colliders_context:e.body},o=s.prototype;o.init=function(){this.find_collisions()},o.overlaps=function(t,i){var e=!1,s=!1;return(i.x1>=t.x1&&i.x1<=t.x2||i.x2>=t.x1&&i.x2<=t.x2||t.x1>=i.x1&&t.x2<=i.x2)&&(e=!0),(i.y1>=t.y1&&i.y1<=t.y2||i.y2>=t.y1&&i.y2<=t.y2||t.y1>=i.y1&&t.y2<=i.y2)&&(s=!0),e&&s},o.detect_overlapping_region=function(t,i){var e="",s="";return t.y1>i.cy&&t.y1i.y1&&t.y2i.cx&&t.x1i.x1&&t.x2o;o++)-1===t.inArray(r[o],i)&&e.call(this,r[o]);for(var n=0,h=i.length;h>n;n++)-1===t.inArray(i[n],r)&&s.call(this,i[n])},o.find_collisions=function(i){for(var e=this,s=[],r=[],o=this.colliders||this.$colliders,a=o.length,n=e.$element.coords().update(i||!1).get();a--;){var h=e.$colliders?t(o[a]):o[a],_=h.isCoords?h:h.coords(),d=_.get(),l=e.overlaps(n,d);if(l){var c=e.detect_overlapping_region(n,d);if("C"===c){var p=e.calculate_overlapped_area_coords(n,d),g=e.calculate_overlapped_area(p),u={area:g,area_coords:p,region:c,coords:d,player_coords:n,el:h};e.options.on_overlap&&e.options.on_overlap.call(this,u),s.push(_),r.push(u)}}}return(e.options.on_overlap_stop||e.options.on_overlap_start)&&this.manage_colliders_start_stop(s,e.options.on_overlap_start,e.options.on_overlap_stop),this.last_colliders_coords=s,r},o.get_closest_colliders=function(t){var i=this.find_collisions(t);return i.sort(function(t,i){return"C"===t.region&&"C"===i.region?t.coords.y1this.player_max_left?r=this.player_max_left:this.player_min_left>r&&(r=this.player_min_left)),{left:r,top:o,mouse_left:i.left,mouse_top:i.top}},h.manage_scroll=function(t){var i,e=o.scrollTop(),s=e,r=s+this.window_height,a=r-50,n=s+50;t.mouse_left;var h=s+t.mouse_top,_=this.doc_height-this.window_height+this.player_height;h>=a&&(i=e+30,_>i&&(o.scrollTop(i),this.scrollOffset=this.scrollOffset+30)),n>=h&&(i=e-30,i>0&&(o.scrollTop(i),this.scrollOffset=this.scrollOffset-30))},h.calculate_positions=function(){this.window_height=o.height()},h.drag_handler=function(i){if(i.target.nodeName,!this.disabled&&(1===i.which||a)&&!this.ignore_drag(i)){var e=this,s=!0;return this.$player=t(i.currentTarget),this.el_init_pos=this.get_actual_pos(this.$player),this.mouse_init_pos=this.get_mouse_pos(i),this.offsetY=this.mouse_init_pos.top-this.el_init_pos.top,this.$body.on(n.move,function(t){var i=e.get_mouse_pos(t),r=Math.abs(i.left-e.mouse_init_pos.left),o=Math.abs(i.top-e.mouse_init_pos.top);return r>e.options.distance||o>e.options.distance?s?(s=!1,e.on_dragstart.call(e,t),!1):(e.is_dragging===!0&&e.on_dragmove.call(e,t),!1):!1}),a?undefined:!1}},h.on_dragstart=function(i){i.preventDefault(),this.drag_start=!0,this.is_dragging=!0;var s=this.$container.offset();this.baseX=Math.round(s.left),this.baseY=Math.round(s.top),this.doc_height=t(e).height(),"clone"===this.options.helper?(this.$helper=this.$player.clone().appendTo(this.$container).addClass("helper"),this.helper=!0):this.helper=!1,this.scrollOffset=0,this.el_init_offset=this.$player.offset(),this.player_width=this.$player.width(),this.player_height=this.$player.height();var r=this.options.container_width||this.$container.width();return this.player_max_left=r-this.player_width+this.options.offset_left,this.options.start&&this.options.start.call(this.$player,i,{helper:this.helper?this.$helper:this.$player}),!1},h.on_dragmove=function(t){var i=this.get_offset(t);this.options.autoscroll&&this.manage_scroll(i),(this.helper?this.$helper:this.$player).css({position:"absolute",left:i.left,top:i.top});var e={position:{left:i.left,top:i.top}};return this.options.drag&&this.options.drag.call(this.$player,t,e),!1},h.on_dragstop=function(t){var i=this.get_offset(t);this.drag_start=!1;var e={position:{left:i.left,top:i.top}};return this.options.stop&&this.options.stop.call(this.$player,t,e),this.helper&&this.$helper.remove(),!1},h.on_select_start=function(t){return this.disabled||this.ignore_drag(t)?undefined:!1},h.enable=function(){this.disabled=!1},h.disable=function(){this.disabled=!0},h.destroy=function(){this.disable(),this.$container.off(".gridster-draggable"),this.$body.off(".gridster-draggable"),t(i).off(".gridster-draggable"),t.removeData(this.$container,"drag")},h.ignore_drag=function(i){return this.options.handle?!t(i.target).is(this.options.handle):t.inArray(i.target.nodeName,this.options.ignore_dragging)>=0},t.fn.drag=function(i){return this.each(function(){t.data(this,"drag")||t.data(this,"drag",new s(this,i))})}}(jQuery,window,document),function(t,i,e){function s(i,e){this.options=t.extend(!0,r,e),this.$el=t(i),this.$wrapper=this.$el.parent(),this.$widgets=this.$el.children(this.options.widget_selector).addClass("gs_w"),this.widgets=[],this.$changed=t([]),this.wrapper_width=this.$wrapper.width(),this.min_widget_width=2*this.options.widget_margins[0]+this.options.widget_base_dimensions[0],this.min_widget_height=2*this.options.widget_margins[1]+this.options.widget_base_dimensions[1],this.$style_tags=t([]),this.init()}var r={namespace:"",widget_selector:"li",widget_margins:[10,10],widget_base_dimensions:[400,225],extra_rows:0,extra_cols:0,min_cols:1,max_cols:null,min_rows:15,max_size_x:6,autogenerate_stylesheet:!0,avoid_overlapped_widgets:!0,serialize_params:function(t,i){return{col:i.col,row:i.row,size_x:i.size_x,size_y:i.size_y}},collision:{},draggable:{distance:4}};s.generated_stylesheets=[];var o=s.prototype;o.init=function(){this.generate_grid_and_stylesheet(),this.get_widgets_from_DOM(),this.set_dom_grid_height(),this.$wrapper.addClass("ready"),this.draggable(),t(i).bind("resize.gridster",throttle(t.proxy(this.recalculate_faux_grid,this),200))},o.disable=function(){return this.$wrapper.find(".player-revert").removeClass("player-revert"),this.drag_api.disable(),this},o.enable=function(){return this.drag_api.enable(),this},o.add_widget=function(i,e,s,r,o){var a;e||(e=1),s||(s=1),!r&!o?a=this.next_position(e,s):(a={col:r,row:o},this.empty_cells(r,o,e,s));var n=t(i).attr({"data-col":a.col,"data-row":a.row,"data-sizex":e,"data-sizey":s}).addClass("gs_w").appendTo(this.$el).hide();return this.$widgets=this.$widgets.add(n),this.register_widget(n),this.add_faux_rows(a.size_y),this.set_dom_grid_height(),n.fadeIn()},o.resize_widget=function(i,e,s,r){var o=i.coords().grid;e||(e=o.size_x),s||(s=o.size_y),e>this.cols&&(e=this.cols);var a=this.get_cells_occupied(o),n=o.size_x,h=o.size_y,_=o.col,d=_;if(_+e-1>this.cols){var l=_+(e-1)-this.cols,c=_-l;d=Math.max(1,c)}var p={col:d,row:o.row,size_x:e,size_y:s},g=this.get_cells_occupied(p),u=[];t.each(a.cols,function(i,e){-1===t.inArray(e,g.cols)&&u.push(e)});var f=[];t.each(g.cols,function(i,e){-1===t.inArray(e,a.cols)&&f.push(e)});var w=[];t.each(a.rows,function(i,e){-1===t.inArray(e,g.rows)&&w.push(e)});var y=[];if(t.each(g.rows,function(i,e){-1===t.inArray(e,a.rows)&&y.push(e)}),this.remove_from_gridmap(o),f.length){var m=[d,o.row,e,Math.min(h,s),i];this.empty_cells.apply(this,m)}if(y.length){var v=[d,o.row,e,s,i];this.empty_cells.apply(this,v)}if(o.col=d,o.size_x=e,o.size_y=s,this.add_to_gridmap(p,i),i.data("coords").update({width:e*this.options.widget_base_dimensions[0]+2*(e-1)*this.options.widget_margins[0],height:s*this.options.widget_base_dimensions[1]+2*(s-1)*this.options.widget_margins[1]}),s>h&&this.add_faux_rows(s-h),e>n&&this.add_faux_cols(e-n),i.attr({"data-col":d,"data-sizex":e,"data-sizey":s}),u.length){var x=[u[0],o.row,u.length,Math.min(h,s),i];this.remove_empty_cells.apply(this,x)}if(w.length){var b=[d,o.row,e,s,i];this.remove_empty_cells.apply(this,b)}return r&&r.call(this,e,s),i},o.empty_cells=function(i,e,s,r,o){var a=this.widgets_below({col:i,row:e-r,size_x:s,size_y:r});return a.not(o).each(t.proxy(function(i,s){var o=t(s).coords().grid;if(e+r-1>=o.row){var a=e+r-o.row;this.move_widget_down(t(s),a)}},this)),this.set_dom_grid_height(),this},o.remove_empty_cells=function(i,e,s,r,o){var a=this.widgets_below({col:i,row:e,size_x:s,size_y:r});return a.not(o).each(t.proxy(function(i,e){this.move_widget_up(t(e),r)},this)),this.set_dom_grid_height(),this},o.next_position=function(t,i){t||(t=1),i||(i=1);for(var e,s=this.gridmap,r=s.length,o=[],a=1;r>a;a++){e=s[a].length;for(var n=1;e>=n;n++){var h=this.can_move_to({size_x:t,size_y:i},a,n);h&&o.push({col:a,row:n,size_y:i,size_x:t})}}return o.length?this.sort_by_row_and_col_asc(o)[0]:!1},o.remove_widget=function(i,e,s){var r=i instanceof jQuery?i:t(i),o=r.coords().grid;t.isFunction(e)&&(s=e,e=!1),this.cells_occupied_by_placeholder={},this.$widgets=this.$widgets.not(r);var a=this.widgets_below(r);this.remove_from_gridmap(o),r.fadeOut(t.proxy(function(){r.remove(),e||a.each(t.proxy(function(i,e){this.move_widget_up(t(e),o.size_y)},this)),this.set_dom_grid_height(),s&&s.call(this,i)},this))},o.remove_all_widgets=function(i){return this.$widgets.each(t.proxy(function(t,e){this.remove_widget(e,!0,i)},this)),this},o.serialize=function(i){i||(i=this.$widgets);var e=[];return i.each(t.proxy(function(i,s){e.push(this.options.serialize_params(t(s),t(s).coords().grid))},this)),e},o.serialize_changed=function(){return this.serialize(this.$changed)},o.register_widget=function(t){var i={col:parseInt(t.attr("data-col"),10),row:parseInt(t.attr("data-row"),10),size_x:parseInt(t.attr("data-sizex"),10),size_y:parseInt(t.attr("data-sizey"),10),el:t};return this.options.avoid_overlapped_widgets&&!this.can_move_to({size_x:i.size_x,size_y:i.size_y},i.col,i.row)&&(i=this.next_position(i.size_x,i.size_y),i.el=t,t.attr({"data-col":i.col,"data-row":i.row,"data-sizex":i.size_x,"data-sizey":i.size_y})),t.data("coords",t.coords()),t.data("coords").grid=i,this.add_to_gridmap(i,t),this},o.update_widget_position=function(t,i){return this.for_each_cell_occupied(t,function(t,e){return this.gridmap[t]?(this.gridmap[t][e]=i,undefined):this}),this},o.remove_from_gridmap=function(t){return this.update_widget_position(t,!1)},o.add_to_gridmap=function(i,e){if(this.update_widget_position(i,e||i.el),i.el){var s=this.widgets_below(i.el);s.each(t.proxy(function(i,e){this.move_widget_up(t(e))},this))}},o.draggable=function(){var i=this,e=t.extend(!0,{},this.options.draggable,{offset_left:this.options.widget_margins[0],container_width:this.container_width,start:function(e,s){i.$widgets.filter(".player-revert").removeClass("player-revert"),i.$player=t(this),i.$helper="clone"===i.options.draggable.helper?t(s.helper):i.$player,i.helper=!i.$helper.is(i.$player),i.on_start_drag.call(i,e,s),i.$el.trigger("gridster:dragstart")},stop:function(t,e){i.on_stop_drag.call(i,t,e),i.$el.trigger("gridster:dragstop")},drag:throttle(function(t,e){i.on_drag.call(i,t,e),i.$el.trigger("gridster:drag")},60)});return this.drag_api=this.$el.drag(e).data("drag"),this},o.on_start_drag=function(i,e){this.$helper.add(this.$player).add(this.$wrapper).addClass("dragging"),this.$player.addClass("player"),this.player_grid_data=this.$player.coords().grid,this.placeholder_grid_data=t.extend({},this.player_grid_data),this.$el.css("height",this.$el.height()+this.player_grid_data.size_y*this.min_widget_height);var s=this.faux_grid,r=this.$player.data("coords").coords;this.cells_occupied_by_player=this.get_cells_occupied(this.player_grid_data),this.cells_occupied_by_placeholder=this.get_cells_occupied(this.placeholder_grid_data),this.last_cols=[],this.last_rows=[],this.collision_api=this.$helper.collision(s,this.options.collision),this.$preview_holder=t("",{"class":"preview-holder","data-row":this.$player.attr("data-row"),"data-col":this.$player.attr("data-col"),css:{width:r.width,height:r.height}}).appendTo(this.$el),this.options.draggable.start&&this.options.draggable.start.call(this,i,e)},o.on_drag=function(t,i){if(null===this.$player)return!1;var e={left:i.position.left+this.baseX,top:i.position.top+this.baseY};this.colliders_data=this.collision_api.get_closest_colliders(e),this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column),this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row),this.helper&&this.$player&&this.$player.css({left:i.position.left,top:i.position.top}),this.options.draggable.drag&&this.options.draggable.drag.call(this,t,i)},o.on_stop_drag=function(t,i){this.$helper.add(this.$player).add(this.$wrapper).removeClass("dragging"),i.position.left=i.position.left+this.baseX,i.position.top=i.position.top+this.baseY,this.colliders_data=this.collision_api.get_closest_colliders(i.position),this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column),this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row),this.$player.addClass("player-revert").removeClass("player").attr({"data-col":this.placeholder_grid_data.col,"data-row":this.placeholder_grid_data.row}).css({left:"",top:""}),this.$changed=this.$changed.add(this.$player),this.cells_occupied_by_player=this.get_cells_occupied(this.placeholder_grid_data),this.set_cells_player_occupies(this.placeholder_grid_data.col,this.placeholder_grid_data.row),this.$player.coords().grid.row=this.placeholder_grid_data.row,this.$player.coords().grid.col=this.placeholder_grid_data.col,this.options.draggable.stop&&this.options.draggable.stop.call(this,t,i),this.$preview_holder.remove(),this.$player=null,this.$helper=null,this.placeholder_grid_data={},this.player_grid_data={},this.cells_occupied_by_placeholder={},this.cells_occupied_by_player={},this.set_dom_grid_height()},o.on_overlapped_column_change=function(i,e){if(!this.colliders_data.length)return this;var s,r=this.get_targeted_columns(this.colliders_data[0].el.data.col),o=this.last_cols.length,a=r.length;for(s=0;a>s;s++)-1===t.inArray(r[s],this.last_cols)&&(i||t.noop).call(this,r[s]);for(s=0;o>s;s++)-1===t.inArray(this.last_cols[s],r)&&(e||t.noop).call(this,this.last_cols[s]);return this.last_cols=r,this},o.on_overlapped_row_change=function(i,e){if(!this.colliders_data.length)return this;var s,r=this.get_targeted_rows(this.colliders_data[0].el.data.row),o=this.last_rows.length,a=r.length;for(s=0;a>s;s++)-1===t.inArray(r[s],this.last_rows)&&(i||t.noop).call(this,r[s]);for(s=0;o>s;s++)-1===t.inArray(this.last_rows[s],r)&&(e||t.noop).call(this,this.last_rows[s]);this.last_rows=r},o.set_player=function(t,i,e){var s=this;e||this.empty_cells_player_occupies();var r=e?{col:t}:s.colliders_data[0].el.data,o=r.col,a=i||r.row;this.player_grid_data={col:o,row:a,size_y:this.player_grid_data.size_y,size_x:this.player_grid_data.size_x},this.cells_occupied_by_player=this.get_cells_occupied(this.player_grid_data);var n=this.get_widgets_overlapped(this.player_grid_data),h=this.widgets_constraints(n);if(this.manage_movements(h.can_go_up,o,a),this.manage_movements(h.can_not_go_up,o,a),!n.length){var _=this.can_go_player_up(this.player_grid_data);_!==!1&&(a=_),this.set_placeholder(o,a)}return{col:o,row:a}},o.widgets_constraints=function(i){var e,s=t([]),r=[],o=[];return i.each(t.proxy(function(i,e){var a=t(e),n=a.coords().grid;this.can_go_widget_up(n)?(s=s.add(a),r.push(n)):o.push(n)},this)),e=i.not(s),{can_go_up:this.sort_by_row_asc(r),can_not_go_up:this.sort_by_row_desc(o)}},o.sort_by_row_asc=function(i){return i=i.sort(function(i,e){return i.row||(i=t(i).coords().grid,e=t(e).coords().grid),i.row>e.row?1:-1})},o.sort_by_row_and_col_asc=function(t){return t=t.sort(function(t,i){return t.row>i.row||t.row===i.row&&t.col>i.col?1:-1})},o.sort_by_col_asc=function(t){return t=t.sort(function(t,i){return t.col>i.col?1:-1})},o.sort_by_row_desc=function(t){return t=t.sort(function(t,i){return t.row+t.size_y=0&&t.inArray(e,s.rows)>=0},o.is_placeholder_in=function(i,e){var s=this.cells_occupied_by_placeholder||{};return this.is_placeholder_in_col(i)&&t.inArray(e,s.rows)>=0},o.is_placeholder_in_col=function(i){var e=this.cells_occupied_by_placeholder||[];return t.inArray(i,e.cols)>=0},o.is_empty=function(t,i){return this.gridmap[t]!==undefined?this.gridmap[t][i]!==undefined&&this.gridmap[t][i]===!1?!0:!1:!0},o.is_occupied=function(t,i){return this.gridmap[t]?this.gridmap[t][i]?!0:!1:!1},o.is_widget=function(t,i){var e=this.gridmap[t];return e?(e=e[i],e?e:!1):!1},o.is_widget_under_player=function(t,i){return this.is_widget(t,i)?this.is_player_in(t,i):!1},o.get_widgets_under_player=function(i){i||(i=this.cells_occupied_by_player||{cols:[],rows:[]});var e=t([]);return t.each(i.cols,t.proxy(function(s,r){t.each(i.rows,t.proxy(function(t,i){this.is_widget(r,i)&&(e=e.add(this.gridmap[r][i]))},this))},this)),e},o.set_placeholder=function(i,e){var s=t.extend({},this.placeholder_grid_data),r=this.widgets_below({col:s.col,row:s.row,size_y:s.size_y,size_x:s.size_x}),o=i+s.size_x-1;o>this.cols&&(i-=o-i);var a=e>this.placeholder_grid_data.row,n=this.placeholder_grid_data.col!==i;this.placeholder_grid_data.col=i,this.placeholder_grid_data.row=e,this.cells_occupied_by_placeholder=this.get_cells_occupied(this.placeholder_grid_data),this.$preview_holder.attr({"data-row":e,"data-col":i}),(a||n)&&r.each(t.proxy(function(e,r){this.move_widget_up(t(r),this.placeholder_grid_data.col-i+s.size_y)},this));var h=this.get_widgets_under_player(this.cells_occupied_by_placeholder);h.length&&h.each(t.proxy(function(i,r){var o=t(r);this.move_widget_down(o,e+s.size_y-o.data("coords").grid.row)},this))},o.can_go_player_up=function(t){var i=t.row+t.size_y-1,e=!0,s=[],r=1e4,o=this.get_widgets_under_player();return this.for_each_column_occupied(t,function(t){var a=this.gridmap[t],n=i+1;for(s[t]=[];--n>0&&(this.is_empty(t,n)||this.is_player(t,n)||this.is_widget(t,n)&&a[n].is(o));)s[t].push(n),r=r>n?n:r;return 0===s[t].length?(e=!1,!0):(s[t].sort(function(t,i){return t-i}),undefined)}),e?this.get_valid_rows(t,s,r):!1},o.can_go_widget_up=function(t){var i=t.row+t.size_y-1,e=!0,s=[],r=1e4;return this.for_each_column_occupied(t,function(o){var a=this.gridmap[o];s[o]=[];for(var n=i+1;--n>0&&(!this.is_widget(o,n)||this.is_player_in(o,n)||a[n].is(t.el));)this.is_player(o,n)||this.is_placeholder_in(o,n)||this.is_player_in(o,n)||s[o].push(n),r>n&&(r=n);return 0===s[o].length?(e=!1,!0):(s[o].sort(function(t,i){return t-i}),undefined)}),e?this.get_valid_rows(t,s,r):!1},o.get_valid_rows=function(i,e,s){for(var r=i.row,o=i.row+i.size_y-1,a=i.size_y,n=s-1,h=[];o>=++n;){var _=!0;if(t.each(e,function(i,e){t.isArray(e)&&-1===t.inArray(n,e)&&(_=!1)}),_===!0&&(h.push(n),h.length===a))break}var d=!1;return 1===a?h[0]!==r&&(d=h[0]||!1):h[0]!==r&&(d=this.get_consecutive_numbers_index(h,a)),d},o.get_consecutive_numbers_index=function(t,i){for(var e=t.length,s=[],r=!0,o=-1,a=0;e>a;a++){if(r||t[a]===o+1){if(s.push(a),s.length===i)break;r=!1}else s=[],r=!0;o=t[a]}return s.length>=i?t[s[0]]:!1},o.get_widgets_overlapped=function(){var i=t([]),e=[],s=this.cells_occupied_by_player.rows.slice(0);return s.reverse(),t.each(this.cells_occupied_by_player.cols,t.proxy(function(r,o){t.each(s,t.proxy(function(s,r){if(!this.gridmap[o])return!0;var a=this.gridmap[o][r];this.is_occupied(o,r)&&!this.is_player(a)&&-1===t.inArray(a,e)&&(i=i.add(a),e.push(a))},this))},this)),i},o.on_start_overlapping_column=function(t){this.set_player(t,!1)},o.on_start_overlapping_row=function(t){this.set_player(!1,t)},o.on_stop_overlapping_column=function(t){this.set_player(t,!1);var i=this;this.for_each_widget_below(t,this.cells_occupied_by_player.rows[0],function(){i.move_widget_up(this,i.player_grid_data.size_y)})},o.on_stop_overlapping_row=function(t){this.set_player(!1,t);for(var i=this,e=this.cells_occupied_by_player.cols,s=0,r=e.length;r>s;s++)this.for_each_widget_below(e[s],t,function(){i.move_widget_up(this,i.player_grid_data.size_y)})},o.move_widget_to=function(i,e){var s=this,r=i.coords().grid;e-r.row;var o=this.widgets_below(i),a=this.can_move_to(r,r.col,e,i);return a===!1?!1:(this.remove_from_gridmap(r),r.row=e,this.add_to_gridmap(r),i.attr("data-row",e),this.$changed=this.$changed.add(i),o.each(function(i,e){var r=t(e),o=r.coords().grid,a=s.can_go_widget_up(o);a&&a!==o.row&&s.move_widget_to(r,a)}),this)},o.move_widget_up=function(i,e){var s=i.coords().grid,r=s.row,o=[];return e||(e=1),this.can_go_up(i)?(this.for_each_column_occupied(s,function(s){if(-1===t.inArray(i,o)){var a=i.coords().grid,n=r-e;if(n=this.can_go_up_to_row(a,s,n),!n)return!0;var h=this.widgets_below(i);this.remove_from_gridmap(a),a.row=n,this.add_to_gridmap(a),i.attr("data-row",a.row),this.$changed=this.$changed.add(i),o.push(i),h.each(t.proxy(function(i,s){this.move_widget_up(t(s),e)},this))}}),undefined):!1},o.move_widget_down=function(i,e){var s=i.coords().grid,r=s.row,o=[],a=e;if(!i)return!1;if(-1===t.inArray(i,o)){var n=i.coords().grid,h=r+e,_=this.widgets_below(i);this.remove_from_gridmap(n),_.each(t.proxy(function(i,e){var s=t(e),r=s.coords().grid,o=this.displacement_diff(r,n,a);o>0&&this.move_widget_down(s,o)},this)),n.row=h,this.update_widget_position(n,i),i.attr("data-row",n.row),this.$changed=this.$changed.add(i),o.push(i)}},o.can_go_up_to_row=function(i,e,s){var r,o=this.gridmap,a=!0,n=[],h=i.row;if(this.for_each_column_occupied(i,function(t){for(o[t],n[t]=[],r=h;r--&&this.is_empty(t,r)&&!this.is_placeholder_in(t,r);)n[t].push(r);return n[t].length?undefined:(a=!1,!0)}),!a)return!1;for(r=s,r=1;h>r;r++){for(var _=!0,d=0,l=n.length;l>d;d++)n[d]&&-1===t.inArray(r,n[d])&&(_=!1);if(_===!0){a=r;break}}return a},o.displacement_diff=function(t,i,e){var s=t.row,r=[],o=i.row+i.size_y;this.for_each_column_occupied(t,function(t){for(var i=0,e=o;s>e;e++)this.is_empty(t,e)&&(i+=1);r.push(i)});var a=Math.max.apply(Math,r);return e-=a,e>0?e:0},o.widgets_below=function(i){var e=t.isPlainObject(i)?i:i.coords().grid,s=this;this.gridmap;var r=e.row+e.size_y-1,o=t([]);return this.for_each_column_occupied(e,function(i){s.for_each_widget_below(i,r,function(){return s.is_player(this)||-1!==t.inArray(this,o)?undefined:(o=o.add(this),!0)})}),this.sort_by_row_asc(o)},o.set_cells_player_occupies=function(t,i){return this.remove_from_gridmap(this.placeholder_grid_data),this.placeholder_grid_data.col=t,this.placeholder_grid_data.row=i,this.add_to_gridmap(this.placeholder_grid_data,this.$player),this},o.empty_cells_player_occupies=function(){return this.remove_from_gridmap(this.placeholder_grid_data),this},o.can_go_up=function(t){var i=t.coords().grid,e=i.row,s=e-1;this.gridmap;var r=!0;return 1===e?!1:(this.for_each_column_occupied(i,function(t){return this.is_widget(t,s),this.is_occupied(t,s)||this.is_player(t,s)||this.is_placeholder_in(t,s)||this.is_player_in(t,s)?(r=!1,!0):undefined}),r)},o.can_move_to=function(t,i,e,s){this.gridmap;var r=t.el,o={size_y:t.size_y,size_x:t.size_x,col:i,row:e},a=!0,n=i+t.size_x-1;return n>this.cols?!1:s&&e+t.size_y-1>s?!1:(this.for_each_cell_occupied(o,function(i,e){var s=this.is_widget(i,e);!s||t.el&&!s.is(r)||(a=!1)}),a)},o.get_targeted_columns=function(t){for(var i=(t||this.player_grid_data.col)+(this.player_grid_data.size_x-1),e=[],s=t;i>=s;s++)e.push(s);return e},o.get_targeted_rows=function(t){for(var i=(t||this.player_grid_data.row)+(this.player_grid_data.size_y-1),e=[],s=t;i>=s;s++)e.push(s);return e},o.get_cells_occupied=function(t){var i,e={cols:[],rows:[]};for(arguments[1]instanceof jQuery&&(t=arguments[1].coords().grid),i=0;t.size_x>i;i++){var s=t.col+i;e.cols.push(s)}for(i=0;t.size_y>i;i++){var r=t.row+i;e.rows.push(r)}return e},o.for_each_cell_occupied=function(t,i){return this.for_each_column_occupied(t,function(e){this.for_each_row_occupied(t,function(t){i.call(this,e,t)})}),this},o.for_each_column_occupied=function(t,i){for(var e=0;t.size_x>e;e++){var s=t.col+e;i.call(this,s,t)}},o.for_each_row_occupied=function(t,i){for(var e=0;t.size_y>e;e++){var s=t.row+e;i.call(this,s,t)}},o._traversing_widgets=function(i,e,s,r,o){var a=this.gridmap;if(a[s]){var n,h,_=i+"/"+e;if(arguments[2]instanceof jQuery){var d=arguments[2].coords().grid;s=d.col,r=d.row,o=arguments[3]}var l=[],c=r,p={"for_each/above":function(){for(;c--&&!(c>0&&this.is_widget(s,c)&&-1===t.inArray(a[s][c],l)&&(n=o.call(a[s][c],s,c),l.push(a[s][c]),n)););},"for_each/below":function(){for(c=r+1,h=a[s].length;h>c&&(!this.is_widget(s,c)||-1!==t.inArray(a[s][c],l)||(n=o.call(a[s][c],s,c),l.push(a[s][c]),!n));c++);}};p[_]&&p[_].call(this)}},o.for_each_widget_above=function(t,i,e){return this._traversing_widgets("for_each","above",t,i,e),this},o.for_each_widget_below=function(t,i,e){return this._traversing_widgets("for_each","below",t,i,e),this},o.get_highest_occupied_cell=function(){for(var t,i=this.gridmap,e=[],s=[],r=i.length-1;r>=1;r--)for(t=i[r].length-1;t>=1;t--)if(this.is_widget(r,t)){e.push(t),s[t]=r;break}var o=Math.max.apply(Math,e);return this.highest_occupied_cell={col:s[o],row:o},this.highest_occupied_cell},o.get_widgets_from=function(i,e){this.gridmap;var s=t();return i&&(s=s.add(this.$widgets.filter(function(){var e=t(this).attr("data-col");return e===i||e>i}))),e&&(s=s.add(this.$widgets.filter(function(){var i=t(this).attr("data-row");return i===e||i>e}))),s},o.set_dom_grid_height=function(){var t=this.get_highest_occupied_cell().row;return this.$el.css("height",t*this.min_widget_height),this},o.generate_stylesheet=function(i){var e,r="",o=this.options.max_size_x;i||(i={}),i.cols||(i.cols=this.cols),i.rows||(i.rows=this.rows),i.namespace||(i.namespace=this.options.namespace),i.widget_base_dimensions||(i.widget_base_dimensions=this.options.widget_base_dimensions),i.widget_margins||(i.widget_margins=this.options.widget_margins),i.min_widget_width=2*i.widget_margins[0]+i.widget_base_dimensions[0],i.min_widget_height=2*i.widget_margins[1]+i.widget_base_dimensions[1];var a=t.param(i);if(t.inArray(a,s.generated_stylesheets)>=0)return!1;for(s.generated_stylesheets.push(a),e=i.cols;e>=0;e--)r+=i.namespace+' [data-col="'+(e+1)+'"] { left:'+(e*i.widget_base_dimensions[0]+e*i.widget_margins[0]+(e+1)*i.widget_margins[0])+"px;} ";for(e=i.rows;e>=0;e--)r+=i.namespace+' [data-row="'+(e+1)+'"] { top:'+(e*i.widget_base_dimensions[1]+e*i.widget_margins[1]+(e+1)*i.widget_margins[1])+"px;} ";for(var n=1;i.rows>=n;n++)r+=i.namespace+' [data-sizey="'+n+'"] { height:'+(n*i.widget_base_dimensions[1]+(n-1)*2*i.widget_margins[1])+"px;}";for(var h=1;o>=h;h++)r+=i.namespace+' [data-sizex="'+h+'"] { width:'+(h*i.widget_base_dimensions[0]+(h-1)*2*i.widget_margins[0])+"px;}";return this.add_style_tag(r)},o.add_style_tag=function(t){var i=e,s=i.createElement("style");return i.getElementsByTagName("head")[0].appendChild(s),s.setAttribute("type","text/css"),s.styleSheet?s.styleSheet.cssText=t:s.appendChild(e.createTextNode(t)),this.$style_tags=this.$style_tags.add(s),this},o.remove_style_tags=function(){this.$style_tags.remove()},o.generate_faux_grid=function(t,i){this.faux_grid=[],this.gridmap=[];var e,s;for(e=i;e>0;e--)for(this.gridmap[e]=[],s=t;s>0;s--)this.add_faux_cell(s,e);return this},o.add_faux_cell=function(i,e){var s=t({left:this.baseX+(e-1)*this.min_widget_width,top:this.baseY+(i-1)*this.min_widget_height,width:this.min_widget_width,height:this.min_widget_height,col:e,row:i,original_col:e,original_row:i}).coords();return t.isArray(this.gridmap[e])||(this.gridmap[e]=[]),this.gridmap[e][i]=!1,this.faux_grid.push(s),this},o.add_faux_rows=function(t){for(var i=this.rows,e=i+(t||1),s=e;s>i;s--)for(var r=this.cols;r>=1;r--)this.add_faux_cell(s,r);return this.rows=e,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this},o.add_faux_cols=function(t){for(var i=this.cols,e=i+(t||1),s=i;e>s;s++)for(var r=this.rows;r>=1;r--)this.add_faux_cell(r,s);return this.cols=e,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this},o.recalculate_faux_grid=function(){var e=this.$wrapper.width();
-return this.baseX=(t(i).width()-e)/2,this.baseY=this.$wrapper.offset().top,t.each(this.faux_grid,t.proxy(function(t,i){this.faux_grid[t]=i.update({left:this.baseX+(i.data.col-1)*this.min_widget_width,top:this.baseY+(i.data.row-1)*this.min_widget_height})},this)),this},o.get_widgets_from_DOM=function(){return this.$widgets.each(t.proxy(function(i,e){this.register_widget(t(e))},this)),this},o.generate_grid_and_stylesheet=function(){var e=this.$wrapper.width();this.$wrapper.height();var s=this.options.max_cols,r=Math.floor(e/this.min_widget_width)+this.options.extra_cols,o=this.$widgets.map(function(){return t(this).attr("data-col")}).get();o.length||(o=[0]);var a=Math.max.apply(Math,o),n=this.options.extra_rows;return this.$widgets.each(function(i,e){n+=+t(e).attr("data-sizey")}),this.cols=Math.max(a,r,this.options.min_cols),s&&s>=a&&this.cols>s&&(this.cols=s),this.rows=Math.max(n,this.options.min_rows),this.baseX=(t(i).width()-e)/2,this.baseY=this.$wrapper.offset().top,this.container_width=this.cols*this.options.widget_base_dimensions[0]+2*(this.cols-1)*this.options.widget_margins[0],this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this.generate_faux_grid(this.rows,this.cols)},o.destroy=function(){return t(i).unbind(".gridster"),this.drag_api&&this.drag_api.destroy(),this.remove_style_tags(),this.$el.remove(),this},t.fn.gridster=function(i){return this.each(function(){t(this).data("gridster")||t(this).data("gridster",new s(this,i))})},t.Gridster=o}(jQuery,window,document);
\ No newline at end of file
+/*! gridster.js - v0.2.0 - 2013-10-26 - * http://gridster.net/ - Copyright (c) 2013 ducksboard; Licensed MIT */ (function(t){function i(i){return i[0]&&t.isPlainObject(i[0])?this.data=i[0]:this.el=i,this.isCoords=!0,this.coords={},this.init(),this}var e=i.prototype;e.init=function(){this.set(),this.original_coords=this.get()},e.set=function(t,i){var e=this.el;if(e&&!t&&(this.data=e.offset(),this.data.width=e.width(),this.data.height=e.height()),e&&t&&!i){var s=e.offset();this.data.top=s.top,this.data.left=s.left}var r=this.data;return this.coords.x1=r.left,this.coords.y1=r.top,this.coords.x2=r.left+r.width,this.coords.y2=r.top+r.height,this.coords.cx=r.left+r.width/2,this.coords.cy=r.top+r.height/2,this.coords.width=r.width,this.coords.height=r.height,this.coords.el=e||!1,this},e.update=function(i){if(!i&&!this.el)return this;if(i){var e=t.extend({},this.data,i);return this.data=e,this.set(!0,!0)}return this.set(!0),this},e.get=function(){return this.coords},t.fn.coords=function(){if(this.data("coords"))return this.data("coords");var t=new i(this,arguments[0]);return this.data("coords",t),t}})(jQuery,window,document),function(t,i,e){function s(i,e,s){this.options=t.extend(r,s),this.$element=i,this.last_colliders=[],this.last_colliders_coords=[],"string"==typeof e||e instanceof jQuery?this.$colliders=t(e,this.options.colliders_context).not(this.$element):this.colliders=t(e),this.init()}var r={colliders_context:e.body},o=s.prototype;o.init=function(){this.find_collisions()},o.overlaps=function(t,i){var e=!1,s=!1;return(i.x1>=t.x1&&i.x1<=t.x2||i.x2>=t.x1&&i.x2<=t.x2||t.x1>=i.x1&&t.x2<=i.x2)&&(e=!0),(i.y1>=t.y1&&i.y1<=t.y2||i.y2>=t.y1&&i.y2<=t.y2||t.y1>=i.y1&&t.y2<=i.y2)&&(s=!0),e&&s},o.detect_overlapping_region=function(t,i){var e="",s="";return t.y1>i.cy&&t.y1i.y1&&t.y2i.cx&&t.x1i.x1&&t.x2o;o++)-1===t.inArray(r[o],i)&&e.call(this,r[o]);for(var n=0,h=i.length;h>n;n++)-1===t.inArray(i[n],r)&&s.call(this,i[n])},o.find_collisions=function(i){for(var e=this,s=[],r=[],o=this.colliders||this.$colliders,a=o.length,n=e.$element.coords().update(i||!1).get();a--;){var h=e.$colliders?t(o[a]):o[a],_=h.isCoords?h:h.coords(),d=_.get(),l=e.overlaps(n,d);if(l){var c=e.detect_overlapping_region(n,d);if("C"===c){var p=e.calculate_overlapped_area_coords(n,d),g=e.calculate_overlapped_area(p),u={area:g,area_coords:p,region:c,coords:d,player_coords:n,el:h};e.options.on_overlap&&e.options.on_overlap.call(this,u),s.push(_),r.push(u)}}}return(e.options.on_overlap_stop||e.options.on_overlap_start)&&this.manage_colliders_start_stop(s,e.options.on_overlap_start,e.options.on_overlap_stop),this.last_colliders_coords=s,r},o.get_closest_colliders=function(t){var i=this.find_collisions(t);return i.sort(function(t,i){return"C"===t.region&&"C"===i.region?t.coords.y1this.player_max_left?r=this.player_max_left:this.player_min_left>r&&(r=this.player_min_left)),{position:{left:r,top:o},pointer:{left:i.left,top:i.top,diff_left:e,diff_top:s+this.scrollOffset}}},h.get_drag_data=function(t){var i=this.get_offset(t);return i.$player=this.$player,i.$helper=this.helper?this.$helper:this.$player,i},h.manage_scroll=function(t){var i,e=o.scrollTop(),s=e,r=s+this.window_height,a=r-50,n=s+50;t.pointer.left;var h=s+t.pointer.top,_=this.doc_height-this.window_height+this.player_height;h>=a&&(i=e+30,_>i&&(o.scrollTop(i),this.scrollOffset=this.scrollOffset+30)),n>=h&&(i=e-30,i>0&&(o.scrollTop(i),this.scrollOffset=this.scrollOffset-30))},h.calculate_positions=function(){this.window_height=o.height()},h.drag_handler=function(i){if(i.target.nodeName,!this.disabled&&(1===i.which||a)&&!this.ignore_drag(i)){var e=this,s=!0;return this.$player=t(i.currentTarget),this.el_init_pos=this.get_actual_pos(this.$player),this.mouse_init_pos=this.get_mouse_pos(i),this.offsetY=this.mouse_init_pos.top-this.el_init_pos.top,this.$body.on(n.move,function(t){var i=e.get_mouse_pos(t),r=Math.abs(i.left-e.mouse_init_pos.left),o=Math.abs(i.top-e.mouse_init_pos.top);return r>e.options.distance||o>e.options.distance?s?(s=!1,e.on_dragstart.call(e,t),!1):(e.is_dragging===!0&&e.on_dragmove.call(e,t),!1):!1}),a?undefined:!1}},h.on_dragstart=function(i){if(i.preventDefault(),this.is_dragging)return this;this.drag_start=this.is_dragging=!0;var s=this.$container.offset();this.baseX=Math.round(s.left),this.baseY=Math.round(s.top),this.doc_height=t(e).height(),"clone"===this.options.helper?(this.$helper=this.$player.clone().appendTo(this.$container).addClass("helper"),this.helper=!0):this.helper=!1,this.scrollOffset=0,this.el_init_offset=this.$player.offset(),this.player_width=this.$player.width(),this.player_height=this.$player.height();var r=this.options.container_width||this.$container.width();return this.player_max_left=r-this.player_width+this.options.offset_left,this.options.start&&this.options.start.call(this.$player,i,this.get_drag_data(i)),!1},h.on_dragmove=function(t){var i=this.get_drag_data(t);this.options.autoscroll&&this.manage_scroll(i),this.options.move_element&&(this.helper?this.$helper:this.$player).css({position:"absolute",left:i.position.left,top:i.position.top});var e=this.last_position||i.position;return i.prev_position=e,this.options.drag&&this.options.drag.call(this.$player,t,i),this.last_position=i.position,!1},h.on_dragstop=function(t){var i=this.get_drag_data(t);return this.drag_start=!1,this.options.stop&&this.options.stop.call(this.$player,t,i),this.helper&&this.$helper.remove(),!1},h.on_select_start=function(t){return this.disabled||this.ignore_drag(t)?undefined:!1},h.enable=function(){this.disabled=!1},h.disable=function(){this.disabled=!0},h.destroy=function(){this.disable(),this.$container.off(".gridster-draggable"),this.$body.off(".gridster-draggable"),t(i).off(".gridster-draggable"),t.removeData(this.$container,"drag")},h.ignore_drag=function(i){return this.options.handle?!t(i.target).is(this.options.handle):t(i.target).is(this.options.ignore_dragging.join(", "))},t.fn.drag=function(t){return new s(this,t)}}(jQuery,window,document),function(t,i,e){function s(i,e){this.options=t.extend(!0,r,e),this.$el=t(i),this.$wrapper=this.$el.parent(),this.$widgets=this.$el.children(this.options.widget_selector).addClass("gs-w"),this.widgets=[],this.$changed=t([]),this.wrapper_width=this.$wrapper.width(),this.min_widget_width=2*this.options.widget_margins[0]+this.options.widget_base_dimensions[0],this.min_widget_height=2*this.options.widget_margins[1]+this.options.widget_base_dimensions[1],this.$style_tags=t([]),this.init()}var r={namespace:"",widget_selector:"li",widget_margins:[10,10],widget_base_dimensions:[400,225],extra_rows:0,extra_cols:0,min_cols:1,max_cols:null,min_rows:15,max_size_x:!1,autogenerate_stylesheet:!0,avoid_overlapped_widgets:!0,serialize_params:function(t,i){return{col:i.col,row:i.row,size_x:i.size_x,size_y:i.size_y}},collision:{},draggable:{items:".gs-w",distance:4},resize:{enabled:!1,axes:["x","y","both"],handle_append_to:"",handle_class:"gs-resize-handle",max_size:[1/0,1/0]}};s.generated_stylesheets=[];var o=s.prototype;o.init=function(){this.options.resize.enabled&&this.setup_resize(),this.generate_grid_and_stylesheet(),this.get_widgets_from_DOM(),this.set_dom_grid_height(),this.$wrapper.addClass("ready"),this.draggable(),this.options.resize.enabled&&this.resizable(),t(i).bind("resize.gridster",throttle(t.proxy(this.recalculate_faux_grid,this),200))},o.disable=function(){return this.$wrapper.find(".player-revert").removeClass("player-revert"),this.drag_api.disable(),this},o.enable=function(){return this.drag_api.enable(),this},o.disable_resize=function(){return this.$el.addClass("gs-resize-disabled"),this.resize_api.disable(),this},o.enable_resize=function(){return this.$el.removeClass("gs-resize-disabled"),this.resize_api.enable(),this},o.add_widget=function(i,e,s,r,o,a){var n;e||(e=1),s||(s=1),!r&!o?n=this.next_position(e,s):(n={col:r,row:o},this.empty_cells(r,o,e,s));var h=t(i).attr({"data-col":n.col,"data-row":n.row,"data-sizex":e,"data-sizey":s}).addClass("gs-w").appendTo(this.$el).hide();return this.$widgets=this.$widgets.add(h),this.register_widget(h),this.add_faux_rows(n.size_y),a&&this.set_widget_max_size(h,a),this.set_dom_grid_height(),h.fadeIn()},o.set_widget_max_size=function(t,i){if(t="number"==typeof t?this.$widgets.eq(t):t,!t.length)return this;var e=t.data("coords").grid;return e.max_size_x=i[0],e.max_size_y=i[1],this},o.add_resize_handle=function(i){var e=this.options.resize.handle_append_to;return t(this.resize_handle_tpl).appendTo(e?t(e,i):i),this},o.resize_widget=function(t,i,e,s,r){var o=t.coords().grid;s!==!1&&(s=!0),i||(i=o.size_x),e||(e=o.size_y),i>this.cols&&(i=this.cols);var a=o.size_y,n=o.col,h=n;if(s&&n+i-1>this.cols){var _=n+(i-1)-this.cols,d=n-_;h=Math.max(1,d)}e>a&&this.add_faux_rows(Math.max(e-a,0));var l={col:h,row:o.row,size_x:i,size_y:e};return this.mutate_widget_in_gridmap(t,o,l),this.set_dom_grid_height(),r&&r.call(this,l.size_x,l.size_y),t},o.mutate_widget_in_gridmap=function(i,e,s){e.size_x;var r=e.size_y,o=this.get_cells_occupied(e),a=this.get_cells_occupied(s),n=[];t.each(o.cols,function(i,e){-1===t.inArray(e,a.cols)&&n.push(e)});var h=[];t.each(a.cols,function(i,e){-1===t.inArray(e,o.cols)&&h.push(e)});var _=[];t.each(o.rows,function(i,e){-1===t.inArray(e,a.rows)&&_.push(e)});var d=[];if(t.each(a.rows,function(i,e){-1===t.inArray(e,o.rows)&&d.push(e)}),this.remove_from_gridmap(e),h.length){var l=[s.col,s.row,s.size_x,Math.min(r,s.size_y),i];this.empty_cells.apply(this,l)}if(d.length){var c=[s.col,s.row,s.size_x,s.size_y,i];this.empty_cells.apply(this,c)}if(e.col=s.col,e.row=s.row,e.size_x=s.size_x,e.size_y=s.size_y,this.add_to_gridmap(s,i),i.removeClass("player-revert"),i.data("coords").update({width:s.size_x*this.options.widget_base_dimensions[0]+2*(s.size_x-1)*this.options.widget_margins[0],height:s.size_y*this.options.widget_base_dimensions[1]+2*(s.size_y-1)*this.options.widget_margins[1]}),i.attr({"data-col":s.col,"data-row":s.row,"data-sizex":s.size_x,"data-sizey":s.size_y}),n.length){var p=[n[0],s.row,n.length,Math.min(r,s.size_y),i];this.remove_empty_cells.apply(this,p)}if(_.length){var g=[s.col,s.row,s.size_x,s.size_y,i];this.remove_empty_cells.apply(this,g)}return this.move_widget_up(i),this},o.empty_cells=function(i,e,s,r,o){var a=this.widgets_below({col:i,row:e-r,size_x:s,size_y:r});return a.not(o).each(t.proxy(function(i,s){var o=t(s).coords().grid;if(e+r-1>=o.row){var a=e+r-o.row;this.move_widget_down(t(s),a)}},this)),this.set_dom_grid_height(),this},o.remove_empty_cells=function(i,e,s,r,o){var a=this.widgets_below({col:i,row:e,size_x:s,size_y:r});return a.not(o).each(t.proxy(function(i,e){this.move_widget_up(t(e),r)},this)),this.set_dom_grid_height(),this},o.next_position=function(t,i){t||(t=1),i||(i=1);for(var e,s=this.gridmap,r=s.length,o=[],a=1;r>a;a++){e=s[a].length;for(var n=1;e>=n;n++){var h=this.can_move_to({size_x:t,size_y:i},a,n);h&&o.push({col:a,row:n,size_y:i,size_x:t})}}return o.length?this.sort_by_row_and_col_asc(o)[0]:!1},o.remove_widget=function(i,e,s){var r=i instanceof jQuery?i:t(i),o=r.coords().grid;t.isFunction(e)&&(s=e,e=!1),this.cells_occupied_by_placeholder={},this.$widgets=this.$widgets.not(r);var a=this.widgets_below(r);return this.remove_from_gridmap(o),r.fadeOut(t.proxy(function(){r.remove(),e||a.each(t.proxy(function(i,e){this.move_widget_up(t(e),o.size_y)},this)),this.set_dom_grid_height(),s&&s.call(this,i)},this)),this},o.remove_all_widgets=function(i){return this.$widgets.each(t.proxy(function(t,e){this.remove_widget(e,!0,i)},this)),this},o.serialize=function(i){i||(i=this.$widgets);var e=[];return i.each(t.proxy(function(i,s){e.push(this.options.serialize_params(t(s),t(s).coords().grid))},this)),e},o.serialize_changed=function(){return this.serialize(this.$changed)},o.register_widget=function(i){var e={col:parseInt(i.attr("data-col"),10),row:parseInt(i.attr("data-row"),10),size_x:parseInt(i.attr("data-sizex"),10),size_y:parseInt(i.attr("data-sizey"),10),max_size_x:parseInt(i.attr("data-max-sizex"),10)||!1,max_size_y:parseInt(i.attr("data-max-sizey"),10)||!1,el:i};return this.options.avoid_overlapped_widgets&&!this.can_move_to({size_x:e.size_x,size_y:e.size_y},e.col,e.row)&&(t.extend(e,this.next_position(e.size_x,e.size_y)),i.attr({"data-col":e.col,"data-row":e.row,"data-sizex":e.size_x,"data-sizey":e.size_y})),i.data("coords",i.coords()),i.data("coords").grid=e,this.add_to_gridmap(e,i),this.options.resize.enabled&&this.add_resize_handle(i),this},o.update_widget_position=function(t,i){return this.for_each_cell_occupied(t,function(t,e){return this.gridmap[t]?(this.gridmap[t][e]=i,undefined):this}),this},o.remove_from_gridmap=function(t){return this.update_widget_position(t,!1)},o.add_to_gridmap=function(i,e){if(this.update_widget_position(i,e||i.el),i.el){var s=this.widgets_below(i.el);s.each(t.proxy(function(i,e){this.move_widget_up(t(e))},this))}},o.draggable=function(){var i=this,e=t.extend(!0,{},this.options.draggable,{offset_left:this.options.widget_margins[0],container_width:this.container_width,ignore_dragging:["INPUT","TEXTAREA","SELECT","BUTTON","."+this.options.resize.handle_class],start:function(e,s){i.$widgets.filter(".player-revert").removeClass("player-revert"),i.$player=t(this),i.$helper=t(s.$helper),i.helper=!i.$helper.is(i.$player),i.on_start_drag.call(i,e,s),i.$el.trigger("gridster:dragstart")},stop:function(t,e){i.on_stop_drag.call(i,t,e),i.$el.trigger("gridster:dragstop")},drag:throttle(function(t,e){i.on_drag.call(i,t,e),i.$el.trigger("gridster:drag")},60)});return this.drag_api=this.$el.drag(e),this},o.resizable=function(){return this.resize_api=this.$el.drag({items:"."+this.options.resize.handle_class,offset_left:this.options.widget_margins[0],container_width:this.container_width,move_element:!1,start:t.proxy(this.on_start_resize,this),stop:t.proxy(function(i,e){delay(t.proxy(function(){this.on_stop_resize(i,e)},this),120)},this),drag:throttle(t.proxy(this.on_resize,this),60)}),this},o.setup_resize=function(){this.resize_handle_class=this.options.resize.handle_class;var i=this.options.resize.axes,e='';return this.resize_handle_tpl=t.map(i,function(t){return e.replace("{type}",t)}).join(""),this},o.on_start_drag=function(i,e){this.$helper.add(this.$player).add(this.$wrapper).addClass("dragging"),this.$player.addClass("player"),this.player_grid_data=this.$player.coords().grid,this.placeholder_grid_data=t.extend({},this.player_grid_data),this.$el.css("height",this.$el.height()+this.player_grid_data.size_y*this.min_widget_height);var s=this.faux_grid,r=this.$player.data("coords").coords;this.cells_occupied_by_player=this.get_cells_occupied(this.player_grid_data),this.cells_occupied_by_placeholder=this.get_cells_occupied(this.placeholder_grid_data),this.last_cols=[],this.last_rows=[],this.collision_api=this.$helper.collision(s,this.options.collision),this.$preview_holder=t("<"+this.$player.get(0).tagName+" />",{"class":"preview-holder","data-row":this.$player.attr("data-row"),"data-col":this.$player.attr("data-col"),css:{width:r.width,height:r.height}}).appendTo(this.$el),this.options.draggable.start&&this.options.draggable.start.call(this,i,e)},o.on_drag=function(t,i){if(null===this.$player)return!1;var e={left:i.position.left+this.baseX,top:i.position.top+this.baseY};this.colliders_data=this.collision_api.get_closest_colliders(e),this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column),this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row),this.helper&&this.$player&&this.$player.css({left:i.position.left,top:i.position.top}),this.options.draggable.drag&&this.options.draggable.drag.call(this,t,i)},o.on_stop_drag=function(t,i){this.$helper.add(this.$player).add(this.$wrapper).removeClass("dragging"),i.position.left=i.position.left+this.baseX,i.position.top=i.position.top+this.baseY,this.colliders_data=this.collision_api.get_closest_colliders(i.position),this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column),this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row),this.$player.addClass("player-revert").removeClass("player").attr({"data-col":this.placeholder_grid_data.col,"data-row":this.placeholder_grid_data.row}).css({left:"",top:""}),this.$changed=this.$changed.add(this.$player),this.cells_occupied_by_player=this.get_cells_occupied(this.placeholder_grid_data),this.set_cells_player_occupies(this.placeholder_grid_data.col,this.placeholder_grid_data.row),this.$player.coords().grid.row=this.placeholder_grid_data.row,this.$player.coords().grid.col=this.placeholder_grid_data.col,this.options.draggable.stop&&this.options.draggable.stop.call(this,t,i),this.$preview_holder.remove(),this.$player=null,this.$helper=null,this.placeholder_grid_data={},this.player_grid_data={},this.cells_occupied_by_placeholder={},this.cells_occupied_by_player={},this.set_dom_grid_height()},o.on_start_resize=function(i,e){this.$resized_widget=e.$player.closest(".gs-w"),this.resize_coords=this.$resized_widget.coords(),this.resize_wgd=this.resize_coords.grid,this.resize_initial_width=this.resize_coords.coords.width,this.resize_initial_height=this.resize_coords.coords.height,this.resize_initial_sizex=this.resize_coords.grid.size_x,this.resize_initial_sizey=this.resize_coords.grid.size_y,this.resize_last_sizex=this.resize_initial_sizex,this.resize_last_sizey=this.resize_initial_sizey,this.resize_max_size_x=Math.min(this.resize_wgd.max_size_x||this.options.resize.max_size[0],this.cols-this.resize_wgd.col+1),this.resize_max_size_y=this.resize_wgd.max_size_y||this.options.resize.max_size[1],this.resize_dir={right:e.$player.is("."+this.resize_handle_class+"-x"),bottom:e.$player.is("."+this.resize_handle_class+"-y")},this.$resized_widget.css({"min-width":this.options.widget_base_dimensions[0],"min-height":this.options.widget_base_dimensions[1]});var s=this.$resized_widget.get(0).tagName;this.$resize_preview_holder=t("<"+s+" />",{"class":"preview-holder resize-preview-holder","data-row":this.$resized_widget.attr("data-row"),"data-col":this.$resized_widget.attr("data-col"),css:{width:this.resize_initial_width,height:this.resize_initial_height}}).appendTo(this.$el),this.$resized_widget.addClass("resizing")},o.on_stop_resize=function(){this.$resized_widget.removeClass("resizing").css({width:"",height:""}),delay(t.proxy(function(){this.$resize_preview_holder.remove().css({"min-width":"","min-height":""})},this),300)},o.on_resize=function(t,i){var e=i.pointer.diff_left,s=i.pointer.diff_top,r=this.options.widget_base_dimensions[0],o=this.options.widget_base_dimensions[1],a=1/0,n=1/0,h=Math.ceil(e/(this.options.widget_base_dimensions[0]+2*this.options.widget_margins[0])-.2),_=Math.ceil(s/(this.options.widget_base_dimensions[1]+2*this.options.widget_margins[1])-.2),d=Math.max(1,this.resize_initial_sizex+h),l=Math.max(1,this.resize_initial_sizey+_);d=Math.min(d,this.resize_max_size_x),a=this.resize_max_size_x*r+2*(d-1)*this.options.widget_margins[0],l=Math.min(l,this.resize_max_size_y),n=this.resize_max_size_y*o+2*(l-1)*this.options.widget_margins[1],this.resize_dir.right?l=this.resize_initial_sizey:this.resize_dir.bottom&&(d=this.resize_initial_sizex);var c={};!this.resize_dir.bottom&&(c.width=Math.min(this.resize_initial_width+e,a)),!this.resize_dir.right&&(c.height=Math.min(this.resize_initial_height+s,n)),this.$resized_widget.css(c),(d!==this.resize_last_sizex||l!==this.resize_last_sizey)&&(this.resize_widget(this.$resized_widget,d,l,!1),this.$resize_preview_holder.css({width:"",height:""}).attr({"data-row":this.$resized_widget.attr("data-row"),"data-sizex":d,"data-sizey":l})),this.resize_last_sizex=d,this.resize_last_sizey=l},o.on_overlapped_column_change=function(i,e){if(!this.colliders_data.length)return this;var s,r=this.get_targeted_columns(this.colliders_data[0].el.data.col),o=this.last_cols.length,a=r.length;for(s=0;a>s;s++)-1===t.inArray(r[s],this.last_cols)&&(i||t.noop).call(this,r[s]);for(s=0;o>s;s++)-1===t.inArray(this.last_cols[s],r)&&(e||t.noop).call(this,this.last_cols[s]);return this.last_cols=r,this},o.on_overlapped_row_change=function(i,e){if(!this.colliders_data.length)return this;var s,r=this.get_targeted_rows(this.colliders_data[0].el.data.row),o=this.last_rows.length,a=r.length;for(s=0;a>s;s++)-1===t.inArray(r[s],this.last_rows)&&(i||t.noop).call(this,r[s]);for(s=0;o>s;s++)-1===t.inArray(this.last_rows[s],r)&&(e||t.noop).call(this,this.last_rows[s]);this.last_rows=r},o.set_player=function(t,i,e){var s=this;e||this.empty_cells_player_occupies();var r=e?{col:t}:s.colliders_data[0].el.data,o=r.col,a=i||r.row;this.player_grid_data={col:o,row:a,size_y:this.player_grid_data.size_y,size_x:this.player_grid_data.size_x},this.cells_occupied_by_player=this.get_cells_occupied(this.player_grid_data);var n=this.get_widgets_overlapped(this.player_grid_data),h=this.widgets_constraints(n);if(this.manage_movements(h.can_go_up,o,a),this.manage_movements(h.can_not_go_up,o,a),!n.length){var _=this.can_go_player_up(this.player_grid_data);_!==!1&&(a=_),this.set_placeholder(o,a)}return{col:o,row:a}},o.widgets_constraints=function(i){var e,s=t([]),r=[],o=[];return i.each(t.proxy(function(i,e){var a=t(e),n=a.coords().grid;this.can_go_widget_up(n)?(s=s.add(a),r.push(n)):o.push(n)},this)),e=i.not(s),{can_go_up:this.sort_by_row_asc(r),can_not_go_up:this.sort_by_row_desc(o)}},o.sort_by_row_asc=function(i){return i=i.sort(function(i,e){return i.row||(i=t(i).coords().grid,e=t(e).coords().grid),i.row>e.row?1:-1})},o.sort_by_row_and_col_asc=function(t){return t=t.sort(function(t,i){return t.row>i.row||t.row===i.row&&t.col>i.col?1:-1})},o.sort_by_col_asc=function(t){return t=t.sort(function(t,i){return t.col>i.col?1:-1})},o.sort_by_row_desc=function(t){return t=t.sort(function(t,i){return t.row+t.size_y=0&&t.inArray(e,s.rows)>=0},o.is_placeholder_in=function(i,e){var s=this.cells_occupied_by_placeholder||{};return this.is_placeholder_in_col(i)&&t.inArray(e,s.rows)>=0},o.is_placeholder_in_col=function(i){var e=this.cells_occupied_by_placeholder||[];return t.inArray(i,e.cols)>=0},o.is_empty=function(t,i){return this.gridmap[t]!==undefined?this.gridmap[t][i]!==undefined&&this.gridmap[t][i]===!1?!0:!1:!0},o.is_occupied=function(t,i){return this.gridmap[t]?this.gridmap[t][i]?!0:!1:!1},o.is_widget=function(t,i){var e=this.gridmap[t];return e?(e=e[i],e?e:!1):!1},o.is_widget_under_player=function(t,i){return this.is_widget(t,i)?this.is_player_in(t,i):!1},o.get_widgets_under_player=function(i){i||(i=this.cells_occupied_by_player||{cols:[],rows:[]});var e=t([]);return t.each(i.cols,t.proxy(function(s,r){t.each(i.rows,t.proxy(function(t,i){this.is_widget(r,i)&&(e=e.add(this.gridmap[r][i]))},this))},this)),e},o.set_placeholder=function(i,e){var s=t.extend({},this.placeholder_grid_data),r=this.widgets_below({col:s.col,row:s.row,size_y:s.size_y,size_x:s.size_x}),o=i+s.size_x-1;o>this.cols&&(i-=o-i);var a=e>this.placeholder_grid_data.row,n=this.placeholder_grid_data.col!==i;this.placeholder_grid_data.col=i,this.placeholder_grid_data.row=e,this.cells_occupied_by_placeholder=this.get_cells_occupied(this.placeholder_grid_data),this.$preview_holder.attr({"data-row":e,"data-col":i}),(a||n)&&r.each(t.proxy(function(e,r){this.move_widget_up(t(r),this.placeholder_grid_data.col-i+s.size_y)},this));var h=this.get_widgets_under_player(this.cells_occupied_by_placeholder);h.length&&h.each(t.proxy(function(i,r){var o=t(r);this.move_widget_down(o,e+s.size_y-o.data("coords").grid.row)},this))},o.can_go_player_up=function(t){var i=t.row+t.size_y-1,e=!0,s=[],r=1e4,o=this.get_widgets_under_player();return this.for_each_column_occupied(t,function(t){var a=this.gridmap[t],n=i+1;for(s[t]=[];--n>0&&(this.is_empty(t,n)||this.is_player(t,n)||this.is_widget(t,n)&&a[n].is(o));)s[t].push(n),r=r>n?n:r;return 0===s[t].length?(e=!1,!0):(s[t].sort(function(t,i){return t-i}),undefined)}),e?this.get_valid_rows(t,s,r):!1},o.can_go_widget_up=function(t){var i=t.row+t.size_y-1,e=!0,s=[],r=1e4;return this.for_each_column_occupied(t,function(o){var a=this.gridmap[o];s[o]=[];for(var n=i+1;--n>0&&(!this.is_widget(o,n)||this.is_player_in(o,n)||a[n].is(t.el));)this.is_player(o,n)||this.is_placeholder_in(o,n)||this.is_player_in(o,n)||s[o].push(n),r>n&&(r=n);return 0===s[o].length?(e=!1,!0):(s[o].sort(function(t,i){return t-i}),undefined)}),e?this.get_valid_rows(t,s,r):!1},o.get_valid_rows=function(i,e,s){for(var r=i.row,o=i.row+i.size_y-1,a=i.size_y,n=s-1,h=[];o>=++n;){var _=!0;if(t.each(e,function(i,e){t.isArray(e)&&-1===t.inArray(n,e)&&(_=!1)}),_===!0&&(h.push(n),h.length===a))break}var d=!1;return 1===a?h[0]!==r&&(d=h[0]||!1):h[0]!==r&&(d=this.get_consecutive_numbers_index(h,a)),d},o.get_consecutive_numbers_index=function(t,i){for(var e=t.length,s=[],r=!0,o=-1,a=0;e>a;a++){if(r||t[a]===o+1){if(s.push(a),s.length===i)break;r=!1}else s=[],r=!0;o=t[a]}return s.length>=i?t[s[0]]:!1},o.get_widgets_overlapped=function(){var i=t([]),e=[],s=this.cells_occupied_by_player.rows.slice(0);return s.reverse(),t.each(this.cells_occupied_by_player.cols,t.proxy(function(r,o){t.each(s,t.proxy(function(s,r){if(!this.gridmap[o])return!0;var a=this.gridmap[o][r];this.is_occupied(o,r)&&!this.is_player(a)&&-1===t.inArray(a,e)&&(i=i.add(a),e.push(a))},this))},this)),i},o.on_start_overlapping_column=function(t){this.set_player(t,!1)},o.on_start_overlapping_row=function(t){this.set_player(!1,t)},o.on_stop_overlapping_column=function(t){this.set_player(t,!1);var i=this;this.for_each_widget_below(t,this.cells_occupied_by_player.rows[0],function(){i.move_widget_up(this,i.player_grid_data.size_y)})},o.on_stop_overlapping_row=function(t){this.set_player(!1,t);for(var i=this,e=this.cells_occupied_by_player.cols,s=0,r=e.length;r>s;s++)this.for_each_widget_below(e[s],t,function(){i.move_widget_up(this,i.player_grid_data.size_y)})},o.move_widget_to=function(i,e){var s=this,r=i.coords().grid;e-r.row;var o=this.widgets_below(i),a=this.can_move_to(r,r.col,e,i);return a===!1?!1:(this.remove_from_gridmap(r),r.row=e,this.add_to_gridmap(r),i.attr("data-row",e),this.$changed=this.$changed.add(i),o.each(function(i,e){var r=t(e),o=r.coords().grid,a=s.can_go_widget_up(o);a&&a!==o.row&&s.move_widget_to(r,a)}),this)},o.move_widget_up=function(i,e){var s=i.coords().grid,r=s.row,o=[];return e||(e=1),this.can_go_up(i)?(this.for_each_column_occupied(s,function(s){if(-1===t.inArray(i,o)){var a=i.coords().grid,n=r-e;if(n=this.can_go_up_to_row(a,s,n),!n)return!0;var h=this.widgets_below(i);this.remove_from_gridmap(a),a.row=n,this.add_to_gridmap(a),i.attr("data-row",a.row),this.$changed=this.$changed.add(i),o.push(i),h.each(t.proxy(function(i,s){this.move_widget_up(t(s),e)},this))}}),undefined):!1},o.move_widget_down=function(i,e){var s,r,o,a;if(0>=e)return!1;if(s=i.coords().grid,r=s.row,o=[],a=e,!i)return!1;if(-1===t.inArray(i,o)){var n=i.coords().grid,h=r+e,_=this.widgets_below(i);this.remove_from_gridmap(n),_.each(t.proxy(function(i,e){var s=t(e),r=s.coords().grid,o=this.displacement_diff(r,n,a);o>0&&this.move_widget_down(s,o)},this)),n.row=h,this.update_widget_position(n,i),i.attr("data-row",n.row),this.$changed=this.$changed.add(i),o.push(i)}},o.can_go_up_to_row=function(i,e,s){var r,o=this.gridmap,a=!0,n=[],h=i.row;if(this.for_each_column_occupied(i,function(t){for(o[t],n[t]=[],r=h;r--&&this.is_empty(t,r)&&!this.is_placeholder_in(t,r);)n[t].push(r);return n[t].length?undefined:(a=!1,!0)}),!a)return!1;for(r=s,r=1;h>r;r++){for(var _=!0,d=0,l=n.length;l>d;d++)n[d]&&-1===t.inArray(r,n[d])&&(_=!1);if(_===!0){a=r;break}}return a},o.displacement_diff=function(t,i,e){var s=t.row,r=[],o=i.row+i.size_y;this.for_each_column_occupied(t,function(t){for(var i=0,e=o;s>e;e++)this.is_empty(t,e)&&(i+=1);r.push(i)});var a=Math.max.apply(Math,r);return e-=a,e>0?e:0},o.widgets_below=function(i){var e=t.isPlainObject(i)?i:i.coords().grid,s=this;this.gridmap;var r=e.row+e.size_y-1,o=t([]);return this.for_each_column_occupied(e,function(i){s.for_each_widget_below(i,r,function(){return s.is_player(this)||-1!==t.inArray(this,o)?undefined:(o=o.add(this),!0)})}),this.sort_by_row_asc(o)},o.set_cells_player_occupies=function(t,i){return this.remove_from_gridmap(this.placeholder_grid_data),this.placeholder_grid_data.col=t,this.placeholder_grid_data.row=i,this.add_to_gridmap(this.placeholder_grid_data,this.$player),this},o.empty_cells_player_occupies=function(){return this.remove_from_gridmap(this.placeholder_grid_data),this},o.can_go_up=function(t){var i=t.coords().grid,e=i.row,s=e-1;this.gridmap;var r=!0;return 1===e?!1:(this.for_each_column_occupied(i,function(t){return this.is_widget(t,s),this.is_occupied(t,s)||this.is_player(t,s)||this.is_placeholder_in(t,s)||this.is_player_in(t,s)?(r=!1,!0):undefined
+}),r)},o.can_move_to=function(t,i,e,s){this.gridmap;var r=t.el,o={size_y:t.size_y,size_x:t.size_x,col:i,row:e},a=!0,n=i+t.size_x-1;return n>this.cols?!1:s&&e+t.size_y-1>s?!1:(this.for_each_cell_occupied(o,function(i,e){var s=this.is_widget(i,e);!s||t.el&&!s.is(r)||(a=!1)}),a)},o.get_targeted_columns=function(t){for(var i=(t||this.player_grid_data.col)+(this.player_grid_data.size_x-1),e=[],s=t;i>=s;s++)e.push(s);return e},o.get_targeted_rows=function(t){for(var i=(t||this.player_grid_data.row)+(this.player_grid_data.size_y-1),e=[],s=t;i>=s;s++)e.push(s);return e},o.get_cells_occupied=function(t){var i,e={cols:[],rows:[]};for(arguments[1]instanceof jQuery&&(t=arguments[1].coords().grid),i=0;t.size_x>i;i++){var s=t.col+i;e.cols.push(s)}for(i=0;t.size_y>i;i++){var r=t.row+i;e.rows.push(r)}return e},o.for_each_cell_occupied=function(t,i){return this.for_each_column_occupied(t,function(e){this.for_each_row_occupied(t,function(t){i.call(this,e,t)})}),this},o.for_each_column_occupied=function(t,i){for(var e=0;t.size_x>e;e++){var s=t.col+e;i.call(this,s,t)}},o.for_each_row_occupied=function(t,i){for(var e=0;t.size_y>e;e++){var s=t.row+e;i.call(this,s,t)}},o._traversing_widgets=function(i,e,s,r,o){var a=this.gridmap;if(a[s]){var n,h,_=i+"/"+e;if(arguments[2]instanceof jQuery){var d=arguments[2].coords().grid;s=d.col,r=d.row,o=arguments[3]}var l=[],c=r,p={"for_each/above":function(){for(;c--&&!(c>0&&this.is_widget(s,c)&&-1===t.inArray(a[s][c],l)&&(n=o.call(a[s][c],s,c),l.push(a[s][c]),n)););},"for_each/below":function(){for(c=r+1,h=a[s].length;h>c&&(!this.is_widget(s,c)||-1!==t.inArray(a[s][c],l)||(n=o.call(a[s][c],s,c),l.push(a[s][c]),!n));c++);}};p[_]&&p[_].call(this)}},o.for_each_widget_above=function(t,i,e){return this._traversing_widgets("for_each","above",t,i,e),this},o.for_each_widget_below=function(t,i,e){return this._traversing_widgets("for_each","below",t,i,e),this},o.get_highest_occupied_cell=function(){for(var t,i=this.gridmap,e=[],s=[],r=i.length-1;r>=1;r--)for(t=i[r].length-1;t>=1;t--)if(this.is_widget(r,t)){e.push(t),s[t]=r;break}var o=Math.max.apply(Math,e);return this.highest_occupied_cell={col:s[o],row:o},this.highest_occupied_cell},o.get_widgets_from=function(i,e){this.gridmap;var s=t();return i&&(s=s.add(this.$widgets.filter(function(){var e=t(this).attr("data-col");return e===i||e>i}))),e&&(s=s.add(this.$widgets.filter(function(){var i=t(this).attr("data-row");return i===e||i>e}))),s},o.set_dom_grid_height=function(){var t=this.get_highest_occupied_cell().row;return this.$el.css("height",t*this.min_widget_height),this},o.generate_stylesheet=function(i){var e,r="",o=this.options.max_size_x||this.cols;i||(i={}),i.cols||(i.cols=this.cols),i.rows||(i.rows=this.rows),i.namespace||(i.namespace=this.options.namespace),i.widget_base_dimensions||(i.widget_base_dimensions=this.options.widget_base_dimensions),i.widget_margins||(i.widget_margins=this.options.widget_margins),i.min_widget_width=2*i.widget_margins[0]+i.widget_base_dimensions[0],i.min_widget_height=2*i.widget_margins[1]+i.widget_base_dimensions[1];var a=t.param(i);if(t.inArray(a,s.generated_stylesheets)>=0)return!1;for(s.generated_stylesheets.push(a),e=i.cols;e>=0;e--)r+=i.namespace+' [data-col="'+(e+1)+'"] { left:'+(e*i.widget_base_dimensions[0]+e*i.widget_margins[0]+(e+1)*i.widget_margins[0])+"px; }\n";for(e=i.rows;e>=0;e--)r+=i.namespace+' [data-row="'+(e+1)+'"] { top:'+(e*i.widget_base_dimensions[1]+e*i.widget_margins[1]+(e+1)*i.widget_margins[1])+"px; }\n";for(var n=1;i.rows>=n;n++)r+=i.namespace+' [data-sizey="'+n+'"] { height:'+(n*i.widget_base_dimensions[1]+(n-1)*2*i.widget_margins[1])+"px; }\n";for(var h=1;o>=h;h++)r+=i.namespace+' [data-sizex="'+h+'"] { width:'+(h*i.widget_base_dimensions[0]+(h-1)*2*i.widget_margins[0])+"px; }\n";return this.add_style_tag(r)},o.add_style_tag=function(t){var i=e,s=i.createElement("style");return i.getElementsByTagName("head")[0].appendChild(s),s.setAttribute("type","text/css"),s.styleSheet?s.styleSheet.cssText=t:s.appendChild(e.createTextNode(t)),this.$style_tags=this.$style_tags.add(s),this},o.remove_style_tags=function(){this.$style_tags.remove()},o.generate_faux_grid=function(t,i){this.faux_grid=[],this.gridmap=[];var e,s;for(e=i;e>0;e--)for(this.gridmap[e]=[],s=t;s>0;s--)this.add_faux_cell(s,e);return this},o.add_faux_cell=function(i,e){var s=t({left:this.baseX+(e-1)*this.min_widget_width,top:this.baseY+(i-1)*this.min_widget_height,width:this.min_widget_width,height:this.min_widget_height,col:e,row:i,original_col:e,original_row:i}).coords();return t.isArray(this.gridmap[e])||(this.gridmap[e]=[]),this.gridmap[e][i]=!1,this.faux_grid.push(s),this},o.add_faux_rows=function(t){for(var i=this.rows,e=i+(t||1),s=e;s>i;s--)for(var r=this.cols;r>=1;r--)this.add_faux_cell(s,r);return this.rows=e,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this},o.add_faux_cols=function(t){for(var i=this.cols,e=i+(t||1),s=i;e>s;s++)for(var r=this.rows;r>=1;r--)this.add_faux_cell(r,s);return this.cols=e,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this},o.recalculate_faux_grid=function(){var e=this.$wrapper.width();return this.baseX=(t(i).width()-e)/2,this.baseY=this.$wrapper.offset().top,t.each(this.faux_grid,t.proxy(function(t,i){this.faux_grid[t]=i.update({left:this.baseX+(i.data.col-1)*this.min_widget_width,top:this.baseY+(i.data.row-1)*this.min_widget_height})},this)),this},o.get_widgets_from_DOM=function(){return this.$widgets.each(t.proxy(function(i,e){this.register_widget(t(e))},this)),this},o.generate_grid_and_stylesheet=function(){var e=this.$wrapper.width();this.$wrapper.height();var s=this.options.max_cols,r=Math.floor(e/this.min_widget_width)+this.options.extra_cols,o=this.$widgets.map(function(){return t(this).attr("data-col")}).get();o.length||(o=[0]);var a=Math.max.apply(Math,o),n=this.options.extra_rows;return this.$widgets.each(function(i,e){n+=+t(e).attr("data-sizey")}),this.cols=Math.max(a,r,this.options.min_cols),s&&s>=a&&this.cols>s&&(this.cols=s),this.rows=Math.max(n,this.options.min_rows),this.baseX=(t(i).width()-e)/2,this.baseY=this.$wrapper.offset().top,this.container_width=this.cols*this.options.widget_base_dimensions[0]+2*(this.cols-1)*this.options.widget_margins[0],this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this.generate_faux_grid(this.rows,this.cols)},o.destroy=function(){return t(i).unbind(".gridster"),this.drag_api&&this.drag_api.destroy(),this.remove_style_tags(),this.$el.remove(),this},t.fn.gridster=function(i){return this.each(function(){t(this).data("gridster")||t(this).data("gridster",new s(this,i))})},t.Gridster=o}(jQuery,window,document);
\ No newline at end of file
diff --git a/dist/jquery.gridster.with-extras.js b/dist/jquery.gridster.with-extras.js
index 2409c767c..6269c79e2 100644
--- a/dist/jquery.gridster.with-extras.js
+++ b/dist/jquery.gridster.with-extras.js
@@ -1,4 +1,4 @@
-/*! gridster.js - v0.1.0 - 2013-06-14
+/*! gridster.js - v0.2.0 - 2013-10-26
* http://gridster.net/
* Copyright (c) 2013 ducksboard; Licensed MIT */
@@ -317,6 +317,14 @@
}(jQuery, window, document));
;(function(window, undefined) {
+
+
+ window.delay = function(func, wait) {
+ var args = Array.prototype.slice.call(arguments, 2);
+ return setTimeout(function(){ return func.apply(null, args); }, wait);
+ };
+
+
/* Debounce and throttle functions taken from underscore.js */
window.debounce = function(func, wait, immediate) {
var timeout;
@@ -358,20 +366,22 @@
})(window);
-;(function($, window, document, undefined){
+;(function($, window, document, undefined) {
var defaults = {
- items: '.gs_w',
+ items: 'li',
distance: 1,
limit: true,
offset_left: 0,
autoscroll: true,
ignore_dragging: ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'],
handle: null,
- container_width: 0 // 0 == auto
- // drag: function(e){},
- // start : function(e, ui){},
- // stop : function(e){}
+ container_width: 0, // 0 == auto
+ move_element: true,
+ helper: false // or 'clone'
+ // drag: function(e) {},
+ // start : function(e, ui) {},
+ // stop : function(e) {}
};
var $window = $(window);
@@ -480,21 +490,36 @@
if (this.options.limit) {
if (left > this.player_max_left) {
left = this.player_max_left;
- }else if(left < this.player_min_left) {
+ } else if(left < this.player_min_left) {
left = this.player_min_left;
}
}
return {
- left: left,
- top: top,
- mouse_left: mouse_actual_pos.left,
- mouse_top: mouse_actual_pos.top
+ position: {
+ left: left,
+ top: top
+ },
+ pointer: {
+ left: mouse_actual_pos.left,
+ top: mouse_actual_pos.top,
+ diff_left: diff_x,
+ diff_top: diff_y + this.scrollOffset
+ }
};
};
- fn.manage_scroll = function(offset) {
+ fn.get_drag_data = function(e) {
+ var offset = this.get_offset(e);
+ offset.$player = this.$player;
+ offset.$helper = this.helper ? this.$helper : this.$player;
+
+ return offset;
+ };
+
+
+ fn.manage_scroll = function(data) {
/* scroll document */
var nextScrollTop;
var scrollTop = $window.scrollTop();
@@ -504,8 +529,8 @@
var mouse_down_zone = max_window_y - 50;
var mouse_up_zone = min_window_y + 50;
- var abs_mouse_left = offset.mouse_left;
- var abs_mouse_top = min_window_y + offset.mouse_top;
+ var abs_mouse_left = data.pointer.left;
+ var abs_mouse_top = min_window_y + data.pointer.top;
var max_player_y = (this.doc_height - this.window_height +
this.player_height);
@@ -551,7 +576,7 @@
this.mouse_init_pos = this.get_mouse_pos(e);
this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top;
- this.$body.on(pointer_events.move, function(mme){
+ this.$body.on(pointer_events.move, function(mme) {
var mouse_actual_pos = self.get_mouse_pos(mme);
var diff_x = Math.abs(
mouse_actual_pos.left - self.mouse_init_pos.left);
@@ -582,8 +607,10 @@
fn.on_dragstart = function(e) {
e.preventDefault();
- this.drag_start = true;
- this.is_dragging = true;
+
+ if (this.is_dragging) { return this; }
+
+ this.drag_start = this.is_dragging = true;
var offset = this.$container.offset();
this.baseX = Math.round(offset.left);
this.baseY = Math.round(offset.top);
@@ -593,9 +620,10 @@
this.$helper = this.$player.clone()
.appendTo(this.$container).addClass('helper');
this.helper = true;
- }else{
+ } else {
this.helper = false;
}
+
this.scrollOffset = 0;
this.el_init_offset = this.$player.offset();
this.player_width = this.$player.width();
@@ -606,52 +634,43 @@
this.options.offset_left);
if (this.options.start) {
- this.options.start.call(this.$player, e, {
- helper: this.helper ? this.$helper : this.$player
- });
+ this.options.start.call(this.$player, e, this.get_drag_data(e));
}
return false;
};
fn.on_dragmove = function(e) {
- var offset = this.get_offset(e);
+ var data = this.get_drag_data(e);
- this.options.autoscroll && this.manage_scroll(offset);
+ this.options.autoscroll && this.manage_scroll(data);
- (this.helper ? this.$helper : this.$player).css({
- 'position': 'absolute',
- 'left' : offset.left,
- 'top' : offset.top
- });
+ if (this.options.move_element) {
+ (this.helper ? this.$helper : this.$player).css({
+ 'position': 'absolute',
+ 'left' : data.position.left,
+ 'top' : data.position.top
+ });
+ }
- var ui = {
- 'position': {
- 'left': offset.left,
- 'top': offset.top
- }
- };
+ var last_position = this.last_position || data.position;
+ data.prev_position = last_position;
if (this.options.drag) {
- this.options.drag.call(this.$player, e, ui);
+ this.options.drag.call(this.$player, e, data);
}
+
+ this.last_position = data.position;
return false;
};
fn.on_dragstop = function(e) {
- var offset = this.get_offset(e);
+ var data = this.get_drag_data(e);
this.drag_start = false;
- var ui = {
- 'position': {
- 'left': offset.left,
- 'top': offset.top
- }
- };
-
if (this.options.stop) {
- this.options.stop.call(this.$player, e, ui);
+ this.options.stop.call(this.$player, e, data);
}
if (this.helper) {
@@ -679,8 +698,7 @@
this.disabled = true;
};
-
- fn.destroy = function(){
+ fn.destroy = function() {
this.disable();
this.$container.off('.gridster-draggable');
@@ -695,16 +713,12 @@
return !$(event.target).is(this.options.handle);
}
- return $.inArray(event.target.nodeName, this.options.ignore_dragging) >= 0;
+ return $(event.target).is(this.options.ignore_dragging.join(', '));
};
//jQuery adapter
$.fn.drag = function ( options ) {
- return this.each(function () {
- if (!$.data(this, 'drag')) {
- $.data(this, 'drag', new Draggable( this, options ));
- }
- });
+ return new Draggable(this, options);
};
@@ -722,7 +736,7 @@
min_cols: 1,
max_cols: null,
min_rows: 15,
- max_size_x: 6,
+ max_size_x: false,
autogenerate_stylesheet: true,
avoid_overlapped_widgets: true,
serialize_params: function($w, wgd) {
@@ -735,7 +749,15 @@
},
collision: {},
draggable: {
+ items: '.gs-w',
distance: 4
+ },
+ resize: {
+ enabled: false,
+ axes: ['x', 'y', 'both'],
+ handle_append_to: '',
+ handle_class: 'gs-resize-handle',
+ max_size: [Infinity, Infinity]
}
};
@@ -784,6 +806,19 @@
* @param {Object} [options.draggable] An Object with all options for
* Draggable class you want to overwrite. See Draggable docs for more
* info.
+ * @param {Object} [options.resize] An Object with resize config
+ * options.
+ * @param {Boolean} [options.resize.enabled] Set to true to enable
+ * resizing.
+ * @param {Array} [options.resize.axes] Axes in which widgets can be
+ * resized. Possible values: ['x', 'y', 'both'].
+ * @param {String} [options.resize.handle_append_to] Set a valid CSS
+ * selector to append resize handles to.
+ * @param {String} [options.resize.handle_class] CSS class name used
+ * by resize handles.
+ * @param {Array} [options.resize.max_size] Limit widget dimensions
+ * when resizing. Array values should be integers:
+ * `[max_cols_occupied, max_rows_occupied]`
*
* @constructor
*/
@@ -791,7 +826,8 @@
this.options = $.extend(true, defaults, options);
this.$el = $(el);
this.$wrapper = this.$el.parent();
- this.$widgets = this.$el.children(this.options.widget_selector).addClass('gs_w');
+ this.$widgets = this.$el.children(
+ this.options.widget_selector).addClass('gs-w');
this.widgets = [];
this.$changed = $([]);
this.wrapper_width = this.$wrapper.width();
@@ -810,13 +846,16 @@
var fn = Gridster.prototype;
fn.init = function() {
+ this.options.resize.enabled && this.setup_resize();
this.generate_grid_and_stylesheet();
this.get_widgets_from_DOM();
this.set_dom_grid_height();
this.$wrapper.addClass('ready');
this.draggable();
+ this.options.resize.enabled && this.resizable();
- $(window).bind('resize.gridster', throttle($.proxy(this.recalculate_faux_grid, this), 200));
+ $(window).bind('resize.gridster', throttle(
+ $.proxy(this.recalculate_faux_grid, this), 200));
};
@@ -845,6 +884,33 @@
};
+
+ /**
+ * Disables drag-and-drop widget resizing.
+ *
+ * @method disable
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.disable_resize = function() {
+ this.$el.addClass('gs-resize-disabled');
+ this.resize_api.disable();
+ return this;
+ };
+
+
+ /**
+ * Enables drag-and-drop widget resizing.
+ *
+ * @method enable
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.enable_resize = function() {
+ this.$el.removeClass('gs-resize-disabled');
+ this.resize_api.enable();
+ return this;
+ };
+
+
/**
* Add a new widget to the grid.
*
@@ -855,10 +921,11 @@
* @param {Number} [size_y] The nÂș of columns the widget occupies vertically.
* @param {Number} [col] The column the widget should start in.
* @param {Number} [row] The row the widget should start in.
+ * @param {Array} [max_size] max_size Maximun size (in units) for width and height.
* @return {HTMLElement} Returns the jQuery wrapped HTMLElement representing.
* the widget that was just created.
*/
- fn.add_widget = function(html, size_x, size_y, col, row) {
+ fn.add_widget = function(html, size_x, size_y, col, row, max_size) {
var pos;
size_x || (size_x = 1);
size_y || (size_y = 1);
@@ -879,7 +946,7 @@
'data-row': pos.row,
'data-sizex' : size_x,
'data-sizey' : size_y
- }).addClass('gs_w').appendTo(this.$el).hide();
+ }).addClass('gs-w').appendTo(this.$el).hide();
this.$widgets = this.$widgets.add($w);
@@ -888,26 +955,73 @@
this.add_faux_rows(pos.size_y);
//this.add_faux_cols(pos.size_x);
+ if (max_size) {
+ this.set_widget_max_size($w, max_size);
+ }
+
this.set_dom_grid_height();
return $w.fadeIn();
};
+ /**
+ * Change widget size limits.
+ *
+ * @method set_widget_max_size
+ * @param {HTMLElement|Number} $widget The jQuery wrapped HTMLElement
+ * representing the widget or an index representing the desired widget.
+ * @param {Array} max_size Maximun size (in units) for width and height.
+ * @return {HTMLElement} Returns instance of gridster Class.
+ */
+ fn.set_widget_max_size = function($widget, max_size) {
+ $widget = typeof $widget === 'number' ?
+ this.$widgets.eq($widget) : $widget;
- /**
- * Change the size of a widget.
+ if (!$widget.length) { return this; }
+
+ var wgd = $widget.data('coords').grid;
+ wgd.max_size_x = max_size[0];
+ wgd.max_size_y = max_size[1];
+
+ return this;
+ };
+
+
+ /**
+ * Append the resize handle into a widget.
+ *
+ * @method add_resize_handle
+ * @param {HTMLElement} $widget The jQuery wrapped HTMLElement
+ * representing the widget.
+ * @return {HTMLElement} Returns instance of gridster Class.
+ */
+ fn.add_resize_handle = function($w) {
+ var append_to = this.options.resize.handle_append_to;
+ $(this.resize_handle_tpl).appendTo( append_to ? $(append_to, $w) : $w);
+
+ return this;
+ };
+
+
+ /**
+ * Change the size of a widget. Width is limited to the current grid width.
*
* @method resize_widget
* @param {HTMLElement} $widget The jQuery wrapped HTMLElement
* representing the widget.
* @param {Number} size_x The number of columns that will occupy the widget.
* @param {Number} size_y The number of rows that will occupy the widget.
- * @param {Function} callback Function executed when the widget is removed.
+ * @param {Boolean} [reposition] Set to false to not move the widget to
+ * the left if there is insufficient space on the right.
+ * By default size_x is limited to the space available from
+ * the column where the widget begins, until the last column to the right.
+ * @param {Function} [callback] Function executed when the widget is removed.
* @return {HTMLElement} Returns $widget.
*/
- fn.resize_widget = function($widget, size_x, size_y, callback) {
+ fn.resize_widget = function($widget, size_x, size_y, reposition, callback) {
var wgd = $widget.coords().grid;
+ reposition !== false && (reposition = true);
size_x || (size_x = wgd.size_x);
size_y || (size_y = wgd.size_y);
@@ -915,20 +1029,20 @@
size_x = this.cols;
}
- var old_cells_occupied = this.get_cells_occupied(wgd);
- var old_size_x = wgd.size_x;
var old_size_y = wgd.size_y;
var old_col = wgd.col;
var new_col = old_col;
- var wider = size_x > old_size_x;
- var taller = size_y > old_size_y;
- if (old_col + size_x - 1 > this.cols) {
+ if (reposition && old_col + size_x - 1 > this.cols) {
var diff = old_col + (size_x - 1) - this.cols;
var c = old_col - diff;
new_col = Math.max(1, c);
}
+ if (size_y > old_size_y) {
+ this.add_faux_rows(Math.max(size_y - old_size_y, 0));
+ }
+
var new_grid_data = {
col: new_col,
row: wgd.row,
@@ -936,7 +1050,34 @@
size_y: size_y
};
- var new_cells_occupied = this.get_cells_occupied(new_grid_data);
+ this.mutate_widget_in_gridmap($widget, wgd, new_grid_data);
+
+ this.set_dom_grid_height();
+
+ if (callback) {
+ callback.call(this, new_grid_data.size_x, new_grid_data.size_y);
+ }
+
+ return $widget;
+ };
+
+
+ /**
+ * Mutate widget dimensions and position in the grid map.
+ *
+ * @method mutate_widget_in_gridmap
+ * @param {HTMLElement} $widget The jQuery wrapped HTMLElement
+ * representing the widget to mutate.
+ * @param {Object} wgd Current widget grid data (col, row, size_x, size_y).
+ * @param {Object} new_wgd New widget grid data.
+ * @return {HTMLElement} Returns instance of gridster Class.
+ */
+ fn.mutate_widget_in_gridmap = function($widget, wgd, new_wgd) {
+ var old_size_x = wgd.size_x;
+ var old_size_y = wgd.size_y;
+
+ var old_cells_occupied = this.get_cells_occupied(wgd);
+ var new_cells_occupied = this.get_cells_occupied(new_wgd);
var empty_cols = [];
$.each(old_cells_occupied.cols, function(i, col) {
@@ -970,48 +1111,46 @@
if (occupied_cols.length) {
var cols_to_empty = [
- new_col, wgd.row, size_x, Math.min(old_size_y, size_y), $widget
+ new_wgd.col, new_wgd.row, new_wgd.size_x, Math.min(old_size_y, new_wgd.size_y), $widget
];
this.empty_cells.apply(this, cols_to_empty);
}
if (occupied_rows.length) {
- var rows_to_empty = [new_col, wgd.row, size_x, size_y, $widget];
+ var rows_to_empty = [new_wgd.col, new_wgd.row, new_wgd.size_x, new_wgd.size_y, $widget];
this.empty_cells.apply(this, rows_to_empty);
}
- wgd.col = new_col;
- wgd.size_x = size_x;
- wgd.size_y = size_y;
- this.add_to_gridmap(new_grid_data, $widget);
+ // not the same that wgd = new_wgd;
+ wgd.col = new_wgd.col;
+ wgd.row = new_wgd.row;
+ wgd.size_x = new_wgd.size_x;
+ wgd.size_y = new_wgd.size_y;
+
+ this.add_to_gridmap(new_wgd, $widget);
+
+ $widget.removeClass('player-revert');
//update coords instance attributes
$widget.data('coords').update({
- width: (size_x * this.options.widget_base_dimensions[0] +
- ((size_x - 1) * this.options.widget_margins[0]) * 2),
- height: (size_y * this.options.widget_base_dimensions[1] +
- ((size_y - 1) * this.options.widget_margins[1]) * 2)
+ width: (new_wgd.size_x * this.options.widget_base_dimensions[0] +
+ ((new_wgd.size_x - 1) * this.options.widget_margins[0]) * 2),
+ height: (new_wgd.size_y * this.options.widget_base_dimensions[1] +
+ ((new_wgd.size_y - 1) * this.options.widget_margins[1]) * 2)
});
- if (size_y > old_size_y) {
- this.add_faux_rows(size_y - old_size_y);
- }
-
- if (size_x > old_size_x) {
- this.add_faux_cols(size_x - old_size_x);
- }
-
$widget.attr({
- 'data-col': new_col,
- 'data-sizex': size_x,
- 'data-sizey': size_y
+ 'data-col': new_wgd.col,
+ 'data-row': new_wgd.row,
+ 'data-sizex': new_wgd.size_x,
+ 'data-sizey': new_wgd.size_y
});
if (empty_cols.length) {
var cols_to_remove_holes = [
- empty_cols[0], wgd.row,
+ empty_cols[0], new_wgd.row,
empty_cols.length,
- Math.min(old_size_y, size_y),
+ Math.min(old_size_y, new_wgd.size_y),
$widget
];
@@ -1020,18 +1159,17 @@
if (empty_rows.length) {
var rows_to_remove_holes = [
- new_col, wgd.row, size_x, size_y, $widget
+ new_wgd.col, new_wgd.row, new_wgd.size_x, new_wgd.size_y, $widget
];
this.remove_empty_cells.apply(this, rows_to_remove_holes);
}
- if (callback) {
- callback.call(this, size_x, size_y);
- }
+ this.move_widget_up($widget);
- return $widget;
+ return this;
};
+
/**
* Move down widgets in cells represented by the arguments col, row, size_x,
* size_y
@@ -1184,6 +1322,8 @@
callback.call(this, el);
}
}, this));
+
+ return this;
};
@@ -1246,12 +1386,13 @@
* @return {Array} Returns the instance of the Gridster class.
*/
fn.register_widget = function($el) {
-
var wgd = {
'col': parseInt($el.attr('data-col'), 10),
'row': parseInt($el.attr('data-row'), 10),
'size_x': parseInt($el.attr('data-sizex'), 10),
'size_y': parseInt($el.attr('data-sizey'), 10),
+ 'max_size_x': parseInt($el.attr('data-max-sizex'), 10) || false,
+ 'max_size_y': parseInt($el.attr('data-max-sizey'), 10) || false,
'el': $el
};
@@ -1259,8 +1400,7 @@
!this.can_move_to(
{size_x: wgd.size_x, size_y: wgd.size_y}, wgd.col, wgd.row)
) {
- wgd = this.next_position(wgd.size_x, wgd.size_y);
- wgd.el = $el;
+ $.extend(wgd, this.next_position(wgd.size_x, wgd.size_y));
$el.attr({
'data-col': wgd.col,
'data-row': wgd.row,
@@ -1271,12 +1411,13 @@
// attach Coord object to player data-coord attribute
$el.data('coords', $el.coords());
-
// Extend Coord object with grid position info
$el.data('coords').grid = wgd;
this.add_to_gridmap(wgd, $el);
+ this.options.resize.enabled && this.add_resize_handle($el);
+
return this;
};
@@ -1349,13 +1490,15 @@
var draggable_options = $.extend(true, {}, this.options.draggable, {
offset_left: this.options.widget_margins[0],
container_width: this.container_width,
+ ignore_dragging: ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON',
+ '.' + this.options.resize.handle_class],
start: function(event, ui) {
self.$widgets.filter('.player-revert')
.removeClass('player-revert');
self.$player = $(this);
- self.$helper = self.options.draggable.helper === 'clone' ?
- $(ui.helper) : self.$player;
+ self.$helper = $(ui.$helper);
+
self.helper = !self.$helper.is(self.$player);
self.on_start_drag.call(self, event, ui);
@@ -1371,7 +1514,51 @@
}, 60)
});
- this.drag_api = this.$el.drag(draggable_options).data('drag');
+ this.drag_api = this.$el.drag(draggable_options);
+ return this;
+ };
+
+
+ /**
+ * Bind resize events to get resize working.
+ *
+ * @method resizable
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.resizable = function() {
+ this.resize_api = this.$el.drag({
+ items: '.' + this.options.resize.handle_class,
+ offset_left: this.options.widget_margins[0],
+ container_width: this.container_width,
+ move_element: false,
+ start: $.proxy(this.on_start_resize, this),
+ stop: $.proxy(function(event, ui) {
+ delay($.proxy(function() {
+ this.on_stop_resize(event, ui);
+ }, this), 120);
+ }, this),
+ drag: throttle($.proxy(this.on_resize, this), 60)
+ });
+
+ return this;
+ };
+
+
+ /**
+ * Setup things required for resizing. Like build templates for drag handles.
+ *
+ * @method setup_resize
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.setup_resize = function() {
+ this.resize_handle_class = this.options.resize.handle_class;
+ var axes = this.options.resize.axes;
+ var handle_tpl = '';
+
+ this.resize_handle_tpl = $.map(axes, function(type) {
+ return handle_tpl.replace('{type}', type);
+ }).join('');
return this;
};
@@ -1381,10 +1568,9 @@
*
* @method on_start_drag
* @param {Event} event The original browser event
- * @param {Object} ui A prepared ui object.
+ * @param {Object} ui A prepared ui object with useful drag-related data
*/
fn.on_start_drag = function(event, ui) {
-
this.$helper.add(this.$player).add(this.$wrapper).addClass('dragging');
this.$player.addClass('player');
@@ -1406,12 +1592,11 @@
this.last_cols = [];
this.last_rows = [];
-
// see jquery.collision.js
this.collision_api = this.$helper.collision(
colliders, this.options.collision);
- this.$preview_holder = $('', {
+ this.$preview_holder = $('<' + this.$player.get(0).tagName + ' />', {
'class': 'preview-holder',
'data-row': this.$player.attr('data-row'),
'data-col': this.$player.attr('data-col'),
@@ -1432,7 +1617,7 @@
*
* @method on_drag
* @param {Event} event The original browser event
- * @param {Object} ui A prepared ui object.
+ * @param {Object} ui A prepared ui object with useful drag-related data
*/
fn.on_drag = function(event, ui) {
//break if dragstop has been fired
@@ -1475,7 +1660,7 @@
*
* @method on_stop_drag
* @param {Event} event The original browser event
- * @param {Object} ui A prepared ui object.
+ * @param {Object} ui A prepared ui object with useful drag-related data
*/
fn.on_stop_drag = function(event, ui) {
this.$helper.add(this.$player).add(this.$wrapper)
@@ -1483,7 +1668,8 @@
ui.position.left = ui.position.left + this.baseX;
ui.position.top = ui.position.top + this.baseY;
- this.colliders_data = this.collision_api.get_closest_colliders(ui.position);
+ this.colliders_data = this.collision_api.get_closest_colliders(
+ ui.position);
this.on_overlapped_column_change(
this.on_start_overlapping_column,
@@ -1531,6 +1717,148 @@
};
+
+ /**
+ * This function is executed every time a widget starts to be resized.
+ *
+ * @method on_start_resize
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_start_resize = function(event, ui) {
+ this.$resized_widget = ui.$player.closest('.gs-w');
+ this.resize_coords = this.$resized_widget.coords();
+ this.resize_wgd = this.resize_coords.grid;
+ this.resize_initial_width = this.resize_coords.coords.width;
+ this.resize_initial_height = this.resize_coords.coords.height;
+ this.resize_initial_sizex = this.resize_coords.grid.size_x;
+ this.resize_initial_sizey = this.resize_coords.grid.size_y;
+ this.resize_last_sizex = this.resize_initial_sizex;
+ this.resize_last_sizey = this.resize_initial_sizey;
+ this.resize_max_size_x = Math.min(this.resize_wgd.max_size_x ||
+ this.options.resize.max_size[0], this.cols - this.resize_wgd.col + 1);
+ this.resize_max_size_y = this.resize_wgd.max_size_y ||
+ this.options.resize.max_size[1];
+
+ this.resize_dir = {
+ right: ui.$player.is('.' + this.resize_handle_class + '-x'),
+ bottom: ui.$player.is('.' + this.resize_handle_class + '-y')
+ };
+
+ this.$resized_widget.css({
+ 'min-width': this.options.widget_base_dimensions[0],
+ 'min-height': this.options.widget_base_dimensions[1]
+ });
+
+ var nodeName = this.$resized_widget.get(0).tagName;
+ this.$resize_preview_holder = $('<' + nodeName + ' />', {
+ 'class': 'preview-holder resize-preview-holder',
+ 'data-row': this.$resized_widget.attr('data-row'),
+ 'data-col': this.$resized_widget.attr('data-col'),
+ 'css': {
+ 'width': this.resize_initial_width,
+ 'height': this.resize_initial_height
+ }
+ }).appendTo(this.$el);
+
+ this.$resized_widget.addClass('resizing');
+ };
+
+
+ /**
+ * This function is executed every time a widget stops being resized.
+ *
+ * @method on_stop_resize
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_stop_resize = function(event, ui) {
+ this.$resized_widget
+ .removeClass('resizing')
+ .css({
+ 'width': '',
+ 'height': ''
+ });
+
+ delay($.proxy(function() {
+ this.$resize_preview_holder
+ .remove()
+ .css({
+ 'min-width': '',
+ 'min-height': ''
+ });
+ }, this), 300);
+ };
+
+ /**
+ * This function is executed when a widget is being resized.
+ *
+ * @method on_resize
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_resize = function(event, ui) {
+ var rel_x = (ui.pointer.diff_left);
+ var rel_y = (ui.pointer.diff_top);
+ var wbd_x = this.options.widget_base_dimensions[0];
+ var wbd_y = this.options.widget_base_dimensions[1];
+ var max_width = Infinity;
+ var max_height = Infinity;
+
+ var inc_units_x = Math.ceil((rel_x /
+ (this.options.widget_base_dimensions[0] +
+ this.options.widget_margins[0] * 2)) - 0.2);
+
+ var inc_units_y = Math.ceil((rel_y /
+ (this.options.widget_base_dimensions[1] +
+ this.options.widget_margins[1] * 2)) - 0.2);
+
+ var size_x = Math.max(1, this.resize_initial_sizex + inc_units_x);
+ var size_y = Math.max(1, this.resize_initial_sizey + inc_units_y);
+
+ size_x = Math.min(size_x, this.resize_max_size_x);
+ max_width = (this.resize_max_size_x * wbd_x) +
+ ((size_x - 1) * this.options.widget_margins[0] * 2);
+
+ size_y = Math.min(size_y, this.resize_max_size_y);
+ max_height = (this.resize_max_size_y * wbd_y) +
+ ((size_y - 1) * this.options.widget_margins[1] * 2);
+
+
+ if (this.resize_dir.right) {
+ size_y = this.resize_initial_sizey;
+ } else if (this.resize_dir.bottom) {
+ size_x = this.resize_initial_sizex;
+ }
+
+ var css_props = {};
+ !this.resize_dir.bottom && (css_props.width = Math.min(
+ this.resize_initial_width + rel_x, max_width));
+ !this.resize_dir.right && (css_props.height = Math.min(
+ this.resize_initial_height + rel_y, max_height));
+
+ this.$resized_widget.css(css_props);
+
+ if (size_x !== this.resize_last_sizex ||
+ size_y !== this.resize_last_sizey) {
+
+ this.resize_widget(this.$resized_widget, size_x, size_y, false);
+
+ this.$resize_preview_holder.css({
+ 'width': '',
+ 'height': ''
+ }).attr({
+ 'data-row': this.$resized_widget.attr('data-row'),
+ 'data-sizex': size_x,
+ 'data-sizey': size_y
+ });
+ }
+
+ this.resize_last_sizex = size_x;
+ this.resize_last_sizey = size_y;
+ };
+
+
/**
* Executes the callbacks passed as arguments when a column begins to be
* overlapped or stops being overlapped.
@@ -2036,8 +2364,9 @@
}, this));
}
+ var $widgets_under_ph = this.get_widgets_under_player(
+ this.cells_occupied_by_placeholder);
- var $widgets_under_ph = this.get_widgets_under_player(this.cells_occupied_by_placeholder);
if ($widgets_under_ph.length) {
$widgets_under_ph.each($.proxy(function(i, widget) {
var $w = $(widget);
@@ -2429,10 +2758,14 @@
* @return {Class} Returns the instance of the Gridster Class.
*/
fn.move_widget_down = function($widget, y_units) {
- var el_grid_data = $widget.coords().grid;
- var actual_row = el_grid_data.row;
- var moved = [];
- var y_diff = y_units;
+ var el_grid_data, actual_row, moved, y_diff;
+
+ if (y_units <= 0) { return false; }
+
+ el_grid_data = $widget.coords().grid;
+ actual_row = el_grid_data.row;
+ moved = [];
+ y_diff = y_units;
if (!$widget) { return false; }
@@ -2971,7 +3304,7 @@
*/
fn.generate_stylesheet = function(opts) {
var styles = '';
- var max_size_x = this.options.max_size_x;
+ var max_size_x = this.options.max_size_x || this.cols;
var max_rows = 0;
var max_cols = 0;
var i;
@@ -3003,7 +3336,7 @@
styles += (opts.namespace + ' [data-col="'+ (i + 1) + '"] { left:' +
((i * opts.widget_base_dimensions[0]) +
(i * opts.widget_margins[0]) +
- ((i + 1) * opts.widget_margins[0])) + 'px;} ');
+ ((i + 1) * opts.widget_margins[0])) + 'px; }\n');
}
/* generate CSS styles for rows */
@@ -3011,19 +3344,19 @@
styles += (opts.namespace + ' [data-row="' + (i + 1) + '"] { top:' +
((i * opts.widget_base_dimensions[1]) +
(i * opts.widget_margins[1]) +
- ((i + 1) * opts.widget_margins[1]) ) + 'px;} ');
+ ((i + 1) * opts.widget_margins[1]) ) + 'px; }\n');
}
for (var y = 1; y <= opts.rows; y++) {
styles += (opts.namespace + ' [data-sizey="' + y + '"] { height:' +
(y * opts.widget_base_dimensions[1] +
- (y - 1) * (opts.widget_margins[1] * 2)) + 'px;}');
+ (y - 1) * (opts.widget_margins[1] * 2)) + 'px; }\n');
}
for (var x = 1; x <= max_size_x; x++) {
styles += (opts.namespace + ' [data-sizex="' + x + '"] { width:' +
(x * opts.widget_base_dimensions[0] +
- (x - 1) * (opts.widget_margins[0] * 2)) + 'px;}');
+ (x - 1) * (opts.widget_margins[0] * 2)) + 'px; }\n');
}
return this.add_style_tag(styles);
diff --git a/dist/jquery.gridster.with-extras.min.js b/dist/jquery.gridster.with-extras.min.js
index 1fcec3d99..4d57f782f 100644
--- a/dist/jquery.gridster.with-extras.min.js
+++ b/dist/jquery.gridster.with-extras.min.js
@@ -1,2 +1,2 @@
-/*! gridster.js - v0.1.0 - 2013-06-14 - * http://gridster.net/ - Copyright (c) 2013 ducksboard; Licensed MIT */ (function(t){function i(i){return i[0]&&t.isPlainObject(i[0])?this.data=i[0]:this.el=i,this.isCoords=!0,this.coords={},this.init(),this}var e=i.prototype;e.init=function(){this.set(),this.original_coords=this.get()},e.set=function(t,i){var e=this.el;if(e&&!t&&(this.data=e.offset(),this.data.width=e.width(),this.data.height=e.height()),e&&t&&!i){var s=e.offset();this.data.top=s.top,this.data.left=s.left}var r=this.data;return this.coords.x1=r.left,this.coords.y1=r.top,this.coords.x2=r.left+r.width,this.coords.y2=r.top+r.height,this.coords.cx=r.left+r.width/2,this.coords.cy=r.top+r.height/2,this.coords.width=r.width,this.coords.height=r.height,this.coords.el=e||!1,this},e.update=function(i){if(!i&&!this.el)return this;if(i){var e=t.extend({},this.data,i);return this.data=e,this.set(!0,!0)}return this.set(!0),this},e.get=function(){return this.coords},t.fn.coords=function(){if(this.data("coords"))return this.data("coords");var t=new i(this,arguments[0]);return this.data("coords",t),t}})(jQuery,window,document),function(t,i,e){function s(i,e,s){this.options=t.extend(r,s),this.$element=i,this.last_colliders=[],this.last_colliders_coords=[],"string"==typeof e||e instanceof jQuery?this.$colliders=t(e,this.options.colliders_context).not(this.$element):this.colliders=t(e),this.init()}var r={colliders_context:e.body},o=s.prototype;o.init=function(){this.find_collisions()},o.overlaps=function(t,i){var e=!1,s=!1;return(i.x1>=t.x1&&i.x1<=t.x2||i.x2>=t.x1&&i.x2<=t.x2||t.x1>=i.x1&&t.x2<=i.x2)&&(e=!0),(i.y1>=t.y1&&i.y1<=t.y2||i.y2>=t.y1&&i.y2<=t.y2||t.y1>=i.y1&&t.y2<=i.y2)&&(s=!0),e&&s},o.detect_overlapping_region=function(t,i){var e="",s="";return t.y1>i.cy&&t.y1i.y1&&t.y2i.cx&&t.x1i.x1&&t.x2o;o++)-1===t.inArray(r[o],i)&&e.call(this,r[o]);for(var n=0,h=i.length;h>n;n++)-1===t.inArray(i[n],r)&&s.call(this,i[n])},o.find_collisions=function(i){for(var e=this,s=[],r=[],o=this.colliders||this.$colliders,a=o.length,n=e.$element.coords().update(i||!1).get();a--;){var h=e.$colliders?t(o[a]):o[a],_=h.isCoords?h:h.coords(),d=_.get(),l=e.overlaps(n,d);if(l){var c=e.detect_overlapping_region(n,d);if("C"===c){var p=e.calculate_overlapped_area_coords(n,d),g=e.calculate_overlapped_area(p),u={area:g,area_coords:p,region:c,coords:d,player_coords:n,el:h};e.options.on_overlap&&e.options.on_overlap.call(this,u),s.push(_),r.push(u)}}}return(e.options.on_overlap_stop||e.options.on_overlap_start)&&this.manage_colliders_start_stop(s,e.options.on_overlap_start,e.options.on_overlap_stop),this.last_colliders_coords=s,r},o.get_closest_colliders=function(t){var i=this.find_collisions(t);return i.sort(function(t,i){return"C"===t.region&&"C"===i.region?t.coords.y1this.player_max_left?r=this.player_max_left:this.player_min_left>r&&(r=this.player_min_left)),{left:r,top:o,mouse_left:i.left,mouse_top:i.top}},h.manage_scroll=function(t){var i,e=o.scrollTop(),s=e,r=s+this.window_height,a=r-50,n=s+50;t.mouse_left;var h=s+t.mouse_top,_=this.doc_height-this.window_height+this.player_height;h>=a&&(i=e+30,_>i&&(o.scrollTop(i),this.scrollOffset=this.scrollOffset+30)),n>=h&&(i=e-30,i>0&&(o.scrollTop(i),this.scrollOffset=this.scrollOffset-30))},h.calculate_positions=function(){this.window_height=o.height()},h.drag_handler=function(i){if(i.target.nodeName,!this.disabled&&(1===i.which||a)&&!this.ignore_drag(i)){var e=this,s=!0;return this.$player=t(i.currentTarget),this.el_init_pos=this.get_actual_pos(this.$player),this.mouse_init_pos=this.get_mouse_pos(i),this.offsetY=this.mouse_init_pos.top-this.el_init_pos.top,this.$body.on(n.move,function(t){var i=e.get_mouse_pos(t),r=Math.abs(i.left-e.mouse_init_pos.left),o=Math.abs(i.top-e.mouse_init_pos.top);return r>e.options.distance||o>e.options.distance?s?(s=!1,e.on_dragstart.call(e,t),!1):(e.is_dragging===!0&&e.on_dragmove.call(e,t),!1):!1}),a?undefined:!1}},h.on_dragstart=function(i){i.preventDefault(),this.drag_start=!0,this.is_dragging=!0;var s=this.$container.offset();this.baseX=Math.round(s.left),this.baseY=Math.round(s.top),this.doc_height=t(e).height(),"clone"===this.options.helper?(this.$helper=this.$player.clone().appendTo(this.$container).addClass("helper"),this.helper=!0):this.helper=!1,this.scrollOffset=0,this.el_init_offset=this.$player.offset(),this.player_width=this.$player.width(),this.player_height=this.$player.height();var r=this.options.container_width||this.$container.width();return this.player_max_left=r-this.player_width+this.options.offset_left,this.options.start&&this.options.start.call(this.$player,i,{helper:this.helper?this.$helper:this.$player}),!1},h.on_dragmove=function(t){var i=this.get_offset(t);this.options.autoscroll&&this.manage_scroll(i),(this.helper?this.$helper:this.$player).css({position:"absolute",left:i.left,top:i.top});var e={position:{left:i.left,top:i.top}};return this.options.drag&&this.options.drag.call(this.$player,t,e),!1},h.on_dragstop=function(t){var i=this.get_offset(t);this.drag_start=!1;var e={position:{left:i.left,top:i.top}};return this.options.stop&&this.options.stop.call(this.$player,t,e),this.helper&&this.$helper.remove(),!1},h.on_select_start=function(t){return this.disabled||this.ignore_drag(t)?undefined:!1},h.enable=function(){this.disabled=!1},h.disable=function(){this.disabled=!0},h.destroy=function(){this.disable(),this.$container.off(".gridster-draggable"),this.$body.off(".gridster-draggable"),t(i).off(".gridster-draggable"),t.removeData(this.$container,"drag")},h.ignore_drag=function(i){return this.options.handle?!t(i.target).is(this.options.handle):t.inArray(i.target.nodeName,this.options.ignore_dragging)>=0},t.fn.drag=function(i){return this.each(function(){t.data(this,"drag")||t.data(this,"drag",new s(this,i))})}}(jQuery,window,document),function(t,i,e){function s(i,e){this.options=t.extend(!0,r,e),this.$el=t(i),this.$wrapper=this.$el.parent(),this.$widgets=this.$el.children(this.options.widget_selector).addClass("gs_w"),this.widgets=[],this.$changed=t([]),this.wrapper_width=this.$wrapper.width(),this.min_widget_width=2*this.options.widget_margins[0]+this.options.widget_base_dimensions[0],this.min_widget_height=2*this.options.widget_margins[1]+this.options.widget_base_dimensions[1],this.$style_tags=t([]),this.init()}var r={namespace:"",widget_selector:"li",widget_margins:[10,10],widget_base_dimensions:[400,225],extra_rows:0,extra_cols:0,min_cols:1,max_cols:null,min_rows:15,max_size_x:6,autogenerate_stylesheet:!0,avoid_overlapped_widgets:!0,serialize_params:function(t,i){return{col:i.col,row:i.row,size_x:i.size_x,size_y:i.size_y}},collision:{},draggable:{distance:4}};s.generated_stylesheets=[];var o=s.prototype;o.init=function(){this.generate_grid_and_stylesheet(),this.get_widgets_from_DOM(),this.set_dom_grid_height(),this.$wrapper.addClass("ready"),this.draggable(),t(i).bind("resize.gridster",throttle(t.proxy(this.recalculate_faux_grid,this),200))},o.disable=function(){return this.$wrapper.find(".player-revert").removeClass("player-revert"),this.drag_api.disable(),this},o.enable=function(){return this.drag_api.enable(),this},o.add_widget=function(i,e,s,r,o){var a;e||(e=1),s||(s=1),!r&!o?a=this.next_position(e,s):(a={col:r,row:o},this.empty_cells(r,o,e,s));var n=t(i).attr({"data-col":a.col,"data-row":a.row,"data-sizex":e,"data-sizey":s}).addClass("gs_w").appendTo(this.$el).hide();return this.$widgets=this.$widgets.add(n),this.register_widget(n),this.add_faux_rows(a.size_y),this.set_dom_grid_height(),n.fadeIn()},o.resize_widget=function(i,e,s,r){var o=i.coords().grid;e||(e=o.size_x),s||(s=o.size_y),e>this.cols&&(e=this.cols);var a=this.get_cells_occupied(o),n=o.size_x,h=o.size_y,_=o.col,d=_;if(_+e-1>this.cols){var l=_+(e-1)-this.cols,c=_-l;d=Math.max(1,c)}var p={col:d,row:o.row,size_x:e,size_y:s},g=this.get_cells_occupied(p),u=[];t.each(a.cols,function(i,e){-1===t.inArray(e,g.cols)&&u.push(e)});var f=[];t.each(g.cols,function(i,e){-1===t.inArray(e,a.cols)&&f.push(e)});var w=[];t.each(a.rows,function(i,e){-1===t.inArray(e,g.rows)&&w.push(e)});var y=[];if(t.each(g.rows,function(i,e){-1===t.inArray(e,a.rows)&&y.push(e)}),this.remove_from_gridmap(o),f.length){var m=[d,o.row,e,Math.min(h,s),i];this.empty_cells.apply(this,m)}if(y.length){var v=[d,o.row,e,s,i];this.empty_cells.apply(this,v)}if(o.col=d,o.size_x=e,o.size_y=s,this.add_to_gridmap(p,i),i.data("coords").update({width:e*this.options.widget_base_dimensions[0]+2*(e-1)*this.options.widget_margins[0],height:s*this.options.widget_base_dimensions[1]+2*(s-1)*this.options.widget_margins[1]}),s>h&&this.add_faux_rows(s-h),e>n&&this.add_faux_cols(e-n),i.attr({"data-col":d,"data-sizex":e,"data-sizey":s}),u.length){var x=[u[0],o.row,u.length,Math.min(h,s),i];this.remove_empty_cells.apply(this,x)}if(w.length){var b=[d,o.row,e,s,i];this.remove_empty_cells.apply(this,b)}return r&&r.call(this,e,s),i},o.empty_cells=function(i,e,s,r,o){var a=this.widgets_below({col:i,row:e-r,size_x:s,size_y:r});return a.not(o).each(t.proxy(function(i,s){var o=t(s).coords().grid;if(e+r-1>=o.row){var a=e+r-o.row;this.move_widget_down(t(s),a)}},this)),this.set_dom_grid_height(),this},o.remove_empty_cells=function(i,e,s,r,o){var a=this.widgets_below({col:i,row:e,size_x:s,size_y:r});return a.not(o).each(t.proxy(function(i,e){this.move_widget_up(t(e),r)},this)),this.set_dom_grid_height(),this},o.next_position=function(t,i){t||(t=1),i||(i=1);for(var e,s=this.gridmap,r=s.length,o=[],a=1;r>a;a++){e=s[a].length;for(var n=1;e>=n;n++){var h=this.can_move_to({size_x:t,size_y:i},a,n);h&&o.push({col:a,row:n,size_y:i,size_x:t})}}return o.length?this.sort_by_row_and_col_asc(o)[0]:!1},o.remove_widget=function(i,e,s){var r=i instanceof jQuery?i:t(i),o=r.coords().grid;t.isFunction(e)&&(s=e,e=!1),this.cells_occupied_by_placeholder={},this.$widgets=this.$widgets.not(r);var a=this.widgets_below(r);this.remove_from_gridmap(o),r.fadeOut(t.proxy(function(){r.remove(),e||a.each(t.proxy(function(i,e){this.move_widget_up(t(e),o.size_y)},this)),this.set_dom_grid_height(),s&&s.call(this,i)},this))},o.remove_all_widgets=function(i){return this.$widgets.each(t.proxy(function(t,e){this.remove_widget(e,!0,i)},this)),this},o.serialize=function(i){i||(i=this.$widgets);var e=[];return i.each(t.proxy(function(i,s){e.push(this.options.serialize_params(t(s),t(s).coords().grid))},this)),e},o.serialize_changed=function(){return this.serialize(this.$changed)},o.register_widget=function(t){var i={col:parseInt(t.attr("data-col"),10),row:parseInt(t.attr("data-row"),10),size_x:parseInt(t.attr("data-sizex"),10),size_y:parseInt(t.attr("data-sizey"),10),el:t};return this.options.avoid_overlapped_widgets&&!this.can_move_to({size_x:i.size_x,size_y:i.size_y},i.col,i.row)&&(i=this.next_position(i.size_x,i.size_y),i.el=t,t.attr({"data-col":i.col,"data-row":i.row,"data-sizex":i.size_x,"data-sizey":i.size_y})),t.data("coords",t.coords()),t.data("coords").grid=i,this.add_to_gridmap(i,t),this},o.update_widget_position=function(t,i){return this.for_each_cell_occupied(t,function(t,e){return this.gridmap[t]?(this.gridmap[t][e]=i,undefined):this}),this},o.remove_from_gridmap=function(t){return this.update_widget_position(t,!1)},o.add_to_gridmap=function(i,e){if(this.update_widget_position(i,e||i.el),i.el){var s=this.widgets_below(i.el);s.each(t.proxy(function(i,e){this.move_widget_up(t(e))},this))}},o.draggable=function(){var i=this,e=t.extend(!0,{},this.options.draggable,{offset_left:this.options.widget_margins[0],container_width:this.container_width,start:function(e,s){i.$widgets.filter(".player-revert").removeClass("player-revert"),i.$player=t(this),i.$helper="clone"===i.options.draggable.helper?t(s.helper):i.$player,i.helper=!i.$helper.is(i.$player),i.on_start_drag.call(i,e,s),i.$el.trigger("gridster:dragstart")},stop:function(t,e){i.on_stop_drag.call(i,t,e),i.$el.trigger("gridster:dragstop")},drag:throttle(function(t,e){i.on_drag.call(i,t,e),i.$el.trigger("gridster:drag")},60)});return this.drag_api=this.$el.drag(e).data("drag"),this},o.on_start_drag=function(i,e){this.$helper.add(this.$player).add(this.$wrapper).addClass("dragging"),this.$player.addClass("player"),this.player_grid_data=this.$player.coords().grid,this.placeholder_grid_data=t.extend({},this.player_grid_data),this.$el.css("height",this.$el.height()+this.player_grid_data.size_y*this.min_widget_height);var s=this.faux_grid,r=this.$player.data("coords").coords;this.cells_occupied_by_player=this.get_cells_occupied(this.player_grid_data),this.cells_occupied_by_placeholder=this.get_cells_occupied(this.placeholder_grid_data),this.last_cols=[],this.last_rows=[],this.collision_api=this.$helper.collision(s,this.options.collision),this.$preview_holder=t("",{"class":"preview-holder","data-row":this.$player.attr("data-row"),"data-col":this.$player.attr("data-col"),css:{width:r.width,height:r.height}}).appendTo(this.$el),this.options.draggable.start&&this.options.draggable.start.call(this,i,e)},o.on_drag=function(t,i){if(null===this.$player)return!1;var e={left:i.position.left+this.baseX,top:i.position.top+this.baseY};this.colliders_data=this.collision_api.get_closest_colliders(e),this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column),this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row),this.helper&&this.$player&&this.$player.css({left:i.position.left,top:i.position.top}),this.options.draggable.drag&&this.options.draggable.drag.call(this,t,i)},o.on_stop_drag=function(t,i){this.$helper.add(this.$player).add(this.$wrapper).removeClass("dragging"),i.position.left=i.position.left+this.baseX,i.position.top=i.position.top+this.baseY,this.colliders_data=this.collision_api.get_closest_colliders(i.position),this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column),this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row),this.$player.addClass("player-revert").removeClass("player").attr({"data-col":this.placeholder_grid_data.col,"data-row":this.placeholder_grid_data.row}).css({left:"",top:""}),this.$changed=this.$changed.add(this.$player),this.cells_occupied_by_player=this.get_cells_occupied(this.placeholder_grid_data),this.set_cells_player_occupies(this.placeholder_grid_data.col,this.placeholder_grid_data.row),this.$player.coords().grid.row=this.placeholder_grid_data.row,this.$player.coords().grid.col=this.placeholder_grid_data.col,this.options.draggable.stop&&this.options.draggable.stop.call(this,t,i),this.$preview_holder.remove(),this.$player=null,this.$helper=null,this.placeholder_grid_data={},this.player_grid_data={},this.cells_occupied_by_placeholder={},this.cells_occupied_by_player={},this.set_dom_grid_height()},o.on_overlapped_column_change=function(i,e){if(!this.colliders_data.length)return this;var s,r=this.get_targeted_columns(this.colliders_data[0].el.data.col),o=this.last_cols.length,a=r.length;for(s=0;a>s;s++)-1===t.inArray(r[s],this.last_cols)&&(i||t.noop).call(this,r[s]);for(s=0;o>s;s++)-1===t.inArray(this.last_cols[s],r)&&(e||t.noop).call(this,this.last_cols[s]);return this.last_cols=r,this},o.on_overlapped_row_change=function(i,e){if(!this.colliders_data.length)return this;var s,r=this.get_targeted_rows(this.colliders_data[0].el.data.row),o=this.last_rows.length,a=r.length;for(s=0;a>s;s++)-1===t.inArray(r[s],this.last_rows)&&(i||t.noop).call(this,r[s]);for(s=0;o>s;s++)-1===t.inArray(this.last_rows[s],r)&&(e||t.noop).call(this,this.last_rows[s]);this.last_rows=r},o.set_player=function(t,i,e){var s=this;e||this.empty_cells_player_occupies();var r=e?{col:t}:s.colliders_data[0].el.data,o=r.col,a=i||r.row;this.player_grid_data={col:o,row:a,size_y:this.player_grid_data.size_y,size_x:this.player_grid_data.size_x},this.cells_occupied_by_player=this.get_cells_occupied(this.player_grid_data);var n=this.get_widgets_overlapped(this.player_grid_data),h=this.widgets_constraints(n);if(this.manage_movements(h.can_go_up,o,a),this.manage_movements(h.can_not_go_up,o,a),!n.length){var _=this.can_go_player_up(this.player_grid_data);_!==!1&&(a=_),this.set_placeholder(o,a)}return{col:o,row:a}},o.widgets_constraints=function(i){var e,s=t([]),r=[],o=[];return i.each(t.proxy(function(i,e){var a=t(e),n=a.coords().grid;this.can_go_widget_up(n)?(s=s.add(a),r.push(n)):o.push(n)},this)),e=i.not(s),{can_go_up:this.sort_by_row_asc(r),can_not_go_up:this.sort_by_row_desc(o)}},o.sort_by_row_asc=function(i){return i=i.sort(function(i,e){return i.row||(i=t(i).coords().grid,e=t(e).coords().grid),i.row>e.row?1:-1})},o.sort_by_row_and_col_asc=function(t){return t=t.sort(function(t,i){return t.row>i.row||t.row===i.row&&t.col>i.col?1:-1})},o.sort_by_col_asc=function(t){return t=t.sort(function(t,i){return t.col>i.col?1:-1})},o.sort_by_row_desc=function(t){return t=t.sort(function(t,i){return t.row+t.size_y=0&&t.inArray(e,s.rows)>=0},o.is_placeholder_in=function(i,e){var s=this.cells_occupied_by_placeholder||{};return this.is_placeholder_in_col(i)&&t.inArray(e,s.rows)>=0},o.is_placeholder_in_col=function(i){var e=this.cells_occupied_by_placeholder||[];return t.inArray(i,e.cols)>=0},o.is_empty=function(t,i){return this.gridmap[t]!==undefined?this.gridmap[t][i]!==undefined&&this.gridmap[t][i]===!1?!0:!1:!0},o.is_occupied=function(t,i){return this.gridmap[t]?this.gridmap[t][i]?!0:!1:!1},o.is_widget=function(t,i){var e=this.gridmap[t];return e?(e=e[i],e?e:!1):!1},o.is_widget_under_player=function(t,i){return this.is_widget(t,i)?this.is_player_in(t,i):!1},o.get_widgets_under_player=function(i){i||(i=this.cells_occupied_by_player||{cols:[],rows:[]});var e=t([]);return t.each(i.cols,t.proxy(function(s,r){t.each(i.rows,t.proxy(function(t,i){this.is_widget(r,i)&&(e=e.add(this.gridmap[r][i]))},this))},this)),e},o.set_placeholder=function(i,e){var s=t.extend({},this.placeholder_grid_data),r=this.widgets_below({col:s.col,row:s.row,size_y:s.size_y,size_x:s.size_x}),o=i+s.size_x-1;o>this.cols&&(i-=o-i);var a=e>this.placeholder_grid_data.row,n=this.placeholder_grid_data.col!==i;this.placeholder_grid_data.col=i,this.placeholder_grid_data.row=e,this.cells_occupied_by_placeholder=this.get_cells_occupied(this.placeholder_grid_data),this.$preview_holder.attr({"data-row":e,"data-col":i}),(a||n)&&r.each(t.proxy(function(e,r){this.move_widget_up(t(r),this.placeholder_grid_data.col-i+s.size_y)},this));var h=this.get_widgets_under_player(this.cells_occupied_by_placeholder);h.length&&h.each(t.proxy(function(i,r){var o=t(r);this.move_widget_down(o,e+s.size_y-o.data("coords").grid.row)},this))},o.can_go_player_up=function(t){var i=t.row+t.size_y-1,e=!0,s=[],r=1e4,o=this.get_widgets_under_player();return this.for_each_column_occupied(t,function(t){var a=this.gridmap[t],n=i+1;for(s[t]=[];--n>0&&(this.is_empty(t,n)||this.is_player(t,n)||this.is_widget(t,n)&&a[n].is(o));)s[t].push(n),r=r>n?n:r;return 0===s[t].length?(e=!1,!0):(s[t].sort(function(t,i){return t-i}),undefined)}),e?this.get_valid_rows(t,s,r):!1},o.can_go_widget_up=function(t){var i=t.row+t.size_y-1,e=!0,s=[],r=1e4;return this.for_each_column_occupied(t,function(o){var a=this.gridmap[o];s[o]=[];for(var n=i+1;--n>0&&(!this.is_widget(o,n)||this.is_player_in(o,n)||a[n].is(t.el));)this.is_player(o,n)||this.is_placeholder_in(o,n)||this.is_player_in(o,n)||s[o].push(n),r>n&&(r=n);return 0===s[o].length?(e=!1,!0):(s[o].sort(function(t,i){return t-i}),undefined)}),e?this.get_valid_rows(t,s,r):!1},o.get_valid_rows=function(i,e,s){for(var r=i.row,o=i.row+i.size_y-1,a=i.size_y,n=s-1,h=[];o>=++n;){var _=!0;if(t.each(e,function(i,e){t.isArray(e)&&-1===t.inArray(n,e)&&(_=!1)}),_===!0&&(h.push(n),h.length===a))break}var d=!1;return 1===a?h[0]!==r&&(d=h[0]||!1):h[0]!==r&&(d=this.get_consecutive_numbers_index(h,a)),d},o.get_consecutive_numbers_index=function(t,i){for(var e=t.length,s=[],r=!0,o=-1,a=0;e>a;a++){if(r||t[a]===o+1){if(s.push(a),s.length===i)break;r=!1}else s=[],r=!0;o=t[a]}return s.length>=i?t[s[0]]:!1},o.get_widgets_overlapped=function(){var i=t([]),e=[],s=this.cells_occupied_by_player.rows.slice(0);return s.reverse(),t.each(this.cells_occupied_by_player.cols,t.proxy(function(r,o){t.each(s,t.proxy(function(s,r){if(!this.gridmap[o])return!0;var a=this.gridmap[o][r];this.is_occupied(o,r)&&!this.is_player(a)&&-1===t.inArray(a,e)&&(i=i.add(a),e.push(a))},this))},this)),i},o.on_start_overlapping_column=function(t){this.set_player(t,!1)},o.on_start_overlapping_row=function(t){this.set_player(!1,t)},o.on_stop_overlapping_column=function(t){this.set_player(t,!1);var i=this;this.for_each_widget_below(t,this.cells_occupied_by_player.rows[0],function(){i.move_widget_up(this,i.player_grid_data.size_y)})},o.on_stop_overlapping_row=function(t){this.set_player(!1,t);for(var i=this,e=this.cells_occupied_by_player.cols,s=0,r=e.length;r>s;s++)this.for_each_widget_below(e[s],t,function(){i.move_widget_up(this,i.player_grid_data.size_y)})},o.move_widget_to=function(i,e){var s=this,r=i.coords().grid;e-r.row;var o=this.widgets_below(i),a=this.can_move_to(r,r.col,e,i);return a===!1?!1:(this.remove_from_gridmap(r),r.row=e,this.add_to_gridmap(r),i.attr("data-row",e),this.$changed=this.$changed.add(i),o.each(function(i,e){var r=t(e),o=r.coords().grid,a=s.can_go_widget_up(o);a&&a!==o.row&&s.move_widget_to(r,a)}),this)},o.move_widget_up=function(i,e){var s=i.coords().grid,r=s.row,o=[];return e||(e=1),this.can_go_up(i)?(this.for_each_column_occupied(s,function(s){if(-1===t.inArray(i,o)){var a=i.coords().grid,n=r-e;if(n=this.can_go_up_to_row(a,s,n),!n)return!0;var h=this.widgets_below(i);this.remove_from_gridmap(a),a.row=n,this.add_to_gridmap(a),i.attr("data-row",a.row),this.$changed=this.$changed.add(i),o.push(i),h.each(t.proxy(function(i,s){this.move_widget_up(t(s),e)},this))}}),undefined):!1},o.move_widget_down=function(i,e){var s=i.coords().grid,r=s.row,o=[],a=e;if(!i)return!1;if(-1===t.inArray(i,o)){var n=i.coords().grid,h=r+e,_=this.widgets_below(i);this.remove_from_gridmap(n),_.each(t.proxy(function(i,e){var s=t(e),r=s.coords().grid,o=this.displacement_diff(r,n,a);o>0&&this.move_widget_down(s,o)},this)),n.row=h,this.update_widget_position(n,i),i.attr("data-row",n.row),this.$changed=this.$changed.add(i),o.push(i)}},o.can_go_up_to_row=function(i,e,s){var r,o=this.gridmap,a=!0,n=[],h=i.row;if(this.for_each_column_occupied(i,function(t){for(o[t],n[t]=[],r=h;r--&&this.is_empty(t,r)&&!this.is_placeholder_in(t,r);)n[t].push(r);return n[t].length?undefined:(a=!1,!0)}),!a)return!1;for(r=s,r=1;h>r;r++){for(var _=!0,d=0,l=n.length;l>d;d++)n[d]&&-1===t.inArray(r,n[d])&&(_=!1);if(_===!0){a=r;break}}return a},o.displacement_diff=function(t,i,e){var s=t.row,r=[],o=i.row+i.size_y;this.for_each_column_occupied(t,function(t){for(var i=0,e=o;s>e;e++)this.is_empty(t,e)&&(i+=1);r.push(i)});var a=Math.max.apply(Math,r);return e-=a,e>0?e:0},o.widgets_below=function(i){var e=t.isPlainObject(i)?i:i.coords().grid,s=this;this.gridmap;var r=e.row+e.size_y-1,o=t([]);return this.for_each_column_occupied(e,function(i){s.for_each_widget_below(i,r,function(){return s.is_player(this)||-1!==t.inArray(this,o)?undefined:(o=o.add(this),!0)})}),this.sort_by_row_asc(o)},o.set_cells_player_occupies=function(t,i){return this.remove_from_gridmap(this.placeholder_grid_data),this.placeholder_grid_data.col=t,this.placeholder_grid_data.row=i,this.add_to_gridmap(this.placeholder_grid_data,this.$player),this},o.empty_cells_player_occupies=function(){return this.remove_from_gridmap(this.placeholder_grid_data),this},o.can_go_up=function(t){var i=t.coords().grid,e=i.row,s=e-1;this.gridmap;var r=!0;return 1===e?!1:(this.for_each_column_occupied(i,function(t){return this.is_widget(t,s),this.is_occupied(t,s)||this.is_player(t,s)||this.is_placeholder_in(t,s)||this.is_player_in(t,s)?(r=!1,!0):undefined}),r)},o.can_move_to=function(t,i,e,s){this.gridmap;var r=t.el,o={size_y:t.size_y,size_x:t.size_x,col:i,row:e},a=!0,n=i+t.size_x-1;return n>this.cols?!1:s&&e+t.size_y-1>s?!1:(this.for_each_cell_occupied(o,function(i,e){var s=this.is_widget(i,e);!s||t.el&&!s.is(r)||(a=!1)}),a)},o.get_targeted_columns=function(t){for(var i=(t||this.player_grid_data.col)+(this.player_grid_data.size_x-1),e=[],s=t;i>=s;s++)e.push(s);return e},o.get_targeted_rows=function(t){for(var i=(t||this.player_grid_data.row)+(this.player_grid_data.size_y-1),e=[],s=t;i>=s;s++)e.push(s);return e},o.get_cells_occupied=function(t){var i,e={cols:[],rows:[]};for(arguments[1]instanceof jQuery&&(t=arguments[1].coords().grid),i=0;t.size_x>i;i++){var s=t.col+i;e.cols.push(s)}for(i=0;t.size_y>i;i++){var r=t.row+i;e.rows.push(r)}return e},o.for_each_cell_occupied=function(t,i){return this.for_each_column_occupied(t,function(e){this.for_each_row_occupied(t,function(t){i.call(this,e,t)})}),this},o.for_each_column_occupied=function(t,i){for(var e=0;t.size_x>e;e++){var s=t.col+e;i.call(this,s,t)}},o.for_each_row_occupied=function(t,i){for(var e=0;t.size_y>e;e++){var s=t.row+e;i.call(this,s,t)}},o._traversing_widgets=function(i,e,s,r,o){var a=this.gridmap;if(a[s]){var n,h,_=i+"/"+e;if(arguments[2]instanceof jQuery){var d=arguments[2].coords().grid;s=d.col,r=d.row,o=arguments[3]}var l=[],c=r,p={"for_each/above":function(){for(;c--&&!(c>0&&this.is_widget(s,c)&&-1===t.inArray(a[s][c],l)&&(n=o.call(a[s][c],s,c),l.push(a[s][c]),n)););},"for_each/below":function(){for(c=r+1,h=a[s].length;h>c&&(!this.is_widget(s,c)||-1!==t.inArray(a[s][c],l)||(n=o.call(a[s][c],s,c),l.push(a[s][c]),!n));c++);}};p[_]&&p[_].call(this)}},o.for_each_widget_above=function(t,i,e){return this._traversing_widgets("for_each","above",t,i,e),this},o.for_each_widget_below=function(t,i,e){return this._traversing_widgets("for_each","below",t,i,e),this},o.get_highest_occupied_cell=function(){for(var t,i=this.gridmap,e=[],s=[],r=i.length-1;r>=1;r--)for(t=i[r].length-1;t>=1;t--)if(this.is_widget(r,t)){e.push(t),s[t]=r;break}var o=Math.max.apply(Math,e);return this.highest_occupied_cell={col:s[o],row:o},this.highest_occupied_cell},o.get_widgets_from=function(i,e){this.gridmap;var s=t();return i&&(s=s.add(this.$widgets.filter(function(){var e=t(this).attr("data-col");return e===i||e>i}))),e&&(s=s.add(this.$widgets.filter(function(){var i=t(this).attr("data-row");return i===e||i>e}))),s},o.set_dom_grid_height=function(){var t=this.get_highest_occupied_cell().row;return this.$el.css("height",t*this.min_widget_height),this},o.generate_stylesheet=function(i){var e,r="",o=this.options.max_size_x;i||(i={}),i.cols||(i.cols=this.cols),i.rows||(i.rows=this.rows),i.namespace||(i.namespace=this.options.namespace),i.widget_base_dimensions||(i.widget_base_dimensions=this.options.widget_base_dimensions),i.widget_margins||(i.widget_margins=this.options.widget_margins),i.min_widget_width=2*i.widget_margins[0]+i.widget_base_dimensions[0],i.min_widget_height=2*i.widget_margins[1]+i.widget_base_dimensions[1];var a=t.param(i);if(t.inArray(a,s.generated_stylesheets)>=0)return!1;for(s.generated_stylesheets.push(a),e=i.cols;e>=0;e--)r+=i.namespace+' [data-col="'+(e+1)+'"] { left:'+(e*i.widget_base_dimensions[0]+e*i.widget_margins[0]+(e+1)*i.widget_margins[0])+"px;} ";for(e=i.rows;e>=0;e--)r+=i.namespace+' [data-row="'+(e+1)+'"] { top:'+(e*i.widget_base_dimensions[1]+e*i.widget_margins[1]+(e+1)*i.widget_margins[1])+"px;} ";for(var n=1;i.rows>=n;n++)r+=i.namespace+' [data-sizey="'+n+'"] { height:'+(n*i.widget_base_dimensions[1]+(n-1)*2*i.widget_margins[1])+"px;}";for(var h=1;o>=h;h++)r+=i.namespace+' [data-sizex="'+h+'"] { width:'+(h*i.widget_base_dimensions[0]+(h-1)*2*i.widget_margins[0])+"px;}";return this.add_style_tag(r)},o.add_style_tag=function(t){var i=e,s=i.createElement("style");return i.getElementsByTagName("head")[0].appendChild(s),s.setAttribute("type","text/css"),s.styleSheet?s.styleSheet.cssText=t:s.appendChild(e.createTextNode(t)),this.$style_tags=this.$style_tags.add(s),this},o.remove_style_tags=function(){this.$style_tags.remove()},o.generate_faux_grid=function(t,i){this.faux_grid=[],this.gridmap=[];var e,s;for(e=i;e>0;e--)for(this.gridmap[e]=[],s=t;s>0;s--)this.add_faux_cell(s,e);return this},o.add_faux_cell=function(i,e){var s=t({left:this.baseX+(e-1)*this.min_widget_width,top:this.baseY+(i-1)*this.min_widget_height,width:this.min_widget_width,height:this.min_widget_height,col:e,row:i,original_col:e,original_row:i}).coords();return t.isArray(this.gridmap[e])||(this.gridmap[e]=[]),this.gridmap[e][i]=!1,this.faux_grid.push(s),this},o.add_faux_rows=function(t){for(var i=this.rows,e=i+(t||1),s=e;s>i;s--)for(var r=this.cols;r>=1;r--)this.add_faux_cell(s,r);return this.rows=e,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this},o.add_faux_cols=function(t){for(var i=this.cols,e=i+(t||1),s=i;e>s;s++)for(var r=this.rows;r>=1;r--)this.add_faux_cell(r,s);return this.cols=e,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this},o.recalculate_faux_grid=function(){var e=this.$wrapper.width();
-return this.baseX=(t(i).width()-e)/2,this.baseY=this.$wrapper.offset().top,t.each(this.faux_grid,t.proxy(function(t,i){this.faux_grid[t]=i.update({left:this.baseX+(i.data.col-1)*this.min_widget_width,top:this.baseY+(i.data.row-1)*this.min_widget_height})},this)),this},o.get_widgets_from_DOM=function(){return this.$widgets.each(t.proxy(function(i,e){this.register_widget(t(e))},this)),this},o.generate_grid_and_stylesheet=function(){var e=this.$wrapper.width();this.$wrapper.height();var s=this.options.max_cols,r=Math.floor(e/this.min_widget_width)+this.options.extra_cols,o=this.$widgets.map(function(){return t(this).attr("data-col")}).get();o.length||(o=[0]);var a=Math.max.apply(Math,o),n=this.options.extra_rows;return this.$widgets.each(function(i,e){n+=+t(e).attr("data-sizey")}),this.cols=Math.max(a,r,this.options.min_cols),s&&s>=a&&this.cols>s&&(this.cols=s),this.rows=Math.max(n,this.options.min_rows),this.baseX=(t(i).width()-e)/2,this.baseY=this.$wrapper.offset().top,this.container_width=this.cols*this.options.widget_base_dimensions[0]+2*(this.cols-1)*this.options.widget_margins[0],this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this.generate_faux_grid(this.rows,this.cols)},o.destroy=function(){return t(i).unbind(".gridster"),this.drag_api&&this.drag_api.destroy(),this.remove_style_tags(),this.$el.remove(),this},t.fn.gridster=function(i){return this.each(function(){t(this).data("gridster")||t(this).data("gridster",new s(this,i))})},t.Gridster=o}(jQuery,window,document),function(t){var i=t.Gridster;i.widgets_in_col=function(t){if(!this.gridmap[t])return!1;for(var i=this.gridmap[t].length-1;i>=0;i--)if(this.is_widget(t,i)!==!1)return!0;return!1},i.widgets_in_row=function(t){for(var i=this.gridmap.length;i>=1;i--)if(this.is_widget(i,t)!==!1)return!0;return!1},i.widgets_in_range=function(i,e,s,r){var o,a,n,h,_=t([]);for(o=s;o>=i;o--)for(a=r;a>=e;a--)n=this.is_widget(o,a),n!==!1&&(h=n.data("coords").grid,h.col>=i&&s>=h.col&&h.row>=e&&r>=h.row&&(_=_.add(n)));return _},i.get_bottom_most_occupied_cell=function(){var t=0,i=0;return this.for_each_cell(function(e,s,r){e&&r>t&&(t=r,i=s)}),{col:i,row:t}},i.get_right_most_occupied_cell=function(){var t=0,i=0;return this.for_each_cell(function(e,s,r){return e?(t=r,i=s,!1):undefined}),{col:i,row:t}},i.for_each_cell=function(t,i){i||(i=this.gridmap);var e=i.length,s=i[1].length;t:for(var r=e-1;r>=1;r--)for(var o=s-1;o>=1;o--){var a=i[r]&&i[r][o];if(t){if(t.call(this,a,r,o)===!1)break t}else;}},i.next_position_in_range=function(t,i,e){t||(t=1),i||(i=1);for(var s,r=this.gridmap,o=r.length,a=[],n=1;o>n;n++){s=e||r[n].length;for(var h=1;s>=h;h++){var _=this.can_move_to({size_x:t,size_y:i},n,h,e);_&&a.push({col:n,row:h,size_y:i,size_x:t})}}return a.length>=1?this.sort_by_col_asc(a)[0]:!1},i.closest_to_right=function(t,i){if(!this.gridmap[t])return!1;for(var e=this.gridmap.length-1,s=t;e>=s;s++)if(this.gridmap[s][i])return{col:s,row:i};return!1},i.closest_to_left=function(t,i){if(this.gridmap.length-1,!this.gridmap[t])return!1;for(var e=t;e>=1;e--)if(this.gridmap[e][i])return{col:e,row:i};return!1}}(jQuery,window,document);
\ No newline at end of file
+/*! gridster.js - v0.2.0 - 2013-10-26 - * http://gridster.net/ - Copyright (c) 2013 ducksboard; Licensed MIT */ (function(t){function i(i){return i[0]&&t.isPlainObject(i[0])?this.data=i[0]:this.el=i,this.isCoords=!0,this.coords={},this.init(),this}var e=i.prototype;e.init=function(){this.set(),this.original_coords=this.get()},e.set=function(t,i){var e=this.el;if(e&&!t&&(this.data=e.offset(),this.data.width=e.width(),this.data.height=e.height()),e&&t&&!i){var s=e.offset();this.data.top=s.top,this.data.left=s.left}var r=this.data;return this.coords.x1=r.left,this.coords.y1=r.top,this.coords.x2=r.left+r.width,this.coords.y2=r.top+r.height,this.coords.cx=r.left+r.width/2,this.coords.cy=r.top+r.height/2,this.coords.width=r.width,this.coords.height=r.height,this.coords.el=e||!1,this},e.update=function(i){if(!i&&!this.el)return this;if(i){var e=t.extend({},this.data,i);return this.data=e,this.set(!0,!0)}return this.set(!0),this},e.get=function(){return this.coords},t.fn.coords=function(){if(this.data("coords"))return this.data("coords");var t=new i(this,arguments[0]);return this.data("coords",t),t}})(jQuery,window,document),function(t,i,e){function s(i,e,s){this.options=t.extend(r,s),this.$element=i,this.last_colliders=[],this.last_colliders_coords=[],"string"==typeof e||e instanceof jQuery?this.$colliders=t(e,this.options.colliders_context).not(this.$element):this.colliders=t(e),this.init()}var r={colliders_context:e.body},o=s.prototype;o.init=function(){this.find_collisions()},o.overlaps=function(t,i){var e=!1,s=!1;return(i.x1>=t.x1&&i.x1<=t.x2||i.x2>=t.x1&&i.x2<=t.x2||t.x1>=i.x1&&t.x2<=i.x2)&&(e=!0),(i.y1>=t.y1&&i.y1<=t.y2||i.y2>=t.y1&&i.y2<=t.y2||t.y1>=i.y1&&t.y2<=i.y2)&&(s=!0),e&&s},o.detect_overlapping_region=function(t,i){var e="",s="";return t.y1>i.cy&&t.y1i.y1&&t.y2i.cx&&t.x1i.x1&&t.x2o;o++)-1===t.inArray(r[o],i)&&e.call(this,r[o]);for(var n=0,h=i.length;h>n;n++)-1===t.inArray(i[n],r)&&s.call(this,i[n])},o.find_collisions=function(i){for(var e=this,s=[],r=[],o=this.colliders||this.$colliders,a=o.length,n=e.$element.coords().update(i||!1).get();a--;){var h=e.$colliders?t(o[a]):o[a],_=h.isCoords?h:h.coords(),d=_.get(),l=e.overlaps(n,d);if(l){var c=e.detect_overlapping_region(n,d);if("C"===c){var p=e.calculate_overlapped_area_coords(n,d),g=e.calculate_overlapped_area(p),u={area:g,area_coords:p,region:c,coords:d,player_coords:n,el:h};e.options.on_overlap&&e.options.on_overlap.call(this,u),s.push(_),r.push(u)}}}return(e.options.on_overlap_stop||e.options.on_overlap_start)&&this.manage_colliders_start_stop(s,e.options.on_overlap_start,e.options.on_overlap_stop),this.last_colliders_coords=s,r},o.get_closest_colliders=function(t){var i=this.find_collisions(t);return i.sort(function(t,i){return"C"===t.region&&"C"===i.region?t.coords.y1this.player_max_left?r=this.player_max_left:this.player_min_left>r&&(r=this.player_min_left)),{position:{left:r,top:o},pointer:{left:i.left,top:i.top,diff_left:e,diff_top:s+this.scrollOffset}}},h.get_drag_data=function(t){var i=this.get_offset(t);return i.$player=this.$player,i.$helper=this.helper?this.$helper:this.$player,i},h.manage_scroll=function(t){var i,e=o.scrollTop(),s=e,r=s+this.window_height,a=r-50,n=s+50;t.pointer.left;var h=s+t.pointer.top,_=this.doc_height-this.window_height+this.player_height;h>=a&&(i=e+30,_>i&&(o.scrollTop(i),this.scrollOffset=this.scrollOffset+30)),n>=h&&(i=e-30,i>0&&(o.scrollTop(i),this.scrollOffset=this.scrollOffset-30))},h.calculate_positions=function(){this.window_height=o.height()},h.drag_handler=function(i){if(i.target.nodeName,!this.disabled&&(1===i.which||a)&&!this.ignore_drag(i)){var e=this,s=!0;return this.$player=t(i.currentTarget),this.el_init_pos=this.get_actual_pos(this.$player),this.mouse_init_pos=this.get_mouse_pos(i),this.offsetY=this.mouse_init_pos.top-this.el_init_pos.top,this.$body.on(n.move,function(t){var i=e.get_mouse_pos(t),r=Math.abs(i.left-e.mouse_init_pos.left),o=Math.abs(i.top-e.mouse_init_pos.top);return r>e.options.distance||o>e.options.distance?s?(s=!1,e.on_dragstart.call(e,t),!1):(e.is_dragging===!0&&e.on_dragmove.call(e,t),!1):!1}),a?undefined:!1}},h.on_dragstart=function(i){if(i.preventDefault(),this.is_dragging)return this;this.drag_start=this.is_dragging=!0;var s=this.$container.offset();this.baseX=Math.round(s.left),this.baseY=Math.round(s.top),this.doc_height=t(e).height(),"clone"===this.options.helper?(this.$helper=this.$player.clone().appendTo(this.$container).addClass("helper"),this.helper=!0):this.helper=!1,this.scrollOffset=0,this.el_init_offset=this.$player.offset(),this.player_width=this.$player.width(),this.player_height=this.$player.height();var r=this.options.container_width||this.$container.width();return this.player_max_left=r-this.player_width+this.options.offset_left,this.options.start&&this.options.start.call(this.$player,i,this.get_drag_data(i)),!1},h.on_dragmove=function(t){var i=this.get_drag_data(t);this.options.autoscroll&&this.manage_scroll(i),this.options.move_element&&(this.helper?this.$helper:this.$player).css({position:"absolute",left:i.position.left,top:i.position.top});var e=this.last_position||i.position;return i.prev_position=e,this.options.drag&&this.options.drag.call(this.$player,t,i),this.last_position=i.position,!1},h.on_dragstop=function(t){var i=this.get_drag_data(t);return this.drag_start=!1,this.options.stop&&this.options.stop.call(this.$player,t,i),this.helper&&this.$helper.remove(),!1},h.on_select_start=function(t){return this.disabled||this.ignore_drag(t)?undefined:!1},h.enable=function(){this.disabled=!1},h.disable=function(){this.disabled=!0},h.destroy=function(){this.disable(),this.$container.off(".gridster-draggable"),this.$body.off(".gridster-draggable"),t(i).off(".gridster-draggable"),t.removeData(this.$container,"drag")},h.ignore_drag=function(i){return this.options.handle?!t(i.target).is(this.options.handle):t(i.target).is(this.options.ignore_dragging.join(", "))},t.fn.drag=function(t){return new s(this,t)}}(jQuery,window,document),function(t,i,e){function s(i,e){this.options=t.extend(!0,r,e),this.$el=t(i),this.$wrapper=this.$el.parent(),this.$widgets=this.$el.children(this.options.widget_selector).addClass("gs-w"),this.widgets=[],this.$changed=t([]),this.wrapper_width=this.$wrapper.width(),this.min_widget_width=2*this.options.widget_margins[0]+this.options.widget_base_dimensions[0],this.min_widget_height=2*this.options.widget_margins[1]+this.options.widget_base_dimensions[1],this.$style_tags=t([]),this.init()}var r={namespace:"",widget_selector:"li",widget_margins:[10,10],widget_base_dimensions:[400,225],extra_rows:0,extra_cols:0,min_cols:1,max_cols:null,min_rows:15,max_size_x:!1,autogenerate_stylesheet:!0,avoid_overlapped_widgets:!0,serialize_params:function(t,i){return{col:i.col,row:i.row,size_x:i.size_x,size_y:i.size_y}},collision:{},draggable:{items:".gs-w",distance:4},resize:{enabled:!1,axes:["x","y","both"],handle_append_to:"",handle_class:"gs-resize-handle",max_size:[1/0,1/0]}};s.generated_stylesheets=[];var o=s.prototype;o.init=function(){this.options.resize.enabled&&this.setup_resize(),this.generate_grid_and_stylesheet(),this.get_widgets_from_DOM(),this.set_dom_grid_height(),this.$wrapper.addClass("ready"),this.draggable(),this.options.resize.enabled&&this.resizable(),t(i).bind("resize.gridster",throttle(t.proxy(this.recalculate_faux_grid,this),200))},o.disable=function(){return this.$wrapper.find(".player-revert").removeClass("player-revert"),this.drag_api.disable(),this},o.enable=function(){return this.drag_api.enable(),this},o.disable_resize=function(){return this.$el.addClass("gs-resize-disabled"),this.resize_api.disable(),this},o.enable_resize=function(){return this.$el.removeClass("gs-resize-disabled"),this.resize_api.enable(),this},o.add_widget=function(i,e,s,r,o,a){var n;e||(e=1),s||(s=1),!r&!o?n=this.next_position(e,s):(n={col:r,row:o},this.empty_cells(r,o,e,s));var h=t(i).attr({"data-col":n.col,"data-row":n.row,"data-sizex":e,"data-sizey":s}).addClass("gs-w").appendTo(this.$el).hide();return this.$widgets=this.$widgets.add(h),this.register_widget(h),this.add_faux_rows(n.size_y),a&&this.set_widget_max_size(h,a),this.set_dom_grid_height(),h.fadeIn()},o.set_widget_max_size=function(t,i){if(t="number"==typeof t?this.$widgets.eq(t):t,!t.length)return this;var e=t.data("coords").grid;return e.max_size_x=i[0],e.max_size_y=i[1],this},o.add_resize_handle=function(i){var e=this.options.resize.handle_append_to;return t(this.resize_handle_tpl).appendTo(e?t(e,i):i),this},o.resize_widget=function(t,i,e,s,r){var o=t.coords().grid;s!==!1&&(s=!0),i||(i=o.size_x),e||(e=o.size_y),i>this.cols&&(i=this.cols);var a=o.size_y,n=o.col,h=n;if(s&&n+i-1>this.cols){var _=n+(i-1)-this.cols,d=n-_;h=Math.max(1,d)}e>a&&this.add_faux_rows(Math.max(e-a,0));var l={col:h,row:o.row,size_x:i,size_y:e};return this.mutate_widget_in_gridmap(t,o,l),this.set_dom_grid_height(),r&&r.call(this,l.size_x,l.size_y),t},o.mutate_widget_in_gridmap=function(i,e,s){e.size_x;var r=e.size_y,o=this.get_cells_occupied(e),a=this.get_cells_occupied(s),n=[];t.each(o.cols,function(i,e){-1===t.inArray(e,a.cols)&&n.push(e)});var h=[];t.each(a.cols,function(i,e){-1===t.inArray(e,o.cols)&&h.push(e)});var _=[];t.each(o.rows,function(i,e){-1===t.inArray(e,a.rows)&&_.push(e)});var d=[];if(t.each(a.rows,function(i,e){-1===t.inArray(e,o.rows)&&d.push(e)}),this.remove_from_gridmap(e),h.length){var l=[s.col,s.row,s.size_x,Math.min(r,s.size_y),i];this.empty_cells.apply(this,l)}if(d.length){var c=[s.col,s.row,s.size_x,s.size_y,i];this.empty_cells.apply(this,c)}if(e.col=s.col,e.row=s.row,e.size_x=s.size_x,e.size_y=s.size_y,this.add_to_gridmap(s,i),i.removeClass("player-revert"),i.data("coords").update({width:s.size_x*this.options.widget_base_dimensions[0]+2*(s.size_x-1)*this.options.widget_margins[0],height:s.size_y*this.options.widget_base_dimensions[1]+2*(s.size_y-1)*this.options.widget_margins[1]}),i.attr({"data-col":s.col,"data-row":s.row,"data-sizex":s.size_x,"data-sizey":s.size_y}),n.length){var p=[n[0],s.row,n.length,Math.min(r,s.size_y),i];this.remove_empty_cells.apply(this,p)}if(_.length){var g=[s.col,s.row,s.size_x,s.size_y,i];this.remove_empty_cells.apply(this,g)}return this.move_widget_up(i),this},o.empty_cells=function(i,e,s,r,o){var a=this.widgets_below({col:i,row:e-r,size_x:s,size_y:r});return a.not(o).each(t.proxy(function(i,s){var o=t(s).coords().grid;if(e+r-1>=o.row){var a=e+r-o.row;this.move_widget_down(t(s),a)}},this)),this.set_dom_grid_height(),this},o.remove_empty_cells=function(i,e,s,r,o){var a=this.widgets_below({col:i,row:e,size_x:s,size_y:r});return a.not(o).each(t.proxy(function(i,e){this.move_widget_up(t(e),r)},this)),this.set_dom_grid_height(),this},o.next_position=function(t,i){t||(t=1),i||(i=1);for(var e,s=this.gridmap,r=s.length,o=[],a=1;r>a;a++){e=s[a].length;for(var n=1;e>=n;n++){var h=this.can_move_to({size_x:t,size_y:i},a,n);h&&o.push({col:a,row:n,size_y:i,size_x:t})}}return o.length?this.sort_by_row_and_col_asc(o)[0]:!1},o.remove_widget=function(i,e,s){var r=i instanceof jQuery?i:t(i),o=r.coords().grid;t.isFunction(e)&&(s=e,e=!1),this.cells_occupied_by_placeholder={},this.$widgets=this.$widgets.not(r);var a=this.widgets_below(r);return this.remove_from_gridmap(o),r.fadeOut(t.proxy(function(){r.remove(),e||a.each(t.proxy(function(i,e){this.move_widget_up(t(e),o.size_y)},this)),this.set_dom_grid_height(),s&&s.call(this,i)},this)),this},o.remove_all_widgets=function(i){return this.$widgets.each(t.proxy(function(t,e){this.remove_widget(e,!0,i)},this)),this},o.serialize=function(i){i||(i=this.$widgets);var e=[];return i.each(t.proxy(function(i,s){e.push(this.options.serialize_params(t(s),t(s).coords().grid))},this)),e},o.serialize_changed=function(){return this.serialize(this.$changed)},o.register_widget=function(i){var e={col:parseInt(i.attr("data-col"),10),row:parseInt(i.attr("data-row"),10),size_x:parseInt(i.attr("data-sizex"),10),size_y:parseInt(i.attr("data-sizey"),10),max_size_x:parseInt(i.attr("data-max-sizex"),10)||!1,max_size_y:parseInt(i.attr("data-max-sizey"),10)||!1,el:i};return this.options.avoid_overlapped_widgets&&!this.can_move_to({size_x:e.size_x,size_y:e.size_y},e.col,e.row)&&(t.extend(e,this.next_position(e.size_x,e.size_y)),i.attr({"data-col":e.col,"data-row":e.row,"data-sizex":e.size_x,"data-sizey":e.size_y})),i.data("coords",i.coords()),i.data("coords").grid=e,this.add_to_gridmap(e,i),this.options.resize.enabled&&this.add_resize_handle(i),this},o.update_widget_position=function(t,i){return this.for_each_cell_occupied(t,function(t,e){return this.gridmap[t]?(this.gridmap[t][e]=i,undefined):this}),this},o.remove_from_gridmap=function(t){return this.update_widget_position(t,!1)},o.add_to_gridmap=function(i,e){if(this.update_widget_position(i,e||i.el),i.el){var s=this.widgets_below(i.el);s.each(t.proxy(function(i,e){this.move_widget_up(t(e))},this))}},o.draggable=function(){var i=this,e=t.extend(!0,{},this.options.draggable,{offset_left:this.options.widget_margins[0],container_width:this.container_width,ignore_dragging:["INPUT","TEXTAREA","SELECT","BUTTON","."+this.options.resize.handle_class],start:function(e,s){i.$widgets.filter(".player-revert").removeClass("player-revert"),i.$player=t(this),i.$helper=t(s.$helper),i.helper=!i.$helper.is(i.$player),i.on_start_drag.call(i,e,s),i.$el.trigger("gridster:dragstart")},stop:function(t,e){i.on_stop_drag.call(i,t,e),i.$el.trigger("gridster:dragstop")},drag:throttle(function(t,e){i.on_drag.call(i,t,e),i.$el.trigger("gridster:drag")},60)});return this.drag_api=this.$el.drag(e),this},o.resizable=function(){return this.resize_api=this.$el.drag({items:"."+this.options.resize.handle_class,offset_left:this.options.widget_margins[0],container_width:this.container_width,move_element:!1,start:t.proxy(this.on_start_resize,this),stop:t.proxy(function(i,e){delay(t.proxy(function(){this.on_stop_resize(i,e)},this),120)},this),drag:throttle(t.proxy(this.on_resize,this),60)}),this},o.setup_resize=function(){this.resize_handle_class=this.options.resize.handle_class;var i=this.options.resize.axes,e='';return this.resize_handle_tpl=t.map(i,function(t){return e.replace("{type}",t)}).join(""),this},o.on_start_drag=function(i,e){this.$helper.add(this.$player).add(this.$wrapper).addClass("dragging"),this.$player.addClass("player"),this.player_grid_data=this.$player.coords().grid,this.placeholder_grid_data=t.extend({},this.player_grid_data),this.$el.css("height",this.$el.height()+this.player_grid_data.size_y*this.min_widget_height);var s=this.faux_grid,r=this.$player.data("coords").coords;this.cells_occupied_by_player=this.get_cells_occupied(this.player_grid_data),this.cells_occupied_by_placeholder=this.get_cells_occupied(this.placeholder_grid_data),this.last_cols=[],this.last_rows=[],this.collision_api=this.$helper.collision(s,this.options.collision),this.$preview_holder=t("<"+this.$player.get(0).tagName+" />",{"class":"preview-holder","data-row":this.$player.attr("data-row"),"data-col":this.$player.attr("data-col"),css:{width:r.width,height:r.height}}).appendTo(this.$el),this.options.draggable.start&&this.options.draggable.start.call(this,i,e)},o.on_drag=function(t,i){if(null===this.$player)return!1;var e={left:i.position.left+this.baseX,top:i.position.top+this.baseY};this.colliders_data=this.collision_api.get_closest_colliders(e),this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column),this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row),this.helper&&this.$player&&this.$player.css({left:i.position.left,top:i.position.top}),this.options.draggable.drag&&this.options.draggable.drag.call(this,t,i)},o.on_stop_drag=function(t,i){this.$helper.add(this.$player).add(this.$wrapper).removeClass("dragging"),i.position.left=i.position.left+this.baseX,i.position.top=i.position.top+this.baseY,this.colliders_data=this.collision_api.get_closest_colliders(i.position),this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column),this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row),this.$player.addClass("player-revert").removeClass("player").attr({"data-col":this.placeholder_grid_data.col,"data-row":this.placeholder_grid_data.row}).css({left:"",top:""}),this.$changed=this.$changed.add(this.$player),this.cells_occupied_by_player=this.get_cells_occupied(this.placeholder_grid_data),this.set_cells_player_occupies(this.placeholder_grid_data.col,this.placeholder_grid_data.row),this.$player.coords().grid.row=this.placeholder_grid_data.row,this.$player.coords().grid.col=this.placeholder_grid_data.col,this.options.draggable.stop&&this.options.draggable.stop.call(this,t,i),this.$preview_holder.remove(),this.$player=null,this.$helper=null,this.placeholder_grid_data={},this.player_grid_data={},this.cells_occupied_by_placeholder={},this.cells_occupied_by_player={},this.set_dom_grid_height()},o.on_start_resize=function(i,e){this.$resized_widget=e.$player.closest(".gs-w"),this.resize_coords=this.$resized_widget.coords(),this.resize_wgd=this.resize_coords.grid,this.resize_initial_width=this.resize_coords.coords.width,this.resize_initial_height=this.resize_coords.coords.height,this.resize_initial_sizex=this.resize_coords.grid.size_x,this.resize_initial_sizey=this.resize_coords.grid.size_y,this.resize_last_sizex=this.resize_initial_sizex,this.resize_last_sizey=this.resize_initial_sizey,this.resize_max_size_x=Math.min(this.resize_wgd.max_size_x||this.options.resize.max_size[0],this.cols-this.resize_wgd.col+1),this.resize_max_size_y=this.resize_wgd.max_size_y||this.options.resize.max_size[1],this.resize_dir={right:e.$player.is("."+this.resize_handle_class+"-x"),bottom:e.$player.is("."+this.resize_handle_class+"-y")},this.$resized_widget.css({"min-width":this.options.widget_base_dimensions[0],"min-height":this.options.widget_base_dimensions[1]});var s=this.$resized_widget.get(0).tagName;this.$resize_preview_holder=t("<"+s+" />",{"class":"preview-holder resize-preview-holder","data-row":this.$resized_widget.attr("data-row"),"data-col":this.$resized_widget.attr("data-col"),css:{width:this.resize_initial_width,height:this.resize_initial_height}}).appendTo(this.$el),this.$resized_widget.addClass("resizing")},o.on_stop_resize=function(){this.$resized_widget.removeClass("resizing").css({width:"",height:""}),delay(t.proxy(function(){this.$resize_preview_holder.remove().css({"min-width":"","min-height":""})},this),300)},o.on_resize=function(t,i){var e=i.pointer.diff_left,s=i.pointer.diff_top,r=this.options.widget_base_dimensions[0],o=this.options.widget_base_dimensions[1],a=1/0,n=1/0,h=Math.ceil(e/(this.options.widget_base_dimensions[0]+2*this.options.widget_margins[0])-.2),_=Math.ceil(s/(this.options.widget_base_dimensions[1]+2*this.options.widget_margins[1])-.2),d=Math.max(1,this.resize_initial_sizex+h),l=Math.max(1,this.resize_initial_sizey+_);d=Math.min(d,this.resize_max_size_x),a=this.resize_max_size_x*r+2*(d-1)*this.options.widget_margins[0],l=Math.min(l,this.resize_max_size_y),n=this.resize_max_size_y*o+2*(l-1)*this.options.widget_margins[1],this.resize_dir.right?l=this.resize_initial_sizey:this.resize_dir.bottom&&(d=this.resize_initial_sizex);var c={};!this.resize_dir.bottom&&(c.width=Math.min(this.resize_initial_width+e,a)),!this.resize_dir.right&&(c.height=Math.min(this.resize_initial_height+s,n)),this.$resized_widget.css(c),(d!==this.resize_last_sizex||l!==this.resize_last_sizey)&&(this.resize_widget(this.$resized_widget,d,l,!1),this.$resize_preview_holder.css({width:"",height:""}).attr({"data-row":this.$resized_widget.attr("data-row"),"data-sizex":d,"data-sizey":l})),this.resize_last_sizex=d,this.resize_last_sizey=l},o.on_overlapped_column_change=function(i,e){if(!this.colliders_data.length)return this;var s,r=this.get_targeted_columns(this.colliders_data[0].el.data.col),o=this.last_cols.length,a=r.length;for(s=0;a>s;s++)-1===t.inArray(r[s],this.last_cols)&&(i||t.noop).call(this,r[s]);for(s=0;o>s;s++)-1===t.inArray(this.last_cols[s],r)&&(e||t.noop).call(this,this.last_cols[s]);return this.last_cols=r,this},o.on_overlapped_row_change=function(i,e){if(!this.colliders_data.length)return this;var s,r=this.get_targeted_rows(this.colliders_data[0].el.data.row),o=this.last_rows.length,a=r.length;for(s=0;a>s;s++)-1===t.inArray(r[s],this.last_rows)&&(i||t.noop).call(this,r[s]);for(s=0;o>s;s++)-1===t.inArray(this.last_rows[s],r)&&(e||t.noop).call(this,this.last_rows[s]);this.last_rows=r},o.set_player=function(t,i,e){var s=this;e||this.empty_cells_player_occupies();var r=e?{col:t}:s.colliders_data[0].el.data,o=r.col,a=i||r.row;this.player_grid_data={col:o,row:a,size_y:this.player_grid_data.size_y,size_x:this.player_grid_data.size_x},this.cells_occupied_by_player=this.get_cells_occupied(this.player_grid_data);var n=this.get_widgets_overlapped(this.player_grid_data),h=this.widgets_constraints(n);if(this.manage_movements(h.can_go_up,o,a),this.manage_movements(h.can_not_go_up,o,a),!n.length){var _=this.can_go_player_up(this.player_grid_data);_!==!1&&(a=_),this.set_placeholder(o,a)}return{col:o,row:a}},o.widgets_constraints=function(i){var e,s=t([]),r=[],o=[];return i.each(t.proxy(function(i,e){var a=t(e),n=a.coords().grid;this.can_go_widget_up(n)?(s=s.add(a),r.push(n)):o.push(n)},this)),e=i.not(s),{can_go_up:this.sort_by_row_asc(r),can_not_go_up:this.sort_by_row_desc(o)}},o.sort_by_row_asc=function(i){return i=i.sort(function(i,e){return i.row||(i=t(i).coords().grid,e=t(e).coords().grid),i.row>e.row?1:-1})},o.sort_by_row_and_col_asc=function(t){return t=t.sort(function(t,i){return t.row>i.row||t.row===i.row&&t.col>i.col?1:-1})},o.sort_by_col_asc=function(t){return t=t.sort(function(t,i){return t.col>i.col?1:-1})},o.sort_by_row_desc=function(t){return t=t.sort(function(t,i){return t.row+t.size_y=0&&t.inArray(e,s.rows)>=0},o.is_placeholder_in=function(i,e){var s=this.cells_occupied_by_placeholder||{};return this.is_placeholder_in_col(i)&&t.inArray(e,s.rows)>=0},o.is_placeholder_in_col=function(i){var e=this.cells_occupied_by_placeholder||[];return t.inArray(i,e.cols)>=0},o.is_empty=function(t,i){return this.gridmap[t]!==undefined?this.gridmap[t][i]!==undefined&&this.gridmap[t][i]===!1?!0:!1:!0},o.is_occupied=function(t,i){return this.gridmap[t]?this.gridmap[t][i]?!0:!1:!1},o.is_widget=function(t,i){var e=this.gridmap[t];return e?(e=e[i],e?e:!1):!1},o.is_widget_under_player=function(t,i){return this.is_widget(t,i)?this.is_player_in(t,i):!1},o.get_widgets_under_player=function(i){i||(i=this.cells_occupied_by_player||{cols:[],rows:[]});var e=t([]);return t.each(i.cols,t.proxy(function(s,r){t.each(i.rows,t.proxy(function(t,i){this.is_widget(r,i)&&(e=e.add(this.gridmap[r][i]))},this))},this)),e},o.set_placeholder=function(i,e){var s=t.extend({},this.placeholder_grid_data),r=this.widgets_below({col:s.col,row:s.row,size_y:s.size_y,size_x:s.size_x}),o=i+s.size_x-1;o>this.cols&&(i-=o-i);var a=e>this.placeholder_grid_data.row,n=this.placeholder_grid_data.col!==i;this.placeholder_grid_data.col=i,this.placeholder_grid_data.row=e,this.cells_occupied_by_placeholder=this.get_cells_occupied(this.placeholder_grid_data),this.$preview_holder.attr({"data-row":e,"data-col":i}),(a||n)&&r.each(t.proxy(function(e,r){this.move_widget_up(t(r),this.placeholder_grid_data.col-i+s.size_y)},this));var h=this.get_widgets_under_player(this.cells_occupied_by_placeholder);h.length&&h.each(t.proxy(function(i,r){var o=t(r);this.move_widget_down(o,e+s.size_y-o.data("coords").grid.row)},this))},o.can_go_player_up=function(t){var i=t.row+t.size_y-1,e=!0,s=[],r=1e4,o=this.get_widgets_under_player();return this.for_each_column_occupied(t,function(t){var a=this.gridmap[t],n=i+1;for(s[t]=[];--n>0&&(this.is_empty(t,n)||this.is_player(t,n)||this.is_widget(t,n)&&a[n].is(o));)s[t].push(n),r=r>n?n:r;return 0===s[t].length?(e=!1,!0):(s[t].sort(function(t,i){return t-i}),undefined)}),e?this.get_valid_rows(t,s,r):!1},o.can_go_widget_up=function(t){var i=t.row+t.size_y-1,e=!0,s=[],r=1e4;return this.for_each_column_occupied(t,function(o){var a=this.gridmap[o];s[o]=[];for(var n=i+1;--n>0&&(!this.is_widget(o,n)||this.is_player_in(o,n)||a[n].is(t.el));)this.is_player(o,n)||this.is_placeholder_in(o,n)||this.is_player_in(o,n)||s[o].push(n),r>n&&(r=n);return 0===s[o].length?(e=!1,!0):(s[o].sort(function(t,i){return t-i}),undefined)}),e?this.get_valid_rows(t,s,r):!1},o.get_valid_rows=function(i,e,s){for(var r=i.row,o=i.row+i.size_y-1,a=i.size_y,n=s-1,h=[];o>=++n;){var _=!0;if(t.each(e,function(i,e){t.isArray(e)&&-1===t.inArray(n,e)&&(_=!1)}),_===!0&&(h.push(n),h.length===a))break}var d=!1;return 1===a?h[0]!==r&&(d=h[0]||!1):h[0]!==r&&(d=this.get_consecutive_numbers_index(h,a)),d},o.get_consecutive_numbers_index=function(t,i){for(var e=t.length,s=[],r=!0,o=-1,a=0;e>a;a++){if(r||t[a]===o+1){if(s.push(a),s.length===i)break;r=!1}else s=[],r=!0;o=t[a]}return s.length>=i?t[s[0]]:!1},o.get_widgets_overlapped=function(){var i=t([]),e=[],s=this.cells_occupied_by_player.rows.slice(0);return s.reverse(),t.each(this.cells_occupied_by_player.cols,t.proxy(function(r,o){t.each(s,t.proxy(function(s,r){if(!this.gridmap[o])return!0;var a=this.gridmap[o][r];this.is_occupied(o,r)&&!this.is_player(a)&&-1===t.inArray(a,e)&&(i=i.add(a),e.push(a))},this))},this)),i},o.on_start_overlapping_column=function(t){this.set_player(t,!1)},o.on_start_overlapping_row=function(t){this.set_player(!1,t)},o.on_stop_overlapping_column=function(t){this.set_player(t,!1);var i=this;this.for_each_widget_below(t,this.cells_occupied_by_player.rows[0],function(){i.move_widget_up(this,i.player_grid_data.size_y)})},o.on_stop_overlapping_row=function(t){this.set_player(!1,t);for(var i=this,e=this.cells_occupied_by_player.cols,s=0,r=e.length;r>s;s++)this.for_each_widget_below(e[s],t,function(){i.move_widget_up(this,i.player_grid_data.size_y)})},o.move_widget_to=function(i,e){var s=this,r=i.coords().grid;e-r.row;var o=this.widgets_below(i),a=this.can_move_to(r,r.col,e,i);return a===!1?!1:(this.remove_from_gridmap(r),r.row=e,this.add_to_gridmap(r),i.attr("data-row",e),this.$changed=this.$changed.add(i),o.each(function(i,e){var r=t(e),o=r.coords().grid,a=s.can_go_widget_up(o);a&&a!==o.row&&s.move_widget_to(r,a)}),this)},o.move_widget_up=function(i,e){var s=i.coords().grid,r=s.row,o=[];return e||(e=1),this.can_go_up(i)?(this.for_each_column_occupied(s,function(s){if(-1===t.inArray(i,o)){var a=i.coords().grid,n=r-e;if(n=this.can_go_up_to_row(a,s,n),!n)return!0;var h=this.widgets_below(i);this.remove_from_gridmap(a),a.row=n,this.add_to_gridmap(a),i.attr("data-row",a.row),this.$changed=this.$changed.add(i),o.push(i),h.each(t.proxy(function(i,s){this.move_widget_up(t(s),e)},this))}}),undefined):!1},o.move_widget_down=function(i,e){var s,r,o,a;if(0>=e)return!1;if(s=i.coords().grid,r=s.row,o=[],a=e,!i)return!1;if(-1===t.inArray(i,o)){var n=i.coords().grid,h=r+e,_=this.widgets_below(i);this.remove_from_gridmap(n),_.each(t.proxy(function(i,e){var s=t(e),r=s.coords().grid,o=this.displacement_diff(r,n,a);o>0&&this.move_widget_down(s,o)},this)),n.row=h,this.update_widget_position(n,i),i.attr("data-row",n.row),this.$changed=this.$changed.add(i),o.push(i)}},o.can_go_up_to_row=function(i,e,s){var r,o=this.gridmap,a=!0,n=[],h=i.row;if(this.for_each_column_occupied(i,function(t){for(o[t],n[t]=[],r=h;r--&&this.is_empty(t,r)&&!this.is_placeholder_in(t,r);)n[t].push(r);return n[t].length?undefined:(a=!1,!0)}),!a)return!1;for(r=s,r=1;h>r;r++){for(var _=!0,d=0,l=n.length;l>d;d++)n[d]&&-1===t.inArray(r,n[d])&&(_=!1);if(_===!0){a=r;break}}return a},o.displacement_diff=function(t,i,e){var s=t.row,r=[],o=i.row+i.size_y;this.for_each_column_occupied(t,function(t){for(var i=0,e=o;s>e;e++)this.is_empty(t,e)&&(i+=1);r.push(i)});var a=Math.max.apply(Math,r);return e-=a,e>0?e:0},o.widgets_below=function(i){var e=t.isPlainObject(i)?i:i.coords().grid,s=this;this.gridmap;var r=e.row+e.size_y-1,o=t([]);return this.for_each_column_occupied(e,function(i){s.for_each_widget_below(i,r,function(){return s.is_player(this)||-1!==t.inArray(this,o)?undefined:(o=o.add(this),!0)})}),this.sort_by_row_asc(o)},o.set_cells_player_occupies=function(t,i){return this.remove_from_gridmap(this.placeholder_grid_data),this.placeholder_grid_data.col=t,this.placeholder_grid_data.row=i,this.add_to_gridmap(this.placeholder_grid_data,this.$player),this},o.empty_cells_player_occupies=function(){return this.remove_from_gridmap(this.placeholder_grid_data),this},o.can_go_up=function(t){var i=t.coords().grid,e=i.row,s=e-1;this.gridmap;var r=!0;return 1===e?!1:(this.for_each_column_occupied(i,function(t){return this.is_widget(t,s),this.is_occupied(t,s)||this.is_player(t,s)||this.is_placeholder_in(t,s)||this.is_player_in(t,s)?(r=!1,!0):undefined
+}),r)},o.can_move_to=function(t,i,e,s){this.gridmap;var r=t.el,o={size_y:t.size_y,size_x:t.size_x,col:i,row:e},a=!0,n=i+t.size_x-1;return n>this.cols?!1:s&&e+t.size_y-1>s?!1:(this.for_each_cell_occupied(o,function(i,e){var s=this.is_widget(i,e);!s||t.el&&!s.is(r)||(a=!1)}),a)},o.get_targeted_columns=function(t){for(var i=(t||this.player_grid_data.col)+(this.player_grid_data.size_x-1),e=[],s=t;i>=s;s++)e.push(s);return e},o.get_targeted_rows=function(t){for(var i=(t||this.player_grid_data.row)+(this.player_grid_data.size_y-1),e=[],s=t;i>=s;s++)e.push(s);return e},o.get_cells_occupied=function(t){var i,e={cols:[],rows:[]};for(arguments[1]instanceof jQuery&&(t=arguments[1].coords().grid),i=0;t.size_x>i;i++){var s=t.col+i;e.cols.push(s)}for(i=0;t.size_y>i;i++){var r=t.row+i;e.rows.push(r)}return e},o.for_each_cell_occupied=function(t,i){return this.for_each_column_occupied(t,function(e){this.for_each_row_occupied(t,function(t){i.call(this,e,t)})}),this},o.for_each_column_occupied=function(t,i){for(var e=0;t.size_x>e;e++){var s=t.col+e;i.call(this,s,t)}},o.for_each_row_occupied=function(t,i){for(var e=0;t.size_y>e;e++){var s=t.row+e;i.call(this,s,t)}},o._traversing_widgets=function(i,e,s,r,o){var a=this.gridmap;if(a[s]){var n,h,_=i+"/"+e;if(arguments[2]instanceof jQuery){var d=arguments[2].coords().grid;s=d.col,r=d.row,o=arguments[3]}var l=[],c=r,p={"for_each/above":function(){for(;c--&&!(c>0&&this.is_widget(s,c)&&-1===t.inArray(a[s][c],l)&&(n=o.call(a[s][c],s,c),l.push(a[s][c]),n)););},"for_each/below":function(){for(c=r+1,h=a[s].length;h>c&&(!this.is_widget(s,c)||-1!==t.inArray(a[s][c],l)||(n=o.call(a[s][c],s,c),l.push(a[s][c]),!n));c++);}};p[_]&&p[_].call(this)}},o.for_each_widget_above=function(t,i,e){return this._traversing_widgets("for_each","above",t,i,e),this},o.for_each_widget_below=function(t,i,e){return this._traversing_widgets("for_each","below",t,i,e),this},o.get_highest_occupied_cell=function(){for(var t,i=this.gridmap,e=[],s=[],r=i.length-1;r>=1;r--)for(t=i[r].length-1;t>=1;t--)if(this.is_widget(r,t)){e.push(t),s[t]=r;break}var o=Math.max.apply(Math,e);return this.highest_occupied_cell={col:s[o],row:o},this.highest_occupied_cell},o.get_widgets_from=function(i,e){this.gridmap;var s=t();return i&&(s=s.add(this.$widgets.filter(function(){var e=t(this).attr("data-col");return e===i||e>i}))),e&&(s=s.add(this.$widgets.filter(function(){var i=t(this).attr("data-row");return i===e||i>e}))),s},o.set_dom_grid_height=function(){var t=this.get_highest_occupied_cell().row;return this.$el.css("height",t*this.min_widget_height),this},o.generate_stylesheet=function(i){var e,r="",o=this.options.max_size_x||this.cols;i||(i={}),i.cols||(i.cols=this.cols),i.rows||(i.rows=this.rows),i.namespace||(i.namespace=this.options.namespace),i.widget_base_dimensions||(i.widget_base_dimensions=this.options.widget_base_dimensions),i.widget_margins||(i.widget_margins=this.options.widget_margins),i.min_widget_width=2*i.widget_margins[0]+i.widget_base_dimensions[0],i.min_widget_height=2*i.widget_margins[1]+i.widget_base_dimensions[1];var a=t.param(i);if(t.inArray(a,s.generated_stylesheets)>=0)return!1;for(s.generated_stylesheets.push(a),e=i.cols;e>=0;e--)r+=i.namespace+' [data-col="'+(e+1)+'"] { left:'+(e*i.widget_base_dimensions[0]+e*i.widget_margins[0]+(e+1)*i.widget_margins[0])+"px; }\n";for(e=i.rows;e>=0;e--)r+=i.namespace+' [data-row="'+(e+1)+'"] { top:'+(e*i.widget_base_dimensions[1]+e*i.widget_margins[1]+(e+1)*i.widget_margins[1])+"px; }\n";for(var n=1;i.rows>=n;n++)r+=i.namespace+' [data-sizey="'+n+'"] { height:'+(n*i.widget_base_dimensions[1]+(n-1)*2*i.widget_margins[1])+"px; }\n";for(var h=1;o>=h;h++)r+=i.namespace+' [data-sizex="'+h+'"] { width:'+(h*i.widget_base_dimensions[0]+(h-1)*2*i.widget_margins[0])+"px; }\n";return this.add_style_tag(r)},o.add_style_tag=function(t){var i=e,s=i.createElement("style");return i.getElementsByTagName("head")[0].appendChild(s),s.setAttribute("type","text/css"),s.styleSheet?s.styleSheet.cssText=t:s.appendChild(e.createTextNode(t)),this.$style_tags=this.$style_tags.add(s),this},o.remove_style_tags=function(){this.$style_tags.remove()},o.generate_faux_grid=function(t,i){this.faux_grid=[],this.gridmap=[];var e,s;for(e=i;e>0;e--)for(this.gridmap[e]=[],s=t;s>0;s--)this.add_faux_cell(s,e);return this},o.add_faux_cell=function(i,e){var s=t({left:this.baseX+(e-1)*this.min_widget_width,top:this.baseY+(i-1)*this.min_widget_height,width:this.min_widget_width,height:this.min_widget_height,col:e,row:i,original_col:e,original_row:i}).coords();return t.isArray(this.gridmap[e])||(this.gridmap[e]=[]),this.gridmap[e][i]=!1,this.faux_grid.push(s),this},o.add_faux_rows=function(t){for(var i=this.rows,e=i+(t||1),s=e;s>i;s--)for(var r=this.cols;r>=1;r--)this.add_faux_cell(s,r);return this.rows=e,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this},o.add_faux_cols=function(t){for(var i=this.cols,e=i+(t||1),s=i;e>s;s++)for(var r=this.rows;r>=1;r--)this.add_faux_cell(r,s);return this.cols=e,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this},o.recalculate_faux_grid=function(){var e=this.$wrapper.width();return this.baseX=(t(i).width()-e)/2,this.baseY=this.$wrapper.offset().top,t.each(this.faux_grid,t.proxy(function(t,i){this.faux_grid[t]=i.update({left:this.baseX+(i.data.col-1)*this.min_widget_width,top:this.baseY+(i.data.row-1)*this.min_widget_height})},this)),this},o.get_widgets_from_DOM=function(){return this.$widgets.each(t.proxy(function(i,e){this.register_widget(t(e))},this)),this},o.generate_grid_and_stylesheet=function(){var e=this.$wrapper.width();this.$wrapper.height();var s=this.options.max_cols,r=Math.floor(e/this.min_widget_width)+this.options.extra_cols,o=this.$widgets.map(function(){return t(this).attr("data-col")}).get();o.length||(o=[0]);var a=Math.max.apply(Math,o),n=this.options.extra_rows;return this.$widgets.each(function(i,e){n+=+t(e).attr("data-sizey")}),this.cols=Math.max(a,r,this.options.min_cols),s&&s>=a&&this.cols>s&&(this.cols=s),this.rows=Math.max(n,this.options.min_rows),this.baseX=(t(i).width()-e)/2,this.baseY=this.$wrapper.offset().top,this.container_width=this.cols*this.options.widget_base_dimensions[0]+2*(this.cols-1)*this.options.widget_margins[0],this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this.generate_faux_grid(this.rows,this.cols)},o.destroy=function(){return t(i).unbind(".gridster"),this.drag_api&&this.drag_api.destroy(),this.remove_style_tags(),this.$el.remove(),this},t.fn.gridster=function(i){return this.each(function(){t(this).data("gridster")||t(this).data("gridster",new s(this,i))})},t.Gridster=o}(jQuery,window,document),function(t){var i=t.Gridster;i.widgets_in_col=function(t){if(!this.gridmap[t])return!1;for(var i=this.gridmap[t].length-1;i>=0;i--)if(this.is_widget(t,i)!==!1)return!0;return!1},i.widgets_in_row=function(t){for(var i=this.gridmap.length;i>=1;i--)if(this.is_widget(i,t)!==!1)return!0;return!1},i.widgets_in_range=function(i,e,s,r){var o,a,n,h,_=t([]);for(o=s;o>=i;o--)for(a=r;a>=e;a--)n=this.is_widget(o,a),n!==!1&&(h=n.data("coords").grid,h.col>=i&&s>=h.col&&h.row>=e&&r>=h.row&&(_=_.add(n)));return _},i.get_bottom_most_occupied_cell=function(){var t=0,i=0;return this.for_each_cell(function(e,s,r){e&&r>t&&(t=r,i=s)}),{col:i,row:t}},i.get_right_most_occupied_cell=function(){var t=0,i=0;return this.for_each_cell(function(e,s,r){return e?(t=r,i=s,!1):undefined}),{col:i,row:t}},i.for_each_cell=function(t,i){i||(i=this.gridmap);var e=i.length,s=i[1].length;t:for(var r=e-1;r>=1;r--)for(var o=s-1;o>=1;o--){var a=i[r]&&i[r][o];if(t){if(t.call(this,a,r,o)===!1)break t}else;}},i.next_position_in_range=function(t,i,e){t||(t=1),i||(i=1);for(var s,r=this.gridmap,o=r.length,a=[],n=1;o>n;n++){s=e||r[n].length;for(var h=1;s>=h;h++){var _=this.can_move_to({size_x:t,size_y:i},n,h,e);_&&a.push({col:n,row:h,size_y:i,size_x:t})}}return a.length>=1?this.sort_by_col_asc(a)[0]:!1},i.closest_to_right=function(t,i){if(!this.gridmap[t])return!1;for(var e=this.gridmap.length-1,s=t;e>=s;s++)if(this.gridmap[s][i])return{col:s,row:i};return!1},i.closest_to_left=function(t,i){if(this.gridmap.length-1,!this.gridmap[t])return!1;for(var e=t;e>=1;e--)if(this.gridmap[e][i])return{col:e,row:i};return!1}}(jQuery,window,document);
\ No newline at end of file
diff --git a/package.json b/package.json
index fd0e4ecef..0cb6a19e9 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "gridster",
"title": "gridster.js",
"description": "a drag-and-drop multi-column jQuery grid plugin",
- "version": "0.1.0",
+ "version": "0.2.0",
"homepage": "http://gridster.net/",
"author": {
"name": "ducksboard",