From aa939d8bf7ed5360b721a920770336dd6dff1c1c Mon Sep 17 00:00:00 2001 From: vieron <javiersanchezmarin@gmail.com> Date: Mon, 23 Jul 2012 22:08:09 +0200 Subject: [PATCH] updated docs and dist --- dist/jquery.gridster.css | 8 +- dist/jquery.gridster.js | 581 ++++++++++-------- dist/jquery.gridster.min.css | 2 +- dist/jquery.gridster.min.js | 2 +- docs/api.js | 4 +- ...her DOM elements or\nCoords objects..html" | 97 ++- ...d with any DOM element can\ncollide..html" | 70 ++- docs/classes/Draggable.html | 207 ++++++- docs/classes/Gridster.html | 218 ++++--- docs/data.json | 298 +++++---- docs/files/src_jquery.collision.js.html | 302 +++++---- docs/files/src_jquery.coords.js.html | 35 +- docs/files/src_jquery.draggable.js.html | 62 +- docs/files/src_jquery.gridster.js.html | 250 ++++---- docs/index.html | 20 +- 15 files changed, 1387 insertions(+), 769 deletions(-) rename docs/classes/Collision.html => "docs/classes/Collision\n\nDetects collisions between a DOM element against other DOM elements or\nCoords objects..html" (80%) rename docs/classes/Coords.html => "docs/classes/Coords\n\nCreates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height)\nto simulate DOM elements on the screen.\nCoords is used by Gridster to create a faux grid with any DOM element can\ncollide..html" (71%) diff --git a/dist/jquery.gridster.css b/dist/jquery.gridster.css index 800e228bbb..986c69f573 100644 --- a/dist/jquery.gridster.css +++ b/dist/jquery.gridster.css @@ -45,10 +45,10 @@ .gridster .dragging { z-index: 10!important; - -webkit-transition: none!important; - -moz-transition: none!important; - -o-transition: none!important; - transition: none!important; + -webkit-transition: all 0s !important; + -moz-transition: all 0s !important; + -o-transition: all 0s !important; + transition: all 0s !important; } /* Uncomment this if you set helper : "clone" in draggable options */ diff --git a/dist/jquery.gridster.js b/dist/jquery.gridster.js index 54497cffaf..2cc3b61937 100644 --- a/dist/jquery.gridster.js +++ b/dist/jquery.gridster.js @@ -4,10 +4,16 @@ ;(function($, window, document, undefined){ /** - * Coords - * * @class Coords - * @param {HTMLElement|Object} obj HTMLElement or a literal Object with the left, top, width and height properties. + * + * Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) + * to simulate DOM elements on the screen. + * Coords is used by Gridster to create a faux grid with any DOM element can + * collide. + * + * @param {HTMLElement|Object} obj The jQuery HTMLElement or a object with: left, + * top, width and height properties. + * @return {Object} Coords instance. * @constructor */ function Coords(obj) { @@ -23,8 +29,10 @@ return this; } + var fn = Coords.prototype; + fn.init = function(){ this.set(); this.original_coords = this.get(); @@ -82,6 +90,7 @@ return this.coords; }; + //jQuery adapter $.fn.coords = function() { if (this.data('coords') ) { @@ -98,198 +107,216 @@ ;(function($, window, document, undefined){ var defaults = { - colliders_context: document.body, - on_overlap: function(collider_data){}, - on_overlap_start : function(collider_data){ - // console.log('the element START being a collider', collider_data); - }, - on_overlap_stop : function(collider_data){ - // console.log('the element STOP being a collider', collider_data); - } + colliders_context: document.body + // ,on_overlap: function(collider_data){}, + // on_overlap_start : function(collider_data){}, + // on_overlap_stop : function(collider_data){} }; + /** - * Collision - * * @class Collision + * + * Detects collisions between a DOM element against other DOM elements or + * Coords objects. + * * @uses Coords - * @param {HTMLElement} element An Attribute name or object property path - * @param {String|HTMLElement|Array} colliders An Attribute name or object property path - * @param {Object} [options] An Attribute name or object property path - * @param {Function} [options.on_overlap] An Attribute name or object property path - * @param {Function} [options.on_overlap_start] An Attribute name or object property path - * @param {Function} [options.on_overlap_stop] An Attribute name or object property path - * @return {Object} dasdasdadasd + * @param {HTMLElement} el The jQuery wrapped HTMLElement. + * @param {HTMLElement|Array} colliders Can be a jQuery collection + * of HTMLElements or an Array of Coords instances. + * @param {Object} [options] An Object with all options you want to + * overwrite: + * @param {Function} [options.on_overlap_start] Executes a function the first + * time each `collider ` is overlapped. + * @param {Function} [options.on_overlap_stop] Executes a function when a + * `collider` is no longer collided. + * @param {Function} [options.on_overlap] Executes a function when the + * mouse is moved during the collision. + * @return {Object} Collision instance. * @constructor */ - function Collision(element, colliders, options) { - this.options = $.extend(defaults, options); - this.$element = element; - this.last_colliders = []; - this.last_colliders_coords = []; - if (typeof colliders === 'string' || colliders instanceof jQuery) { - this.$colliders = $(colliders, - this.options.colliders_context).not(this.$element); - }else{ - this.colliders = $(colliders); - } + function Collision(el, colliders, options) { + this.options = $.extend(defaults, options); + this.$element = el; + this.last_colliders = []; + this.last_colliders_coords = []; + if (typeof colliders === 'string' || colliders instanceof jQuery) { + this.$colliders = $(colliders, + this.options.colliders_context).not(this.$element); + }else{ + this.colliders = $(colliders); + } - this.init(); + this.init(); } + var fn = Collision.prototype; + fn.init = function() { - this.find_collisions(); + this.find_collisions(); }; + fn.overlaps = function(a, b) { - var x = false; - var y = false; + var x = false; + var y = false; - if ((b.x1 >= a.x1 && b.x1 <= a.x2) || - (b.x2 >= a.x1 && b.x2 <= a.x2) || - (a.x1 >= b.x1 && a.x2 <= b.x2) - ) { x = true; } + if ((b.x1 >= a.x1 && b.x1 <= a.x2) || + (b.x2 >= a.x1 && b.x2 <= a.x2) || + (a.x1 >= b.x1 && a.x2 <= b.x2) + ) { x = true; } - if ((b.y1 >= a.y1 && b.y1 <= a.y2) || - (b.y2 >= a.y1 && b.y2 <= a.y2) || - (a.y1 >= b.y1 && a.y2 <= b.y2) - ) { y = true; } + if ((b.y1 >= a.y1 && b.y1 <= a.y2) || + (b.y2 >= a.y1 && b.y2 <= a.y2) || + (a.y1 >= b.y1 && a.y2 <= b.y2) + ) { y = true; } - return (x && y); + return (x && y); }; + fn.detect_overlapping_region = function(a, b){ - var regionX = ''; - var regionY = ''; + var regionX = ''; + var regionY = ''; - if (a.y1 > b.cy && a.y1 < b.y2) { regionX = 'N'; } - if (a.y2 > b.y1 && a.y2 < b.cy) { regionX = 'S'; } - if (a.x1 > b.cx && a.x1 < b.x2) { regionY = 'W'; } - if (a.x2 > b.x1 && a.x2 < b.cx) { regionY = 'E'; } + if (a.y1 > b.cy && a.y1 < b.y2) { regionX = 'N'; } + if (a.y2 > b.y1 && a.y2 < b.cy) { regionX = 'S'; } + if (a.x1 > b.cx && a.x1 < b.x2) { regionY = 'W'; } + if (a.x2 > b.x1 && a.x2 < b.cx) { regionY = 'E'; } - return (regionX + regionY) || 'C'; + return (regionX + regionY) || 'C'; }; + fn.calculate_overlapped_area_coords = function(a, b){ - var x1 = Math.max(a.x1, b.x1); - var y1 = Math.max(a.y1, b.y1); - var x2 = Math.min(a.x2, b.x2); - var y2 = Math.min(a.y2, b.y2); + var x1 = Math.max(a.x1, b.x1); + var y1 = Math.max(a.y1, b.y1); + var x2 = Math.min(a.x2, b.x2); + var y2 = Math.min(a.y2, b.y2); - return $({ - left: x1, - top: y1, - width : (x2 - x1), - height: (y2 - y1) - }).coords().get(); + return $({ + left: x1, + top: y1, + width : (x2 - x1), + height: (y2 - y1) + }).coords().get(); }; + fn.calculate_overlapped_area = function(coords){ - return (coords.width * coords.height); + return (coords.width * coords.height); }; + fn.manage_colliders_start_stop = function(new_colliders_coords, start_callback, stop_callback){ - var last = this.last_colliders_coords; + var last = this.last_colliders_coords; - for (var i = 0, il = last.length; i < il; i++) { - if ($.inArray(last[i], new_colliders_coords) === -1) { - start_callback.call(this, last[i]); - } - } + for (var i = 0, il = last.length; i < il; i++) { + if ($.inArray(last[i], new_colliders_coords) === -1) { + start_callback.call(this, last[i]); + } + } - for (var j = 0, jl = new_colliders_coords.length; j < jl; j++) { - if ($.inArray(new_colliders_coords[j], last) === -1) { - stop_callback.call(this, new_colliders_coords[j]); - } + for (var j = 0, jl = new_colliders_coords.length; j < jl; j++) { + if ($.inArray(new_colliders_coords[j], last) === -1) { + stop_callback.call(this, new_colliders_coords[j]); + } - } + } }; + fn.find_collisions = function(player_data_coords){ - var self = this; - var colliders_coords = []; - var colliders_data = []; - var $colliders = (this.colliders || this.$colliders); - var count = $colliders.length; - var player_coords = self.$element.coords().update(player_data_coords || false).get(); + var self = this; + var colliders_coords = []; + var colliders_data = []; + var $colliders = (this.colliders || this.$colliders); + var count = $colliders.length; + var player_coords = self.$element.coords() + .update(player_data_coords || false).get(); - while(count--){ - var $collider = self.$colliders ? $($colliders[count]) : $colliders[count]; - var $collider_coords_ins = ($collider.isCoords) ? - $collider : $collider.coords(); - var collider_coords = $collider_coords_ins.get(); - var overlaps = self.overlaps(player_coords, collider_coords); + while(count--){ + var $collider = self.$colliders ? + $($colliders[count]) : $colliders[count]; + var $collider_coords_ins = ($collider.isCoords) ? + $collider : $collider.coords(); + var collider_coords = $collider_coords_ins.get(); + var overlaps = self.overlaps(player_coords, collider_coords); - if (!overlaps) { - continue; + if (!overlaps) { + continue; + } + + var region = self.detect_overlapping_region( + player_coords, collider_coords); + + //todo: make this an option + if (region === 'C'){ + var area_coords = self.calculate_overlapped_area_coords( + player_coords, collider_coords); + var area = self.calculate_overlapped_area(area_coords); + var collider_data = { + area: area, + area_coords : area_coords, + region: region, + coords: collider_coords, + player_coords: player_coords, + el: $collider + }; + + if (self.options.on_overlap) { + self.options.on_overlap.call(this, collider_data); + } + colliders_coords.push($collider_coords_ins); + colliders_data.push(collider_data); + } } - var region = self.detect_overlapping_region(player_coords, - collider_coords); - //todo: make this if customizable - if (region === 'C'){ - var area_coords = self.calculate_overlapped_area_coords( - player_coords, collider_coords); - var area = self.calculate_overlapped_area(area_coords); - var collider_data = { - area: area, - area_coords : area_coords, - region: region, - coords: collider_coords, - player_coords: player_coords, - el: $collider - }; - - self.options.on_overlap.call(this, collider_data); - colliders_coords.push($collider_coords_ins); - colliders_data.push(collider_data); + if (self.options.on_overlap_stop || self.options.on_overlap_start) { + this.manage_colliders_start_stop(colliders_coords, + self.options.on_overlap_stop, self.options.on_overlap_start); } - } + this.last_colliders_coords = colliders_coords; - this.manage_colliders_start_stop(colliders_coords, - self.options.on_overlap_stop, self.options.on_overlap_start); - - this.last_colliders_coords = colliders_coords; - - return colliders_data; + return colliders_data; }; fn.get_closest_colliders = function(player_data_coords){ - var colliders = this.find_collisions(player_data_coords); - var min_area = 100; - colliders.sort(function(a, b){ + var colliders = this.find_collisions(player_data_coords); + var min_area = 100; + colliders.sort(function(a, b){ + if (a.area <= min_area) { + return 1; + } - if (a.area <= min_area) { - return 1; - } + /* if colliders are being overlapped by the "C" (center) region, + * we have to set a lower index in the array to which they are placed + * above in the grid. */ + if (a.region === 'C' && b.region === 'C') { + if (a.coords.y1 < b.coords.y1 || a.coords.x1 < b.coords.x1) { + return - 1; + }else{ + return 1; + } + } - /* if colliders are being overlapped by the "C" (center) region, - * we have to set a lower index in the array to which they are placed - * above in the grid. */ - if (a.region === 'C' && b.region === 'C') { - if (a.coords.y1 < b.coords.y1 || a.coords.x1 < b.coords.x1) { - return - 1; - }else{ + if (a.area < b.area){ return 1; } - } - if (a.area < b.area){ - return 1; - } - - return 1; - }); - return colliders; + return 1; + }); + return colliders; }; + //jQuery adapter $.fn.collision = function(collider, options) { - return new Collision( this, collider, options ); + return new Collision( this, collider, options ); }; @@ -343,24 +370,42 @@ items: '.gs_w', distance: 1, limit: true, - offset_left: 0, - drag: function(e){}, - start : function(e, ui){}, - stop : function(e){} + offset_left: 0 + // ,drag: function(e){}, + // start : function(e, ui){}, + // stop : function(e){} }; var $body = $(document.body); /** - * Draggable - * * @class Draggable + * + * @param {HTMLElement} el The HTMLelement that contains all the widgets + * to be dragged. + * @param {Object} [options] An Object with all options you want to + * overwrite: + * @param {HTMLElement|String} [options.items] Define who will + * be the draggable items. Can be a CSS Selector String or a + * collection of HTMLElements. + * @param {Number} [options.distance] Distance in pixels after mousedown + * the mouse must move before dragging should start. + * @param {Boolean} [options.limit] Constrains dragging to the width of + * the container + * @param {offset_left} [options.offset_left] Offset added to the item + * that is being dragged. + * @param {Number} [options.drag] Executes a callback when the mouse is + * moved during the dragging. + * @param {Number} [options.start] Executes a callback when the drag + * starts. + * @param {Number} [options.stop] Executes a callback when the drag stops. + * @return {Object} Returns `el`. * @constructor */ - function Draggable(element, options) { - this.options = $.extend(defaults, options); - this.$container = $(element); + function Draggable(el, options) { + this.options = $.extend({}, defaults, options); + this.$container = $(el); this.$dragitems = $(this.options.items, this.$container); this.is_dragging = false; this.player_min_left = 0 + this.options.offset_left; @@ -375,6 +420,7 @@ this.enable(); }; + fn.get_actual_pos = function($el) { var pos = $el.position(); return pos; @@ -390,6 +436,10 @@ fn.drag_handler = function(e) { + if (e.which !== 1) { + return false; + }; + var self = this; var first = true; this.$player = $(e.currentTarget); @@ -398,6 +448,7 @@ this.mouse_init_pos = this.get_mouse_pos(e); $body.on('mousemove.draggable', 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); var diff_y = Math.abs(mouse_actual_pos.top - self.mouse_init_pos.top); @@ -562,7 +613,7 @@ extra_rows: 0, extra_cols: 0, min_cols: 1, - min_rows: 10, + min_rows: 15, autogenerate_stylesheet: true, avoid_overlapped_widgets: true, serialize_params: function($w, wgd) { @@ -580,7 +631,7 @@ /** * @class Gridster - * @uses Coords + * @uses Draggable * @uses Collision * @param {HTMLElement} el The HTMLelement that contains all the widgets. * @param {Object} [options] An Object with all options you want to @@ -606,6 +657,9 @@ * `<head>` of the document. You can set this to false, and write * your own CSS targeting rows and cols via data-attributes like so: * `[data-col="1"] { left: 10px; }` + * @param {Boolean} [avoid_overlapped_widgets] Avoid that widgets loaded + * from the DOM can be overlapped. It is helpful if the positions were + * bad stored in the database or if there was any conflict. * @param {Function} [options.serialize_params] Return the data you want * for each widget in the serialization. Two arguments are passed: * `$w`: the jQuery wrapped HTMLElement, and `wgd`: the grid @@ -614,8 +668,8 @@ * Collision class you want to overwrite. See Collision docs for * more info. * @param {Object} [options.draggable] An Object with all options for - * jQuery UI Draggable you want to overwrite. See - * http://jqueryui.com/demos/draggable/ for more info. + * Draggable class you want to overwrite. See Draggable docs for more + * info. * * @constructor */ @@ -623,7 +677,7 @@ this.options = $.extend(true, defaults, options); this.$el = $(el); this.$wrapper = this.$el.parent(); - this.$widgets = this.$el.find(this.options.widget_selector).addClass('gs_w'); + this.$widgets = $(this.options.widget_selector, this.$el).addClass('gs_w'); this.widgets = []; this.$changed = $([]); this.wrapper_width = this.$wrapper.width(); @@ -656,7 +710,7 @@ * @method enable * @return {Class} Returns the instance of the Gridster Class. */ - fn.disable = function(){ + fn.disable = function() { this.$wrapper.find('.player-revert').removeClass('player-revert'); this.drag_api.disable(); return this; @@ -669,7 +723,7 @@ * @method enable * @return {Class} Returns the instance of the Gridster Class. */ - fn.enable = function(){ + fn.enable = function() { this.drag_api.enable(); return this; } @@ -758,14 +812,17 @@ var $el = el instanceof jQuery ? el : $(el); var wgd = $el.coords().grid; + this.cells_occupied_by_placeholder = {}; this.$widgets = this.$widgets.not($el); var $nexts = this.widgets_below($el); + this.remove_from_gridmap(wgd); - $el.fadeOut($.proxy(function(){ + $el.fadeOut($.proxy(function() { $el.remove(); - $nexts.each($.proxy(function(i, widget){ + + $nexts.each($.proxy(function(i, widget) { this.move_widget_up( $(widget), wgd.size_y ); }, this)); @@ -789,9 +846,9 @@ fn.serialize = function($widgets) { $widgets || ($widgets = this.$widgets); var result = []; - $widgets.each($.proxy(function(i, widget){ - result.push( this.options.serialize_params( - $(widget),$(widget).coords().grid ) ); + $widgets.each($.proxy(function(i, widget) { + result.push(this.options.serialize_params( + $(widget), $(widget).coords().grid ) ); }, this)); return result; @@ -799,7 +856,8 @@ /** - * Returns a serialized array of the widgets that have changed their position. + * Returns a serialized array of the widgets that have changed their + * position. * * @method serialize_changed * @return {Array} Returns an Array of Objects with the data specified in @@ -829,7 +887,7 @@ if (this.options.avoid_overlapped_widgets && !this.can_move_to( - { size_x: wgd.size_x, size_y: wgd.size_y }, wgd.col, wgd.row) + {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; @@ -882,7 +940,7 @@ * to update in the mapped array. * @return {Class} Returns the instance of the Gridster Class. */ - fn.remove_from_gridmap = function(grid_data){ + fn.remove_from_gridmap = function(grid_data) { return this.update_widget_position(grid_data, false); }; @@ -897,12 +955,12 @@ * position . * @return {Class} Returns the instance of the Gridster Class. */ - fn.add_to_gridmap = function(grid_data, value){ + fn.add_to_gridmap = function(grid_data, value) { this.update_widget_position(grid_data, value || grid_data.el); if (grid_data.el) { var $widgets = this.widgets_below(grid_data.el); - $widgets.each($.proxy(function(i, widget){ + $widgets.each($.proxy(function(i, widget) { this.move_widget_up( $(widget)); }, this)); } @@ -910,8 +968,9 @@ /** - * Make widgets draggable. It Wraps the jQuery UI Draggable Plugin. + * Make widgets draggable. * + * @uses Draggable * @method draggable * @return {Class} Returns the instance of the Gridster Class. */ @@ -921,7 +980,9 @@ offset_left: this.options.widget_margins[0], items: '.gs_w', start: function(event, ui) { - self.$widgets.filter('.player-revert').removeClass('player-revert'); + self.$widgets.filter('.player-revert') + .removeClass('player-revert'); + self.$player = $(this); self.$helper = self.options.draggable.helper === 'clone' ? $(ui.helper) : self.$player; @@ -951,7 +1012,6 @@ * @method on_start_drag * @param {Event} The original browser event * @param {Object} A prepared ui object. - * See http://jqueryui.com/demos/draggable/ for more info. */ fn.on_start_drag = function(event, ui) { @@ -1003,14 +1063,15 @@ * @method on_drag * @param {Event} The original browser event * @param {Object} A prepared ui object. - * See http://jqueryui.com/demos/draggable/ for more info. */ fn.on_drag = function(event, ui) { var abs_offset = { left: ui.position.left + this.baseX, top: ui.position.top + this.baseY } - this.colliders_data = this.collision_api.get_closest_colliders(abs_offset); + + this.colliders_data = this.collision_api.get_closest_colliders( + abs_offset); this.on_overlapped_column_change( this.on_start_overlapping_column, @@ -1040,10 +1101,10 @@ * @method on_stop_drag * @param {Event} The original browser event * @param {Object} A prepared ui object. - * See http://jqueryui.com/demos/draggable/ for more info. */ fn.on_stop_drag = function(event, ui) { - this.$helper.add(this.$player).add(this.$wrapper).removeClass('dragging'); + this.$helper.add(this.$player).add(this.$wrapper) + .removeClass('dragging'); ui.position.left = ui.position.left + this.baseX; ui.position.top = ui.position.top + this.baseY; @@ -1059,14 +1120,14 @@ 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.$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); @@ -1235,7 +1296,7 @@ var wgd_can_go_up = []; var wgd_can_not_go_up = []; - $widgets.each($.proxy(function(i, w){ + $widgets.each($.proxy(function(i, w) { var $w = $(w); var wgd = $w.coords().grid; if (this.can_go_widget_up(wgd)) { @@ -1264,7 +1325,7 @@ * @return {Array} Returns the array sorted. */ fn.sort_by_row_asc = function(widgets) { - widgets = widgets.sort(function(a, b){ + widgets = widgets.sort(function(a, b) { if (a.row > b.row) { return 1; } @@ -1284,7 +1345,7 @@ * @return {Array} Returns the array sorted. */ fn.sort_by_row_and_col_asc = function(widgets) { - widgets = widgets.sort(function(a, b){ + widgets = widgets.sort(function(a, b) { if (a.row > b.row || a.row == b.row && a.col > b.col) { return 1; } @@ -1304,7 +1365,7 @@ * @return {Array} Returns the array sorted. */ fn.sort_by_col_asc = function(widgets) { - widgets = widgets.sort(function(a, b){ + widgets = widgets.sort(function(a, b) { if (a.col > b.col) { return 1; } @@ -1324,8 +1385,8 @@ * @return {Array} Returns the array sorted. */ fn.sort_by_row_desc = function(widgets) { - widgets = widgets.sort(function(a, b){ - if (a.row + a.size_y < b.row + b.size_y){ + widgets = widgets.sort(function(a, b) { + if (a.row + a.size_y < b.row + b.size_y) { return 1; } return -1; @@ -1346,7 +1407,7 @@ * @return {Class} Returns the instance of the Gridster Class. */ fn.manage_movements = function($widgets, to_col, to_row) { - $.each($widgets, $.proxy(function(i, w){ + $.each($widgets, $.proxy(function(i, w) { var wgd = w; var $w = wgd.el; @@ -1421,7 +1482,7 @@ * @return {Boolean} Returns true or false. */ fn.is_placeholder_in = function(col, row) { - var c = this.cells_occupied_by_placeholder || []; + var c = this.cells_occupied_by_placeholder || {}; return this.is_placeholder_in_col(col) && $.inArray(row, c.rows) >= 0; }; @@ -1530,9 +1591,9 @@ var cells = this.cells_occupied_by_player; var $widgets = $([]); - $.each(cells.cols, $.proxy(function(i, col){ - $.each(cells.rows, $.proxy(function(i, row){ - if(this.is_widget(col, row)){ + $.each(cells.cols, $.proxy(function(i, col) { + $.each(cells.rows, $.proxy(function(i, row) { + if(this.is_widget(col, row)) { $widgets = $widgets.add(this.gridmap[col][row]); } }, this)); @@ -1573,8 +1634,6 @@ this.placeholder_grid_data.col = col; this.placeholder_grid_data.row = row; - - this.cells_occupied_by_placeholder = this.get_cells_occupied( this.placeholder_grid_data); @@ -1584,9 +1643,9 @@ }); if (moved_down || changed_column) { - $nexts.each($.proxy(function(i, widget){ + $nexts.each($.proxy(function(i, widget) { this.move_widget_up( - $(widget), this.placeholder_grid_data.col - col + phgd.size_y); + $(widget), this.placeholder_grid_data.col - col + phgd.size_y); }, this)); } @@ -1611,12 +1670,12 @@ /* generate an array with columns as index and array with upper rows * empty as value */ - this.for_each_column_occupied(widget_grid_data, function(tcol){ + this.for_each_column_occupied(widget_grid_data, function(tcol) { var grid_col = this.gridmap[tcol]; var r = p_bottom_row + 1; upper_rows[tcol] = []; - while (--r > 0){ + while (--r > 0) { if (this.is_empty(tcol, r) || this.is_player(tcol, r) || this.is_widget(tcol, r) && grid_col[r].is($widgets_under_player) @@ -1659,7 +1718,7 @@ /* generate an array with columns as index and array with upper rows * empty as value */ - this.for_each_column_occupied(widget_grid_data, function(tcol){ + this.for_each_column_occupied(widget_grid_data, function(tcol) { var grid_col = this.gridmap[tcol]; upper_rows[tcol] = []; @@ -1670,7 +1729,9 @@ break; } - if (!this.is_player(tcol, r) &&!this.is_placeholder_in(tcol, r)) { + if (!this.is_player(tcol, r) && + !this.is_placeholder_in(tcol, r) + ) { upper_rows[tcol].push(r); } @@ -1706,7 +1767,7 @@ * @return {Number|Boolean} Returns the upper row valid from the `upper_rows` * for the widget in question. */ - fn.get_valid_rows = function(widget_grid_data, upper_rows, min_row){ + fn.get_valid_rows = function(widget_grid_data, upper_rows, min_row) { var p_top_row = widget_grid_data.row; var p_bottom_row = widget_grid_data.row + widget_grid_data.size_y - 1; var size_y = widget_grid_data.size_y; @@ -1715,7 +1776,7 @@ while (++r <= p_bottom_row ) { var common = true; - $.each(upper_rows, function(col, rows){ + $.each(upper_rows, function(col, rows) { if (rows && $.inArray(r, rows) === -1) { common = false; } @@ -1784,8 +1845,8 @@ var rows_from_bottom = this.cells_occupied_by_player.rows.slice(0); rows_from_bottom.reverse(); - $.each(this.cells_occupied_by_player.cols, $.proxy(function(i, col){ - $.each(rows_from_bottom, $.proxy(function(i, row){ + $.each(this.cells_occupied_by_player.cols, $.proxy(function(i, col) { + $.each(rows_from_bottom, $.proxy(function(i, row) { // if there is a widget in the player position if (!this.gridmap[col]) { return true; } //next iteration var $w = this.gridmap[col][row]; @@ -1872,7 +1933,8 @@ * if they can. * * @method move_widget_to - * @param {HTMLElement} $widget The jQuery wrapped HTMLElement of the widget is going to be moved. + * @param {HTMLElement} $widget The jQuery wrapped HTMLElement of the + * widget is going to be moved. * @return {Class} Returns the instance of the Gridster Class. */ fn.move_widget_to = function($widget, row) { @@ -1895,12 +1957,12 @@ this.$changed = this.$changed.add($widget); - $next_widgets.each(function(i, widget){ + $next_widgets.each(function(i, widget) { var $w = $(widget); var wgd = $w.coords().grid; var can_go_up = self.can_go_widget_up(wgd); - if (can_go_up && can_go_up !== wgd.row){ + if (can_go_up && can_go_up !== wgd.row) { self.move_widget_to($w, can_go_up); } }); @@ -1924,33 +1986,31 @@ var can_go_up = true; y_units || (y_units = 1); - // if (!this.can_go_up($widget)) { return false; } //break; - console.log($widget, y_units); + if (!this.can_go_up($widget)) { return false; } //break; - this.for_each_column_occupied(el_grid_data, function(col){ + this.for_each_column_occupied(el_grid_data, function(col) { // can_go_up if ($.inArray($widget, moved) === -1) { - var widget_grid_data = $.extend({}, el_grid_data); + var widget_grid_data = $widget.coords().grid; var next_row = actual_row - y_units; - next_row = this.can_go_up_to_row(widget_grid_data, col, next_row); - console.log('can_go_up_to_row?', $widget, y_units, next_row); - if (next_row === false) { + next_row = this.can_go_up_to_row( + widget_grid_data, col, next_row); + + if (!next_row) { return true; } var $next_widgets = this.widgets_below($widget); - console.log('$next_widgets', $next_widgets); this.remove_from_gridmap(widget_grid_data); widget_grid_data.row = next_row; this.add_to_gridmap(widget_grid_data); - console.log($widget, 'next-row', next_row); - $widget.attr('data-row', next_row); + $widget.attr('data-row', widget_grid_data.row); this.$changed = this.$changed.add($widget); moved.push($widget); - $next_widgets.each($.proxy(function(i, widget){ + $next_widgets.each($.proxy(function(i, widget) { this.move_widget_up($(widget), y_units); }, this)); } @@ -1963,7 +2023,8 @@ * Move down the specified widget and all below it. * * @method move_widget_down - * @param {HTMLElement} $widget The jQuery object representing the widget you want to move. + * @param {HTMLElement} $widget The jQuery object representing the widget + * you want to move. * @param {Number} The number of cells that the widget has to move. * @return {Class} Returns the instance of the Gridster Class. */ @@ -1983,7 +2044,7 @@ this.remove_from_gridmap(widget_grid_data); - $next_widgets.each($.proxy(function(i, widget){ + $next_widgets.each($.proxy(function(i, widget) { var $w = $(widget); var wd = $w.coords().grid; var tmp_y = this.displacement_diff( @@ -2023,20 +2084,17 @@ var actual_row = widget_grid_data.row; var r; - //generate an array with columns as index and array with upper rows empty in the column - this.for_each_column_occupied(widget_grid_data, function(tcol){ + /* generate an array with columns as index and array with + * upper rows empty in the column */ + this.for_each_column_occupied(widget_grid_data, function(tcol) { var grid_col = ga[tcol]; urc[tcol] = []; r = actual_row; - while (r--){ - var $w = this.is_widget(tcol, r); - console.log(tcol, r, $w, this.is_empty(tcol, r)); - if ($w && $w.is(widget_grid_data.el) || - (this.is_empty(tcol, r) && - !this.is_placeholder_in(tcol, r)) + while (r--) { + if (this.is_empty(tcol, r) && + !this.is_placeholder_in(tcol, r) ) { - console.log('push', tcol, r); urc[tcol].push(r); }else{ break; @@ -2050,11 +2108,10 @@ }); - console.log('urc', urc); - if (!result) { return false; } - //get common rows starting from upper position in all the columns widget occupies + /* get common rows starting from upper position in all the columns + * that widget occupies */ r = row; for (r = 1; r < actual_row; r++) { var common = true; @@ -2080,7 +2137,7 @@ var diffs = []; var parent_max_y = parent_bgd.row + parent_bgd.size_y; - this.for_each_column_occupied(widget_grid_data, function(col){ + this.for_each_column_occupied(widget_grid_data, function(col) { var temp_y_units = 0; for (var r = parent_max_y; r < actual_row; r++) { @@ -2113,9 +2170,9 @@ var next_row = el_grid_data.row + el_grid_data.size_y - 1; var $nexts = $([]); - this.for_each_column_occupied(el_grid_data, function(col){ + this.for_each_column_occupied(el_grid_data, function(col) { self.for_each_widget_below(col, next_row, - function(tcol, trow){ + function(tcol, trow) { if (!self.is_player(this) && $.inArray(this, $nexts) === -1) { $nexts = $nexts.add(this); @@ -2167,9 +2224,9 @@ var result = true; if (initial_row === 1) { return false; } - this.for_each_column_occupied(el_grid_data, function(col){ - if (!$el.is(this.is_widget(col, prev_row)) && - this.is_occupied(col, prev_row) || + this.for_each_column_occupied(el_grid_data, function(col) { + var $w = this.is_widget(col, prev_row); + if (this.is_occupied(col, prev_row) || this.is_player(col, prev_row) || this.is_placeholder_in(col, prev_row) ) { @@ -2185,8 +2242,8 @@ /** * Check if it's possible to move a widget to a specific col/row. It takes - * into account the dimensions (`size_y` and `size_x` attrs. of the grid coords - * object) the widget occupies. + * into account the dimensions (`size_y` and `size_x` attrs. of the grid + * coords object) the widget occupies. * * @method can_move_to * @param {Object} widget_grid_data The grid coords object that represents @@ -2212,7 +2269,7 @@ return false; }; - this.for_each_cell_occupied(future_wd, function(tcol, trow){ + this.for_each_cell_occupied(future_wd, function(tcol, trow) { var $tw = this.is_widget(tcol, trow); if ($tw && (!widget_grid_data.el || $tw.is($w))) { result = false; @@ -2224,7 +2281,8 @@ /** - * Given the leftmost column returns all columns that are overlapping with the player. + * Given the leftmost column returns all columns that are overlapping + * with the player. * * @method get_targeted_columns * @param {Number} [from_col] The leftmost column. @@ -2298,8 +2356,8 @@ * @return {Class} Returns the instance of the Gridster Class. */ fn.for_each_cell_occupied = function(grid_data, callback) { - this.for_each_column_occupied(grid_data, function(col){ - this.for_each_row_occupied(grid_data, function(row){ + this.for_each_column_occupied(grid_data, function(col) { + this.for_each_row_occupied(grid_data, function(row) { callback.call(this, col, row); }); }); @@ -2333,7 +2391,8 @@ * @method for_each_row_occupied * @param {Object} el_grid_data The grid coords object that represents * the widget. - * @param {Function} callback The function to execute on each column iteration. The row number is passed as first argument. + * @param {Function} callback The function to execute on each column + * iteration. The row number is passed as first argument. * @return {Class} Returns the instance of the Gridster Class. */ fn.for_each_row_occupied = function(el_grid_data, callback) { @@ -2399,7 +2458,8 @@ * @param {Number} col The column to start iterating. * @param {Number} row The row to start iterating. * @param {Function} callback The function to execute on each widget - * iteration. The value of `this` inside the function is the jQuery wrapped HTMLElement. + * iteration. The value of `this` inside the function is the jQuery + * wrapped HTMLElement. * @return {Class} Returns the instance of the Gridster Class. */ fn.for_each_widget_above = function(col, row, callback) { @@ -2415,7 +2475,8 @@ * @param {Number} col The column to start iterating. * @param {Number} row The row to start iterating. * @param {Function} callback The function to execute on each widget - * iteration. The value of `this` inside the function is the jQuery wrapped HTMLElement. + * iteration. The value of `this` inside the function is the jQuery wrapped + * HTMLElement. * @return {Class} Returns the instance of the Gridster Class. */ fn.for_each_widget_below = function(col, row, callback) { @@ -2456,14 +2517,13 @@ }; - fn.get_widgets_from = function(col, row) { var ga = this.gridmap; var $widgets = $(); if (col) { $widgets = $widgets.add( - this.$widgets.filter(function(){ + this.$widgets.filter(function() { var tcol = $(this).attr('data-col'); return (tcol == col || tcol > col); }) @@ -2472,7 +2532,7 @@ if (row) { $widgets = $widgets.add( - this.$widgets.filter(function(){ + this.$widgets.filter(function() { var trow = $(this).attr('data-row'); return (trow == row || trow > row); }) @@ -2492,7 +2552,6 @@ fn.set_dom_grid_height = function() { var r = this.get_highest_occupied_cell().row; this.$el.css('height', r * this.min_widget_height); - // this.$widgets.draggable("option", "containment", this.$el); return this; }; @@ -2536,27 +2595,31 @@ /* generate CSS styles for cols */ for (i = opts.cols + extra_cells; i >= 0; i--) { - 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;} '; + 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;} '); } /* generate CSS styles for rows */ for (i = opts.rows + extra_cells; i >= 0; i--) { - 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;} '; + 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;} '); } for (var y = 1; y < max_size_y; y++) { - styles += opts.namespace + ' [data-sizey="' + (y) + '"] { height: ' + - (y * opts.widget_base_dimensions[1] + (y-1)*(opts.widget_margins[1]*2)) + 'px;}'; + styles += (opts.namespace + ' [data-sizey="' + y + '"] { height:' + + (y * opts.widget_base_dimensions[1] + + (y - 1) * (opts.widget_margins[1] * 2)) + 'px;}'); } 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;}'; + styles += (opts.namespace + ' [data-sizex="' + x + '"] { width:' + + (x * opts.widget_base_dimensions[0] + + (x - 1) * (opts.widget_margins[0] * 2)) + 'px;}'); } return this.add_style_tag(styles); @@ -2570,7 +2633,7 @@ * @param {String} css The styles to apply. * @return {Object} Returns the instance of the Gridster class. */ - fn.add_style_tag = function(css){ + fn.add_style_tag = function(css) { var d = document; var tag = d.createElement('style'); @@ -2634,7 +2697,7 @@ this.baseX = ($(window).width() - aw) / 2; this.baseY = this.$wrapper.offset().top; - $.each(this.faux_grid, $.proxy(function(i, coords){ + $.each(this.faux_grid, $.proxy(function(i, coords) { this.faux_grid[i] = coords.update({ left: this.baseX + (coords.data.col -1) * this.min_widget_width, top: this.baseY + (coords.data.row -1) * this.min_widget_height @@ -2653,7 +2716,7 @@ * @return {Object} Returns the instance of the Gridster class. */ fn.get_widgets_from_DOM = function() { - this.$widgets.each($.proxy(function(i, widget){ + this.$widgets.each($.proxy(function(i, widget) { this.register_widget($(widget)); }, this)); return this; diff --git a/dist/jquery.gridster.min.css b/dist/jquery.gridster.min.css index 7d676b6f5b..3cce5bc9d1 100644 --- a/dist/jquery.gridster.min.css +++ b/dist/jquery.gridster.min.css @@ -1,3 +1,3 @@ /*! gridster.js - v0.1.0 - 2012-07-23 * https://github.com/ducksboard/gridster.js -* Copyright (c) 2012 ducksboard; Licensed MIT, GPL */.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}.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{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;transition:none!important} \ No newline at end of file +* Copyright (c) 2012 ducksboard; Licensed MIT, GPL */.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}.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 diff --git a/dist/jquery.gridster.min.js b/dist/jquery.gridster.min.js index bb48c41add..9be252218e 100644 --- a/dist/jquery.gridster.min.js +++ b/dist/jquery.gridster.min.js @@ -1,4 +1,4 @@ /*! gridster.js - v0.1.0 - 2012-07-23 * https://github.com/ducksboard/gridster.js * Copyright (c) 2012 ducksboard; Licensed MIT, GPL */ -(function(a,b,c,d){function e(b){return b[0]&&a.isPlainObject(b[0])?this.data=b[0]:this.el=b,this.isCoords=!0,this.coords={},this.init(),this}var f=e.prototype;f.init=function(){this.set(),this.original_coords=this.get()},f.set=function(a,b){var c=this.el;c&&!a&&(this.data={}||c.offset(),this.data.width=c.width(),this.data.height=c.height());if(c&&a&&!b){var d=c.offset();this.data.top=d.top,this.data.left=d.left}var e=this.data;return this.coords.x1=e.left,this.coords.y1=e.top,this.coords.x2=e.left+e.width,this.coords.y2=e.top+e.height,this.coords.cx=e.left+e.width/2,this.coords.cy=e.top+e.height/2,this.coords.width=e.width,this.coords.height=e.height,this.coords.el=c||!1,this},f.update=function(b){if(!b&&!this.el)return this;if(b){var c=a.extend({},this.data,b);return this.data=c,this.set(!0,!0)}return this.set(!0),this},f.get=function(){return this.coords},a.fn.coords=function(){if(this.data("coords"))return this.data("coords");var a=new e(this,arguments[0]);return this.data("coords",a),a}})(jQuery,window,document),function(a,b,c,d){function f(b,c,d){this.options=a.extend(e,d),this.$element=b,this.last_colliders=[],this.last_colliders_coords=[],typeof c=="string"||c instanceof jQuery?this.$colliders=a(c,this.options.colliders_context).not(this.$element):this.colliders=a(c),this.init()}var e={colliders_context:c.body,on_overlap:function(a){},on_overlap_start:function(a){},on_overlap_stop:function(a){}},g=f.prototype;g.init=function(){this.find_collisions()},g.overlaps=function(a,b){var c=!1,d=!1;if(b.x1>=a.x1&&b.x1<=a.x2||b.x2>=a.x1&&b.x2<=a.x2||a.x1>=b.x1&&a.x2<=b.x2)c=!0;if(b.y1>=a.y1&&b.y1<=a.y2||b.y2>=a.y1&&b.y2<=a.y2||a.y1>=b.y1&&a.y2<=b.y2)d=!0;return c&&d},g.detect_overlapping_region=function(a,b){var c="",d="";return a.y1>b.cy&&a.y1<b.y2&&(c="N"),a.y2>b.y1&&a.y2<b.cy&&(c="S"),a.x1>b.cx&&a.x1<b.x2&&(d="W"),a.x2>b.x1&&a.x2<b.cx&&(d="E"),c+d||"C"},g.calculate_overlapped_area_coords=function(b,c){var d=Math.max(b.x1,c.x1),e=Math.max(b.y1,c.y1),f=Math.min(b.x2,c.x2),g=Math.min(b.y2,c.y2);return a({left:d,top:e,width:f-d,height:g-e}).coords().get()},g.calculate_overlapped_area=function(a){return a.width*a.height},g.manage_colliders_start_stop=function(b,c,d){var e=this.last_colliders_coords;for(var f=0,g=e.length;f<g;f++)a.inArray(e[f],b)===-1&&c.call(this,e[f]);for(var h=0,i=b.length;h<i;h++)a.inArray(b[h],e)===-1&&d.call(this,b[h])},g.find_collisions=function(b){var c=this,d=[],e=[],f=this.colliders||this.$colliders,g=f.length,h=c.$element.coords().update(b||!1).get();while(g--){var i=c.$colliders?a(f[g]):f[g],j=i.isCoords?i:i.coords(),k=j.get(),l=c.overlaps(h,k);if(!l)continue;var m=c.detect_overlapping_region(h,k);if(m==="C"){var n=c.calculate_overlapped_area_coords(h,k),o=c.calculate_overlapped_area(n),p={area:o,area_coords:n,region:m,coords:k,player_coords:h,el:i};c.options.on_overlap.call(this,p),d.push(j),e.push(p)}}return this.manage_colliders_start_stop(d,c.options.on_overlap_stop,c.options.on_overlap_start),this.last_colliders_coords=d,e},g.get_closest_colliders=function(a){var b=this.find_collisions(a),c=100;return b.sort(function(a,b){return a.area<=c?1:a.region==="C"&&b.region==="C"?a.coords.y1<b.coords.y1||a.coords.x1<b.coords.x1?-1:1:a.area<b.area?1:1}),b},a.fn.collision=function(a,b){return new f(this,a,b)}}(jQuery,window,document),function(a,b){a.debounce=function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)};c&&!d&&a.apply(e,f),clearTimeout(d),d=setTimeout(g,b)}},a.throttle=function(a,b){var c,d,e,f,g,h,i=debounce(function(){g=f=!1},b);return function(){c=this,d=arguments;var j=function(){e=null,g&&a.apply(c,d),i()};return e||(e=setTimeout(j,b)),f?g=!0:h=a.apply(c,d),i(),f=!0,h}}}(window),function(a,b,c,d){function g(b,c){this.options=a.extend(e,c),this.$container=a(b),this.$dragitems=a(this.options.items,this.$container),this.is_dragging=!1,this.player_min_left=0+this.options.offset_left,this.init()}var e={items:".gs_w",distance:1,limit:!0,offset_left:0,drag:function(a){},start:function(a,b){},stop:function(a){}},f=a(c.body),h=g.prototype;h.init=function(){this.$container.css("position","relative"),this.enable()},h.get_actual_pos=function(a){var b=a.position();return b},h.get_mouse_pos=function(a){return{left:a.clientX,top:a.clientY}},h.drag_handler=function(b){var c=this,d=!0;return this.$player=a(b.currentTarget),this.el_init_pos=this.get_actual_pos(this.$player),this.mouse_init_pos=this.get_mouse_pos(b),f.on("mousemove.draggable",function(a){var b=c.get_mouse_pos(a),e=Math.abs(b.left-c.mouse_init_pos.left),f=Math.abs(b.top-c.mouse_init_pos.top);return e>c.options.distance||f>c.options.distance?d?(d=!1,c.on_dragstart.call(c,a),!1):(c.is_dragging==!0&&throttle(c.on_dragmove.call(c,a),130),!1):!1}),!1},h.on_dragstart=function(a){return a.preventDefault(),this.drag_start=!0,this.is_dragging=!0,this.$container_offset=this.$container.offset(),this.options.helper==="clone"?(this.$helper=this.$player.clone().appendTo(this.$container).addClass("helper"),this.helper=!0):this.helper=!1,this.el_init_offset=this.$player.offset(),this.player_width=this.$player.width(),this.player_max_left=this.$container.width()-this.player_width+this.options.offset_left,this.options.start&&this.options.start.call(this.$player,a,{helper:this.helper?this.$helper:this.$player}),!1},h.get_offset=function(a){a.preventDefault();var b=this.get_mouse_pos(a),c=b.left-this.mouse_init_pos.left,d=b.top-this.mouse_init_pos.top,e=this.el_init_offset.left+c-this.$container_offset.left,f=this.el_init_offset.top+d-this.$container_offset.top;return this.options.limit&&(e>this.player_max_left?e=this.player_max_left:e<this.player_min_left&&(e=this.player_min_left)),{left:e,top:f}},h.on_dragmove=function(a){var b=this.get_offset(a);(this.helper?this.$helper:this.$player).css({position:"absolute",left:b.left,top:b.top});var c={position:{left:b.left,top:b.top}};return this.options.drag&&this.options.drag.call(this.$player,a,c),!1},h.on_dragstop=function(a){var b=this.get_offset(a);this.drag_start=!1;var c={position:{left:b.left,top:b.top}};return this.options.stop&&this.options.stop.call(this.$player,a,c),this.helper&&this.$helper.remove(),!1},h.enable=function(){this.$container.on("mousedown.draggable",this.options.items,a.proxy(this.drag_handler,this)),f.on("mouseup.draggable",a.proxy(function(a){this.is_dragging=!1,f.off("mousemove.draggable"),this.drag_start&&this.on_dragstop(a)},this))},h.disable=function(){this.$container.off("mousedown.draggable"),f.off("mouseup.draggable")},h.destroy=function(){this.disable(),a.removeData(this.$container,"draggable")},a.fn.draggable=function(b){return this.each(function(){a.data(this,"draggable")||a.data(this,"draggable",new g(this,b))})}}(jQuery,window,document),function(a,b,c,d){function f(b,c){this.options=a.extend(!0,e,c),this.$el=a(b),this.$wrapper=this.$el.parent(),this.$widgets=this.$el.find(this.options.widget_selector).addClass("gs_w"),this.widgets=[],this.$changed=a([]),this.wrapper_width=this.$wrapper.width(),this.min_widget_width=this.options.widget_margins[0]*2+this.options.widget_base_dimensions[0],this.min_widget_height=this.options.widget_margins[1]*2+this.options.widget_base_dimensions[1],this.init()}var e={widget_selector:"> li",widget_margins:[10,10],widget_base_dimensions:[400,225],extra_rows:0,extra_cols:0,min_cols:1,min_rows:10,autogenerate_stylesheet:!0,avoid_overlapped_widgets:!0,serialize_params:function(a,b){return{col:b.col,row:b.row}},collision:{},draggable:{distance:4}};f.generated_stylesheets=[];var g=f.prototype;g.init=function(){this.generate_grid_and_stylesheet(),this.get_widgets_from_DOM(),this.set_dom_grid_height(),this.$wrapper.addClass("ready"),this.draggable(),a(b).bind("resize",throttle(a.proxy(this.recalculate_faux_grid,this),200))},g.disable=function(){return this.drag_api.disable(),this},g.enable=function(){return this.drag_api.enable(),this},g.add_widget=function(b,c,d){var e=this.next_position(c,d),f=a(b).attr({"data-col":e.col,"data-row":e.row,"data-sizex":e.size_x,"data-sizey":e.size_y}).addClass("gs_w").appendTo(this.$el).hide();return this.$widgets=this.$widgets.add(f),this.register_widget(f),this.set_dom_grid_height(),f.fadeIn()},g.next_position=function(a,b){a||(a=1),b||(b=1);var c=this.gridmap,d=c.length,e=[];for(var f=1;f<d;f++){var g=c[f].length;for(var h=1;h<=g;h++){var i=this.can_move_to({size_x:a,size_y:b},f,h);i&&e.push({col:f,row:h,size_y:b,size_x:a})}}return e.length?this.sort_by_row_and_col_asc(e)[0]:!1},g.remove_widget=function(b,c){var d=b instanceof jQuery?b:a(b),e=d.coords().grid;this.$widgets=this.$widgets.not(d);var f=this.widgets_below(d);this.remove_from_gridmap(e),d.fadeOut(a.proxy(function(){d.remove(),f.each(a.proxy(function(b,c){this.move_widget_up(a(c),e.size_y)},this)),c&&c.apply(this,b)},this))},g.serialize=function(b){b||(b=this.$widgets);var c=[];return b.each(a.proxy(function(b,d){c.push(this.options.serialize_params(a(d),a(d).coords().grid))},this)),c},g.serialize_changed=function(){return this.serialize(this.$changed)},g.register_widget=function(a){var b={col:parseInt(a.attr("data-col"),10),row:parseInt(a.attr("data-row"),10),size_x:parseInt(a.attr("data-sizex"),10),size_y:parseInt(a.attr("data-sizey"),10),el:a};return this.options.avoid_overlapped_widgets&&!this.can_move_to({size_x:b.size_x,size_y:b.size_y},b.col,b.row)&&(b=this.next_position(b.size_x,b.size_y),b.el=a,a.attr({"data-col":b.col,"data-row":b.row,"data-sizex":b.size_x,"data-sizey":b.size_y})),a.data("coords",a.coords()),a.data("coords").grid=b,this.add_to_gridmap(b,a),this.widgets.push(a),this},g.update_widget_position=function(a,b){return this.for_each_cell_occupied(a,function(a,c){if(!this.gridmap[a])return this;this.gridmap[a][c]=b}),this},g.remove_from_gridmap=function(a){return this.update_widget_position(a,!1)},g.add_to_gridmap=function(b,c){this.update_widget_position(b,c||b.el);if(b.el){var d=this.widgets_below(b.el);d.each(a.proxy(function(b,c){this.move_widget_up(a(c))},this))}},g.draggable=function(){var b=this,c=a.extend(!0,{},this.options.draggable,{offset_left:this.options.widget_margins[0],items:".gs_w",start:function(c,d){b.$widgets.filter(".player-revert").removeClass("player-revert"),b.$player=a(this),b.$helper=b.options.draggable.helper==="clone"?a(d.helper):b.$player,b.helper=!b.$helper.is(b.$player),b.on_start_drag.call(b,c,d),b.$el.trigger("gridster:dragstart")},stop:function(a,c){b.on_stop_drag.call(b,a,c),b.$el.trigger("gridster:dragstop")},drag:function(a,c){b.on_drag.call(b,a,c),b.$el.trigger("gridster:drag")}});return this.drag_api=this.$el.draggable(c).data("draggable"),this},g.on_start_drag=function(b,c){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=a.extend({},this.player_grid_data),this.$el.css("height",this.$el.height()+this.player_grid_data.size_y*this.min_widget_height);var d=this.faux_grid,e=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(d,this.options.collision),this.$preview_holder=a("<li />",{"class":"preview-holder","data-row":this.$player.attr("data-row"),"data-col":this.$player.attr("data-col"),css:{width:e.width,height:e.height}}).appendTo(this.$el),this.options.draggable.start&&this.options.draggable.start.call(this,b,c)},g.on_drag=function(a,b){var c={left:b.position.left+this.baseX,top:b.position.top+this.baseY};this.colliders_data=this.collision_api.get_closest_colliders(c),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:b.position.left,top:b.position.top}),this.options.draggable.drag&&this.options.draggable.drag.call(this,a,b)},g.on_stop_drag=function(a,b){this.$helper.add(this.$player).add(this.$wrapper).removeClass("dragging"),b.position.left=b.position.left+this.baseX,b.position.top=b.position.top+this.baseY,this.colliders_data=this.collision_api.get_closest_colliders(b.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.$player=null,this.$preview_holder.remove(),this.set_dom_grid_height(),this.options.draggable.stop&&this.options.draggable.stop.call(this,a,b)},g.on_overlapped_column_change=function(b,c){if(!this.colliders_data.length)return;var d=this.get_targeted_columns(this.colliders_data[0].el.data.col),e=this.last_cols.length,f=d.length,g;for(g=0;g<f;g++)a.inArray(d[g],this.last_cols)===-1&&(b||a.noop).call(this,d[g]);for(g=0;g<e;g++)a.inArray(this.last_cols[g],d)===-1&&(c||a.noop).call(this,this.last_cols[g]);return this.last_cols=d,this},g.on_overlapped_row_change=function(b,c){if(!this.colliders_data.length)return;var d=this.get_targeted_rows(this.colliders_data[0].el.data.row),e=this.last_rows.length,f=d.length,g;for(g=0;g<f;g++)a.inArray(d[g],this.last_rows)===-1&&(b||a.noop).call(this,d[g]);for(g=0;g<e;g++)a.inArray(this.last_rows[g],d)===-1&&(c||a.noop).call(this,this.last_rows[g]);this.last_rows=d},g.set_player=function(a,b){this.empty_cells_player_occupies();var c=this,d=c.colliders_data[0].el.data,e=d.col,f=b||d.row;this.player_grid_data={col:e,row:f,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 g=this.get_widgets_overlapped(this.player_grid_data),h=this.widgets_constraints(g);this.manage_movements(h.can_go_up,e,f),this.manage_movements(h.can_not_go_up,e,f);if(!g.length){var i=this.can_go_player_up(this.player_grid_data);i!==!1&&(f=i),this.set_placeholder(e,f)}return{col:e,row:f}},g.widgets_constraints=function(b){var c=a([]),d,e=[],f=[];return b.each(a.proxy(function(b,d){var g=a(d),h=g.coords().grid;this.can_go_widget_up(h)?(c=c.add(g),e.push(h)):f.push(h)},this)),d=b.not(c),{can_go_up:this.sort_by_row_asc(e),can_not_go_up:this.sort_by_row_desc(f)}},g.sort_by_row_asc=function(a){return a=a.sort(function(a,b){return a.row>b.row?1:-1}),a},g.sort_by_row_and_col_asc=function(a){return a=a.sort(function(a,b){return a.row>b.row||a.row==b.row&&a.col>b.col?1:-1}),a},g.sort_by_col_asc=function(a){return a=a.sort(function(a,b){return a.col>b.col?1:-1}),a},g.sort_by_row_desc=function(a){return a=a.sort(function(a,b){return a.row+a.size_y<b.row+b.size_y?1:-1}),a},g.manage_movements=function(b,c,d){return a.each(b,a.proxy(function(a,b){var e=b,f=e.el,g=this.can_go_widget_up(e);if(g)this.move_widget_to(f,g),this.set_placeholder(c,g+e.size_y);else{var h=this.can_go_player_up(this.player_grid_data);if(!h){var i=d+this.player_grid_data.size_y-e.row;this.move_widget_down(f,i),this.set_placeholder(c,d)}}},this)),this},g.is_player=function(a,b){if(b&&!this.gridmap[a])return!1;var c=b?this.gridmap[a][b]:a;return c&&(c.is(this.$player)||c.is(this.$helper))},g.is_player_in=function(b,c){var d=this.cells_occupied_by_player;return a.inArray(b,d.cols)>=0&&a.inArray(c,d.rows)>=0},g.is_placeholder_in=function(b,c){var d=this.cells_occupied_by_placeholder||[];return this.is_placeholder_in_col(b)&&a.inArray(c,d.rows)>=0},g.is_placeholder_in_col=function(b){var c=this.cells_occupied_by_placeholder||[];return a.inArray(b,c.cols)>=0},g.is_empty=function(a,b){return typeof this.gridmap[a]!="undefined"&&typeof this.gridmap[a][b]!="undefined"&&this.gridmap[a][b]===!1?!0:!1},g.is_occupied=function(a,b){return this.gridmap[a]?this.gridmap[a][b]?!0:!1:!1},g.is_widget=function(a,b){var c=this.gridmap[a];return c?(c=c[b],c?c:!1):!1},g.is_widget_under_player=function(a,b){return this.is_widget(a,b)?this.is_player_in(a,b):!1},g.get_widgets_under_player=function(){var b=this.cells_occupied_by_player,c=a([]);return a.each(b.cols,a.proxy(function(d,e){a.each(b.rows,a.proxy(function(a,b){this.is_widget(e,b)&&(c=c.add(this.gridmap[e][b]))},this))},this)),c},g.set_placeholder=function(b,c){var d=a.extend({},this.placeholder_grid_data),e=this.widgets_below({col:d.col,row:d.row,size_y:d.size_y,size_x:d.size_x}),f=b+d.size_x-1;f>this.cols&&(b=b-(f-b));var g=this.placeholder_grid_data.row<c,h=this.placeholder_grid_data.col!==b;this.placeholder_grid_data.col=b,this.placeholder_grid_data.row=c,this.cells_occupied_by_placeholder=this.get_cells_occupied(this.placeholder_grid_data),this.$preview_holder.attr({"data-row":c,"data-col":b}),(g||h)&&e.each(a.proxy(function(c,e){this.move_widget_up(a(e),this.placeholder_grid_data.col-b+d.size_y)},this))},g.can_go_player_up=function(a){var b=a.row+a.size_y-1,c=!0,d=[],e=1e4,f=this.get_widgets_under_player();return this.for_each_column_occupied(a,function(a){var g=this.gridmap[a],h=b+1;d[a]=[];while(--h>0)if(this.is_empty(a,h)||this.is_player(a,h)||this.is_widget(a,h)&&g[h].is(f))d[a].push(h),e=h<e?h:e;else break;if(d[a].length===0)return c=!1,!0;d[a].sort()}),c?this.get_valid_rows(a,d,e):!1},g.can_go_widget_up=function(a){var b=a.row+a.size_y-1,c=!0,d=[],e=1e4;return this.for_each_column_occupied(a,function(a){var f=this.gridmap[a];d[a]=[];var g=b+1;while(--g>0){if(this.is_occupied(a,g)&&!this.is_player(a,g))break;!this.is_player(a,g)&&!this.is_placeholder_in(a,g)&&d[a].push(g),g<e&&(e=g)}if(d[a].length===0)return c=!1,!0;d[a].sort()}),c?this.get_valid_rows(a,d,e):!1},g.get_valid_rows=function(b,c,d){var e=b.row,f=b.row+b.size_y-1,g=b.size_y,h=d-1,i=[];while(++h<=f){var j=!0;a.each(c,function(b,c){c&&a.inArray(h,c)===-1&&(j=!1)});if(j===!0){i.push(h);if(i.length===g)break}}var k=!1;return g===1?i[0]!==e&&(k=i[0]||!1):i[0]!==e&&(k=this.get_consecutive_numbers_index(i,g)),k},g.get_consecutive_numbers_index=function(a,b){var c=a.length,d=[],e=!0,f=-1;for(var g=0;g<c;g++){if(e||a[g]===f+1){d.push(g);if(d.length===b)break;e=!1}else d=[],e=!0;f=a[g]}return d.length>=b?a[d[0]]:!1},g.get_widgets_overlapped=function(){var b,c=a([]),d=[],e=this.cells_occupied_by_player.rows.slice(0);return e.reverse(),a.each(this.cells_occupied_by_player.cols,a.proxy(function(b,f){a.each(e,a.proxy(function(b,e){if(!this.gridmap[f])return!0;var g=this.gridmap[f][e];this.is_occupied(f,e)&&!this.is_player(g)&&a.inArray(g,d)===-1&&(c=c.add(g),d.push(g))},this))},this)),c},g.on_start_overlapping_column=function(a){this.set_player(a,!1)},g.on_start_overlapping_row=function(a){this.set_player(!1,a)},g.on_stop_overlapping_column=function(a){this.set_player();var b=this;this.for_each_widget_below(a,this.cells_occupied_by_player.rows[0],function(a,c){b.move_widget_up(this,b.player_grid_data.size_y)})},g.on_stop_overlapping_row=function(a){this.set_player();var b=this,c=this.cells_occupied_by_player.cols;for(var d=0,e=c.length;d<e;d++)this.for_each_widget_below(c[d],a,function(a,c){b.move_widget_up(this,b.player_grid_data.size_y)})},g.move_widget_to=function(b,c){var d=this,e=b.coords().grid,f=c-e.row,g=this.widgets_below(b),h=this.can_move_to(e,e.col,c,b);return h===!1?!1:(this.remove_from_gridmap(e),e.row=c,this.add_to_gridmap(e),b.attr("data-row",c),this.$changed=this.$changed.add(b),g.each(function(b,c){var e=a(c),f=e.coords().grid,g=d.can_go_widget_up(f);g&&g!==f.row&&d.move_widget_to(e,g)}),this)},g.move_widget_up=function(b,c){var d=b.coords().grid,e=d.row,f=[],g=!0;c||(c=1);if(!this.can_go_up(b))return!1;this.for_each_column_occupied(d,function(d){if(a.inArray(b,f)===-1){var g=b.coords().grid,h=e-c;h=this.can_go_up_to_row(g,d,h);if(!h)return!0;var i=this.widgets_below(b);this.remove_from_gridmap(g),g.row=h,this.add_to_gridmap(g),b.attr("data-row",g.row),this.$changed=this.$changed.add(b),f.push(b),i.each(a.proxy(function(b,d){this.move_widget_up(a(d),c)},this))}})},g.move_widget_down=function(b,c){var d=b.coords().grid,e=d.row,f=[],g=c;if(!b)return!1;if(a.inArray(b,f)===-1){var h=b.coords().grid,i=e+c,j=this.widgets_below(b);this.remove_from_gridmap(h),j.each(a.proxy(function(b,c){var d=a(c),e=d.coords().grid,f=this.displacement_diff(e,h,g);f>0&&this.move_widget_down(d,f)},this)),h.row=i,this.update_widget_position(h,b),b.attr("data-row",h.row),this.$changed=this.$changed.add(b),f.push(b)}},g.can_go_up_to_row=function(b,c,d){var e=this.gridmap,f=!0,g=[],h=b.row,i;this.for_each_column_occupied(b,function(a){var b=e[a];g[a]=[],i=h;while(i--)if(this.is_empty(a,i)&&!this.is_placeholder_in(a,i))g[a].push(i);else break;if(!g[a].length)return f=!1,!0});if(!f)return!1;i=d;for(i=1;i<h;i++){var j=!0;for(var k=0,l=g.length;k<l;k++)g[k]&&a.inArray(i,g[k])===-1&&(j=!1);if(j===!0){f=i;break}}return f},g.displacement_diff=function(a,b,c){var d=a.row,e=[],f=b.row+b.size_y;this.for_each_column_occupied(a,function(a){var b=0;for(var c=f;c<d;c++)this.is_empty(a,c)&&(b=b+1);e.push(b)});var g=Math.max.apply(null,e);return c=c-g,c>0?c:0},g.widgets_below=function(b){var c=a.isPlainObject(b)?b:b.coords().grid,d=this,e=this.gridmap,f=c.row+c.size_y-1,g=a([]);return this.for_each_column_occupied(c,function(b){d.for_each_widget_below(b,f,function(b,c){if(!d.is_player(this)&&a.inArray(this,g)===-1)return g=g.add(this),!0})}),this.sort_by_row_asc(g)},g.set_cells_player_occupies=function(a,b){return this.remove_from_gridmap(this.placeholder_grid_data),this.placeholder_grid_data.col=a,this.placeholder_grid_data.row=b,this.add_to_gridmap(this.placeholder_grid_data,this.$player),this},g.empty_cells_player_occupies=function(){return this.remove_from_gridmap(this.placeholder_grid_data),this},g.can_go_up=function(a){var b=a.coords().grid,c=b.row,d=c-1,e=this.gridmap,f=[],g=!0;return c===1?!1:(this.for_each_column_occupied(b,function(a){if(this.is_occupied(a,d)||this.is_player(a,d)||this.is_placeholder_in(a,d))return g=!1,!0}),g)},g.can_move_to=function(a,b,c){var d=this.gridmap,e=a.el,f={size_y:a.size_y,size_x:a.size_x,col:b,row:c},g=!0,h=b+a.size_x-1;return h>this.cols?!1:(this.for_each_cell_occupied(f,function(b,c){var d=this.is_widget(b,c);d&&(!a.el||d.is(e))&&(g=!1)}),g)},g.get_targeted_columns=function(a){var b=(a||this.player_grid_data.col)+(this.player_grid_data.size_x-1),c=[];for(var d=a;d<=b;d++)c.push(d);return c},g.get_targeted_rows=function(a){var b=(a||this.player_grid_data.row)+(this.player_grid_data.size_y-1),c=[];for(var d=a;d<=b;d++)c.push(d);return c},g.get_cells_occupied=function(a){var b={cols:[],rows:[]},c;arguments[1]instanceof jQuery&&(a=arguments[1].coords().grid);for(c=0;c<a.size_x;c++){var d=a.col+c;b.cols.push(d)}for(c=0;c<a.size_y;c++){var e=a.row+c;b.rows.push(e)}return b},g.for_each_cell_occupied=function(a,b){return this.for_each_column_occupied(a,function(c){this.for_each_row_occupied(a,function(a){b.call(this,c,a)})}),this},g.for_each_column_occupied=function(a,b){for(var c=0;c<a.size_x;c++){var d=a.col+c;b.call(this,d,a)}},g.for_each_row_occupied=function(a,b){for(var c=0;c<a.size_y;c++){var d=a.row+c;b.call(this,d,a)}},g._traversing_widgets=function(b,c,d,e,f){var g=this.gridmap;if(!g[d])return;var h,i,j=b+"/"+c;if(arguments[2]instanceof jQuery){var k=arguments[2].coords().grid;d=k.col,e=k.row,f=arguments[3]}var l=[],m=e,n={"for_each/above":function(){while(m--)if(m>0&&this.is_widget(d,m)&&a.inArray(g[d][m],l)===-1){h=f.call(g[d][m],d,m),l.push(g[d][m]);if(h)break}},"for_each/below":function(){for(m=e+1,i=g[d].length;m<i;m++)if(this.is_widget(d,m)&&a.inArray(g[d][m],l)===-1){h=f.call(g[d][m],d,m),l.push(g[d][m]);if(h)break}}};n[j]&&n[j].call(this)},g.for_each_widget_above=function(a,b,c){return this._traversing_widgets("for_each","above",a,b,c),this},g.for_each_widget_below=function(a,b,c){return this._traversing_widgets("for_each","below",a,b,c),this},g.get_highest_occupied_cell=function(){var a,b=this.gridmap,c=[],d=[];for(var e=b.length-1;e>=1;e--)for(a=b[e].length-1;a>=1;a--)if(this.is_widget(e,a)){c.push(a),d[a]=e;break}var f=Math.max.apply(null,c);return this.highest_occupied_cell={col:d[f],row:f},this.highest_occupied_cell},g.get_widgets_from=function(b,c){var d=this.gridmap,e=a();return b&&(e=e.add(this.$widgets.filter(function(){var c=a(this).attr("data-col");return c==b||c>b}))),c&&(e=e.add(this.$widgets.filter(function(){var b=a(this).attr("data-row");return b==c||b>c}))),e},g.set_dom_grid_height=function(){var a=this.get_highest_occupied_cell().row;return this.$el.css("height",a*this.min_widget_height),this},g.generate_stylesheet=function(b){var c="",d=10,e=6,g=6,h,i;b||(b={}),b.cols||(b.cols=this.cols),b.rows||(b.rows=this.rows),b.namespace||(b.namespace=""),b.widget_base_dimensions||(b.widget_base_dimensions=this.options.widget_base_dimensions),b.widget_margins||(b.widget_margins=this.options.widget_margins),b.min_widget_width=b.widget_margins[0]*2+b.widget_base_dimensions[0],b.min_widget_height=b.widget_margins[1]*2+b.widget_base_dimensions[1];var j=a.param(b);if(a.inArray(j,f.generated_stylesheets)>=0)return!1;f.generated_stylesheets.push(j);for(h=b.cols+d;h>=0;h--)c+=b.namespace+' [data-col="'+(h+1)+'"] { left: '+(h*b.widget_base_dimensions[0]+h*b.widget_margins[0]+(h+1)*b.widget_margins[0])+"px;} ";for(h=b.rows+d;h>=0;h--)c+=b.namespace+' [data-row="'+(h+1)+'"] { top: '+(h*b.widget_base_dimensions[1]+h*b.widget_margins[1]+(h+1)*b.widget_margins[1])+"px;} ";for(var k=1;k<e;k++)c+=b.namespace+' [data-sizey="'+k+'"] { height: '+(k*b.widget_base_dimensions[1]+(k-1)*b.widget_margins[1]*2)+"px;}";for(var l=1;l<g;l++)c+=b.namespace+' [data-sizex="'+l+'"] { width: '+(l*b.widget_base_dimensions[0]+(l-1)*b.widget_margins[0]*2)+"px;}";return this.add_style_tag(c)},g.add_style_tag=function(a){var b=c,d=b.createElement("style");return b.getElementsByTagName("head")[0].appendChild(d),d.setAttribute("type","text/css"),d.styleSheet?d.styleSheet.cssText=a:d.appendChild(c.createTextNode(a)),this},g.generate_faux_grid=function(b,c){this.faux_grid=[],this.gridmap=[];var d,e;for(d=c;d>0;d--){this.gridmap[d]=[];for(e=b;e>0;e--){var f=a({left:this.baseX+(d-1)*this.min_widget_width,top:this.baseY+(e-1)*this.min_widget_height,width:this.min_widget_width,height:this.min_widget_height,col:d,row:e,original_col:d,original_row:e}).coords();this.gridmap[d][e]=!1,this.faux_grid.push(f)}}return this},g.recalculate_faux_grid=function(){var c=this.$wrapper.width();return this.baseX=(a(b).width()-c)/2,this.baseY=this.$wrapper.offset().top,a.each(this.faux_grid,a.proxy(function(a,b){this.faux_grid[a]=b.update({left:this.baseX+(b.data.col-1)*this.min_widget_width,top:this.baseY+(b.data.row-1)*this.min_widget_height})},this)),this},g.get_widgets_from_DOM=function(){return this.$widgets.each(a.proxy(function(b,c){this.register_widget(a(c))},this)),this},g.generate_grid_and_stylesheet=function(){var c=this.$wrapper.width(),d=this.$wrapper.height(),e=Math.floor(c/this.min_widget_width)+this.options.extra_cols,f=Math.floor(d/this.min_widget_height)+this.options.extra_rows,g=this.$widgets.map(function(){return a(this).attr("data-col")}),h=this.$widgets.map(function(){return a(this).attr("data-row")}),i=Math.max.apply(null,g),j=Math.max.apply(null,h);return this.cols=Math.max(i,e,this.options.min_cols),this.rows=Math.max(j,f,this.options.min_rows),this.baseX=(a(b).width()-c)/2,this.baseY=this.$wrapper.offset().top,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this.generate_faux_grid(this.rows,this.cols)},a.fn.gridster=function(b){return this.each(function(){a(this).data("gridster")||a(this).data("gridster",new f(this,b))})}}(jQuery,window,document); \ No newline at end of file +(function(a,b,c,d){function e(b){return b[0]&&a.isPlainObject(b[0])?this.data=b[0]:this.el=b,this.isCoords=!0,this.coords={},this.init(),this}var f=e.prototype;f.init=function(){this.set(),this.original_coords=this.get()},f.set=function(a,b){var c=this.el;c&&!a&&(this.data={}||c.offset(),this.data.width=c.width(),this.data.height=c.height());if(c&&a&&!b){var d=c.offset();this.data.top=d.top,this.data.left=d.left}var e=this.data;return this.coords.x1=e.left,this.coords.y1=e.top,this.coords.x2=e.left+e.width,this.coords.y2=e.top+e.height,this.coords.cx=e.left+e.width/2,this.coords.cy=e.top+e.height/2,this.coords.width=e.width,this.coords.height=e.height,this.coords.el=c||!1,this},f.update=function(b){if(!b&&!this.el)return this;if(b){var c=a.extend({},this.data,b);return this.data=c,this.set(!0,!0)}return this.set(!0),this},f.get=function(){return this.coords},a.fn.coords=function(){if(this.data("coords"))return this.data("coords");var a=new e(this,arguments[0]);return this.data("coords",a),a}})(jQuery,window,document),function(a,b,c,d){function f(b,c,d){this.options=a.extend(e,d),this.$element=b,this.last_colliders=[],this.last_colliders_coords=[],typeof c=="string"||c instanceof jQuery?this.$colliders=a(c,this.options.colliders_context).not(this.$element):this.colliders=a(c),this.init()}var e={colliders_context:c.body},g=f.prototype;g.init=function(){this.find_collisions()},g.overlaps=function(a,b){var c=!1,d=!1;if(b.x1>=a.x1&&b.x1<=a.x2||b.x2>=a.x1&&b.x2<=a.x2||a.x1>=b.x1&&a.x2<=b.x2)c=!0;if(b.y1>=a.y1&&b.y1<=a.y2||b.y2>=a.y1&&b.y2<=a.y2||a.y1>=b.y1&&a.y2<=b.y2)d=!0;return c&&d},g.detect_overlapping_region=function(a,b){var c="",d="";return a.y1>b.cy&&a.y1<b.y2&&(c="N"),a.y2>b.y1&&a.y2<b.cy&&(c="S"),a.x1>b.cx&&a.x1<b.x2&&(d="W"),a.x2>b.x1&&a.x2<b.cx&&(d="E"),c+d||"C"},g.calculate_overlapped_area_coords=function(b,c){var d=Math.max(b.x1,c.x1),e=Math.max(b.y1,c.y1),f=Math.min(b.x2,c.x2),g=Math.min(b.y2,c.y2);return a({left:d,top:e,width:f-d,height:g-e}).coords().get()},g.calculate_overlapped_area=function(a){return a.width*a.height},g.manage_colliders_start_stop=function(b,c,d){var e=this.last_colliders_coords;for(var f=0,g=e.length;f<g;f++)a.inArray(e[f],b)===-1&&c.call(this,e[f]);for(var h=0,i=b.length;h<i;h++)a.inArray(b[h],e)===-1&&d.call(this,b[h])},g.find_collisions=function(b){var c=this,d=[],e=[],f=this.colliders||this.$colliders,g=f.length,h=c.$element.coords().update(b||!1).get();while(g--){var i=c.$colliders?a(f[g]):f[g],j=i.isCoords?i:i.coords(),k=j.get(),l=c.overlaps(h,k);if(!l)continue;var m=c.detect_overlapping_region(h,k);if(m==="C"){var n=c.calculate_overlapped_area_coords(h,k),o=c.calculate_overlapped_area(n),p={area:o,area_coords:n,region:m,coords:k,player_coords:h,el:i};c.options.on_overlap.call(this,p),d.push(j),e.push(p)}}return this.manage_colliders_start_stop(d,c.options.on_overlap_stop,c.options.on_overlap_start),this.last_colliders_coords=d,e},g.get_closest_colliders=function(a){var b=this.find_collisions(a),c=100;return b.sort(function(a,b){return a.area<=c?1:a.region==="C"&&b.region==="C"?a.coords.y1<b.coords.y1||a.coords.x1<b.coords.x1?-1:1:a.area<b.area?1:1}),b},a.fn.collision=function(a,b){return new f(this,a,b)}}(jQuery,window,document),function(a,b){a.debounce=function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)};c&&!d&&a.apply(e,f),clearTimeout(d),d=setTimeout(g,b)}},a.throttle=function(a,b){var c,d,e,f,g,h,i=debounce(function(){g=f=!1},b);return function(){c=this,d=arguments;var j=function(){e=null,g&&a.apply(c,d),i()};return e||(e=setTimeout(j,b)),f?g=!0:h=a.apply(c,d),i(),f=!0,h}}}(window),function(a,b,c,d){function g(b,c){this.options=a.extend({},e,c),this.$container=a(b),this.$dragitems=a(this.options.items,this.$container),this.is_dragging=!1,this.player_min_left=0+this.options.offset_left,this.init()}var e={items:".gs_w",distance:1,limit:!0,offset_left:0},f=a(c.body),h=g.prototype;h.init=function(){this.$container.css("position","relative"),this.enable()},h.get_actual_pos=function(a){var b=a.position();return b},h.get_mouse_pos=function(a){return{left:a.clientX,top:a.clientY}},h.drag_handler=function(b){if(b.which!==1)return!1;var c=this,d=!0;return this.$player=a(b.currentTarget),this.el_init_pos=this.get_actual_pos(this.$player),this.mouse_init_pos=this.get_mouse_pos(b),f.on("mousemove.draggable",function(a){var b=c.get_mouse_pos(a),e=Math.abs(b.left-c.mouse_init_pos.left),f=Math.abs(b.top-c.mouse_init_pos.top);return e>c.options.distance||f>c.options.distance?d?(d=!1,c.on_dragstart.call(c,a),!1):(c.is_dragging==!0&&throttle(c.on_dragmove.call(c,a),130),!1):!1}),!1},h.on_dragstart=function(a){return a.preventDefault(),this.drag_start=!0,this.is_dragging=!0,this.$container_offset=this.$container.offset(),this.options.helper==="clone"?(this.$helper=this.$player.clone().appendTo(this.$container).addClass("helper"),this.helper=!0):this.helper=!1,this.el_init_offset=this.$player.offset(),this.player_width=this.$player.width(),this.player_max_left=this.$container.width()-this.player_width+this.options.offset_left,this.options.start&&this.options.start.call(this.$player,a,{helper:this.helper?this.$helper:this.$player}),!1},h.get_offset=function(a){a.preventDefault();var b=this.get_mouse_pos(a),c=b.left-this.mouse_init_pos.left,d=b.top-this.mouse_init_pos.top,e=this.el_init_offset.left+c-this.$container_offset.left,f=this.el_init_offset.top+d-this.$container_offset.top;return this.options.limit&&(e>this.player_max_left?e=this.player_max_left:e<this.player_min_left&&(e=this.player_min_left)),{left:e,top:f}},h.on_dragmove=function(a){var b=this.get_offset(a);(this.helper?this.$helper:this.$player).css({position:"absolute",left:b.left,top:b.top});var c={position:{left:b.left,top:b.top}};return this.options.drag&&this.options.drag.call(this.$player,a,c),!1},h.on_dragstop=function(a){var b=this.get_offset(a);this.drag_start=!1;var c={position:{left:b.left,top:b.top}};return this.options.stop&&this.options.stop.call(this.$player,a,c),this.helper&&this.$helper.remove(),!1},h.enable=function(){this.$container.on("mousedown.draggable",this.options.items,a.proxy(this.drag_handler,this)),f.on("mouseup.draggable",a.proxy(function(a){this.is_dragging=!1,f.off("mousemove.draggable"),this.drag_start&&this.on_dragstop(a)},this))},h.disable=function(){this.$container.off("mousedown.draggable"),f.off("mouseup.draggable")},h.destroy=function(){this.disable(),a.removeData(this.$container,"draggable")},a.fn.draggable=function(b){return this.each(function(){a.data(this,"draggable")||a.data(this,"draggable",new g(this,b))})}}(jQuery,window,document),function(a,b,c,d){function f(b,c){this.options=a.extend(!0,e,c),this.$el=a(b),this.$wrapper=this.$el.parent(),this.$widgets=a(this.options.widget_selector,this.$el).addClass("gs_w"),this.widgets=[],this.$changed=a([]),this.wrapper_width=this.$wrapper.width(),this.min_widget_width=this.options.widget_margins[0]*2+this.options.widget_base_dimensions[0],this.min_widget_height=this.options.widget_margins[1]*2+this.options.widget_base_dimensions[1],this.init()}var e={widget_selector:"> li",widget_margins:[10,10],widget_base_dimensions:[400,225],extra_rows:0,extra_cols:0,min_cols:1,min_rows:15,autogenerate_stylesheet:!0,avoid_overlapped_widgets:!0,serialize_params:function(a,b){return{col:b.col,row:b.row}},collision:{},draggable:{distance:4}};f.generated_stylesheets=[];var g=f.prototype;g.init=function(){this.generate_grid_and_stylesheet(),this.get_widgets_from_DOM(),this.set_dom_grid_height(),this.$wrapper.addClass("ready"),this.draggable(),a(b).bind("resize",throttle(a.proxy(this.recalculate_faux_grid,this),200))},g.disable=function(){return this.$wrapper.find(".player-revert").removeClass("player-revert"),this.drag_api.disable(),this},g.enable=function(){return this.drag_api.enable(),this},g.add_widget=function(b,c,d){var e=this.next_position(c,d),f=a(b).attr({"data-col":e.col,"data-row":e.row,"data-sizex":e.size_x,"data-sizey":e.size_y}).addClass("gs_w").appendTo(this.$el).hide();return this.$widgets=this.$widgets.add(f),this.register_widget(f),this.set_dom_grid_height(),f.fadeIn()},g.next_position=function(a,b){a||(a=1),b||(b=1);var c=this.gridmap,d=c.length,e=[];for(var f=1;f<d;f++){var g=c[f].length;for(var h=1;h<=g;h++){var i=this.can_move_to({size_x:a,size_y:b},f,h);i&&e.push({col:f,row:h,size_y:b,size_x:a})}}return e.length?this.sort_by_row_and_col_asc(e)[0]:!1},g.remove_widget=function(b,c){var d=b instanceof jQuery?b:a(b),e=d.coords().grid;this.cells_occupied_by_placeholder={},this.$widgets=this.$widgets.not(d);var f=this.widgets_below(d);this.remove_from_gridmap(e),d.fadeOut(a.proxy(function(){d.remove(),f.each(a.proxy(function(b,c){this.move_widget_up(a(c),e.size_y)},this)),c&&c.apply(this,b)},this))},g.serialize=function(b){b||(b=this.$widgets);var c=[];return b.each(a.proxy(function(b,d){c.push(this.options.serialize_params(a(d),a(d).coords().grid))},this)),c},g.serialize_changed=function(){return this.serialize(this.$changed)},g.register_widget=function(a){var b={col:parseInt(a.attr("data-col"),10),row:parseInt(a.attr("data-row"),10),size_x:parseInt(a.attr("data-sizex"),10),size_y:parseInt(a.attr("data-sizey"),10),el:a};return this.options.avoid_overlapped_widgets&&!this.can_move_to({size_x:b.size_x,size_y:b.size_y},b.col,b.row)&&(b=this.next_position(b.size_x,b.size_y),b.el=a,a.attr({"data-col":b.col,"data-row":b.row,"data-sizex":b.size_x,"data-sizey":b.size_y})),a.data("coords",a.coords()),a.data("coords").grid=b,this.add_to_gridmap(b,a),this.widgets.push(a),this},g.update_widget_position=function(a,b){return this.for_each_cell_occupied(a,function(a,c){if(!this.gridmap[a])return this;this.gridmap[a][c]=b}),this},g.remove_from_gridmap=function(a){return this.update_widget_position(a,!1)},g.add_to_gridmap=function(b,c){this.update_widget_position(b,c||b.el);if(b.el){var d=this.widgets_below(b.el);d.each(a.proxy(function(b,c){this.move_widget_up(a(c))},this))}},g.draggable=function(){var b=this,c=a.extend(!0,{},this.options.draggable,{offset_left:this.options.widget_margins[0],items:".gs_w",start:function(c,d){b.$widgets.filter(".player-revert").removeClass("player-revert"),b.$player=a(this),b.$helper=b.options.draggable.helper==="clone"?a(d.helper):b.$player,b.helper=!b.$helper.is(b.$player),b.on_start_drag.call(b,c,d),b.$el.trigger("gridster:dragstart")},stop:function(a,c){b.on_stop_drag.call(b,a,c),b.$el.trigger("gridster:dragstop")},drag:function(a,c){b.on_drag.call(b,a,c),b.$el.trigger("gridster:drag")}});return this.drag_api=this.$el.draggable(c).data("draggable"),this},g.on_start_drag=function(b,c){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=a.extend({},this.player_grid_data),this.$el.css("height",this.$el.height()+this.player_grid_data.size_y*this.min_widget_height);var d=this.faux_grid,e=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(d,this.options.collision),this.$preview_holder=a("<li />",{"class":"preview-holder","data-row":this.$player.attr("data-row"),"data-col":this.$player.attr("data-col"),css:{width:e.width,height:e.height}}).appendTo(this.$el),this.options.draggable.start&&this.options.draggable.start.call(this,b,c)},g.on_drag=function(a,b){var c={left:b.position.left+this.baseX,top:b.position.top+this.baseY};this.colliders_data=this.collision_api.get_closest_colliders(c),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:b.position.left,top:b.position.top}),this.options.draggable.drag&&this.options.draggable.drag.call(this,a,b)},g.on_stop_drag=function(a,b){this.$helper.add(this.$player).add(this.$wrapper).removeClass("dragging"),b.position.left=b.position.left+this.baseX,b.position.top=b.position.top+this.baseY,this.colliders_data=this.collision_api.get_closest_colliders(b.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.$player=null,this.$preview_holder.remove(),this.set_dom_grid_height(),this.options.draggable.stop&&this.options.draggable.stop.call(this,a,b)},g.on_overlapped_column_change=function(b,c){if(!this.colliders_data.length)return;var d=this.get_targeted_columns(this.colliders_data[0].el.data.col),e=this.last_cols.length,f=d.length,g;for(g=0;g<f;g++)a.inArray(d[g],this.last_cols)===-1&&(b||a.noop).call(this,d[g]);for(g=0;g<e;g++)a.inArray(this.last_cols[g],d)===-1&&(c||a.noop).call(this,this.last_cols[g]);return this.last_cols=d,this},g.on_overlapped_row_change=function(b,c){if(!this.colliders_data.length)return;var d=this.get_targeted_rows(this.colliders_data[0].el.data.row),e=this.last_rows.length,f=d.length,g;for(g=0;g<f;g++)a.inArray(d[g],this.last_rows)===-1&&(b||a.noop).call(this,d[g]);for(g=0;g<e;g++)a.inArray(this.last_rows[g],d)===-1&&(c||a.noop).call(this,this.last_rows[g]);this.last_rows=d},g.set_player=function(a,b){this.empty_cells_player_occupies();var c=this,d=c.colliders_data[0].el.data,e=d.col,f=b||d.row;this.player_grid_data={col:e,row:f,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 g=this.get_widgets_overlapped(this.player_grid_data),h=this.widgets_constraints(g);this.manage_movements(h.can_go_up,e,f),this.manage_movements(h.can_not_go_up,e,f);if(!g.length){var i=this.can_go_player_up(this.player_grid_data);i!==!1&&(f=i),this.set_placeholder(e,f)}return{col:e,row:f}},g.widgets_constraints=function(b){var c=a([]),d,e=[],f=[];return b.each(a.proxy(function(b,d){var g=a(d),h=g.coords().grid;this.can_go_widget_up(h)?(c=c.add(g),e.push(h)):f.push(h)},this)),d=b.not(c),{can_go_up:this.sort_by_row_asc(e),can_not_go_up:this.sort_by_row_desc(f)}},g.sort_by_row_asc=function(a){return a=a.sort(function(a,b){return a.row>b.row?1:-1}),a},g.sort_by_row_and_col_asc=function(a){return a=a.sort(function(a,b){return a.row>b.row||a.row==b.row&&a.col>b.col?1:-1}),a},g.sort_by_col_asc=function(a){return a=a.sort(function(a,b){return a.col>b.col?1:-1}),a},g.sort_by_row_desc=function(a){return a=a.sort(function(a,b){return a.row+a.size_y<b.row+b.size_y?1:-1}),a},g.manage_movements=function(b,c,d){return a.each(b,a.proxy(function(a,b){var e=b,f=e.el,g=this.can_go_widget_up(e);if(g)this.move_widget_to(f,g),this.set_placeholder(c,g+e.size_y);else{var h=this.can_go_player_up(this.player_grid_data);if(!h){var i=d+this.player_grid_data.size_y-e.row;this.move_widget_down(f,i),this.set_placeholder(c,d)}}},this)),this},g.is_player=function(a,b){if(b&&!this.gridmap[a])return!1;var c=b?this.gridmap[a][b]:a;return c&&(c.is(this.$player)||c.is(this.$helper))},g.is_player_in=function(b,c){var d=this.cells_occupied_by_player;return a.inArray(b,d.cols)>=0&&a.inArray(c,d.rows)>=0},g.is_placeholder_in=function(b,c){var d=this.cells_occupied_by_placeholder||{};return this.is_placeholder_in_col(b)&&a.inArray(c,d.rows)>=0},g.is_placeholder_in_col=function(b){var c=this.cells_occupied_by_placeholder||[];return a.inArray(b,c.cols)>=0},g.is_empty=function(a,b){return typeof this.gridmap[a]!="undefined"&&typeof this.gridmap[a][b]!="undefined"&&this.gridmap[a][b]===!1?!0:!1},g.is_occupied=function(a,b){return this.gridmap[a]?this.gridmap[a][b]?!0:!1:!1},g.is_widget=function(a,b){var c=this.gridmap[a];return c?(c=c[b],c?c:!1):!1},g.is_widget_under_player=function(a,b){return this.is_widget(a,b)?this.is_player_in(a,b):!1},g.get_widgets_under_player=function(){var b=this.cells_occupied_by_player,c=a([]);return a.each(b.cols,a.proxy(function(d,e){a.each(b.rows,a.proxy(function(a,b){this.is_widget(e,b)&&(c=c.add(this.gridmap[e][b]))},this))},this)),c},g.set_placeholder=function(b,c){var d=a.extend({},this.placeholder_grid_data),e=this.widgets_below({col:d.col,row:d.row,size_y:d.size_y,size_x:d.size_x}),f=b+d.size_x-1;f>this.cols&&(b=b-(f-b));var g=this.placeholder_grid_data.row<c,h=this.placeholder_grid_data.col!==b;this.placeholder_grid_data.col=b,this.placeholder_grid_data.row=c,this.cells_occupied_by_placeholder=this.get_cells_occupied(this.placeholder_grid_data),this.$preview_holder.attr({"data-row":c,"data-col":b}),(g||h)&&e.each(a.proxy(function(c,e){this.move_widget_up(a(e),this.placeholder_grid_data.col-b+d.size_y)},this))},g.can_go_player_up=function(a){var b=a.row+a.size_y-1,c=!0,d=[],e=1e4,f=this.get_widgets_under_player();return this.for_each_column_occupied(a,function(a){var g=this.gridmap[a],h=b+1;d[a]=[];while(--h>0)if(this.is_empty(a,h)||this.is_player(a,h)||this.is_widget(a,h)&&g[h].is(f))d[a].push(h),e=h<e?h:e;else break;if(d[a].length===0)return c=!1,!0;d[a].sort()}),c?this.get_valid_rows(a,d,e):!1},g.can_go_widget_up=function(a){var b=a.row+a.size_y-1,c=!0,d=[],e=1e4;return this.for_each_column_occupied(a,function(a){var f=this.gridmap[a];d[a]=[];var g=b+1;while(--g>0){if(this.is_occupied(a,g)&&!this.is_player(a,g))break;!this.is_player(a,g)&&!this.is_placeholder_in(a,g)&&d[a].push(g),g<e&&(e=g)}if(d[a].length===0)return c=!1,!0;d[a].sort()}),c?this.get_valid_rows(a,d,e):!1},g.get_valid_rows=function(b,c,d){var e=b.row,f=b.row+b.size_y-1,g=b.size_y,h=d-1,i=[];while(++h<=f){var j=!0;a.each(c,function(b,c){c&&a.inArray(h,c)===-1&&(j=!1)});if(j===!0){i.push(h);if(i.length===g)break}}var k=!1;return g===1?i[0]!==e&&(k=i[0]||!1):i[0]!==e&&(k=this.get_consecutive_numbers_index(i,g)),k},g.get_consecutive_numbers_index=function(a,b){var c=a.length,d=[],e=!0,f=-1;for(var g=0;g<c;g++){if(e||a[g]===f+1){d.push(g);if(d.length===b)break;e=!1}else d=[],e=!0;f=a[g]}return d.length>=b?a[d[0]]:!1},g.get_widgets_overlapped=function(){var b,c=a([]),d=[],e=this.cells_occupied_by_player.rows.slice(0);return e.reverse(),a.each(this.cells_occupied_by_player.cols,a.proxy(function(b,f){a.each(e,a.proxy(function(b,e){if(!this.gridmap[f])return!0;var g=this.gridmap[f][e];this.is_occupied(f,e)&&!this.is_player(g)&&a.inArray(g,d)===-1&&(c=c.add(g),d.push(g))},this))},this)),c},g.on_start_overlapping_column=function(a){this.set_player(a,!1)},g.on_start_overlapping_row=function(a){this.set_player(!1,a)},g.on_stop_overlapping_column=function(a){this.set_player();var b=this;this.for_each_widget_below(a,this.cells_occupied_by_player.rows[0],function(a,c){b.move_widget_up(this,b.player_grid_data.size_y)})},g.on_stop_overlapping_row=function(a){this.set_player();var b=this,c=this.cells_occupied_by_player.cols;for(var d=0,e=c.length;d<e;d++)this.for_each_widget_below(c[d],a,function(a,c){b.move_widget_up(this,b.player_grid_data.size_y)})},g.move_widget_to=function(b,c){var d=this,e=b.coords().grid,f=c-e.row,g=this.widgets_below(b),h=this.can_move_to(e,e.col,c,b);return h===!1?!1:(this.remove_from_gridmap(e),e.row=c,this.add_to_gridmap(e),b.attr("data-row",c),this.$changed=this.$changed.add(b),g.each(function(b,c){var e=a(c),f=e.coords().grid,g=d.can_go_widget_up(f);g&&g!==f.row&&d.move_widget_to(e,g)}),this)},g.move_widget_up=function(b,c){var d=b.coords().grid,e=d.row,f=[],g=!0;c||(c=1);if(!this.can_go_up(b))return!1;this.for_each_column_occupied(d,function(d){if(a.inArray(b,f)===-1){var g=b.coords().grid,h=e-c;h=this.can_go_up_to_row(g,d,h);if(!h)return!0;var i=this.widgets_below(b);this.remove_from_gridmap(g),g.row=h,this.add_to_gridmap(g),b.attr("data-row",g.row),this.$changed=this.$changed.add(b),f.push(b),i.each(a.proxy(function(b,d){this.move_widget_up(a(d),c)},this))}})},g.move_widget_down=function(b,c){var d=b.coords().grid,e=d.row,f=[],g=c;if(!b)return!1;if(a.inArray(b,f)===-1){var h=b.coords().grid,i=e+c,j=this.widgets_below(b);this.remove_from_gridmap(h),j.each(a.proxy(function(b,c){var d=a(c),e=d.coords().grid,f=this.displacement_diff(e,h,g);f>0&&this.move_widget_down(d,f)},this)),h.row=i,this.update_widget_position(h,b),b.attr("data-row",h.row),this.$changed=this.$changed.add(b),f.push(b)}},g.can_go_up_to_row=function(b,c,d){var e=this.gridmap,f=!0,g=[],h=b.row,i;this.for_each_column_occupied(b,function(a){var b=e[a];g[a]=[],i=h;while(i--)if(this.is_empty(a,i)&&!this.is_placeholder_in(a,i))g[a].push(i);else break;if(!g[a].length)return f=!1,!0});if(!f)return!1;i=d;for(i=1;i<h;i++){var j=!0;for(var k=0,l=g.length;k<l;k++)g[k]&&a.inArray(i,g[k])===-1&&(j=!1);if(j===!0){f=i;break}}return f},g.displacement_diff=function(a,b,c){var d=a.row,e=[],f=b.row+b.size_y;this.for_each_column_occupied(a,function(a){var b=0;for(var c=f;c<d;c++)this.is_empty(a,c)&&(b=b+1);e.push(b)});var g=Math.max.apply(null,e);return c=c-g,c>0?c:0},g.widgets_below=function(b){var c=a.isPlainObject(b)?b:b.coords().grid,d=this,e=this.gridmap,f=c.row+c.size_y-1,g=a([]);return this.for_each_column_occupied(c,function(b){d.for_each_widget_below(b,f,function(b,c){if(!d.is_player(this)&&a.inArray(this,g)===-1)return g=g.add(this),!0})}),this.sort_by_row_asc(g)},g.set_cells_player_occupies=function(a,b){return this.remove_from_gridmap(this.placeholder_grid_data),this.placeholder_grid_data.col=a,this.placeholder_grid_data.row=b,this.add_to_gridmap(this.placeholder_grid_data,this.$player),this},g.empty_cells_player_occupies=function(){return this.remove_from_gridmap(this.placeholder_grid_data),this},g.can_go_up=function(a){var b=a.coords().grid,c=b.row,d=c-1,e=this.gridmap,f=[],g=!0;return c===1?!1:(this.for_each_column_occupied(b,function(a){var b=this.is_widget(a,d);if(this.is_occupied(a,d)||this.is_player(a,d)||this.is_placeholder_in(a,d))return g=!1,!0}),g)},g.can_move_to=function(a,b,c){var d=this.gridmap,e=a.el,f={size_y:a.size_y,size_x:a.size_x,col:b,row:c},g=!0,h=b+a.size_x-1;return h>this.cols?!1:(this.for_each_cell_occupied(f,function(b,c){var d=this.is_widget(b,c);d&&(!a.el||d.is(e))&&(g=!1)}),g)},g.get_targeted_columns=function(a){var b=(a||this.player_grid_data.col)+(this.player_grid_data.size_x-1),c=[];for(var d=a;d<=b;d++)c.push(d);return c},g.get_targeted_rows=function(a){var b=(a||this.player_grid_data.row)+(this.player_grid_data.size_y-1),c=[];for(var d=a;d<=b;d++)c.push(d);return c},g.get_cells_occupied=function(a){var b={cols:[],rows:[]},c;arguments[1]instanceof jQuery&&(a=arguments[1].coords().grid);for(c=0;c<a.size_x;c++){var d=a.col+c;b.cols.push(d)}for(c=0;c<a.size_y;c++){var e=a.row+c;b.rows.push(e)}return b},g.for_each_cell_occupied=function(a,b){return this.for_each_column_occupied(a,function(c){this.for_each_row_occupied(a,function(a){b.call(this,c,a)})}),this},g.for_each_column_occupied=function(a,b){for(var c=0;c<a.size_x;c++){var d=a.col+c;b.call(this,d,a)}},g.for_each_row_occupied=function(a,b){for(var c=0;c<a.size_y;c++){var d=a.row+c;b.call(this,d,a)}},g._traversing_widgets=function(b,c,d,e,f){var g=this.gridmap;if(!g[d])return;var h,i,j=b+"/"+c;if(arguments[2]instanceof jQuery){var k=arguments[2].coords().grid;d=k.col,e=k.row,f=arguments[3]}var l=[],m=e,n={"for_each/above":function(){while(m--)if(m>0&&this.is_widget(d,m)&&a.inArray(g[d][m],l)===-1){h=f.call(g[d][m],d,m),l.push(g[d][m]);if(h)break}},"for_each/below":function(){for(m=e+1,i=g[d].length;m<i;m++)if(this.is_widget(d,m)&&a.inArray(g[d][m],l)===-1){h=f.call(g[d][m],d,m),l.push(g[d][m]);if(h)break}}};n[j]&&n[j].call(this)},g.for_each_widget_above=function(a,b,c){return this._traversing_widgets("for_each","above",a,b,c),this},g.for_each_widget_below=function(a,b,c){return this._traversing_widgets("for_each","below",a,b,c),this},g.get_highest_occupied_cell=function(){var a,b=this.gridmap,c=[],d=[];for(var e=b.length-1;e>=1;e--)for(a=b[e].length-1;a>=1;a--)if(this.is_widget(e,a)){c.push(a),d[a]=e;break}var f=Math.max.apply(null,c);return this.highest_occupied_cell={col:d[f],row:f},this.highest_occupied_cell},g.get_widgets_from=function(b,c){var d=this.gridmap,e=a();return b&&(e=e.add(this.$widgets.filter(function(){var c=a(this).attr("data-col");return c==b||c>b}))),c&&(e=e.add(this.$widgets.filter(function(){var b=a(this).attr("data-row");return b==c||b>c}))),e},g.set_dom_grid_height=function(){var a=this.get_highest_occupied_cell().row;return this.$el.css("height",a*this.min_widget_height),this},g.generate_stylesheet=function(b){var c="",d=10,e=6,g=6,h,i;b||(b={}),b.cols||(b.cols=this.cols),b.rows||(b.rows=this.rows),b.namespace||(b.namespace=""),b.widget_base_dimensions||(b.widget_base_dimensions=this.options.widget_base_dimensions),b.widget_margins||(b.widget_margins=this.options.widget_margins),b.min_widget_width=b.widget_margins[0]*2+b.widget_base_dimensions[0],b.min_widget_height=b.widget_margins[1]*2+b.widget_base_dimensions[1];var j=a.param(b);if(a.inArray(j,f.generated_stylesheets)>=0)return!1;f.generated_stylesheets.push(j);for(h=b.cols+d;h>=0;h--)c+=b.namespace+' [data-col="'+(h+1)+'"] { left:'+(h*b.widget_base_dimensions[0]+h*b.widget_margins[0]+(h+1)*b.widget_margins[0])+"px;} ";for(h=b.rows+d;h>=0;h--)c+=b.namespace+' [data-row="'+(h+1)+'"] { top:'+(h*b.widget_base_dimensions[1]+h*b.widget_margins[1]+(h+1)*b.widget_margins[1])+"px;} ";for(var k=1;k<e;k++)c+=b.namespace+' [data-sizey="'+k+'"] { height:'+(k*b.widget_base_dimensions[1]+(k-1)*b.widget_margins[1]*2)+"px;}";for(var l=1;l<g;l++)c+=b.namespace+' [data-sizex="'+l+'"] { width:'+(l*b.widget_base_dimensions[0]+(l-1)*b.widget_margins[0]*2)+"px;}";return this.add_style_tag(c)},g.add_style_tag=function(a){var b=c,d=b.createElement("style");return b.getElementsByTagName("head")[0].appendChild(d),d.setAttribute("type","text/css"),d.styleSheet?d.styleSheet.cssText=a:d.appendChild(c.createTextNode(a)),this},g.generate_faux_grid=function(b,c){this.faux_grid=[],this.gridmap=[];var d,e;for(d=c;d>0;d--){this.gridmap[d]=[];for(e=b;e>0;e--){var f=a({left:this.baseX+(d-1)*this.min_widget_width,top:this.baseY+(e-1)*this.min_widget_height,width:this.min_widget_width,height:this.min_widget_height,col:d,row:e,original_col:d,original_row:e}).coords();this.gridmap[d][e]=!1,this.faux_grid.push(f)}}return this},g.recalculate_faux_grid=function(){var c=this.$wrapper.width();return this.baseX=(a(b).width()-c)/2,this.baseY=this.$wrapper.offset().top,a.each(this.faux_grid,a.proxy(function(a,b){this.faux_grid[a]=b.update({left:this.baseX+(b.data.col-1)*this.min_widget_width,top:this.baseY+(b.data.row-1)*this.min_widget_height})},this)),this},g.get_widgets_from_DOM=function(){return this.$widgets.each(a.proxy(function(b,c){this.register_widget(a(c))},this)),this},g.generate_grid_and_stylesheet=function(){var c=this.$wrapper.width(),d=this.$wrapper.height(),e=Math.floor(c/this.min_widget_width)+this.options.extra_cols,f=Math.floor(d/this.min_widget_height)+this.options.extra_rows,g=this.$widgets.map(function(){return a(this).attr("data-col")}),h=this.$widgets.map(function(){return a(this).attr("data-row")}),i=Math.max.apply(null,g),j=Math.max.apply(null,h);return this.cols=Math.max(i,e,this.options.min_cols),this.rows=Math.max(j,f,this.options.min_rows),this.baseX=(a(b).width()-c)/2,this.baseY=this.$wrapper.offset().top,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this.generate_faux_grid(this.rows,this.cols)},a.fn.gridster=function(b){return this.each(function(){a(this).data("gridster")||a(this).data("gridster",new f(this,b))})}}(jQuery,window,document); \ No newline at end of file diff --git a/docs/api.js b/docs/api.js index 8b7efa7acb..47d6d2545a 100644 --- a/docs/api.js +++ b/docs/api.js @@ -1,8 +1,8 @@ YUI.add("yuidoc-meta", function(Y) { Y.YUIDoc = { meta: { "classes": [ - "Collision", - "Coords", + "Collision\n\nDetects collisions between a DOM element against other DOM elements or\nCoords objects.", + "Coords\n\nCreates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height)\nto simulate DOM elements on the screen.\nCoords is used by Gridster to create a faux grid with any DOM element can\ncollide.", "Draggable", "Gridster" ], diff --git a/docs/classes/Collision.html "b/docs/classes/Collision\n\nDetects collisions between a DOM element against other DOM elements or\nCoords objects..html" similarity index 80% rename from docs/classes/Collision.html rename to "docs/classes/Collision\n\nDetects collisions between a DOM element against other DOM elements or\nCoords objects..html" index 74c25d5b5d..7b89b6fc6c 100644 --- a/docs/classes/Collision.html +++ "b/docs/classes/Collision\n\nDetects collisions between a DOM element against other DOM elements or\nCoords objects..html" @@ -2,7 +2,10 @@ <html lang="en"> <head> <meta charset="utf-8"> - <title>Collision</title> + <title>Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects.</title> <link rel="stylesheet" href="http://yui.yahooapis.com/3.5.1/build/cssgrids/cssgrids-min.css"> <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> <link rel="stylesheet" href="../assets/css/main.css" id="site_styles"> @@ -42,9 +45,25 @@ <div id="api-tabview-panel"> <ul id="api-classes" class="apis classes"> - <li><a href="../classes/Collision.html">Collision</a></li> + <li><a href="../classes/Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects..html">Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects.</a></li> - <li><a href="../classes/Coords.html">Coords</a></li> + <li><a href="../classes/Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide..html">Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide.</a></li> <li><a href="../classes/Draggable.html">Draggable</a></li> @@ -89,7 +108,10 @@ <div class="apidocs"> <div id="docs-main"> <div class="content"> - <h1>Collision Class</h1> + <h1>Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects. Class</h1> <div class="box meta"> <div class="uses"> @@ -106,7 +128,7 @@ <div class="foundat"> - Defined in: <a href="../files/src_jquery.collision.js.html#l22"><code>src/jquery.collision.js:22</code></a> + Defined in: <a href="../files/src_jquery.collision.js.html#l19"><code>src/jquery.collision.js:19</code></a> </div> @@ -118,14 +140,20 @@ <div class="box intro"> - <p>Collision</p> + </div> <div class="constructor"> <h2>Constructor</h2> - <div id="method_Collision" class="method item"> - <h3 class="name"><code>Collision</code></h3> + <div id="method_Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects." class="method item"> + <h3 class="name"><code>Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects.</code></h3> <div class="args"> @@ -133,7 +161,7 @@ <li class="arg"> - <code>element</code> + <code>el</code> </li> @@ -182,7 +210,7 @@ - <a href="../files/src_jquery.collision.js.html#l22"><code>src/jquery.collision.js:22</code></a> + <a href="../files/src_jquery.collision.js.html#l19"><code>src/jquery.collision.js:19</code></a> </p> @@ -204,14 +232,14 @@ <li class="param"> - <code class="param-name">element</code> + <code class="param-name">el</code> <span class="type">HTMLElement</span> <div class="param-description"> - <p>An Attribute name or object property path</p> + <p>The jQuery wrapped HTMLElement.</p> </div> @@ -220,13 +248,14 @@ <li class="param"> <code class="param-name">colliders</code> - <span class="type">String | HTMLElement | Array</span> + <span class="type">HTMLElement | Array</span> <div class="param-description"> - <p>An Attribute name or object property path</p> + <p>Can be a jQuery collection + of HTMLElements or an Array of Coords instances.</p> </div> @@ -242,26 +271,13 @@ <div class="param-description"> - <p>An Attribute name or object property path</p> + <p>An Object with all options you want to + overwrite:</p> </div> <ul class="params-list"> - <li class="param"> - - <code class="param-name optional">[on_overlap]</code> - <span class="type">Function</span> - <span class="flag optional" title="This parameter is optional.">optional</span> - - - <div class="param-description"> - <p>An Attribute name or object property path</p> - </div> - - - </li> - <li class="param"> <code class="param-name optional">[on_overlap_start]</code> @@ -270,7 +286,8 @@ <div class="param-description"> - <p>An Attribute name or object property path</p> + <p>Executes a function the first + time each <code>collider</code> is overlapped.</p> </div> @@ -284,7 +301,23 @@ <div class="param-description"> - <p>An Attribute name or object property path</p> + <p>Executes a function when a + <code>collider</code> is no longer collided.</p> + </div> + + + </li> + + <li class="param"> + + <code class="param-name optional">[on_overlap]</code> + <span class="type">Function</span> + <span class="flag optional" title="This parameter is optional.">optional</span> + + + <div class="param-description"> + <p>Executes a function when the +mouse is moved during the collision.</p> </div> @@ -307,7 +340,7 @@ <span class="type">Object</span>: - dasdasdadasd + Collision instance. </div> </div> diff --git a/docs/classes/Coords.html "b/docs/classes/Coords\n\nCreates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height)\nto simulate DOM elements on the screen.\nCoords is used by Gridster to create a faux grid with any DOM element can\ncollide..html" similarity index 71% rename from docs/classes/Coords.html rename to "docs/classes/Coords\n\nCreates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height)\nto simulate DOM elements on the screen.\nCoords is used by Gridster to create a faux grid with any DOM element can\ncollide..html" index 603259dcf0..eace6a44b7 100644 --- a/docs/classes/Coords.html +++ "b/docs/classes/Coords\n\nCreates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height)\nto simulate DOM elements on the screen.\nCoords is used by Gridster to create a faux grid with any DOM element can\ncollide..html" @@ -2,7 +2,12 @@ <html lang="en"> <head> <meta charset="utf-8"> - <title>Coords</title> + <title>Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide.</title> <link rel="stylesheet" href="http://yui.yahooapis.com/3.5.1/build/cssgrids/cssgrids-min.css"> <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> <link rel="stylesheet" href="../assets/css/main.css" id="site_styles"> @@ -42,9 +47,25 @@ <div id="api-tabview-panel"> <ul id="api-classes" class="apis classes"> - <li><a href="../classes/Collision.html">Collision</a></li> + <li><a href="../classes/Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects..html">Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects.</a></li> - <li><a href="../classes/Coords.html">Coords</a></li> + <li><a href="../classes/Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide..html">Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide.</a></li> <li><a href="../classes/Draggable.html">Draggable</a></li> @@ -89,7 +110,12 @@ <div class="apidocs"> <div id="docs-main"> <div class="content"> - <h1>Coords Class</h1> + <h1>Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide. Class</h1> <div class="box meta"> @@ -109,14 +135,24 @@ <div class="box intro"> - <p>Coords</p> + </div> <div class="constructor"> <h2>Constructor</h2> - <div id="method_Coords" class="method item"> - <h3 class="name"><code>Coords</code></h3> + <div id="method_Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide." class="method item"> + <h3 class="name"><code>Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide.</code></h3> <div class="args"> @@ -133,6 +169,10 @@ + <span class="returns-inline"> + <span class="type">Object</span> + </span> + @@ -186,7 +226,8 @@ <div class="param-description"> - <p>HTMLElement or a literal Object with the left, top, width and height properties.</p> + <p>The jQuery HTMLElement or a object with: left, +top, width and height properties.</p> </div> @@ -197,6 +238,19 @@ + <div class="returns"> + <h4>Returns:</h4> + + <div class="returns-description"> + + + <span class="type">Object</span>: + + Coords instance. + + </div> + </div> + </div> diff --git a/docs/classes/Draggable.html b/docs/classes/Draggable.html index 62f883a3ad..98d00f602e 100644 --- a/docs/classes/Draggable.html +++ b/docs/classes/Draggable.html @@ -42,9 +42,25 @@ <div id="api-tabview-panel"> <ul id="api-classes" class="apis classes"> - <li><a href="../classes/Collision.html">Collision</a></li> + <li><a href="../classes/Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects..html">Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects.</a></li> - <li><a href="../classes/Coords.html">Coords</a></li> + <li><a href="../classes/Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide..html">Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide.</a></li> <li><a href="../classes/Draggable.html">Draggable</a></li> @@ -109,7 +125,7 @@ <div class="box intro"> - <p>Draggable</p> + </div> @@ -119,10 +135,30 @@ <h3 class="name"><code>Draggable</code></h3> - <span class="paren">()</span> + <div class="args"> + <span class="paren">(</span><ul class="args-list inline commas"> + + <li class="arg"> + + <code>el</code> + + </li> + + <li class="arg"> + + <code class="optional">[options]</code> + + </li> + + </ul><span class="paren">)</span> + </div> + <span class="returns-inline"> + <span class="type">Object</span> + </span> + @@ -162,7 +198,170 @@ </div> + <div class="params"> + <h4>Parameters:</h4> + <ul class="params-list"> + + <li class="param"> + + <code class="param-name">el</code> + <span class="type">HTMLElement</span> + + + + + <div class="param-description"> + <p>The HTMLelement that contains all the widgets + to be dragged.</p> + </div> + + + </li> + + <li class="param"> + + <code class="param-name optional">[options]</code> + <span class="type">Object</span> + <span class="flag optional" title="This parameter is optional.">optional</span> + + + + + <div class="param-description"> + <p>An Object with all options you want to + overwrite:</p> + </div> + + + <ul class="params-list"> + + <li class="param"> + + <code class="param-name optional">[items]</code> + <span class="type">HTMLElement | String</span> + <span class="flag optional" title="This parameter is optional.">optional</span> + + + <div class="param-description"> + <p>Define who will + be the draggable items. Can be a CSS Selector String or a + collection of HTMLElements.</p> + </div> + + + </li> + + <li class="param"> + + <code class="param-name optional">[distance]</code> + <span class="type">Number</span> + <span class="flag optional" title="This parameter is optional.">optional</span> + + + <div class="param-description"> + <p>Distance in pixels after mousedown + the mouse must move before dragging should start.</p> + </div> + + + </li> + + <li class="param"> + + <code class="param-name optional">[limit]</code> + <span class="type">Boolean</span> + <span class="flag optional" title="This parameter is optional.">optional</span> + + + <div class="param-description"> + <p>Constrains dragging to the width of + the container</p> + </div> + + + </li> + + <li class="param"> + + <code class="param-name optional">[offset_left]</code> + <span class="type">Offset_left</span> + <span class="flag optional" title="This parameter is optional.">optional</span> + + + <div class="param-description"> + <p>Offset added to the item + that is being dragged.</p> + </div> + + + </li> + + <li class="param"> + + <code class="param-name optional">[drag]</code> + <span class="type">Number</span> + <span class="flag optional" title="This parameter is optional.">optional</span> + + + <div class="param-description"> + <p>Executes a callback when the mouse is + moved during the dragging.</p> + </div> + + + </li> + + <li class="param"> + + <code class="param-name optional">[start]</code> + <span class="type">Number</span> + <span class="flag optional" title="This parameter is optional.">optional</span> + + + <div class="param-description"> + <p>Executes a callback when the drag + starts.</p> + </div> + + + </li> + + <li class="param"> + + <code class="param-name optional">[stop]</code> + <span class="type">Number</span> + <span class="flag optional" title="This parameter is optional.">optional</span> + + + <div class="param-description"> + <p>Executes a callback when the drag stops.</p> + </div> + + + </li> + + </ul> + + </li> + + </ul> + </div> + + + + <div class="returns"> + <h4>Returns:</h4> + + <div class="returns-description"> + + + <span class="type">Object</span>: + + Returns <code>el</code>. + + </div> + </div> diff --git a/docs/classes/Gridster.html b/docs/classes/Gridster.html index c052ce9429..b6b876c6e6 100644 --- a/docs/classes/Gridster.html +++ b/docs/classes/Gridster.html @@ -42,9 +42,25 @@ <div id="api-tabview-panel"> <ul id="api-classes" class="apis classes"> - <li><a href="../classes/Collision.html">Collision</a></li> + <li><a href="../classes/Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects..html">Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects.</a></li> - <li><a href="../classes/Coords.html">Coords</a></li> + <li><a href="../classes/Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide..html">Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide.</a></li> <li><a href="../classes/Draggable.html">Draggable</a></li> @@ -96,7 +112,7 @@ Uses <ul class="inline commas"> - <li><a href="Coords.html">Coords</a></li> + <li><a href="Draggable.html">Draggable</a></li> <li><a href="Collision.html">Collision</a></li> @@ -145,6 +161,12 @@ </li> + <li class="arg"> + + <code class="optional">[avoid_overlapped_widgets]</code> + + </li> + </ul><span class="paren">)</span> </div> @@ -393,8 +415,8 @@ <div class="param-description"> <p>An Object with all options for - jQuery UI Draggable you want to overwrite. See - http://jqueryui.com/demos/draggable/ for more info.</p> + Draggable class you want to overwrite. See Draggable docs for more + info.</p> </div> @@ -404,6 +426,24 @@ </li> + <li class="param"> + + <code class="param-name optional">[avoid_overlapped_widgets]</code> + <span class="type">Boolean</span> + <span class="flag optional" title="This parameter is optional.">optional</span> + + + + + <div class="param-description"> + <p>Avoid that widgets loaded + from the DOM can be overlapped. It is helpful if the positions were + bad stored in the database or if there was any conflict.</p> + </div> + + + </li> + </ul> </div> @@ -962,7 +1002,7 @@ - <a href="../files/src_jquery.gridster.js.html#l2004"><code>src/jquery.gridster.js:2004</code></a> + <a href="../files/src_jquery.gridster.js.html#l2030"><code>src/jquery.gridster.js:2030</code></a> </p> @@ -1072,7 +1112,7 @@ - <a href="../files/src_jquery.gridster.js.html#l342"><code>src/jquery.gridster.js:342</code></a> + <a href="../files/src_jquery.gridster.js.html#l349"><code>src/jquery.gridster.js:349</code></a> </p> @@ -1205,7 +1245,7 @@ - <a href="../files/src_jquery.gridster.js.html#l129"><code>src/jquery.gridster.js:129</code></a> + <a href="../files/src_jquery.gridster.js.html#l133"><code>src/jquery.gridster.js:133</code></a> </p> @@ -1340,7 +1380,7 @@ - <a href="../files/src_jquery.gridster.js.html#l1048"><code>src/jquery.gridster.js:1048</code></a> + <a href="../files/src_jquery.gridster.js.html#l1056"><code>src/jquery.gridster.js:1056</code></a> </p> @@ -1458,7 +1498,7 @@ - <a href="../files/src_jquery.gridster.js.html#l1455"><code>src/jquery.gridster.js:1455</code></a> + <a href="../files/src_jquery.gridster.js.html#l1469"><code>src/jquery.gridster.js:1469</code></a> </p> @@ -1595,7 +1635,7 @@ upper row possible.</p> - <a href="../files/src_jquery.gridster.js.html#l1097"><code>src/jquery.gridster.js:1097</code></a> + <a href="../files/src_jquery.gridster.js.html#l1105"><code>src/jquery.gridster.js:1105</code></a> </p> @@ -1713,7 +1753,7 @@ upper row possible.</p> - <a href="../files/src_jquery.gridster.js.html#l1627"><code>src/jquery.gridster.js:1627</code></a> + <a href="../files/src_jquery.gridster.js.html#l1644"><code>src/jquery.gridster.js:1644</code></a> </p> @@ -1725,8 +1765,8 @@ upper row possible.</p> <div class="description"> <p>Check if it's possible to move a widget to a specific col/row. It takes -into account the dimensions (<code>size_y</code> and <code>size_x</code> attrs. of the grid coords - object) the widget occupies.</p> +into account the dimensions (<code>size_y</code> and <code>size_x</code> attrs. of the grid + coords object) the widget occupies.</p> </div> @@ -1840,7 +1880,7 @@ into account the dimensions (<code>size_y</code> and <code>size_x</code> attrs. - <a href="../files/src_jquery.gridster.js.html#l364"><code>src/jquery.gridster.js:364</code></a> + <a href="../files/src_jquery.gridster.js.html#l371"><code>src/jquery.gridster.js:371</code></a> </p> @@ -1851,7 +1891,7 @@ into account the dimensions (<code>size_y</code> and <code>size_x</code> attrs. </div> <div class="description"> - <p>Make widgets draggable. It Wraps the jQuery UI Draggable Plugin.</p> + <p>Make widgets draggable.</p> </div> @@ -1911,7 +1951,7 @@ into account the dimensions (<code>size_y</code> and <code>size_x</code> attrs. - <a href="../files/src_jquery.gridster.js.html#l1590"><code>src/jquery.gridster.js:1590</code></a> + <a href="../files/src_jquery.gridster.js.html#l1606"><code>src/jquery.gridster.js:1606</code></a> </p> @@ -1982,7 +2022,7 @@ into account the dimensions (<code>size_y</code> and <code>size_x</code> attrs. - <a href="../files/src_jquery.gridster.js.html#l105"><code>src/jquery.gridster.js:105</code></a> + <a href="../files/src_jquery.gridster.js.html#l108"><code>src/jquery.gridster.js:108</code></a> </p> @@ -2053,7 +2093,7 @@ into account the dimensions (<code>size_y</code> and <code>size_x</code> attrs. - <a href="../files/src_jquery.gridster.js.html#l117"><code>src/jquery.gridster.js:117</code></a> + <a href="../files/src_jquery.gridster.js.html#l121"><code>src/jquery.gridster.js:121</code></a> </p> @@ -2140,7 +2180,7 @@ into account the dimensions (<code>size_y</code> and <code>size_x</code> attrs. - <a href="../files/src_jquery.gridster.js.html#l1730"><code>src/jquery.gridster.js:1730</code></a> + <a href="../files/src_jquery.gridster.js.html#l1748"><code>src/jquery.gridster.js:1748</code></a> </p> @@ -2268,7 +2308,7 @@ each one.</p> - <a href="../files/src_jquery.gridster.js.html#l1751"><code>src/jquery.gridster.js:1751</code></a> + <a href="../files/src_jquery.gridster.js.html#l1769"><code>src/jquery.gridster.js:1769</code></a> </p> @@ -2396,7 +2436,7 @@ each one.</p> - <a href="../files/src_jquery.gridster.js.html#l1770"><code>src/jquery.gridster.js:1770</code></a> + <a href="../files/src_jquery.gridster.js.html#l1788"><code>src/jquery.gridster.js:1788</code></a> </p> @@ -2442,7 +2482,8 @@ each one.</p> <div class="param-description"> - <p>The function to execute on each column iteration. The row number is passed as first argument.</p> + <p>The function to execute on each column + iteration. The row number is passed as first argument.</p> </div> @@ -2529,7 +2570,7 @@ each one.</p> - <a href="../files/src_jquery.gridster.js.html#l1836"><code>src/jquery.gridster.js:1836</code></a> + <a href="../files/src_jquery.gridster.js.html#l1855"><code>src/jquery.gridster.js:1855</code></a> </p> @@ -2589,7 +2630,8 @@ each one.</p> <div class="param-description"> <p>The function to execute on each widget -iteration. The value of <code>this</code> inside the function is the jQuery wrapped HTMLElement.</p> + iteration. The value of <code>this</code> inside the function is the jQuery + wrapped HTMLElement.</p> </div> @@ -2676,7 +2718,7 @@ iteration. The value of <code>this</code> inside the function is the jQuery wrap - <a href="../files/src_jquery.gridster.js.html#l1852"><code>src/jquery.gridster.js:1852</code></a> + <a href="../files/src_jquery.gridster.js.html#l1872"><code>src/jquery.gridster.js:1872</code></a> </p> @@ -2736,7 +2778,8 @@ iteration. The value of <code>this</code> inside the function is the jQuery wrap <div class="param-description"> <p>The function to execute on each widget -iteration. The value of <code>this</code> inside the function is the jQuery wrapped HTMLElement.</p> + iteration. The value of <code>this</code> inside the function is the jQuery wrapped + HTMLElement.</p> </div> @@ -2817,7 +2860,7 @@ iteration. The value of <code>this</code> inside the function is the jQuery wrap - <a href="../files/src_jquery.gridster.js.html#l2027"><code>src/jquery.gridster.js:2027</code></a> + <a href="../files/src_jquery.gridster.js.html#l2053"><code>src/jquery.gridster.js:2053</code></a> </p> @@ -2927,7 +2970,7 @@ detect row or column that we want to go.</p> - <a href="../files/src_jquery.gridster.js.html#l2101"><code>src/jquery.gridster.js:2101</code></a> + <a href="../files/src_jquery.gridster.js.html#l2127"><code>src/jquery.gridster.js:2127</code></a> </p> @@ -3015,7 +3058,7 @@ detect row or column that we want to go.</p> - <a href="../files/src_jquery.gridster.js.html#l1941"><code>src/jquery.gridster.js:1941</code></a> + <a href="../files/src_jquery.gridster.js.html#l1960"><code>src/jquery.gridster.js:1960</code></a> </p> @@ -3134,7 +3177,7 @@ detect row or column that we want to go.</p> - <a href="../files/src_jquery.gridster.js.html#l1702"><code>src/jquery.gridster.js:1702</code></a> + <a href="../files/src_jquery.gridster.js.html#l1720"><code>src/jquery.gridster.js:1720</code></a> </p> @@ -3228,7 +3271,7 @@ detect row or column that we want to go.</p> - <a href="../files/src_jquery.gridster.js.html#l1868"><code>src/jquery.gridster.js:1868</code></a> + <a href="../files/src_jquery.gridster.js.html#l1889"><code>src/jquery.gridster.js:1889</code></a> </p> @@ -3309,7 +3352,7 @@ detect row or column that we want to go.</p> - <a href="../files/src_jquery.gridster.js.html#l1667"><code>src/jquery.gridster.js:1667</code></a> + <a href="../files/src_jquery.gridster.js.html#l1684"><code>src/jquery.gridster.js:1684</code></a> </p> @@ -3320,7 +3363,8 @@ detect row or column that we want to go.</p> </div> <div class="description"> - <p>Given the leftmost column returns all columns that are overlapping with the player.</p> + <p>Given the leftmost column returns all columns that are overlapping + with the player.</p> </div> @@ -3414,7 +3458,7 @@ detect row or column that we want to go.</p> - <a href="../files/src_jquery.gridster.js.html#l1685"><code>src/jquery.gridster.js:1685</code></a> + <a href="../files/src_jquery.gridster.js.html#l1703"><code>src/jquery.gridster.js:1703</code></a> </p> @@ -3531,7 +3575,7 @@ detect row or column that we want to go.</p> - <a href="../files/src_jquery.gridster.js.html#l1148"><code>src/jquery.gridster.js:1148</code></a> + <a href="../files/src_jquery.gridster.js.html#l1158"><code>src/jquery.gridster.js:1158</code></a> </p> @@ -3659,7 +3703,7 @@ the</code>upper<em>rows<code>array. Iteration starts from row specified in</code - <a href="../files/src_jquery.gridster.js.html#l2087"><code>src/jquery.gridster.js:2087</code></a> + <a href="../files/src_jquery.gridster.js.html#l2113"><code>src/jquery.gridster.js:2113</code></a> </p> @@ -3730,7 +3774,7 @@ the</code>upper<em>rows<code>array. Iteration starts from row specified in</code - <a href="../files/src_jquery.gridster.js.html#l1226"><code>src/jquery.gridster.js:1226</code></a> + <a href="../files/src_jquery.gridster.js.html#l1236"><code>src/jquery.gridster.js:1236</code></a> </p> @@ -3801,7 +3845,7 @@ the</code>upper<em>rows<code>array. Iteration starts from row specified in</code - <a href="../files/src_jquery.gridster.js.html#l975"><code>src/jquery.gridster.js:975</code></a> + <a href="../files/src_jquery.gridster.js.html#l985"><code>src/jquery.gridster.js:985</code></a> </p> @@ -3888,7 +3932,7 @@ the</code>upper<em>rows<code>array. Iteration starts from row specified in</code - <a href="../files/src_jquery.gridster.js.html#l894"><code>src/jquery.gridster.js:894</code></a> + <a href="../files/src_jquery.gridster.js.html#l904"><code>src/jquery.gridster.js:904</code></a> </p> @@ -4013,7 +4057,7 @@ the</code>upper<em>rows<code>array. Iteration starts from row specified in</code - <a href="../files/src_jquery.gridster.js.html#l913"><code>src/jquery.gridster.js:913</code></a> + <a href="../files/src_jquery.gridster.js.html#l923"><code>src/jquery.gridster.js:923</code></a> </p> @@ -4138,7 +4182,7 @@ the</code>upper<em>rows<code>array. Iteration starts from row specified in</code - <a href="../files/src_jquery.gridster.js.html#l867"><code>src/jquery.gridster.js:867</code></a> + <a href="../files/src_jquery.gridster.js.html#l877"><code>src/jquery.gridster.js:877</code></a> </p> @@ -4257,7 +4301,7 @@ the</code>upper<em>rows<code>array. Iteration starts from row specified in</code - <a href="../files/src_jquery.gridster.js.html#l881"><code>src/jquery.gridster.js:881</code></a> + <a href="../files/src_jquery.gridster.js.html#l891"><code>src/jquery.gridster.js:891</code></a> </p> @@ -4367,7 +4411,7 @@ the</code>upper<em>rows<code>array. Iteration starts from row specified in</code - <a href="../files/src_jquery.gridster.js.html#l835"><code>src/jquery.gridster.js:835</code></a> + <a href="../files/src_jquery.gridster.js.html#l845"><code>src/jquery.gridster.js:845</code></a> </p> @@ -4495,7 +4539,7 @@ HTMLElements.</p> - <a href="../files/src_jquery.gridster.js.html#l852"><code>src/jquery.gridster.js:852</code></a> + <a href="../files/src_jquery.gridster.js.html#l862"><code>src/jquery.gridster.js:862</code></a> </p> @@ -4621,7 +4665,7 @@ and col given.</p> - <a href="../files/src_jquery.gridster.js.html#l933"><code>src/jquery.gridster.js:933</code></a> + <a href="../files/src_jquery.gridster.js.html#l943"><code>src/jquery.gridster.js:943</code></a> </p> @@ -4747,7 +4791,7 @@ else returns the jQuery HTMLElement - <a href="../files/src_jquery.gridster.js.html#l958"><code>src/jquery.gridster.js:958</code></a> + <a href="../files/src_jquery.gridster.js.html#l968"><code>src/jquery.gridster.js:968</code></a> </p> @@ -4879,7 +4923,7 @@ params and if this is under the widget that is being dragged.</p> - <a href="../files/src_jquery.gridster.js.html#l789"><code>src/jquery.gridster.js:789</code></a> + <a href="../files/src_jquery.gridster.js.html#l799"><code>src/jquery.gridster.js:799</code></a> </p> @@ -5021,7 +5065,7 @@ each widget) in descending way.</p> - <a href="../files/src_jquery.gridster.js.html#l1410"><code>src/jquery.gridster.js:1410</code></a> + <a href="../files/src_jquery.gridster.js.html#l1423"><code>src/jquery.gridster.js:1423</code></a> </p> @@ -5050,7 +5094,8 @@ each widget) in descending way.</p> <div class="param-description"> - <p>The jQuery object representing the widget you want to move.</p> + <p>The jQuery object representing the widget + you want to move.</p> </div> @@ -5140,7 +5185,7 @@ each widget) in descending way.</p> - <a href="../files/src_jquery.gridster.js.html#l1321"><code>src/jquery.gridster.js:1321</code></a> + <a href="../files/src_jquery.gridster.js.html#l1331"><code>src/jquery.gridster.js:1331</code></a> </p> @@ -5171,7 +5216,8 @@ if they can.</p> <div class="param-description"> - <p>The jQuery wrapped HTMLElement of the widget is going to be moved.</p> + <p>The jQuery wrapped HTMLElement of the +widget is going to be moved.</p> </div> @@ -5252,7 +5298,7 @@ if they can.</p> - <a href="../files/src_jquery.gridster.js.html#l1364"><code>src/jquery.gridster.js:1364</code></a> + <a href="../files/src_jquery.gridster.js.html#l1375"><code>src/jquery.gridster.js:1375</code></a> </p> @@ -5378,7 +5424,7 @@ if they can.</p> - <a href="../files/src_jquery.gridster.js.html#l159"><code>src/jquery.gridster.js:159</code></a> + <a href="../files/src_jquery.gridster.js.html#l163"><code>src/jquery.gridster.js:163</code></a> </p> @@ -5500,7 +5546,7 @@ if they can.</p> - <a href="../files/src_jquery.gridster.js.html#l452"><code>src/jquery.gridster.js:452</code></a> + <a href="../files/src_jquery.gridster.js.html#l461"><code>src/jquery.gridster.js:461</code></a> </p> @@ -5544,8 +5590,7 @@ if they can.</p> <div class="param-description"> - <p>prepared ui object. - See http://jqueryui.com/demos/draggable/ for more info.</p> + <p>prepared ui object.</p> </div> @@ -5613,7 +5658,7 @@ if they can.</p> - <a href="../files/src_jquery.gridster.js.html#l545"><code>src/jquery.gridster.js:545</code></a> + <a href="../files/src_jquery.gridster.js.html#l555"><code>src/jquery.gridster.js:555</code></a> </p> @@ -5741,7 +5786,7 @@ overlapped or stops being overlapped.</p> - <a href="../files/src_jquery.gridster.js.html#l585"><code>src/jquery.gridster.js:585</code></a> + <a href="../files/src_jquery.gridster.js.html#l595"><code>src/jquery.gridster.js:595</code></a> </p> @@ -5865,7 +5910,7 @@ overlapped or stops being overlapped.</p> - <a href="../files/src_jquery.gridster.js.html#l400"><code>src/jquery.gridster.js:400</code></a> + <a href="../files/src_jquery.gridster.js.html#l410"><code>src/jquery.gridster.js:410</code></a> </p> @@ -5909,8 +5954,7 @@ overlapped or stops being overlapped.</p> <div class="param-description"> - <p>prepared ui object. - See http://jqueryui.com/demos/draggable/ for more info.</p> + <p>prepared ui object.</p> </div> @@ -5972,7 +6016,7 @@ overlapped or stops being overlapped.</p> - <a href="../files/src_jquery.gridster.js.html#l1259"><code>src/jquery.gridster.js:1259</code></a> + <a href="../files/src_jquery.gridster.js.html#l1269"><code>src/jquery.gridster.js:1269</code></a> </p> @@ -6076,7 +6120,7 @@ overlapped or stops being overlapped.</p> - <a href="../files/src_jquery.gridster.js.html#l1271"><code>src/jquery.gridster.js:1271</code></a> + <a href="../files/src_jquery.gridster.js.html#l1281"><code>src/jquery.gridster.js:1281</code></a> </p> @@ -6182,7 +6226,7 @@ overlapped or stops being overlapped.</p> - <a href="../files/src_jquery.gridster.js.html#l489"><code>src/jquery.gridster.js:489</code></a> + <a href="../files/src_jquery.gridster.js.html#l499"><code>src/jquery.gridster.js:499</code></a> </p> @@ -6226,8 +6270,7 @@ overlapped or stops being overlapped.</p> <div class="param-description"> - <p>prepared ui object. - See http://jqueryui.com/demos/draggable/ for more info.</p> + <p>prepared ui object.</p> </div> @@ -6289,7 +6332,7 @@ overlapped or stops being overlapped.</p> - <a href="../files/src_jquery.gridster.js.html#l1283"><code>src/jquery.gridster.js:1283</code></a> + <a href="../files/src_jquery.gridster.js.html#l1293"><code>src/jquery.gridster.js:1293</code></a> </p> @@ -6393,7 +6436,7 @@ overlapped or stops being overlapped.</p> - <a href="../files/src_jquery.gridster.js.html#l1301"><code>src/jquery.gridster.js:1301</code></a> + <a href="../files/src_jquery.gridster.js.html#l1311"><code>src/jquery.gridster.js:1311</code></a> </p> @@ -6487,7 +6530,7 @@ overlapped or stops being overlapped.</p> - <a href="../files/src_jquery.gridster.js.html#l2063"><code>src/jquery.gridster.js:2063</code></a> + <a href="../files/src_jquery.gridster.js.html#l2089"><code>src/jquery.gridster.js:2089</code></a> </p> @@ -6559,7 +6602,7 @@ the browser is resized.</p> - <a href="../files/src_jquery.gridster.js.html#l265"><code>src/jquery.gridster.js:265</code></a> + <a href="../files/src_jquery.gridster.js.html#l272"><code>src/jquery.gridster.js:272</code></a> </p> @@ -6641,7 +6684,7 @@ mapped array of positions.</p> - <a href="../files/src_jquery.gridster.js.html#l329"><code>src/jquery.gridster.js:329</code></a> + <a href="../files/src_jquery.gridster.js.html#l336"><code>src/jquery.gridster.js:336</code></a> </p> @@ -6746,7 +6789,7 @@ mapped array of positions.</p> - <a href="../files/src_jquery.gridster.js.html#l201"><code>src/jquery.gridster.js:201</code></a> + <a href="../files/src_jquery.gridster.js.html#l205"><code>src/jquery.gridster.js:205</code></a> </p> @@ -6850,7 +6893,7 @@ mapped array of positions.</p> - <a href="../files/src_jquery.gridster.js.html#l231"><code>src/jquery.gridster.js:231</code></a> + <a href="../files/src_jquery.gridster.js.html#l237"><code>src/jquery.gridster.js:237</code></a> </p> @@ -6948,7 +6991,7 @@ mapped array of positions.</p> - <a href="../files/src_jquery.gridster.js.html#l253"><code>src/jquery.gridster.js:253</code></a> + <a href="../files/src_jquery.gridster.js.html#l259"><code>src/jquery.gridster.js:259</code></a> </p> @@ -6959,7 +7002,8 @@ mapped array of positions.</p> </div> <div class="description"> - <p>Returns a serialized array of the widgets that have changed their position.</p> + <p>Returns a serialized array of the widgets that have changed their + position.</p> </div> @@ -7036,7 +7080,7 @@ mapped array of positions.</p> - <a href="../files/src_jquery.gridster.js.html#l1573"><code>src/jquery.gridster.js:1573</code></a> + <a href="../files/src_jquery.gridster.js.html#l1589"><code>src/jquery.gridster.js:1589</code></a> </p> @@ -7145,7 +7189,7 @@ mapped array of positions.</p> - <a href="../files/src_jquery.gridster.js.html#l1927"><code>src/jquery.gridster.js:1927</code></a> + <a href="../files/src_jquery.gridster.js.html#l1947"><code>src/jquery.gridster.js:1947</code></a> </p> @@ -7232,7 +7276,7 @@ mapped array of positions.</p> - <a href="../files/src_jquery.gridster.js.html#l997"><code>src/jquery.gridster.js:997</code></a> + <a href="../files/src_jquery.gridster.js.html#l1007"><code>src/jquery.gridster.js:1007</code></a> </p> @@ -7359,7 +7403,7 @@ mapped array of positions.</p> - <a href="../files/src_jquery.gridster.js.html#l621"><code>src/jquery.gridster.js:621</code></a> + <a href="../files/src_jquery.gridster.js.html#l631"><code>src/jquery.gridster.js:631</code></a> </p> @@ -7480,7 +7524,7 @@ mapped array of positions.</p> - <a href="../files/src_jquery.gridster.js.html#l710"><code>src/jquery.gridster.js:710</code></a> + <a href="../files/src_jquery.gridster.js.html#l720"><code>src/jquery.gridster.js:720</code></a> </p> @@ -7585,7 +7629,7 @@ each widget) in ascending way.</p> - <a href="../files/src_jquery.gridster.js.html#l750"><code>src/jquery.gridster.js:750</code></a> + <a href="../files/src_jquery.gridster.js.html#l760"><code>src/jquery.gridster.js:760</code></a> </p> @@ -7690,7 +7734,7 @@ coords of each widget) in ascending way.</p> - <a href="../files/src_jquery.gridster.js.html#l730"><code>src/jquery.gridster.js:730</code></a> + <a href="../files/src_jquery.gridster.js.html#l740"><code>src/jquery.gridster.js:740</code></a> </p> @@ -7795,7 +7839,7 @@ each widget) placing first the empty cells upper left.</p> - <a href="../files/src_jquery.gridster.js.html#l770"><code>src/jquery.gridster.js:770</code></a> + <a href="../files/src_jquery.gridster.js.html#l780"><code>src/jquery.gridster.js:780</code></a> </p> @@ -7906,7 +7950,7 @@ each widget) in descending way.</p> - <a href="../files/src_jquery.gridster.js.html#l308"><code>src/jquery.gridster.js:308</code></a> + <a href="../files/src_jquery.gridster.js.html#l315"><code>src/jquery.gridster.js:315</code></a> </p> @@ -8029,7 +8073,7 @@ the grid coords object passed in the <code>grid_data</code> param.</p> - <a href="../files/src_jquery.gridster.js.html#l1544"><code>src/jquery.gridster.js:1544</code></a> + <a href="../files/src_jquery.gridster.js.html#l1560"><code>src/jquery.gridster.js:1560</code></a> </p> @@ -8133,7 +8177,7 @@ the grid coords object passed in the <code>grid_data</code> param.</p> - <a href="../files/src_jquery.gridster.js.html#l674"><code>src/jquery.gridster.js:674</code></a> + <a href="../files/src_jquery.gridster.js.html#l684"><code>src/jquery.gridster.js:684</code></a> </p> diff --git a/docs/data.json b/docs/data.json index 63b56646c8..b050d5dd75 100644 --- a/docs/data.json +++ b/docs/data.json @@ -5,7 +5,7 @@ "name": "src/jquery.collision.js", "modules": {}, "classes": { - "Collision": 1 + "Collision\n\nDetects collisions between a DOM element against other DOM elements or\nCoords objects.": 1 }, "fors": {}, "namespaces": {} @@ -14,7 +14,7 @@ "name": "src/jquery.coords.js", "modules": {}, "classes": { - "Coords": 1 + "Coords\n\nCreates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height)\nto simulate DOM elements on the screen.\nCoords is used by Gridster to create a faux grid with any DOM element can\ncollide.": 1 }, "fors": {}, "namespaces": {} @@ -40,54 +40,51 @@ }, "modules": {}, "classes": { - "Collision": { - "name": "Collision", - "shortname": "Collision", + "Collision\n\nDetects collisions between a DOM element against other DOM elements or\nCoords objects.": { + "name": "Collision\n\nDetects collisions between a DOM element against other DOM elements or\nCoords objects.", + "shortname": "Collision\n\nDetects collisions between a DOM element against other DOM elements or\nCoords objects.", "classitems": [], "plugins": [], "extensions": [], "plugin_for": [], - "extension_for": [ - "Gridster" - ], + "extension_for": [], "file": "src/jquery.collision.js", - "line": 22, - "description": "Collision", + "line": 19, "uses": [ "Coords" ], "params": [ { - "name": "element", - "description": "An Attribute name or object property path", + "name": "el", + "description": "The jQuery wrapped HTMLElement.", "type": "HTMLElement" }, { "name": "colliders", - "description": "An Attribute name or object property path", - "type": "String|HTMLElement|Array" + "description": "Can be a jQuery collection\n of HTMLElements or an Array of Coords instances.", + "type": "HTMLElement|Array" }, { "name": "options", - "description": "An Attribute name or object property path", + "description": "An Object with all options you want to\n overwrite:", "type": "Object", "optional": true, "props": [ - { - "name": "on_overlap", - "description": "An Attribute name or object property path", - "type": "Function", - "optional": true - }, { "name": "on_overlap_start", - "description": "An Attribute name or object property path", + "description": "Executes a function the first\n time each `collider ` is overlapped.", "type": "Function", "optional": true }, { "name": "on_overlap_stop", - "description": "An Attribute name or object property path", + "description": "Executes a function when a\n `collider` is no longer collided.", + "type": "Function", + "optional": true + }, + { + "name": "on_overlap", + "description": "Executes a function when the\nmouse is moved during the collision.", "type": "Function", "optional": true } @@ -95,32 +92,32 @@ } ], "return": { - "description": "dasdasdadasd", + "description": "Collision instance.", "type": "Object" }, "is_constructor": 1 }, - "Coords": { - "name": "Coords", - "shortname": "Coords", + "Coords\n\nCreates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height)\nto simulate DOM elements on the screen.\nCoords is used by Gridster to create a faux grid with any DOM element can\ncollide.": { + "name": "Coords\n\nCreates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height)\nto simulate DOM elements on the screen.\nCoords is used by Gridster to create a faux grid with any DOM element can\ncollide.", + "shortname": "Coords\n\nCreates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height)\nto simulate DOM elements on the screen.\nCoords is used by Gridster to create a faux grid with any DOM element can\ncollide.", "classitems": [], "plugins": [], "extensions": [], "plugin_for": [], - "extension_for": [ - "Collision", - "Gridster" - ], + "extension_for": [], "file": "src/jquery.coords.js", "line": 10, - "description": "Coords", "params": [ { "name": "obj", - "description": "HTMLElement or a literal Object with the left, top, width and height properties.", + "description": "The jQuery HTMLElement or a object with: left,\ntop, width and height properties.", "type": "HTMLElement|Object" } ], + "return": { + "description": "Coords instance.", + "type": "Object" + }, "is_constructor": 1 }, "Draggable": { @@ -130,10 +127,72 @@ "plugins": [], "extensions": [], "plugin_for": [], - "extension_for": [], + "extension_for": [ + "Gridster" + ], "file": "src/jquery.draggable.js", "line": 24, - "description": "Draggable", + "params": [ + { + "name": "el", + "description": "The HTMLelement that contains all the widgets\n to be dragged.", + "type": "HTMLElement" + }, + { + "name": "options", + "description": "An Object with all options you want to\n overwrite:", + "type": "Object", + "optional": true, + "props": [ + { + "name": "items", + "description": "Define who will\n be the draggable items. Can be a CSS Selector String or a\n collection of HTMLElements.", + "type": "HTMLElement|String", + "optional": true + }, + { + "name": "distance", + "description": "Distance in pixels after mousedown\n the mouse must move before dragging should start.", + "type": "Number", + "optional": true + }, + { + "name": "limit", + "description": "Constrains dragging to the width of\n the container", + "type": "Boolean", + "optional": true + }, + { + "name": "offset_left", + "description": "Offset added to the item\n that is being dragged.", + "type": "Offset_left", + "optional": true + }, + { + "name": "drag", + "description": "Executes a callback when the mouse is\n moved during the dragging.", + "type": "Number", + "optional": true + }, + { + "name": "start", + "description": "Executes a callback when the drag\n starts.", + "type": "Number", + "optional": true + }, + { + "name": "stop", + "description": "Executes a callback when the drag stops.", + "type": "Number", + "optional": true + } + ] + } + ], + "return": { + "description": "Returns `el`.", + "type": "Object" + }, "is_constructor": 1 }, "Gridster": { @@ -147,7 +206,7 @@ "file": "src/jquery.gridster.js", "line": 33, "uses": [ - "Coords", + "Draggable", "Collision" ], "params": [ @@ -224,11 +283,17 @@ }, { "name": "draggable", - "description": "An Object with all options for\n jQuery UI Draggable you want to overwrite. See\n http://jqueryui.com/demos/draggable/ for more info.", + "description": "An Object with all options for\n Draggable class you want to overwrite. See Draggable docs for more\n info.", "type": "Object", "optional": true } ] + }, + { + "name": "avoid_overlapped_widgets", + "description": "Avoid that widgets loaded\n from the DOM can be overlapped. It is helpful if the positions were\n bad stored in the database or if there was any conflict.", + "type": "Boolean", + "optional": true } ], "is_constructor": 1 @@ -237,7 +302,7 @@ "classitems": [ { "file": "src/jquery.gridster.js", - "line": 105, + "line": 108, "description": "Disable dragging.", "itemtype": "method", "name": "enable", @@ -249,7 +314,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 117, + "line": 121, "description": "Enable dragging.", "itemtype": "method", "name": "enable", @@ -261,7 +326,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 129, + "line": 133, "description": "Add a new widget to the grid.", "itemtype": "method", "name": "add_widget", @@ -290,7 +355,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 159, + "line": 163, "description": "Get the most left column below to add a new widget.", "itemtype": "method", "name": "next_position", @@ -314,7 +379,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 201, + "line": 205, "description": "Remove a widget from the grid.", "itemtype": "method", "name": "remove_widget", @@ -333,7 +398,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 231, + "line": 237, "description": "Returns a serialized array of the widgets in the grid.", "itemtype": "method", "name": "serialize", @@ -353,8 +418,8 @@ }, { "file": "src/jquery.gridster.js", - "line": 253, - "description": "Returns a serialized array of the widgets that have changed their position.", + "line": 259, + "description": "Returns a serialized array of the widgets that have changed their\n position.", "itemtype": "method", "name": "serialize_changed", "return": { @@ -365,7 +430,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 265, + "line": 272, "description": "Creates the grid coords object representing the widget a add it to the\nmapped array of positions.", "itemtype": "method", "name": "register_widget", @@ -377,7 +442,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 308, + "line": 315, "description": "Update in the mapped array of positions the value of cells represented by\nthe grid coords object passed in the `grid_data` param.", "params": [ { @@ -401,7 +466,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 329, + "line": 336, "description": "Remove a widget from the mapped array of positions.", "itemtype": "method", "name": "remove_from_gridmap", @@ -420,7 +485,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 342, + "line": 349, "description": "Add a widget to the mapped array of positions.", "itemtype": "method", "name": "add_to_gridmap", @@ -444,8 +509,11 @@ }, { "file": "src/jquery.gridster.js", - "line": 364, - "description": "Make widgets draggable. It Wraps the jQuery UI Draggable Plugin.", + "line": 371, + "description": "Make widgets draggable.", + "uses": [ + "Draggable" + ], "itemtype": "method", "name": "draggable", "return": { @@ -456,7 +524,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 400, + "line": 410, "description": "This function is executed when the player begins to be dragged.", "itemtype": "method", "name": "on_start_drag", @@ -468,7 +536,7 @@ }, { "name": "A", - "description": "prepared ui object.\n See http://jqueryui.com/demos/draggable/ for more info.", + "description": "prepared ui object.", "type": "Object" } ], @@ -476,7 +544,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 452, + "line": 461, "description": "This function is executed when the player is being dragged.", "itemtype": "method", "name": "on_drag", @@ -488,7 +556,7 @@ }, { "name": "A", - "description": "prepared ui object.\n See http://jqueryui.com/demos/draggable/ for more info.", + "description": "prepared ui object.", "type": "Object" } ], @@ -496,7 +564,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 489, + "line": 499, "description": "This function is executed when the player stops being dragged.", "itemtype": "method", "name": "on_stop_drag", @@ -508,7 +576,7 @@ }, { "name": "A", - "description": "prepared ui object.\n See http://jqueryui.com/demos/draggable/ for more info.", + "description": "prepared ui object.", "type": "Object" } ], @@ -516,7 +584,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 545, + "line": 555, "description": "Executes the callbacks passed as arguments when a column begins to be\noverlapped or stops being overlapped.", "params": [ { @@ -540,7 +608,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 585, + "line": 595, "description": "Executes the callbacks passed as arguments when a row starts to be\noverlapped or stops being overlapped.", "params": [ { @@ -564,7 +632,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 621, + "line": 631, "description": "Sets the current position of the player", "params": [ { @@ -588,7 +656,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 674, + "line": 684, "description": "See which of the widgets in the $widgets param collection can go to\na upper row and which not.", "itemtype": "method", "name": "widgets_contraints", @@ -607,7 +675,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 710, + "line": 720, "description": "Sorts an Array of grid coords objects (representing the grid coords of\neach widget) in ascending way.", "itemtype": "method", "name": "sort_by_row_asc", @@ -626,7 +694,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 730, + "line": 740, "description": "Sorts an Array of grid coords objects (representing the grid coords of\neach widget) placing first the empty cells upper left.", "itemtype": "method", "name": "sort_by_row_asc", @@ -645,7 +713,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 750, + "line": 760, "description": "Sorts an Array of grid coords objects by column (representing the grid\ncoords of each widget) in ascending way.", "itemtype": "method", "name": "sort_by_row_asc", @@ -664,7 +732,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 770, + "line": 780, "description": "Sorts an Array of grid coords objects (representing the grid coords of\neach widget) in descending way.", "itemtype": "method", "name": "sort_by_row_desc", @@ -683,7 +751,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 789, + "line": 799, "description": "Sorts an Array of grid coords objects (representing the grid coords of\neach widget) in descending way.", "itemtype": "method", "name": "manage_movements", @@ -712,7 +780,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 835, + "line": 845, "description": "Determines if there is a widget in the row and col given. Or if the\nHTMLElement passed as first argument is the player.", "itemtype": "method", "name": "is_player", @@ -737,7 +805,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 852, + "line": 862, "description": "Determines if the widget that is being dragged is currently over the row\nand col given.", "itemtype": "method", "name": "is_player_in", @@ -761,7 +829,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 867, + "line": 877, "description": "Determines if the placeholder is currently over the row and col given.", "itemtype": "method", "name": "is_placeholder_in", @@ -785,7 +853,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 881, + "line": 891, "description": "Determines if the placeholder is currently over the column given.", "itemtype": "method", "name": "is_placeholder_in_col", @@ -804,7 +872,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 894, + "line": 904, "description": "Determines if the cell represented by col and row params is empty.", "itemtype": "method", "name": "is_empty", @@ -828,7 +896,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 913, + "line": 923, "description": "Determines if the cell represented by col and row params is occupied.", "itemtype": "method", "name": "is_occupied", @@ -852,7 +920,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 933, + "line": 943, "description": "Determines if there is a widget in the cell represented by col/row params.", "itemtype": "method", "name": "is_widget", @@ -876,7 +944,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 958, + "line": 968, "description": "Determines if there is a widget in the cell represented by col/row\nparams and if this is under the widget that is being dragged.", "itemtype": "method", "name": "is_widget_under_player", @@ -900,7 +968,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 975, + "line": 985, "description": "Get widgets overlapping with the player.", "itemtype": "method", "name": "get_widgets_under_player", @@ -912,7 +980,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 997, + "line": 1007, "description": "Put placeholder at the row and column specified.", "itemtype": "method", "name": "set_placeholder", @@ -936,7 +1004,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1048, + "line": 1056, "description": "Determines whether the player can move to a position above.", "itemtype": "method", "name": "can_go_player_up", @@ -955,7 +1023,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1097, + "line": 1105, "description": "Determines whether a widget can move to a position above.", "itemtype": "method", "name": "can_go_widget_up", @@ -974,7 +1042,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1148, + "line": 1158, "description": "Search a valid row for the widget represented by `widget_grid_data' in\nthe `upper_rows` array. Iteration starts from row specified in `min_row`.", "itemtype": "method", "name": "get_valid_rows", @@ -1003,7 +1071,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1226, + "line": 1236, "description": "Get widgets overlapping with the player.", "itemtype": "method", "name": "get_widgets_overlapped", @@ -1015,7 +1083,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1259, + "line": 1269, "description": "This callback is executed when the player begins to collide with a column.", "itemtype": "method", "name": "on_start_overlapping_column", @@ -1034,7 +1102,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1271, + "line": 1281, "description": "A callback executed when the player begins to collide with a row.", "itemtype": "method", "name": "on_start_overlapping_row", @@ -1053,7 +1121,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1283, + "line": 1293, "description": "A callback executed when the the player ends to collide with a column.", "itemtype": "method", "name": "on_stop_overlapping_column", @@ -1072,7 +1140,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1301, + "line": 1311, "description": "This callback is executed when the player ends to collide with a row.", "itemtype": "method", "name": "on_stop_overlapping_row", @@ -1091,14 +1159,14 @@ }, { "file": "src/jquery.gridster.js", - "line": 1321, + "line": 1331, "description": "Move a widget to a specific row. The cell or cells must be empty.\nIf the widget has widgets below, all of these widgets will be moved also\nif they can.", "itemtype": "method", "name": "move_widget_to", "params": [ { "name": "$widget", - "description": "The jQuery wrapped HTMLElement of the widget is going to be moved.", + "description": "The jQuery wrapped HTMLElement of the\nwidget is going to be moved.", "type": "HTMLElement" } ], @@ -1110,7 +1178,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1364, + "line": 1375, "description": "Move up the specified widget and all below it.", "itemtype": "method", "name": "move_widget_up", @@ -1135,14 +1203,14 @@ }, { "file": "src/jquery.gridster.js", - "line": 1410, + "line": 1423, "description": "Move down the specified widget and all below it.", "itemtype": "method", "name": "move_widget_down", "params": [ { "name": "$widget", - "description": "The jQuery object representing the widget you want to move.", + "description": "The jQuery object representing the widget\n you want to move.", "type": "HTMLElement" }, { @@ -1159,7 +1227,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1455, + "line": 1469, "description": "Check if the widget can move to the specified row, else returns the\nupper row possible.", "itemtype": "method", "name": "can_go_up_to_row", @@ -1188,7 +1256,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1544, + "line": 1560, "description": "Get widgets below a widget.", "itemtype": "method", "name": "widgets_below", @@ -1207,7 +1275,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1573, + "line": 1589, "description": "Update the array of mapped positions with the new player position.", "itemtype": "method", "name": "set_cells_player_occupies", @@ -1231,7 +1299,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1590, + "line": 1606, "description": "Remove from the array of mapped positions the reference to the player.", "itemtype": "method", "name": "empty_cells_player_occupies", @@ -1243,8 +1311,8 @@ }, { "file": "src/jquery.gridster.js", - "line": 1627, - "description": "Check if it's possible to move a widget to a specific col/row. It takes\ninto account the dimensions (`size_y` and `size_x` attrs. of the grid coords\n object) the widget occupies.", + "line": 1644, + "description": "Check if it's possible to move a widget to a specific col/row. It takes\ninto account the dimensions (`size_y` and `size_x` attrs. of the grid\n coords object) the widget occupies.", "itemtype": "method", "name": "can_move_to", "params": [ @@ -1272,8 +1340,8 @@ }, { "file": "src/jquery.gridster.js", - "line": 1667, - "description": "Given the leftmost column returns all columns that are overlapping with the player.", + "line": 1684, + "description": "Given the leftmost column returns all columns that are overlapping\n with the player.", "itemtype": "method", "name": "get_targeted_columns", "params": [ @@ -1292,7 +1360,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1685, + "line": 1703, "description": "Given the upper row returns all rows that are overlapping with the player.", "itemtype": "method", "name": "get_targeted_rows", @@ -1312,7 +1380,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1702, + "line": 1720, "description": "Get all columns and rows that a widget occupies.", "itemtype": "method", "name": "get_cells_occupied", @@ -1331,7 +1399,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1730, + "line": 1748, "description": "Iterate over the cells occupied by a widget executing a function for\neach one.", "itemtype": "method", "name": "for_each_cell_occupied", @@ -1355,7 +1423,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1751, + "line": 1769, "description": "Iterate over the columns occupied by a widget executing a function for\neach one.", "itemtype": "method", "name": "for_each_column_occupied", @@ -1379,7 +1447,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1770, + "line": 1788, "description": "Iterate over the rows occupied by a widget executing a function for\neach one.", "itemtype": "method", "name": "for_each_row_occupied", @@ -1391,7 +1459,7 @@ }, { "name": "callback", - "description": "The function to execute on each column iteration. The row number is passed as first argument.", + "description": "The function to execute on each column\n iteration. The row number is passed as first argument.", "type": "Function" } ], @@ -1403,7 +1471,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1836, + "line": 1855, "description": "Iterate over each widget above the column and row specified.", "itemtype": "method", "name": "for_each_widget_above", @@ -1420,7 +1488,7 @@ }, { "name": "callback", - "description": "The function to execute on each widget\niteration. The value of `this` inside the function is the jQuery wrapped HTMLElement.", + "description": "The function to execute on each widget\n iteration. The value of `this` inside the function is the jQuery\n wrapped HTMLElement.", "type": "Function" } ], @@ -1432,7 +1500,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1852, + "line": 1872, "description": "Iterate over each widget below the column and row specified.", "itemtype": "method", "name": "for_each_widget_below", @@ -1449,7 +1517,7 @@ }, { "name": "callback", - "description": "The function to execute on each widget\niteration. The value of `this` inside the function is the jQuery wrapped HTMLElement.", + "description": "The function to execute on each widget\n iteration. The value of `this` inside the function is the jQuery wrapped\n HTMLElement.", "type": "Function" } ], @@ -1461,7 +1529,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1868, + "line": 1889, "description": "Returns the highest occupied cell in the grid.", "itemtype": "method", "name": "get_highest_occupied_cell", @@ -1473,7 +1541,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1927, + "line": 1947, "description": "Set the current height of the parent grid.", "itemtype": "method", "name": "set_dom_grid_height", @@ -1485,7 +1553,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1941, + "line": 1960, "description": "It generates the neccessary styles to position the widgets.", "itemtype": "method", "name": "generate_stylesheet", @@ -1509,7 +1577,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 2004, + "line": 2030, "description": "Injects the given CSS as string to the head of the document.", "itemtype": "method", "name": "add_style_tag", @@ -1528,7 +1596,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 2027, + "line": 2053, "description": "Generates a faux grid to collide with it when a widget is dragged and\ndetect row or column that we want to go.", "itemtype": "method", "name": "generate_faux_grid", @@ -1552,7 +1620,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 2063, + "line": 2089, "description": "Recalculates the offsets for the faux grid. You need to use it when\nthe browser is resized.", "itemtype": "method", "name": "recalculate_faux_grid", @@ -1564,7 +1632,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 2087, + "line": 2113, "description": "Get all widgets in the DOM and register them.", "itemtype": "method", "name": "get_widgets_from_DOM", @@ -1576,7 +1644,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 2101, + "line": 2127, "description": "Calculate columns and rows to be set based on the configuration\n parameters, grid dimensions, etc ...", "itemtype": "method", "name": "generate_grid_and_stylesheet", diff --git a/docs/files/src_jquery.collision.js.html b/docs/files/src_jquery.collision.js.html index 0d078d2bd7..6e0eeefb54 100644 --- a/docs/files/src_jquery.collision.js.html +++ b/docs/files/src_jquery.collision.js.html @@ -42,9 +42,25 @@ <div id="api-tabview-panel"> <ul id="api-classes" class="apis classes"> - <li><a href="../classes/Collision.html">Collision</a></li> + <li><a href="../classes/Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects..html">Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects.</a></li> - <li><a href="../classes/Coords.html">Coords</a></li> + <li><a href="../classes/Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide..html">Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide.</a></li> <li><a href="../classes/Draggable.html">Draggable</a></li> @@ -104,198 +120,216 @@ ;(function($, window, document, undefined){ var defaults = { - colliders_context: document.body, - on_overlap: function(collider_data){}, - on_overlap_start : function(collider_data){ - // console.log('the element START being a collider', collider_data); - }, - on_overlap_stop : function(collider_data){ - // console.log('the element STOP being a collider', collider_data); - } + colliders_context: document.body + // ,on_overlap: function(collider_data){}, + // on_overlap_start : function(collider_data){}, + // on_overlap_stop : function(collider_data){} }; + /** - * Collision - * * @class Collision + * + * Detects collisions between a DOM element against other DOM elements or + * Coords objects. + * * @uses Coords - * @param {HTMLElement} element An Attribute name or object property path - * @param {String|HTMLElement|Array} colliders An Attribute name or object property path - * @param {Object} [options] An Attribute name or object property path - * @param {Function} [options.on_overlap] An Attribute name or object property path - * @param {Function} [options.on_overlap_start] An Attribute name or object property path - * @param {Function} [options.on_overlap_stop] An Attribute name or object property path - * @return {Object} dasdasdadasd + * @param {HTMLElement} el The jQuery wrapped HTMLElement. + * @param {HTMLElement|Array} colliders Can be a jQuery collection + * of HTMLElements or an Array of Coords instances. + * @param {Object} [options] An Object with all options you want to + * overwrite: + * @param {Function} [options.on_overlap_start] Executes a function the first + * time each `collider ` is overlapped. + * @param {Function} [options.on_overlap_stop] Executes a function when a + * `collider` is no longer collided. + * @param {Function} [options.on_overlap] Executes a function when the + * mouse is moved during the collision. + * @return {Object} Collision instance. * @constructor */ - function Collision(element, colliders, options) { - this.options = $.extend(defaults, options); - this.$element = element; - this.last_colliders = []; - this.last_colliders_coords = []; - if (typeof colliders === 'string' || colliders instanceof jQuery) { - this.$colliders = $(colliders, - this.options.colliders_context).not(this.$element); - }else{ - this.colliders = $(colliders); - } + function Collision(el, colliders, options) { + this.options = $.extend(defaults, options); + this.$element = el; + this.last_colliders = []; + this.last_colliders_coords = []; + if (typeof colliders === 'string' || colliders instanceof jQuery) { + this.$colliders = $(colliders, + this.options.colliders_context).not(this.$element); + }else{ + this.colliders = $(colliders); + } - this.init(); + this.init(); } + var fn = Collision.prototype; + fn.init = function() { - this.find_collisions(); + this.find_collisions(); }; + fn.overlaps = function(a, b) { - var x = false; - var y = false; + var x = false; + var y = false; - if ((b.x1 >= a.x1 && b.x1 <= a.x2) || - (b.x2 >= a.x1 && b.x2 <= a.x2) || - (a.x1 >= b.x1 && a.x2 <= b.x2) - ) { x = true; } + if ((b.x1 >= a.x1 && b.x1 <= a.x2) || + (b.x2 >= a.x1 && b.x2 <= a.x2) || + (a.x1 >= b.x1 && a.x2 <= b.x2) + ) { x = true; } - if ((b.y1 >= a.y1 && b.y1 <= a.y2) || - (b.y2 >= a.y1 && b.y2 <= a.y2) || - (a.y1 >= b.y1 && a.y2 <= b.y2) - ) { y = true; } + if ((b.y1 >= a.y1 && b.y1 <= a.y2) || + (b.y2 >= a.y1 && b.y2 <= a.y2) || + (a.y1 >= b.y1 && a.y2 <= b.y2) + ) { y = true; } - return (x && y); + return (x && y); }; + fn.detect_overlapping_region = function(a, b){ - var regionX = ''; - var regionY = ''; + var regionX = ''; + var regionY = ''; - if (a.y1 > b.cy && a.y1 < b.y2) { regionX = 'N'; } - if (a.y2 > b.y1 && a.y2 < b.cy) { regionX = 'S'; } - if (a.x1 > b.cx && a.x1 < b.x2) { regionY = 'W'; } - if (a.x2 > b.x1 && a.x2 < b.cx) { regionY = 'E'; } + if (a.y1 > b.cy && a.y1 < b.y2) { regionX = 'N'; } + if (a.y2 > b.y1 && a.y2 < b.cy) { regionX = 'S'; } + if (a.x1 > b.cx && a.x1 < b.x2) { regionY = 'W'; } + if (a.x2 > b.x1 && a.x2 < b.cx) { regionY = 'E'; } - return (regionX + regionY) || 'C'; + return (regionX + regionY) || 'C'; }; + fn.calculate_overlapped_area_coords = function(a, b){ - var x1 = Math.max(a.x1, b.x1); - var y1 = Math.max(a.y1, b.y1); - var x2 = Math.min(a.x2, b.x2); - var y2 = Math.min(a.y2, b.y2); + var x1 = Math.max(a.x1, b.x1); + var y1 = Math.max(a.y1, b.y1); + var x2 = Math.min(a.x2, b.x2); + var y2 = Math.min(a.y2, b.y2); - return $({ - left: x1, - top: y1, - width : (x2 - x1), - height: (y2 - y1) - }).coords().get(); + return $({ + left: x1, + top: y1, + width : (x2 - x1), + height: (y2 - y1) + }).coords().get(); }; + fn.calculate_overlapped_area = function(coords){ - return (coords.width * coords.height); + return (coords.width * coords.height); }; + fn.manage_colliders_start_stop = function(new_colliders_coords, start_callback, stop_callback){ - var last = this.last_colliders_coords; + var last = this.last_colliders_coords; - for (var i = 0, il = last.length; i < il; i++) { - if ($.inArray(last[i], new_colliders_coords) === -1) { - start_callback.call(this, last[i]); - } - } + for (var i = 0, il = last.length; i < il; i++) { + if ($.inArray(last[i], new_colliders_coords) === -1) { + start_callback.call(this, last[i]); + } + } - for (var j = 0, jl = new_colliders_coords.length; j < jl; j++) { - if ($.inArray(new_colliders_coords[j], last) === -1) { - stop_callback.call(this, new_colliders_coords[j]); - } + for (var j = 0, jl = new_colliders_coords.length; j < jl; j++) { + if ($.inArray(new_colliders_coords[j], last) === -1) { + stop_callback.call(this, new_colliders_coords[j]); + } - } + } }; + fn.find_collisions = function(player_data_coords){ - var self = this; - var colliders_coords = []; - var colliders_data = []; - var $colliders = (this.colliders || this.$colliders); - var count = $colliders.length; - var player_coords = self.$element.coords().update(player_data_coords || false).get(); + var self = this; + var colliders_coords = []; + var colliders_data = []; + var $colliders = (this.colliders || this.$colliders); + var count = $colliders.length; + var player_coords = self.$element.coords() + .update(player_data_coords || false).get(); - while(count--){ - var $collider = self.$colliders ? $($colliders[count]) : $colliders[count]; - var $collider_coords_ins = ($collider.isCoords) ? - $collider : $collider.coords(); - var collider_coords = $collider_coords_ins.get(); - var overlaps = self.overlaps(player_coords, collider_coords); + while(count--){ + var $collider = self.$colliders ? + $($colliders[count]) : $colliders[count]; + var $collider_coords_ins = ($collider.isCoords) ? + $collider : $collider.coords(); + var collider_coords = $collider_coords_ins.get(); + var overlaps = self.overlaps(player_coords, collider_coords); - if (!overlaps) { - continue; + if (!overlaps) { + continue; + } + + var region = self.detect_overlapping_region( + player_coords, collider_coords); + + //todo: make this an option + if (region === 'C'){ + var area_coords = self.calculate_overlapped_area_coords( + player_coords, collider_coords); + var area = self.calculate_overlapped_area(area_coords); + var collider_data = { + area: area, + area_coords : area_coords, + region: region, + coords: collider_coords, + player_coords: player_coords, + el: $collider + }; + + if (self.options.on_overlap) { + self.options.on_overlap.call(this, collider_data); + } + colliders_coords.push($collider_coords_ins); + colliders_data.push(collider_data); + } } - var region = self.detect_overlapping_region(player_coords, - collider_coords); - //todo: make this if customizable - if (region === 'C'){ - var area_coords = self.calculate_overlapped_area_coords( - player_coords, collider_coords); - var area = self.calculate_overlapped_area(area_coords); - var collider_data = { - area: area, - area_coords : area_coords, - region: region, - coords: collider_coords, - player_coords: player_coords, - el: $collider - }; - - self.options.on_overlap.call(this, collider_data); - colliders_coords.push($collider_coords_ins); - colliders_data.push(collider_data); + if (self.options.on_overlap_stop || self.options.on_overlap_start) { + this.manage_colliders_start_stop(colliders_coords, + self.options.on_overlap_stop, self.options.on_overlap_start); } - } + this.last_colliders_coords = colliders_coords; - this.manage_colliders_start_stop(colliders_coords, - self.options.on_overlap_stop, self.options.on_overlap_start); - - this.last_colliders_coords = colliders_coords; - - return colliders_data; + return colliders_data; }; fn.get_closest_colliders = function(player_data_coords){ - var colliders = this.find_collisions(player_data_coords); - var min_area = 100; - colliders.sort(function(a, b){ + var colliders = this.find_collisions(player_data_coords); + var min_area = 100; + colliders.sort(function(a, b){ + if (a.area <= min_area) { + return 1; + } - if (a.area <= min_area) { - return 1; - } + /* if colliders are being overlapped by the "C" (center) region, + * we have to set a lower index in the array to which they are placed + * above in the grid. */ + if (a.region === 'C' && b.region === 'C') { + if (a.coords.y1 < b.coords.y1 || a.coords.x1 < b.coords.x1) { + return - 1; + }else{ + return 1; + } + } - /* if colliders are being overlapped by the "C" (center) region, - * we have to set a lower index in the array to which they are placed - * above in the grid. */ - if (a.region === 'C' && b.region === 'C') { - if (a.coords.y1 < b.coords.y1 || a.coords.x1 < b.coords.x1) { - return - 1; - }else{ + if (a.area < b.area){ return 1; } - } - if (a.area < b.area){ - return 1; - } - - return 1; - }); - return colliders; + return 1; + }); + return colliders; }; + //jQuery adapter $.fn.collision = function(collider, options) { - return new Collision( this, collider, options ); + return new Collision( this, collider, options ); }; diff --git a/docs/files/src_jquery.coords.js.html b/docs/files/src_jquery.coords.js.html index ef5dd34b99..a7fe8710dc 100644 --- a/docs/files/src_jquery.coords.js.html +++ b/docs/files/src_jquery.coords.js.html @@ -42,9 +42,25 @@ <div id="api-tabview-panel"> <ul id="api-classes" class="apis classes"> - <li><a href="../classes/Collision.html">Collision</a></li> + <li><a href="../classes/Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects..html">Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects.</a></li> - <li><a href="../classes/Coords.html">Coords</a></li> + <li><a href="../classes/Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide..html">Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide.</a></li> <li><a href="../classes/Draggable.html">Draggable</a></li> @@ -103,10 +119,16 @@ ;(function($, window, document, undefined){ /** - * Coords - * * @class Coords - * @param {HTMLElement|Object} obj HTMLElement or a literal Object with the left, top, width and height properties. + * + * Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) + * to simulate DOM elements on the screen. + * Coords is used by Gridster to create a faux grid with any DOM element can + * collide. + * + * @param {HTMLElement|Object} obj The jQuery HTMLElement or a object with: left, + * top, width and height properties. + * @return {Object} Coords instance. * @constructor */ function Coords(obj) { @@ -122,8 +144,10 @@ return this; } + var fn = Coords.prototype; + fn.init = function(){ this.set(); this.original_coords = this.get(); @@ -181,6 +205,7 @@ return this.coords; }; + //jQuery adapter $.fn.coords = function() { if (this.data('coords') ) { diff --git a/docs/files/src_jquery.draggable.js.html b/docs/files/src_jquery.draggable.js.html index 01b39af04c..c87d7bac27 100644 --- a/docs/files/src_jquery.draggable.js.html +++ b/docs/files/src_jquery.draggable.js.html @@ -42,9 +42,25 @@ <div id="api-tabview-panel"> <ul id="api-classes" class="apis classes"> - <li><a href="../classes/Collision.html">Collision</a></li> + <li><a href="../classes/Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects..html">Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects.</a></li> - <li><a href="../classes/Coords.html">Coords</a></li> + <li><a href="../classes/Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide..html">Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide.</a></li> <li><a href="../classes/Draggable.html">Draggable</a></li> @@ -107,24 +123,42 @@ items: '.gs_w', distance: 1, limit: true, - offset_left: 0, - drag: function(e){}, - start : function(e, ui){}, - stop : function(e){} + offset_left: 0 + // ,drag: function(e){}, + // start : function(e, ui){}, + // stop : function(e){} }; var $body = $(document.body); /** - * Draggable - * * @class Draggable + * + * @param {HTMLElement} el The HTMLelement that contains all the widgets + * to be dragged. + * @param {Object} [options] An Object with all options you want to + * overwrite: + * @param {HTMLElement|String} [options.items] Define who will + * be the draggable items. Can be a CSS Selector String or a + * collection of HTMLElements. + * @param {Number} [options.distance] Distance in pixels after mousedown + * the mouse must move before dragging should start. + * @param {Boolean} [options.limit] Constrains dragging to the width of + * the container + * @param {offset_left} [options.offset_left] Offset added to the item + * that is being dragged. + * @param {Number} [options.drag] Executes a callback when the mouse is + * moved during the dragging. + * @param {Number} [options.start] Executes a callback when the drag + * starts. + * @param {Number} [options.stop] Executes a callback when the drag stops. + * @return {Object} Returns `el`. * @constructor */ - function Draggable(element, options) { - this.options = $.extend(defaults, options); - this.$container = $(element); + function Draggable(el, options) { + this.options = $.extend({}, defaults, options); + this.$container = $(el); this.$dragitems = $(this.options.items, this.$container); this.is_dragging = false; this.player_min_left = 0 + this.options.offset_left; @@ -139,6 +173,7 @@ this.enable(); }; + fn.get_actual_pos = function($el) { var pos = $el.position(); return pos; @@ -154,6 +189,10 @@ fn.drag_handler = function(e) { + if (e.which !== 1) { + return false; + }; + var self = this; var first = true; this.$player = $(e.currentTarget); @@ -162,6 +201,7 @@ this.mouse_init_pos = this.get_mouse_pos(e); $body.on('mousemove.draggable', 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); var diff_y = Math.abs(mouse_actual_pos.top - self.mouse_init_pos.top); diff --git a/docs/files/src_jquery.gridster.js.html b/docs/files/src_jquery.gridster.js.html index 4df4a9e481..42645e3f95 100644 --- a/docs/files/src_jquery.gridster.js.html +++ b/docs/files/src_jquery.gridster.js.html @@ -42,9 +42,25 @@ <div id="api-tabview-panel"> <ul id="api-classes" class="apis classes"> - <li><a href="../classes/Collision.html">Collision</a></li> + <li><a href="../classes/Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects..html">Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects.</a></li> - <li><a href="../classes/Coords.html">Coords</a></li> + <li><a href="../classes/Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide..html">Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide.</a></li> <li><a href="../classes/Draggable.html">Draggable</a></li> @@ -109,7 +125,7 @@ extra_rows: 0, extra_cols: 0, min_cols: 1, - min_rows: 10, + min_rows: 15, autogenerate_stylesheet: true, avoid_overlapped_widgets: true, serialize_params: function($w, wgd) { @@ -127,7 +143,7 @@ /** * @class Gridster - * @uses Coords + * @uses Draggable * @uses Collision * @param {HTMLElement} el The HTMLelement that contains all the widgets. * @param {Object} [options] An Object with all options you want to @@ -153,6 +169,9 @@ * `<head>` of the document. You can set this to false, and write * your own CSS targeting rows and cols via data-attributes like so: * `[data-col="1"] { left: 10px; }` + * @param {Boolean} [avoid_overlapped_widgets] Avoid that widgets loaded + * from the DOM can be overlapped. It is helpful if the positions were + * bad stored in the database or if there was any conflict. * @param {Function} [options.serialize_params] Return the data you want * for each widget in the serialization. Two arguments are passed: * `$w`: the jQuery wrapped HTMLElement, and `wgd`: the grid @@ -161,8 +180,8 @@ * Collision class you want to overwrite. See Collision docs for * more info. * @param {Object} [options.draggable] An Object with all options for - * jQuery UI Draggable you want to overwrite. See - * http://jqueryui.com/demos/draggable/ for more info. + * Draggable class you want to overwrite. See Draggable docs for more + * info. * * @constructor */ @@ -170,7 +189,7 @@ this.options = $.extend(true, defaults, options); this.$el = $(el); this.$wrapper = this.$el.parent(); - this.$widgets = this.$el.find(this.options.widget_selector).addClass('gs_w'); + this.$widgets = $(this.options.widget_selector, this.$el).addClass('gs_w'); this.widgets = []; this.$changed = $([]); this.wrapper_width = this.$wrapper.width(); @@ -203,7 +222,8 @@ * @method enable * @return {Class} Returns the instance of the Gridster Class. */ - fn.disable = function(){ + fn.disable = function() { + this.$wrapper.find('.player-revert').removeClass('player-revert'); this.drag_api.disable(); return this; } @@ -215,7 +235,7 @@ * @method enable * @return {Class} Returns the instance of the Gridster Class. */ - fn.enable = function(){ + fn.enable = function() { this.drag_api.enable(); return this; } @@ -304,15 +324,17 @@ var $el = el instanceof jQuery ? el : $(el); var wgd = $el.coords().grid; + this.cells_occupied_by_placeholder = {}; this.$widgets = this.$widgets.not($el); var $nexts = this.widgets_below($el); this.remove_from_gridmap(wgd); - $el.fadeOut($.proxy(function(){ + $el.fadeOut($.proxy(function() { $el.remove(); - $nexts.each($.proxy(function(i, widget){ + + $nexts.each($.proxy(function(i, widget) { this.move_widget_up( $(widget), wgd.size_y ); }, this)); @@ -336,9 +358,9 @@ fn.serialize = function($widgets) { $widgets || ($widgets = this.$widgets); var result = []; - $widgets.each($.proxy(function(i, widget){ - result.push( this.options.serialize_params( - $(widget),$(widget).coords().grid ) ); + $widgets.each($.proxy(function(i, widget) { + result.push(this.options.serialize_params( + $(widget), $(widget).coords().grid ) ); }, this)); return result; @@ -346,7 +368,8 @@ /** - * Returns a serialized array of the widgets that have changed their position. + * Returns a serialized array of the widgets that have changed their + * position. * * @method serialize_changed * @return {Array} Returns an Array of Objects with the data specified in @@ -376,7 +399,7 @@ if (this.options.avoid_overlapped_widgets && !this.can_move_to( - { size_x: wgd.size_x, size_y: wgd.size_y }, wgd.col, wgd.row) + {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; @@ -429,7 +452,7 @@ * to update in the mapped array. * @return {Class} Returns the instance of the Gridster Class. */ - fn.remove_from_gridmap = function(grid_data){ + fn.remove_from_gridmap = function(grid_data) { return this.update_widget_position(grid_data, false); }; @@ -444,12 +467,12 @@ * position . * @return {Class} Returns the instance of the Gridster Class. */ - fn.add_to_gridmap = function(grid_data, value){ + fn.add_to_gridmap = function(grid_data, value) { this.update_widget_position(grid_data, value || grid_data.el); if (grid_data.el) { var $widgets = this.widgets_below(grid_data.el); - $widgets.each($.proxy(function(i, widget){ + $widgets.each($.proxy(function(i, widget) { this.move_widget_up( $(widget)); }, this)); } @@ -457,8 +480,9 @@ /** - * Make widgets draggable. It Wraps the jQuery UI Draggable Plugin. + * Make widgets draggable. * + * @uses Draggable * @method draggable * @return {Class} Returns the instance of the Gridster Class. */ @@ -468,7 +492,9 @@ offset_left: this.options.widget_margins[0], items: '.gs_w', start: function(event, ui) { - self.$widgets.filter('.player-revert').removeClass('player-revert'); + self.$widgets.filter('.player-revert') + .removeClass('player-revert'); + self.$player = $(this); self.$helper = self.options.draggable.helper === 'clone' ? $(ui.helper) : self.$player; @@ -498,7 +524,6 @@ * @method on_start_drag * @param {Event} The original browser event * @param {Object} A prepared ui object. - * See http://jqueryui.com/demos/draggable/ for more info. */ fn.on_start_drag = function(event, ui) { @@ -550,14 +575,15 @@ * @method on_drag * @param {Event} The original browser event * @param {Object} A prepared ui object. - * See http://jqueryui.com/demos/draggable/ for more info. */ fn.on_drag = function(event, ui) { var abs_offset = { left: ui.position.left + this.baseX, top: ui.position.top + this.baseY } - this.colliders_data = this.collision_api.get_closest_colliders(abs_offset); + + this.colliders_data = this.collision_api.get_closest_colliders( + abs_offset); this.on_overlapped_column_change( this.on_start_overlapping_column, @@ -587,10 +613,10 @@ * @method on_stop_drag * @param {Event} The original browser event * @param {Object} A prepared ui object. - * See http://jqueryui.com/demos/draggable/ for more info. */ fn.on_stop_drag = function(event, ui) { - this.$helper.add(this.$player).add(this.$wrapper).removeClass('dragging'); + this.$helper.add(this.$player).add(this.$wrapper) + .removeClass('dragging'); ui.position.left = ui.position.left + this.baseX; ui.position.top = ui.position.top + this.baseY; @@ -606,14 +632,14 @@ 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.$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); @@ -782,7 +808,7 @@ var wgd_can_go_up = []; var wgd_can_not_go_up = []; - $widgets.each($.proxy(function(i, w){ + $widgets.each($.proxy(function(i, w) { var $w = $(w); var wgd = $w.coords().grid; if (this.can_go_widget_up(wgd)) { @@ -811,7 +837,7 @@ * @return {Array} Returns the array sorted. */ fn.sort_by_row_asc = function(widgets) { - widgets = widgets.sort(function(a, b){ + widgets = widgets.sort(function(a, b) { if (a.row > b.row) { return 1; } @@ -831,7 +857,7 @@ * @return {Array} Returns the array sorted. */ fn.sort_by_row_and_col_asc = function(widgets) { - widgets = widgets.sort(function(a, b){ + widgets = widgets.sort(function(a, b) { if (a.row > b.row || a.row == b.row && a.col > b.col) { return 1; } @@ -851,7 +877,7 @@ * @return {Array} Returns the array sorted. */ fn.sort_by_col_asc = function(widgets) { - widgets = widgets.sort(function(a, b){ + widgets = widgets.sort(function(a, b) { if (a.col > b.col) { return 1; } @@ -871,8 +897,8 @@ * @return {Array} Returns the array sorted. */ fn.sort_by_row_desc = function(widgets) { - widgets = widgets.sort(function(a, b){ - if (a.row + a.size_y < b.row + b.size_y){ + widgets = widgets.sort(function(a, b) { + if (a.row + a.size_y < b.row + b.size_y) { return 1; } return -1; @@ -893,7 +919,7 @@ * @return {Class} Returns the instance of the Gridster Class. */ fn.manage_movements = function($widgets, to_col, to_row) { - $.each($widgets, $.proxy(function(i, w){ + $.each($widgets, $.proxy(function(i, w) { var wgd = w; var $w = wgd.el; @@ -968,7 +994,7 @@ * @return {Boolean} Returns true or false. */ fn.is_placeholder_in = function(col, row) { - var c = this.cells_occupied_by_placeholder || []; + var c = this.cells_occupied_by_placeholder || {}; return this.is_placeholder_in_col(col) && $.inArray(row, c.rows) >= 0; }; @@ -1077,9 +1103,9 @@ var cells = this.cells_occupied_by_player; var $widgets = $([]); - $.each(cells.cols, $.proxy(function(i, col){ - $.each(cells.rows, $.proxy(function(i, row){ - if(this.is_widget(col, row)){ + $.each(cells.cols, $.proxy(function(i, col) { + $.each(cells.rows, $.proxy(function(i, row) { + if(this.is_widget(col, row)) { $widgets = $widgets.add(this.gridmap[col][row]); } }, this)); @@ -1120,8 +1146,6 @@ this.placeholder_grid_data.col = col; this.placeholder_grid_data.row = row; - - this.cells_occupied_by_placeholder = this.get_cells_occupied( this.placeholder_grid_data); @@ -1131,9 +1155,9 @@ }); if (moved_down || changed_column) { - $nexts.each($.proxy(function(i, widget){ + $nexts.each($.proxy(function(i, widget) { this.move_widget_up( - $(widget), this.placeholder_grid_data.col - col + phgd.size_y); + $(widget), this.placeholder_grid_data.col - col + phgd.size_y); }, this)); } @@ -1158,12 +1182,12 @@ /* generate an array with columns as index and array with upper rows * empty as value */ - this.for_each_column_occupied(widget_grid_data, function(tcol){ + this.for_each_column_occupied(widget_grid_data, function(tcol) { var grid_col = this.gridmap[tcol]; var r = p_bottom_row + 1; upper_rows[tcol] = []; - while (--r > 0){ + while (--r > 0) { if (this.is_empty(tcol, r) || this.is_player(tcol, r) || this.is_widget(tcol, r) && grid_col[r].is($widgets_under_player) @@ -1206,7 +1230,7 @@ /* generate an array with columns as index and array with upper rows * empty as value */ - this.for_each_column_occupied(widget_grid_data, function(tcol){ + this.for_each_column_occupied(widget_grid_data, function(tcol) { var grid_col = this.gridmap[tcol]; upper_rows[tcol] = []; @@ -1217,7 +1241,9 @@ break; } - if (!this.is_player(tcol, r) &&!this.is_placeholder_in(tcol, r)) { + if (!this.is_player(tcol, r) && + !this.is_placeholder_in(tcol, r) + ) { upper_rows[tcol].push(r); } @@ -1253,7 +1279,7 @@ * @return {Number|Boolean} Returns the upper row valid from the `upper_rows` * for the widget in question. */ - fn.get_valid_rows = function(widget_grid_data, upper_rows, min_row){ + fn.get_valid_rows = function(widget_grid_data, upper_rows, min_row) { var p_top_row = widget_grid_data.row; var p_bottom_row = widget_grid_data.row + widget_grid_data.size_y - 1; var size_y = widget_grid_data.size_y; @@ -1262,7 +1288,7 @@ while (++r <= p_bottom_row ) { var common = true; - $.each(upper_rows, function(col, rows){ + $.each(upper_rows, function(col, rows) { if (rows && $.inArray(r, rows) === -1) { common = false; } @@ -1331,8 +1357,8 @@ var rows_from_bottom = this.cells_occupied_by_player.rows.slice(0); rows_from_bottom.reverse(); - $.each(this.cells_occupied_by_player.cols, $.proxy(function(i, col){ - $.each(rows_from_bottom, $.proxy(function(i, row){ + $.each(this.cells_occupied_by_player.cols, $.proxy(function(i, col) { + $.each(rows_from_bottom, $.proxy(function(i, row) { // if there is a widget in the player position if (!this.gridmap[col]) { return true; } //next iteration var $w = this.gridmap[col][row]; @@ -1419,7 +1445,8 @@ * if they can. * * @method move_widget_to - * @param {HTMLElement} $widget The jQuery wrapped HTMLElement of the widget is going to be moved. + * @param {HTMLElement} $widget The jQuery wrapped HTMLElement of the + * widget is going to be moved. * @return {Class} Returns the instance of the Gridster Class. */ fn.move_widget_to = function($widget, row) { @@ -1442,12 +1469,12 @@ this.$changed = this.$changed.add($widget); - $next_widgets.each(function(i, widget){ + $next_widgets.each(function(i, widget) { var $w = $(widget); var wgd = $w.coords().grid; var can_go_up = self.can_go_widget_up(wgd); - if (can_go_up && can_go_up !== wgd.row){ + if (can_go_up && can_go_up !== wgd.row) { self.move_widget_to($w, can_go_up); } }); @@ -1473,12 +1500,14 @@ if (!this.can_go_up($widget)) { return false; } //break; - this.for_each_column_occupied(el_grid_data, function(col){ + this.for_each_column_occupied(el_grid_data, function(col) { // can_go_up if ($.inArray($widget, moved) === -1) { var widget_grid_data = $widget.coords().grid; var next_row = actual_row - y_units; - next_row = this.can_go_up_to_row(widget_grid_data, col, next_row); + next_row = this.can_go_up_to_row( + widget_grid_data, col, next_row); + if (!next_row) { return true; } @@ -1493,7 +1522,7 @@ moved.push($widget); - $next_widgets.each($.proxy(function(i, widget){ + $next_widgets.each($.proxy(function(i, widget) { this.move_widget_up($(widget), y_units); }, this)); } @@ -1506,7 +1535,8 @@ * Move down the specified widget and all below it. * * @method move_widget_down - * @param {HTMLElement} $widget The jQuery object representing the widget you want to move. + * @param {HTMLElement} $widget The jQuery object representing the widget + * you want to move. * @param {Number} The number of cells that the widget has to move. * @return {Class} Returns the instance of the Gridster Class. */ @@ -1526,7 +1556,7 @@ this.remove_from_gridmap(widget_grid_data); - $next_widgets.each($.proxy(function(i, widget){ + $next_widgets.each($.proxy(function(i, widget) { var $w = $(widget); var wd = $w.coords().grid; var tmp_y = this.displacement_diff( @@ -1566,13 +1596,14 @@ var actual_row = widget_grid_data.row; var r; - //generate an array with columns as index and array with upper rows empty in the column - this.for_each_column_occupied(widget_grid_data, function(tcol){ + /* generate an array with columns as index and array with + * upper rows empty in the column */ + this.for_each_column_occupied(widget_grid_data, function(tcol) { var grid_col = ga[tcol]; urc[tcol] = []; r = actual_row; - while (r--){ + while (r--) { if (this.is_empty(tcol, r) && !this.is_placeholder_in(tcol, r) ) { @@ -1591,7 +1622,8 @@ if (!result) { return false; } - //get common rows starting from upper position in all the columns widget occupies + /* get common rows starting from upper position in all the columns + * that widget occupies */ r = row; for (r = 1; r < actual_row; r++) { var common = true; @@ -1617,7 +1649,7 @@ var diffs = []; var parent_max_y = parent_bgd.row + parent_bgd.size_y; - this.for_each_column_occupied(widget_grid_data, function(col){ + this.for_each_column_occupied(widget_grid_data, function(col) { var temp_y_units = 0; for (var r = parent_max_y; r < actual_row; r++) { @@ -1650,9 +1682,9 @@ var next_row = el_grid_data.row + el_grid_data.size_y - 1; var $nexts = $([]); - this.for_each_column_occupied(el_grid_data, function(col){ + this.for_each_column_occupied(el_grid_data, function(col) { self.for_each_widget_below(col, next_row, - function(tcol, trow){ + function(tcol, trow) { if (!self.is_player(this) && $.inArray(this, $nexts) === -1) { $nexts = $nexts.add(this); @@ -1704,7 +1736,8 @@ var result = true; if (initial_row === 1) { return false; } - this.for_each_column_occupied(el_grid_data, function(col){ + this.for_each_column_occupied(el_grid_data, function(col) { + var $w = this.is_widget(col, prev_row); if (this.is_occupied(col, prev_row) || this.is_player(col, prev_row) || this.is_placeholder_in(col, prev_row) @@ -1721,8 +1754,8 @@ /** * Check if it's possible to move a widget to a specific col/row. It takes - * into account the dimensions (`size_y` and `size_x` attrs. of the grid coords - * object) the widget occupies. + * into account the dimensions (`size_y` and `size_x` attrs. of the grid + * coords object) the widget occupies. * * @method can_move_to * @param {Object} widget_grid_data The grid coords object that represents @@ -1748,7 +1781,7 @@ return false; }; - this.for_each_cell_occupied(future_wd, function(tcol, trow){ + this.for_each_cell_occupied(future_wd, function(tcol, trow) { var $tw = this.is_widget(tcol, trow); if ($tw && (!widget_grid_data.el || $tw.is($w))) { result = false; @@ -1760,7 +1793,8 @@ /** - * Given the leftmost column returns all columns that are overlapping with the player. + * Given the leftmost column returns all columns that are overlapping + * with the player. * * @method get_targeted_columns * @param {Number} [from_col] The leftmost column. @@ -1834,8 +1868,8 @@ * @return {Class} Returns the instance of the Gridster Class. */ fn.for_each_cell_occupied = function(grid_data, callback) { - this.for_each_column_occupied(grid_data, function(col){ - this.for_each_row_occupied(grid_data, function(row){ + this.for_each_column_occupied(grid_data, function(col) { + this.for_each_row_occupied(grid_data, function(row) { callback.call(this, col, row); }); }); @@ -1869,7 +1903,8 @@ * @method for_each_row_occupied * @param {Object} el_grid_data The grid coords object that represents * the widget. - * @param {Function} callback The function to execute on each column iteration. The row number is passed as first argument. + * @param {Function} callback The function to execute on each column + * iteration. The row number is passed as first argument. * @return {Class} Returns the instance of the Gridster Class. */ fn.for_each_row_occupied = function(el_grid_data, callback) { @@ -1935,7 +1970,8 @@ * @param {Number} col The column to start iterating. * @param {Number} row The row to start iterating. * @param {Function} callback The function to execute on each widget - * iteration. The value of `this` inside the function is the jQuery wrapped HTMLElement. + * iteration. The value of `this` inside the function is the jQuery + * wrapped HTMLElement. * @return {Class} Returns the instance of the Gridster Class. */ fn.for_each_widget_above = function(col, row, callback) { @@ -1951,7 +1987,8 @@ * @param {Number} col The column to start iterating. * @param {Number} row The row to start iterating. * @param {Function} callback The function to execute on each widget - * iteration. The value of `this` inside the function is the jQuery wrapped HTMLElement. + * iteration. The value of `this` inside the function is the jQuery wrapped + * HTMLElement. * @return {Class} Returns the instance of the Gridster Class. */ fn.for_each_widget_below = function(col, row, callback) { @@ -1992,14 +2029,13 @@ }; - fn.get_widgets_from = function(col, row) { var ga = this.gridmap; var $widgets = $(); if (col) { $widgets = $widgets.add( - this.$widgets.filter(function(){ + this.$widgets.filter(function() { var tcol = $(this).attr('data-col'); return (tcol == col || tcol > col); }) @@ -2008,7 +2044,7 @@ if (row) { $widgets = $widgets.add( - this.$widgets.filter(function(){ + this.$widgets.filter(function() { var trow = $(this).attr('data-row'); return (trow == row || trow > row); }) @@ -2028,7 +2064,6 @@ fn.set_dom_grid_height = function() { var r = this.get_highest_occupied_cell().row; this.$el.css('height', r * this.min_widget_height); - // this.$widgets.draggable("option", "containment", this.$el); return this; }; @@ -2053,11 +2088,14 @@ opts.cols || (opts.cols = this.cols); opts.rows || (opts.rows = this.rows); opts.namespace || (opts.namespace = ''); - opts.widget_base_dimensions || (opts.widget_base_dimensions = this.options.widget_base_dimensions); - opts.widget_margins || (opts.widget_margins = this.options.widget_margins); - - opts.min_widget_width = (opts.widget_margins[0] * 2) + opts.widget_base_dimensions[0]; - opts.min_widget_height = (opts.widget_margins[1] * 2) + opts.widget_base_dimensions[1]; + opts.widget_base_dimensions || + (opts.widget_base_dimensions = this.options.widget_base_dimensions); + opts.widget_margins || + (opts.widget_margins = this.options.widget_margins); + opts.min_widget_width = (opts.widget_margins[0] * 2) + + opts.widget_base_dimensions[0]; + opts.min_widget_height = (opts.widget_margins[1] * 2) + + opts.widget_base_dimensions[1]; var serialized_opts = $.param(opts); // don't duplicate stylesheets for the same configuration @@ -2069,27 +2107,31 @@ /* generate CSS styles for cols */ for (i = opts.cols + extra_cells; i >= 0; i--) { - 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;} '; + 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;} '); } /* generate CSS styles for rows */ for (i = opts.rows + extra_cells; i >= 0; i--) { - 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;} '; + 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;} '); } for (var y = 1; y < max_size_y; y++) { - styles += opts.namespace + ' [data-sizey="' + (y) + '"] { height: ' + - (y * opts.widget_base_dimensions[1] + (y-1)*(opts.widget_margins[1]*2)) + 'px;}'; + styles += (opts.namespace + ' [data-sizey="' + y + '"] { height:' + + (y * opts.widget_base_dimensions[1] + + (y - 1) * (opts.widget_margins[1] * 2)) + 'px;}'); } 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;}'; + styles += (opts.namespace + ' [data-sizex="' + x + '"] { width:' + + (x * opts.widget_base_dimensions[0] + + (x - 1) * (opts.widget_margins[0] * 2)) + 'px;}'); } return this.add_style_tag(styles); @@ -2103,7 +2145,7 @@ * @param {String} css The styles to apply. * @return {Object} Returns the instance of the Gridster class. */ - fn.add_style_tag = function(css){ + fn.add_style_tag = function(css) { var d = document; var tag = d.createElement('style'); @@ -2167,7 +2209,7 @@ this.baseX = ($(window).width() - aw) / 2; this.baseY = this.$wrapper.offset().top; - $.each(this.faux_grid, $.proxy(function(i, coords){ + $.each(this.faux_grid, $.proxy(function(i, coords) { this.faux_grid[i] = coords.update({ left: this.baseX + (coords.data.col -1) * this.min_widget_width, top: this.baseY + (coords.data.row -1) * this.min_widget_height @@ -2186,7 +2228,7 @@ * @return {Object} Returns the instance of the Gridster class. */ fn.get_widgets_from_DOM = function() { - this.$widgets.each($.proxy(function(i, widget){ + this.$widgets.each($.proxy(function(i, widget) { this.register_widget($(widget)); }, this)); return this; diff --git a/docs/index.html b/docs/index.html index b51bc488fc..2b30280325 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,9 +42,25 @@ <div id="api-tabview-panel"> <ul id="api-classes" class="apis classes"> - <li><a href="./classes/Collision.html">Collision</a></li> + <li><a href="./classes/Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects..html">Collision + +Detects collisions between a DOM element against other DOM elements or +Coords objects.</a></li> - <li><a href="./classes/Coords.html">Coords</a></li> + <li><a href="./classes/Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide..html">Coords + +Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height) +to simulate DOM elements on the screen. +Coords is used by Gridster to create a faux grid with any DOM element can +collide.</a></li> <li><a href="./classes/Draggable.html">Draggable</a></li>