Gridster Class
Constructor
Gridster
-
el
-
[options]
Parameters:
-
el
HTMLElementThe HTMLelement that contains all the widgets.
-
[options]
Object optionalAn Object with all options you want to overwrite:
-
[widget_selector]
HTMLElement | String optionalDefine who will be the draggable widgets. Can be a CSS Selector String or a collection of HTMLElements
-
[widget_margins]
Array optionalMargin between widgets. The first index for the horizontal margin (left, right) and the second for the vertical margin (top, bottom).
-
[widget_base_dimensions]
Array optionalBase widget dimensions in pixels. The first index for the width and the second for the height.
-
[extra_cols]
Number optionalAdd more columns in addition to those that have been calculated.
-
[extra_rows]
Number optionalAdd more rows in addition to those that have been calculated.
-
[min_cols]
Number optionalThe minimum required columns.
-
[min_rows]
Number optionalThe minimum required rows.
-
[autogenerate_stylesheet]
Boolean optionalIf true, all the CSS required to position all widgets in their respective columns and rows will be generated automatically and injected to the
<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; }
-
[serialize_params]
Function optionalReturn the data you want for each widget in the serialization. Two arguments are passed:
$w
: the jQuery wrapped HTMLElement, andwgd
: the grid coords object (col
,row
,size_x
,size_y
). -
[collision]
Object optionalAn Object with all options for Collision class you want to overwrite. See Collision docs for more info.
-
[draggable]
Object optionalAn Object with all options for jQuery UI Draggable you want to overwrite. See http://jqueryui.com/demos/draggable/ for more info.
-
Item Index
Methods
- add_style_tag
- add_to_gridmap
- add_widget
- can_go_player_up
- can_go_up_to_row
- can_go_widget_up
- can_move_to
- draggable
- empty_cells_player_occupies
- for_each_cell_occupied
- for_each_column_occupied
- for_each_row_occupied
- for_each_widget_above
- for_each_widget_below
- generate_faux_grid
- generate_grid_and_stylesheet
- generate_stylesheet
- get_cells_occupied
- get_highest_occupied_cell
- get_targeted_columns
- get_targeted_rows
- get_valid_rows
- get_widgets_from_DOM
- get_widgets_overlapped
- get_widgets_under_player
- is_empty
- is_occupied
- is_placeholder_in
- is_placeholder_in_col
- is_player
- is_player_in
- is_widget
- is_widget_under_player
- manage_movements
- move_widget_down
- move_widget_to
- move_widget_up
- next_position
- on_drag
- on_overlapped_column_change
- on_overlapped_row_change
- on_start_drag
- on_start_overlapping_column
- on_start_overlapping_row
- on_stop_drag
- on_stop_overlapping_column
- on_stop_overlapping_row
- recalculate_faux_grid
- register_widget
- remove_from_gridmap
- remove_widget
- serialize
- serialize_changed
- set_cells_player_occupies
- set_dom_grid_height
- set_placeholder
- set_player
- sort_by_row_asc
- sort_by_row_asc
- sort_by_row_desc
- update_widget_position
- widgets_below
- widgets_contraints
Methods
add_style_tag
-
css
Injects the given CSS as string to the head of the document.
Parameters:
-
css
StringThe styles to apply.
Returns:
add_to_gridmap
-
grid_data
-
value
Add a widget to the mapped array of positions.
Parameters:
-
grid_data
ObjectThe grid coords object representing the cells to update in the mapped array.
-
value
HTMLElement | BooleanThe value to set in the specified position .
Returns:
add_widget
-
html
-
size_x
-
size_y
Add a new widget to the grid.
Parameters:
-
html
StringThe string representing the HTML of the widget.
-
size_x
NumberThe nº of rows the widget occupies horizontally.
-
size_y
NumberThe nº of columns the widget occupies vertically.
Returns:
can_go_player_up
-
widget_grid_data
Determines whether the player can move to a position above.
Parameters:
-
widget_grid_data
ObjectThe actual grid coords object of the player.
Returns:
can_go_up_to_row
-
widget_grid_data
-
col
-
row
Check if the widget can move to the specified row, else returns the upper row possible.
Parameters:
-
widget_grid_data
NumberThe current grid coords object of the widget.
-
col
NumberThe target column.
-
row
NumberThe target row.
Returns:
can_go_widget_up
-
widget_grid_data
Determines whether a widget can move to a position above.
Parameters:
-
widget_grid_data
ObjectThe actual grid coords object of the widget we want to check.
Returns:
can_move_to
-
widget_grid_data
-
The
-
The
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.
Parameters:
-
widget_grid_data
ObjectThe grid coords object that represents the widget.
-
The
Objectcol target col.
-
The
Objectrow target row.
Returns:
draggable
()
Class
Make widgets draggable. It Wraps the jQuery UI Draggable Plugin.
Returns:
empty_cells_player_occupies
()
Class
Remove from the array of mapped positions the reference to the player.
Returns:
for_each_cell_occupied
-
el_grid_data
-
callback
Iterate over the cells occupied by a widget executing a function for each one.
Parameters:
-
el_grid_data
ObjectThe grid coords object that represents the widget.
-
callback
FunctionThe function to execute on each column iteration. Column and row are passed as arguments.
Returns:
for_each_column_occupied
-
el_grid_data
-
callback
Iterate over the columns occupied by a widget executing a function for each one.
Parameters:
-
el_grid_data
ObjectThe grid coords object that represents the widget.
-
callback
FunctionThe function to execute on each column iteration. The column number is passed as first argument.
Returns:
for_each_row_occupied
-
el_grid_data
-
callback
Iterate over the rows occupied by a widget executing a function for each one.
Parameters:
-
el_grid_data
ObjectThe grid coords object that represents the widget.
-
callback
FunctionThe function to execute on each column iteration. The row number is passed as first argument.
Returns:
for_each_widget_above
-
col
-
row
-
callback
Iterate over each widget above the column and row specified.
Parameters:
-
col
NumberThe column to start iterating.
-
row
NumberThe row to start iterating.
-
callback
FunctionThe function to execute on each widget iteration. The value of
this
inside the function is the jQuery wrapped HTMLElement.
Returns:
for_each_widget_below
-
col
-
row
-
callback
Iterate over each widget below the column and row specified.
Parameters:
-
col
NumberThe column to start iterating.
-
row
NumberThe row to start iterating.
-
callback
FunctionThe function to execute on each widget iteration. The value of
this
inside the function is the jQuery wrapped HTMLElement.
Returns:
generate_faux_grid
-
rows
-
cols
Generates a faux grid to collide with it when a widget is dragged and detect row or column that we want to go.
Parameters:
-
rows
NumberNumber of columns.
-
cols
NumberNumber of rows.
Returns:
generate_grid_and_stylesheet
()
Object
Calculate columns and rows to be set based on the configuration parameters, grid dimensions, etc ...
Returns:
generate_stylesheet
-
rows
-
cols
It generates the neccessary styles to position the widgets.
Parameters:
-
rows
NumberNumber of columns.
-
cols
NumberNumber of rows.
Returns:
get_cells_occupied
-
el_grid_data
Get all columns and rows that a widget occupies.
Parameters:
-
el_grid_data
ObjectThe grid coords object of the widget.
Returns:
{ cols: [], rows: []}
.
get_highest_occupied_cell
()
Object
Returns the highest occupied cell in the grid.
Returns:
col
and row
numbers.
get_targeted_columns
-
[from_col]
Given the leftmost column returns all columns that are overlapping with the player.
Parameters:
-
[from_col]
Number optionalThe leftmost column.
Returns:
get_targeted_rows
-
[from_row]
Given the upper row returns all rows that are overlapping with the player.
Parameters:
-
[from_row]
Number optionalThe upper row.
Returns:
get_valid_rows
-
widget_grid_data
-
upper_rows
-
min_row
Search a valid row for the widget represented by widget_grid_data' in
the
upperrowsarray. Iteration starts from row specified in
minrow`.
Parameters:
-
widget_grid_data
ObjectThe actual grid coords object of the player.
-
upper_rows
ArrayAn array with columns as index and arrays of valid rows as values.
-
min_row
NumberThe upper row from which the iteration will start.
Returns:
upper_rows
for the widget in question.
get_widgets_from_DOM
()
Object
Get all widgets in the DOM and register them.
Returns:
get_widgets_overlapped
()
HTMLElements
Get widgets overlapping with the player.
Returns:
get_widgets_under_player
()
HTMLElement
Get widgets overlapping with the player.
Returns:
is_empty
-
col
-
row
Determines if the cell represented by col and row params is empty.
Parameters:
-
col
NumberThe column to check.
-
row
NumberThe row to check.
Returns:
is_occupied
-
col
-
row
Determines if the cell represented by col and row params is occupied.
Parameters:
-
col
NumberThe column to check.
-
row
NumberThe row to check.
Returns:
is_placeholder_in
-
col
-
row
Determines if the placeholder is currently over the row and col given.
Parameters:
-
col
NumberThe column to check.
-
row
NumberThe row to check.
Returns:
is_placeholder_in_col
-
col
Determines if the placeholder is currently over the column given.
Parameters:
-
col
NumberThe column to check.
Returns:
is_player
-
col_or_el
-
[row]
Determines if there is a widget in the row and col given. Or if the HTMLElement passed as first argument is the player.
Parameters:
-
col_or_el
Number | HTMLElementA jQuery wrapped collection of HTMLElements.
-
[row]
Number optionalThe column to which we want to move the widgets.
Returns:
is_player_in
-
col
-
row
Determines if the widget that is being dragged is currently over the row and col given.
Parameters:
-
col
NumberThe column to check.
-
row
NumberThe row to check.
Returns:
is_widget
-
col
-
row
Determines if there is a widget in the cell represented by col/row params.
Parameters:
-
col
NumberThe column to check.
-
row
NumberThe row to check.
Returns:
is_widget_under_player
-
col
-
row
Determines if there is a widget in the cell represented by col/row params and if this is under the widget that is being dragged.
Parameters:
-
col
NumberThe column to check.
-
row
NumberThe row to check.
Returns:
manage_movements
-
$widgets
-
to_col
-
to_row
Sorts an Array of grid coords objects (representing the grid coords of each widget) in descending way.
Parameters:
-
$widgets
HTMLElementsA jQuery collection of HTMLElements representing the widgets you want to move.
-
to_col
NumberThe column to which we want to move the widgets.
-
to_row
NumberThe row to which we want to move the widgets.
Returns:
move_widget_down
-
$widget
-
The
Move down the specified widget and all below it.
Parameters:
-
$widget
HTMLElementThe jQuery object representing the widget you want to move.
-
The
Numbernumber of cells that the widget has to move.
Returns:
move_widget_to
-
$widget
Move a widget to a specific row. The cell or cells must be empty. If the widget has widgets below, all of these widgets will be moved also if they can.
Parameters:
-
$widget
HTMLElementThe jQuery wrapped HTMLElement of the widget is going to be moved.
Returns:
move_widget_up
-
$widget
-
[y_units]
Move up the specified widget and all below it.
Parameters:
-
$widget
HTMLElementThe widget you want to move.
-
[y_units]
Number optionalThe number of cells that the widget has to move.
Returns:
next_position
-
size_x
-
size_y
Get the most left column below to add a new widget.
Parameters:
-
size_x
NumberThe nº of rows the widget occupies horizontally.
-
size_y
NumberThe nº of columns the widget occupies vertically.
Returns:
on_drag
-
The
-
A
This function is executed when the player is being dragged.
Parameters:
-
The
Eventoriginal browser event
-
A
Objectprepared ui object. See http://jqueryui.com/demos/draggable/ for more info.
on_overlapped_column_change
-
start_callback
-
stop_callback
Executes the callbacks passed as arguments when a column begins to be overlapped or stops being overlapped.
Parameters:
-
start_callback
FunctionFunction executed when a new column begins to be overlapped. The column is passed as first argument.
-
stop_callback
FunctionFunction executed when a column stops being overlapped. The column is passed as first argument.
Returns:
on_overlapped_row_change
-
start_callback
-
stop_callback
Executes the callbacks passed as arguments when a row starts to be overlapped or stops being overlapped.
Parameters:
-
start_callback
FunctionFunction executed when a new row begins to be overlapped. The row is passed as first argument.
-
stop_callback
FunctionFunction executed when a row stops being overlapped. The row is passed as first argument.
Returns:
on_start_drag
-
The
-
A
This function is executed when the player begins to be dragged.
Parameters:
-
The
Eventoriginal browser event
-
A
Objectprepared ui object. See http://jqueryui.com/demos/draggable/ for more info.
on_start_overlapping_column
-
col
This callback is executed when the player begins to collide with a column.
Parameters:
-
col
NumberThe collided column.
Returns:
on_start_overlapping_row
-
col
A callback executed when the player begins to collide with a row.
Parameters:
-
col
NumberThe collided row.
Returns:
on_stop_drag
-
The
-
A
This function is executed when the player stops being dragged.
Parameters:
-
The
Eventoriginal browser event
-
A
Objectprepared ui object. See http://jqueryui.com/demos/draggable/ for more info.
on_stop_overlapping_column
-
col
A callback executed when the the player ends to collide with a column.
Parameters:
-
col
NumberThe collided row.
Returns:
on_stop_overlapping_row
-
row
This callback is executed when the player ends to collide with a row.
Parameters:
-
row
NumberThe collided row.
Returns:
recalculate_faux_grid
()
Object
Recalculates the offsets for the faux grid. You need to use it when the browser is resized.
Returns:
register_widget
()
Array
Creates the grid coords object representing the widget a add it to the mapped array of positions.
Returns:
remove_from_gridmap
-
grid_data
Remove a widget from the mapped array of positions.
Parameters:
-
grid_data
ObjectThe grid coords object representing the cells to update in the mapped array.
Returns:
remove_widget
-
el
Remove a widget from the grid.
Parameters:
-
el
HTMLElementThe jQuery wrapped HTMLElement you want to remove.
Returns:
serialize
-
[$widgets]
Returns a serialized array of the widgets in the grid.
Parameters:
-
[$widgets]
HTMLElement optionalThe collection of jQuery wrapped HTMLElements you want to serialize. If no argument is passed all widgets will be serialized.
Returns:
serialize_changed
()
Array
Returns a serialized array of the widgets that have changed their position.
Returns:
set_cells_player_occupies
-
col
-
col
Update the array of mapped positions with the new player position.
Parameters:
-
col
NumberThe new player col.
-
col
NumberThe new player row.
Returns:
set_dom_grid_height
()
Object
Set the current height of the parent grid.
Returns:
set_placeholder
-
col
-
row
Put placeholder at the row and column specified.
Parameters:
-
col
NumberThe column to which we want to move the placeholder.
-
row
NumberThe row to which we want to move the placeholder.
Returns:
set_player
-
start_callback
-
stop_callback
Sets the current position of the player
Parameters:
-
start_callback
FunctionFunction executed when a new row begins to be overlapped. The row is passed as first argument.
-
stop_callback
FunctionFunction executed when a row stops being overlapped. The row is passed as first argument.
Returns:
sort_by_row_asc
-
widgets
Sorts an Array of grid coords objects (representing the grid coords of each widget) in ascending way.
Parameters:
-
widgets
ArrayArray of grid coords objects
Returns:
sort_by_row_asc
-
widgets
Sorts an Array of grid coords objects by column (representing the grid coords of each widget) in ascending way.
Parameters:
-
widgets
ArrayArray of grid coords objects
Returns:
sort_by_row_desc
-
widgets
Sorts an Array of grid coords objects (representing the grid coords of each widget) in descending way.
Parameters:
-
widgets
ArrayArray of grid coords objects
Returns:
update_widget_position
-
grid_data
-
value
Update in the mapped array of positions the value of cells represented by
the grid coords object passed in the grid_data
param.
Parameters:
-
grid_data
ObjectThe grid coords object representing the cells to update in the mapped array.
-
value
HTMLElement | BooleanPass
false
or the jQuery wrapped HTMLElement, depends if you want to delete an existing position or add a new one.
Returns:
widgets_below
-
$el
Get widgets below a widget.
Parameters:
-
$el
HTMLElementThe jQuery wrapped HTMLElement.
Returns:
widgets_contraints
-
$widgets
See which of the widgets in the $widgets param collection can go to a upper row and which not.
Parameters:
-
$widgets
HTMLElementsA jQuery wrapped collection of HTMLElements.
Returns:
can_go_up
&
can_not_go_up
. Each contains a set of HTMLElements.