From d4145e873cf0a975817afa6affdd0082197cc1dd Mon Sep 17 00:00:00 2001 From: vieron Date: Thu, 19 Jul 2012 15:56:12 +0200 Subject: [PATCH] updated doc and dist --- dist/jquery.gridster.js | 42 ++++ dist/jquery.gridster.min.js | 2 +- docs/classes/Gridster.html | 255 +++++++++++++++++++------ docs/data.json | 146 ++++++++------ docs/files/src_jquery.gridster.js.html | 42 ++++ 5 files changed, 364 insertions(+), 123 deletions(-) diff --git a/dist/jquery.gridster.js b/dist/jquery.gridster.js index b81b5cbfb1..ae79d869a8 100644 --- a/dist/jquery.gridster.js +++ b/dist/jquery.gridster.js @@ -409,6 +409,7 @@ this.set_dom_grid_height(); this.$wrapper.addClass('ready'); this.draggable(); + this.next_position(2, 2); $(window).bind( 'resize', throttle($.proxy(this.recalculate_faux_grid, this), 200)); @@ -446,6 +447,47 @@ }; + /** + * Get the most left column below to add a new widget. + * + * @method next_position + * @param {Number} size_x The nº of rows the widget occupies horizontally. + * @param {Number} size_y The nº of columns the widget occupies vertically. + * @return {Object} Returns a grid coords object representing the future + * widget coords. + */ + fn.next_position = function(size_x, size_y) { + var ga = this.gridmap; + var cols_l = ga.length; + var valid_pos = []; + + for (var c = 1; c < cols_l; c++) { + var rows_l = ga[c].length; + for (var r = 1; r <= rows_l; r++) { + var can_move_to = this.can_move_to({ + size_x: size_x, + size_y: size_y + }, c, r); + + if (can_move_to) { + valid_pos.push({ + col: c, + row: r, + size_y: size_y, + size_x: size_x + }); + }; + }; + }; + + if (valid_pos.length) { + this.next_position = this.sort_by_row_asc(valid_pos)[0]; + return this.next_position; + }; + return false; + } + + /** * Remove a widget from the grid. * diff --git a/dist/jquery.gridster.min.js b/dist/jquery.gridster.min.js index 6db18a9aaa..5824d31cb7 100644 --- a/dist/jquery.gridster.min.js +++ b/dist/jquery.gridster.min.js @@ -1,4 +1,4 @@ /*! gridster.js - v0.1.0 - 2012-07-19 * 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(){var a=this.el;a&&(this.data=a.offset(),this.data.width||(this.data.width=a.width()),this.data.height||(this.data.height=a.height()));var b=this.data;return this.coords.x1=b.left,this.coords.y1=b.top,this.coords.x2=b.left+b.width,this.coords.y2=b.top+b.height,this.coords.cx=b.left+b.width/2,this.coords.cy=b.top+b.height/2,this.coords.width=b.width,this.coords.height=b.height,this.coords.el=a||!1,this},f.update=function(b){if(!b&&!this.el)return this;if(b){var c=a.extend(this.data,b);this.data=c}return this.set(),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.y1b.y1&&a.y2b.cx&&a.x1b.x1&&a.x2 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,serialize_params:function(a,b){return{col:b.col,row:b.row}},collision:{},draggable:{}},f=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)}},g=function(a,b){var c,d,e,g,h,i,j=f(function(){h=g=!1},b,!0);return function(){c=this,d=arguments;var f=function(){e=null,h&&a.apply(c,d),j()};return e||(e=setTimeout(f,b)),g?h=!0:i=a.apply(c,d),j(),g=!0,i}},i=h.prototype;i.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",g(a.proxy(this.recalculate_faux_grid,this),200))},i.add_widget=function(b,c,d){var e=a(b).attr({"data-col":this.highest_occupied_cell.col,"data-row":this.highest_occupied_cell.row+1,"data-sizex":c||1,"data-sizey":d||1}).addClass("gs_w").appendTo(this.$el).hide();this.$widgets=this.$widgets.add(e),this.register_widget(e),this.$widgets.draggable("destroy"),this.draggable(),this.set_dom_grid_height(),e.fadeIn()},i.remove_widget=function(b){var c=b instanceof jQuery?b:a(b),d=c.coords().grid;this.$widgets=this.$widgets.not(c);var e=this.widgets_below(c);this.remove_from_gridmap(d),c.fadeOut(a.proxy(function(){c.remove(),e.each(a.proxy(function(b,c){this.move_widget_up(a(c),d.size_y)},this))},this))},i.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},i.serialize_changed=function(){return this.serialize(this.$changed)},i.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 a.data("coords",a.coords()),a.data("coords").grid=b,this.add_to_gridmap(b,a),this.widgets.push(a),this},i.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},i.remove_from_gridmap=function(a){return this.update_widget_position(a,!1)},i.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))}},i.draggable=function(){var b=this,c=a.extend(!0,{},this.options.draggable,{start:function(c,d){b.$player=a(this),b.$helper=b.options.draggable.helper==="clone"?a(d.helper):b.$player,b.on_start_drag.call(b,c,d)},stop:function(a,c){b.on_stop_drag.call(b,c)},drag:g(function(a,c){b.on_drag.call(b,a,c)},100,!0)});return this.$widgets.draggable(c),this},i.on_start_drag=function(b,c){this.$player.addClass("player"),this.$wrapper.addClass("dragging"),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.drag_api=this.$helper.collision(d,this.options.collision),this.$preview_holder=a("
  • ",{"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)},i.on_drag=function(a,b){this.colliders_data=this.drag_api.get_closest_colliders(),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.options.draggable.drag&&this.options.draggable.drag.call(this,a,b)},i.on_stop_drag=function(a,b){this.colliders_data=this.drag_api.get_closest_colliders(),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.add(this.$helper).attr({"data-col":this.placeholder_grid_data.col,"data-row":this.placeholder_grid_data.row}).css({left:"",top:""}).removeClass("player"),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)},i.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;gb.row?1:-1}),a},i.sort_by_row_desc=function(a){return a=a.sort(function(a,b){return a.row+a.size_y=0&&a.inArray(c,d.rows)>=0},i.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},i.is_placeholder_in_col=function(b){return a.inArray(b,this.cells_occupied_by_placeholder.cols)>=0},i.is_empty=function(a,b){return typeof this.gridmap[a]!="undefined"&&typeof this.gridmap[a][b]!="undefined"&&this.gridmap[a][b]===!1?!0:!1},i.is_occupied=function(a,b){return this.gridmap[a]?this.gridmap[a][b]?!0:!1:!1},i.is_widget=function(a,b){var c=this.gridmap[a];return c?(c=c[b],c?c:!1):!1},i.is_widget_under_player=function(a,b){return this.is_widget(a,b)?this.is_player_in(a,b):!1},i.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},i.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=this.placeholder_grid_data.row0)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=h0){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=b?a[d[0]]:!1},i.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},i.on_start_overlapping_column=function(a){this.set_player(a,!1)},i.on_start_overlapping_row=function(a){this.set_player(!1,a)},i.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)})},i.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;d0&&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)}},i.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;i0?c:0},i.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)},i.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},i.empty_cells_player_occupies=function(){return this.remove_from_gridmap(this.placeholder_grid_data),this},i.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)},i.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=this.get_cells_occupied(a),h=!0;return this.for_each_cell_occupied(f,function(a,b){var c=this.is_widget(a,b);c&&!c.is(e)&&(h=!1)}),h},i.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},i.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},i.get_cells_occupied=function(a){var b={cols:[],rows:[]},c;arguments[1]instanceof jQuery&&(a=arguments[1].coords().grid);for(c=0;c0&&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=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},i.set_dom_grid_height=function(){var a=this.get_highest_occupied_cell().row;return this.$el.css("height",a*this.min_widget_height),this},i.generate_stylesheet=function(a,b){var c="",d=10,e=6,f=6,g,h;for(g=b+d;g>=0;g--)c+='[data-col="'+(g+1)+'"] { left: '+g*this.min_widget_width+"px;} ";for(g=a+d;g>=0;g--)c+='[data-row="'+(g+1)+'"] { top: '+g*this.min_widget_height+"px;} ";for(var i=1;i0;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},i.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},i.get_widgets_from_DOM=function(){return this.$widgets.each(a.proxy(function(b,c){this.register_widget(a(c))},this)),this},i.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 e=Math.max(i,e,this.options.min_cols),f=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(f,e),this.generate_faux_grid(f,e)},a.fn.gridster=function(b){return this.each(function(){a(this).data("gridster")||a(this).data("gridster",new h(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(){var a=this.el;a&&(this.data=a.offset(),this.data.width||(this.data.width=a.width()),this.data.height||(this.data.height=a.height()));var b=this.data;return this.coords.x1=b.left,this.coords.y1=b.top,this.coords.x2=b.left+b.width,this.coords.y2=b.top+b.height,this.coords.cx=b.left+b.width/2,this.coords.cy=b.top+b.height/2,this.coords.width=b.width,this.coords.height=b.height,this.coords.el=a||!1,this},f.update=function(b){if(!b&&!this.el)return this;if(b){var c=a.extend(this.data,b);this.data=c}return this.set(),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.y1b.y1&&a.y2b.cx&&a.x1b.x1&&a.x2 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,serialize_params:function(a,b){return{col:b.col,row:b.row}},collision:{},draggable:{}},f=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)}},g=function(a,b){var c,d,e,g,h,i,j=f(function(){h=g=!1},b,!0);return function(){c=this,d=arguments;var f=function(){e=null,h&&a.apply(c,d),j()};return e||(e=setTimeout(f,b)),g?h=!0:i=a.apply(c,d),j(),g=!0,i}},i=h.prototype;i.init=function(){this.generate_grid_and_stylesheet(),this.get_widgets_from_DOM(),this.set_dom_grid_height(),this.$wrapper.addClass("ready"),this.draggable(),this.next_position(2,2),a(b).bind("resize",g(a.proxy(this.recalculate_faux_grid,this),200))},i.add_widget=function(b,c,d){var e=a(b).attr({"data-col":this.highest_occupied_cell.col,"data-row":this.highest_occupied_cell.row+1,"data-sizex":c||1,"data-sizey":d||1}).addClass("gs_w").appendTo(this.$el).hide();this.$widgets=this.$widgets.add(e),this.register_widget(e),this.$widgets.draggable("destroy"),this.draggable(),this.set_dom_grid_height(),e.fadeIn()},i.next_position=function(a,b){var c=this.gridmap,d=c.length,e=[];for(var f=1;f",{"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)},i.on_drag=function(a,b){this.colliders_data=this.drag_api.get_closest_colliders(),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.options.draggable.drag&&this.options.draggable.drag.call(this,a,b)},i.on_stop_drag=function(a,b){this.colliders_data=this.drag_api.get_closest_colliders(),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.add(this.$helper).attr({"data-col":this.placeholder_grid_data.col,"data-row":this.placeholder_grid_data.row}).css({left:"",top:""}).removeClass("player"),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)},i.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;gb.row?1:-1}),a},i.sort_by_row_desc=function(a){return a=a.sort(function(a,b){return a.row+a.size_y=0&&a.inArray(c,d.rows)>=0},i.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},i.is_placeholder_in_col=function(b){return a.inArray(b,this.cells_occupied_by_placeholder.cols)>=0},i.is_empty=function(a,b){return typeof this.gridmap[a]!="undefined"&&typeof this.gridmap[a][b]!="undefined"&&this.gridmap[a][b]===!1?!0:!1},i.is_occupied=function(a,b){return this.gridmap[a]?this.gridmap[a][b]?!0:!1:!1},i.is_widget=function(a,b){var c=this.gridmap[a];return c?(c=c[b],c?c:!1):!1},i.is_widget_under_player=function(a,b){return this.is_widget(a,b)?this.is_player_in(a,b):!1},i.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},i.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=this.placeholder_grid_data.row0)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=h0){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=b?a[d[0]]:!1},i.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},i.on_start_overlapping_column=function(a){this.set_player(a,!1)},i.on_start_overlapping_row=function(a){this.set_player(!1,a)},i.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)})},i.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;d0&&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)}},i.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;i0?c:0},i.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)},i.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},i.empty_cells_player_occupies=function(){return this.remove_from_gridmap(this.placeholder_grid_data),this},i.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)},i.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=this.get_cells_occupied(a),h=!0;return this.for_each_cell_occupied(f,function(a,b){var c=this.is_widget(a,b);c&&!c.is(e)&&(h=!1)}),h},i.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},i.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},i.get_cells_occupied=function(a){var b={cols:[],rows:[]},c;arguments[1]instanceof jQuery&&(a=arguments[1].coords().grid);for(c=0;c0&&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=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},i.set_dom_grid_height=function(){var a=this.get_highest_occupied_cell().row;return this.$el.css("height",a*this.min_widget_height),this},i.generate_stylesheet=function(a,b){var c="",d=10,e=6,f=6,g,h;for(g=b+d;g>=0;g--)c+='[data-col="'+(g+1)+'"] { left: '+g*this.min_widget_width+"px;} ";for(g=a+d;g>=0;g--)c+='[data-row="'+(g+1)+'"] { top: '+g*this.min_widget_height+"px;} ";for(var i=1;i0;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},i.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},i.get_widgets_from_DOM=function(){return this.$widgets.each(a.proxy(function(b,c){this.register_widget(a(c))},this)),this},i.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 e=Math.max(i,e,this.options.min_cols),f=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(f,e),this.generate_faux_grid(f,e)},a.fn.gridster=function(b){return this.each(function(){a(this).data("gridster")||a(this).data("gridster",new h(this,b))})}}(jQuery,window,document); \ No newline at end of file diff --git a/docs/classes/Gridster.html b/docs/classes/Gridster.html index 2c88e919c3..046a90ab06 100644 --- a/docs/classes/Gridster.html +++ b/docs/classes/Gridster.html @@ -693,6 +693,13 @@ +
  • + +
  • + next_position + + +
  • @@ -925,7 +932,7 @@ - src/jquery.gridster.js:1829 + src/jquery.gridster.js:1871

    @@ -1035,7 +1042,7 @@ - src/jquery.gridster.js:293 + src/jquery.gridster.js:335

    @@ -1168,7 +1175,7 @@ - src/jquery.gridster.js:140 + src/jquery.gridster.js:141

    @@ -1303,7 +1310,7 @@ - src/jquery.gridster.js:925 + src/jquery.gridster.js:967

    @@ -1421,7 +1428,7 @@ - src/jquery.gridster.js:1332 + src/jquery.gridster.js:1374

    @@ -1558,7 +1565,7 @@ upper row possible.

    - src/jquery.gridster.js:974 + src/jquery.gridster.js:1016

    @@ -1676,7 +1683,7 @@ upper row possible.

    - src/jquery.gridster.js:1504 + src/jquery.gridster.js:1546

    @@ -1803,7 +1810,7 @@ into account the dimensions (size_y and size_x attrs. - src/jquery.gridster.js:315 + src/jquery.gridster.js:357

    @@ -1874,7 +1881,7 @@ into account the dimensions (size_y and size_x attrs. - src/jquery.gridster.js:1467 + src/jquery.gridster.js:1509

    @@ -1961,7 +1968,7 @@ into account the dimensions (size_y and size_x attrs. - src/jquery.gridster.js:1602 + src/jquery.gridster.js:1644

    @@ -2089,7 +2096,7 @@ each one.

    - src/jquery.gridster.js:1623 + src/jquery.gridster.js:1665

    @@ -2217,7 +2224,7 @@ each one.

    - src/jquery.gridster.js:1642 + src/jquery.gridster.js:1684

    @@ -2350,7 +2357,7 @@ each one.

    - src/jquery.gridster.js:1708 + src/jquery.gridster.js:1750

    @@ -2497,7 +2504,7 @@ iteration. The value of this inside the function is the jQuery wrap - src/jquery.gridster.js:1724 + src/jquery.gridster.js:1766

    @@ -2638,7 +2645,7 @@ iteration. The value of this inside the function is the jQuery wrap - src/jquery.gridster.js:1852 + src/jquery.gridster.js:1894

    @@ -2748,7 +2755,7 @@ detect row or column that we want to go.

    - src/jquery.gridster.js:1926 + src/jquery.gridster.js:1968

    @@ -2836,7 +2843,7 @@ detect row or column that we want to go.

    - src/jquery.gridster.js:1785 + src/jquery.gridster.js:1827

    @@ -2955,7 +2962,7 @@ detect row or column that we want to go.

    - src/jquery.gridster.js:1574 + src/jquery.gridster.js:1616

    @@ -3049,7 +3056,7 @@ detect row or column that we want to go.

    - src/jquery.gridster.js:1740 + src/jquery.gridster.js:1782

    @@ -3130,7 +3137,7 @@ detect row or column that we want to go.

    - src/jquery.gridster.js:1539 + src/jquery.gridster.js:1581

    @@ -3235,7 +3242,7 @@ detect row or column that we want to go.

    - src/jquery.gridster.js:1557 + src/jquery.gridster.js:1599

    @@ -3352,7 +3359,7 @@ detect row or column that we want to go.

    - src/jquery.gridster.js:1025 + src/jquery.gridster.js:1067

    @@ -3480,7 +3487,7 @@ theupperrowsarray. Iteration starts from row specified insrc/jquery.gridster.js:1912 + src/jquery.gridster.js:1954

    @@ -3551,7 +3558,7 @@ theupperrowsarray. Iteration starts from row specified insrc/jquery.gridster.js:1103 + src/jquery.gridster.js:1145

    @@ -3622,7 +3629,7 @@ theupperrowsarray. Iteration starts from row specified insrc/jquery.gridster.js:861 + src/jquery.gridster.js:903

    @@ -3709,7 +3716,7 @@ theupperrowsarray. Iteration starts from row specified insrc/jquery.gridster.js:780 + src/jquery.gridster.js:822

    @@ -3834,7 +3841,7 @@ theupperrowsarray. Iteration starts from row specified insrc/jquery.gridster.js:799 + src/jquery.gridster.js:841

    @@ -3959,7 +3966,7 @@ theupperrowsarray. Iteration starts from row specified insrc/jquery.gridster.js:754 + src/jquery.gridster.js:796

    @@ -4078,7 +4085,7 @@ theupperrowsarray. Iteration starts from row specified insrc/jquery.gridster.js:768 + src/jquery.gridster.js:810

    @@ -4188,7 +4195,7 @@ theupperrowsarray. Iteration starts from row specified insrc/jquery.gridster.js:722 + src/jquery.gridster.js:764

    @@ -4316,7 +4323,7 @@ HTMLElements.

    - src/jquery.gridster.js:739 + src/jquery.gridster.js:781

    @@ -4442,7 +4449,7 @@ and col given.

    - src/jquery.gridster.js:819 + src/jquery.gridster.js:861

    @@ -4568,7 +4575,7 @@ else returns the jQuery HTMLElement - src/jquery.gridster.js:844 + src/jquery.gridster.js:886

    @@ -4700,7 +4707,7 @@ params and if this is under the widget that is being dragged.

    - src/jquery.gridster.js:676 + src/jquery.gridster.js:718

    @@ -4842,7 +4849,7 @@ each widget) in descending way.

    - src/jquery.gridster.js:1287 + src/jquery.gridster.js:1329

    @@ -4961,7 +4968,7 @@ each widget) in descending way.

    - src/jquery.gridster.js:1198 + src/jquery.gridster.js:1240

    @@ -5073,7 +5080,7 @@ if they can.

    - src/jquery.gridster.js:1241 + src/jquery.gridster.js:1283

    @@ -5144,6 +5151,132 @@ if they can.

    + + + +
    +

    next_position

    + + +
    + (
      + +
    • + + size_x + +
    • + +
    • + + size_y + +
    • + +
    ) +
    + + + + + Object + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/jquery.gridster.js:172 + +

    + + + + + +
    + +
    +

    Get the most left column below to add a new widget.

    +
    + + +
    +

    Parameters:

    + +
      + +
    • + + size_x + Number + + + + +
      +

      The nº of rows the widget occupies horizontally.

      +
      + + +
    • + +
    • + + size_y + Number + + + + +
      +

      The nº of columns the widget occupies vertically.

      +
      + + +
    • + +
    +
    + + + +
    +

    Returns:

    + +
    + + + Object: + + Returns a grid coords object representing the future + widget coords. + +
    +
    + + +
    @@ -5195,7 +5328,7 @@ if they can.

    - src/jquery.gridster.js:395 + src/jquery.gridster.js:437

    @@ -5308,7 +5441,7 @@ if they can.

    - src/jquery.gridster.js:472 + src/jquery.gridster.js:514

    @@ -5436,7 +5569,7 @@ overlapped or stops being overlapped.

    - src/jquery.gridster.js:512 + src/jquery.gridster.js:554

    @@ -5560,7 +5693,7 @@ overlapped or stops being overlapped.

    - src/jquery.gridster.js:346 + src/jquery.gridster.js:388

    @@ -5667,7 +5800,7 @@ overlapped or stops being overlapped.

    - src/jquery.gridster.js:1136 + src/jquery.gridster.js:1178

    @@ -5771,7 +5904,7 @@ overlapped or stops being overlapped.

    - src/jquery.gridster.js:1148 + src/jquery.gridster.js:1190

    @@ -5877,7 +6010,7 @@ overlapped or stops being overlapped.

    - src/jquery.gridster.js:421 + src/jquery.gridster.js:463

    @@ -5984,7 +6117,7 @@ overlapped or stops being overlapped.

    - src/jquery.gridster.js:1160 + src/jquery.gridster.js:1202

    @@ -6088,7 +6221,7 @@ overlapped or stops being overlapped.

    - src/jquery.gridster.js:1178 + src/jquery.gridster.js:1220

    @@ -6182,7 +6315,7 @@ overlapped or stops being overlapped.

    - src/jquery.gridster.js:1888 + src/jquery.gridster.js:1930

    @@ -6254,7 +6387,7 @@ the browser is resized.

    - src/jquery.gridster.js:231 + src/jquery.gridster.js:273

    @@ -6336,7 +6469,7 @@ mapped array of positions.

    - src/jquery.gridster.js:280 + src/jquery.gridster.js:322

    @@ -6441,7 +6574,7 @@ mapped array of positions.

    - src/jquery.gridster.js:171 + src/jquery.gridster.js:213

    @@ -6545,7 +6678,7 @@ mapped array of positions.

    - src/jquery.gridster.js:197 + src/jquery.gridster.js:239

    @@ -6643,7 +6776,7 @@ mapped array of positions.

    - src/jquery.gridster.js:219 + src/jquery.gridster.js:261

    @@ -6731,7 +6864,7 @@ mapped array of positions.

    - src/jquery.gridster.js:1450 + src/jquery.gridster.js:1492

    @@ -6840,7 +6973,7 @@ mapped array of positions.

    - src/jquery.gridster.js:1772 + src/jquery.gridster.js:1814

    @@ -6927,7 +7060,7 @@ mapped array of positions.

    - src/jquery.gridster.js:883 + src/jquery.gridster.js:925

    @@ -7054,7 +7187,7 @@ mapped array of positions.

    - src/jquery.gridster.js:548 + src/jquery.gridster.js:590

    @@ -7175,7 +7308,7 @@ mapped array of positions.

    - src/jquery.gridster.js:637 + src/jquery.gridster.js:679

    @@ -7280,7 +7413,7 @@ each widget) in ascending way.

    - src/jquery.gridster.js:657 + src/jquery.gridster.js:699

    @@ -7391,7 +7524,7 @@ each widget) in descending way.

    - src/jquery.gridster.js:259 + src/jquery.gridster.js:301

    @@ -7514,7 +7647,7 @@ the grid coords object passed in the grid_data param.

    - src/jquery.gridster.js:1421 + src/jquery.gridster.js:1463

    @@ -7618,7 +7751,7 @@ the grid coords object passed in the grid_data param.

    - src/jquery.gridster.js:601 + src/jquery.gridster.js:643

    diff --git a/docs/data.json b/docs/data.json index 9b67032d55..bcbfc4e14d 100644 --- a/docs/data.json +++ b/docs/data.json @@ -215,7 +215,7 @@ "classitems": [ { "file": "src/jquery.gridster.js", - "line": 140, + "line": 141, "description": "Add a new widget to the grid.", "itemtype": "method", "name": "add_widget", @@ -244,7 +244,31 @@ }, { "file": "src/jquery.gridster.js", - "line": 171, + "line": 172, + "description": "Get the most left column below to add a new widget.", + "itemtype": "method", + "name": "next_position", + "params": [ + { + "name": "size_x", + "description": "The nº of rows the widget occupies horizontally.", + "type": "Number" + }, + { + "name": "size_y", + "description": "The nº of columns the widget occupies vertically.", + "type": "Number" + } + ], + "return": { + "description": "Returns a grid coords object representing the future\n widget coords.", + "type": "Object" + }, + "class": "Gridster" + }, + { + "file": "src/jquery.gridster.js", + "line": 213, "description": "Remove a widget from the grid.", "itemtype": "method", "name": "remove_widget", @@ -263,7 +287,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 197, + "line": 239, "description": "Returns a serialized array of the widgets in the grid.", "itemtype": "method", "name": "serialize", @@ -283,7 +307,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 219, + "line": 261, "description": "Returns a serialized array of the widgets that have changed their position.", "itemtype": "method", "name": "serialize_changed", @@ -295,7 +319,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 231, + "line": 273, "description": "Creates the grid coords object representing the widget a add it to the\nmapped array of positions.", "itemtype": "method", "name": "register_widget", @@ -307,7 +331,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 259, + "line": 301, "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": [ { @@ -331,7 +355,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 280, + "line": 322, "description": "Remove a widget from the mapped array of positions.", "itemtype": "method", "name": "remove_from_gridmap", @@ -350,7 +374,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 293, + "line": 335, "description": "Add a widget to the mapped array of positions.", "itemtype": "method", "name": "add_to_gridmap", @@ -374,7 +398,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 315, + "line": 357, "description": "Make widgets draggable. It Wraps the jQuery UI Draggable Plugin.", "itemtype": "method", "name": "draggable", @@ -386,7 +410,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 346, + "line": 388, "description": "This function is executed when the player begins to be dragged.", "itemtype": "method", "name": "on_start_drag", @@ -406,7 +430,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 395, + "line": 437, "description": "This function is executed when the player is being dragged.", "itemtype": "method", "name": "on_drag", @@ -426,7 +450,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 421, + "line": 463, "description": "This function is executed when the player stops being dragged.", "itemtype": "method", "name": "on_stop_drag", @@ -446,7 +470,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 472, + "line": 514, "description": "Executes the callbacks passed as arguments when a column begins to be\noverlapped or stops being overlapped.", "params": [ { @@ -470,7 +494,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 512, + "line": 554, "description": "Executes the callbacks passed as arguments when a row starts to be\noverlapped or stops being overlapped.", "params": [ { @@ -494,7 +518,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 548, + "line": 590, "description": "Sets the current position of the player", "params": [ { @@ -518,7 +542,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 601, + "line": 643, "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", @@ -537,7 +561,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 637, + "line": 679, "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", @@ -556,7 +580,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 657, + "line": 699, "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", @@ -575,7 +599,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 676, + "line": 718, "description": "Sorts an Array of grid coords objects (representing the grid coords of\neach widget) in descending way.", "itemtype": "method", "name": "manage_movements", @@ -604,7 +628,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 722, + "line": 764, "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", @@ -629,7 +653,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 739, + "line": 781, "description": "Determines if the widget that is being dragged is currently over the row\nand col given.", "itemtype": "method", "name": "is_player_in", @@ -653,7 +677,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 754, + "line": 796, "description": "Determines if the placeholder is currently over the row and col given.", "itemtype": "method", "name": "is_placeholder_in", @@ -677,7 +701,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 768, + "line": 810, "description": "Determines if the placeholder is currently over the column given.", "itemtype": "method", "name": "is_placeholder_in_col", @@ -696,7 +720,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 780, + "line": 822, "description": "Determines if the cell represented by col and row params is empty.", "itemtype": "method", "name": "is_empty", @@ -720,7 +744,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 799, + "line": 841, "description": "Determines if the cell represented by col and row params is occupied.", "itemtype": "method", "name": "is_occupied", @@ -744,7 +768,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 819, + "line": 861, "description": "Determines if there is a widget in the cell represented by col/row params.", "itemtype": "method", "name": "is_widget", @@ -768,7 +792,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 844, + "line": 886, "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", @@ -792,7 +816,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 861, + "line": 903, "description": "Get widgets overlapping with the player.", "itemtype": "method", "name": "get_widgets_under_player", @@ -804,7 +828,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 883, + "line": 925, "description": "Put placeholder at the row and column specified.", "itemtype": "method", "name": "set_placeholder", @@ -828,7 +852,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 925, + "line": 967, "description": "Determines whether the player can move to a position above.", "itemtype": "method", "name": "can_go_player_up", @@ -847,7 +871,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 974, + "line": 1016, "description": "Determines whether a widget can move to a position above.", "itemtype": "method", "name": "can_go_widget_up", @@ -866,7 +890,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1025, + "line": 1067, "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", @@ -895,7 +919,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1103, + "line": 1145, "description": "Get widgets overlapping with the player.", "itemtype": "method", "name": "get_widgets_overlapped", @@ -907,7 +931,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1136, + "line": 1178, "description": "This callback is executed when the player begins to collide with a column.", "itemtype": "method", "name": "on_start_overlapping_column", @@ -926,7 +950,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1148, + "line": 1190, "description": "A callback executed when the player begins to collide with a row.", "itemtype": "method", "name": "on_start_overlapping_row", @@ -945,7 +969,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1160, + "line": 1202, "description": "A callback executed when the the player ends to collide with a column.", "itemtype": "method", "name": "on_stop_overlapping_column", @@ -964,7 +988,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1178, + "line": 1220, "description": "This callback is executed when the player ends to collide with a row.", "itemtype": "method", "name": "on_stop_overlapping_row", @@ -983,7 +1007,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1198, + "line": 1240, "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", @@ -1002,7 +1026,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1241, + "line": 1283, "description": "Move up the specified widget and all below it.", "itemtype": "method", "name": "move_widget_up", @@ -1027,7 +1051,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1287, + "line": 1329, "description": "Move down the specified widget and all below it.", "itemtype": "method", "name": "move_widget_down", @@ -1051,7 +1075,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1332, + "line": 1374, "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", @@ -1080,7 +1104,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1421, + "line": 1463, "description": "Get widgets below a widget.", "itemtype": "method", "name": "widgets_below", @@ -1099,7 +1123,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1450, + "line": 1492, "description": "Update the array of mapped positions with the new player position.", "itemtype": "method", "name": "set_cells_player_occupies", @@ -1123,7 +1147,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1467, + "line": 1509, "description": "Remove from the array of mapped positions the reference to the player.", "itemtype": "method", "name": "empty_cells_player_occupies", @@ -1135,7 +1159,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1504, + "line": 1546, "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.", "itemtype": "method", "name": "can_move_to", @@ -1164,7 +1188,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1539, + "line": 1581, "description": "Given the leftmost column returns all columns that are overlapping with the player.", "itemtype": "method", "name": "get_targeted_columns", @@ -1184,7 +1208,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1557, + "line": 1599, "description": "Given the upper row returns all rows that are overlapping with the player.", "itemtype": "method", "name": "get_targeted_rows", @@ -1204,7 +1228,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1574, + "line": 1616, "description": "Get all columns and rows that a widget occupies.", "itemtype": "method", "name": "get_cells_occupied", @@ -1223,7 +1247,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1602, + "line": 1644, "description": "Iterate over the cells occupied by a widget executing a function for\neach one.", "itemtype": "method", "name": "for_each_cell_occupied", @@ -1247,7 +1271,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1623, + "line": 1665, "description": "Iterate over the columns occupied by a widget executing a function for\neach one.", "itemtype": "method", "name": "for_each_column_occupied", @@ -1271,7 +1295,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1642, + "line": 1684, "description": "Iterate over the rows occupied by a widget executing a function for\neach one.", "itemtype": "method", "name": "for_each_row_occupied", @@ -1295,7 +1319,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1708, + "line": 1750, "description": "Iterate over each widget above the column and row specified.", "itemtype": "method", "name": "for_each_widget_above", @@ -1324,7 +1348,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1724, + "line": 1766, "description": "Iterate over each widget below the column and row specified.", "itemtype": "method", "name": "for_each_widget_below", @@ -1353,7 +1377,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1740, + "line": 1782, "description": "Returns the highest occupied cell in the grid.", "itemtype": "method", "name": "get_highest_occupied_cell", @@ -1365,7 +1389,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1772, + "line": 1814, "description": "Set the current height of the parent grid.", "itemtype": "method", "name": "set_dom_grid_height", @@ -1377,7 +1401,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1785, + "line": 1827, "description": "It generates the neccessary styles to position the widgets.", "itemtype": "method", "name": "generate_stylesheet", @@ -1401,7 +1425,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1829, + "line": 1871, "description": "Injects the given CSS as string to the head of the document.", "itemtype": "method", "name": "add_style_tag", @@ -1420,7 +1444,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1852, + "line": 1894, "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", @@ -1444,7 +1468,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1888, + "line": 1930, "description": "Recalculates the offsets for the faux grid. You need to use it when\nthe browser is resized.", "itemtype": "method", "name": "recalculate_faux_grid", @@ -1456,7 +1480,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1912, + "line": 1954, "description": "Get all widgets in the DOM and register them.", "itemtype": "method", "name": "get_widgets_from_DOM", @@ -1468,7 +1492,7 @@ }, { "file": "src/jquery.gridster.js", - "line": 1926, + "line": 1968, "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.gridster.js.html b/docs/files/src_jquery.gridster.js.html index 3f02ab798b..f97e074b82 100644 --- a/docs/files/src_jquery.gridster.js.html +++ b/docs/files/src_jquery.gridster.js.html @@ -224,6 +224,7 @@ this.set_dom_grid_height(); this.$wrapper.addClass('ready'); this.draggable(); + this.next_position(2, 2); $(window).bind( 'resize', throttle($.proxy(this.recalculate_faux_grid, this), 200)); @@ -261,6 +262,47 @@ }; + /** + * Get the most left column below to add a new widget. + * + * @method next_position + * @param {Number} size_x The nº of rows the widget occupies horizontally. + * @param {Number} size_y The nº of columns the widget occupies vertically. + * @return {Object} Returns a grid coords object representing the future + * widget coords. + */ + fn.next_position = function(size_x, size_y) { + var ga = this.gridmap; + var cols_l = ga.length; + var valid_pos = []; + + for (var c = 1; c < cols_l; c++) { + var rows_l = ga[c].length; + for (var r = 1; r <= rows_l; r++) { + var can_move_to = this.can_move_to({ + size_x: size_x, + size_y: size_y + }, c, r); + + if (can_move_to) { + valid_pos.push({ + col: c, + row: r, + size_y: size_y, + size_x: size_x + }); + } + } + } + + if (valid_pos.length) { + this.next_position = this.sort_by_row_asc(valid_pos)[0]; + return this.next_position; + } + return false; + }; + + /** * Remove a widget from the grid. *