mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 00:24:21 +02:00
Merge commit '6eb521015cda5212f6fa92492dbe4050bd92e00c'
* commit '6eb521015cda5212f6fa92492dbe4050bd92e00c': Update Readme Updated sample Better handling of widgets slideing down update readme rebuilt dist Added Swap Demo Added disabled dragging init feature gridster.js Working on Static widgets
This commit is contained in:
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
/*! gridster.js - v0.6.6 - 2015-04-08
|
||||
/*! gridster.js - v0.6.6 - 2015-04-09
|
||||
* http://gridster.net/
|
||||
* Copyright (c) 2015 decksterteam; Licensed MIT */
|
||||
|
||||
|
||||
Vendored
+395
-48
@@ -1,4 +1,4 @@
|
||||
/*! gridster.js - v0.6.6 - 2015-04-08
|
||||
/*! gridster.js - v0.6.6 - 2015-04-09
|
||||
* http://gridster.net/
|
||||
* Copyright (c) 2015 decksterteam; Licensed MIT */
|
||||
|
||||
@@ -879,6 +879,14 @@
|
||||
return new Draggable(this, options);
|
||||
};
|
||||
|
||||
$.fn.dragg = function (options) {
|
||||
return this.each(function () {
|
||||
if (!$.data(this, 'drag')) {
|
||||
$.data(this, 'drag', new Draggable(this, options));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return Draggable;
|
||||
|
||||
}));
|
||||
@@ -900,6 +908,7 @@
|
||||
defaults = {
|
||||
namespace: '',
|
||||
widget_selector: 'li',
|
||||
static_class: 'static',
|
||||
widget_margins: [10, 10],
|
||||
widget_base_dimensions: [400, 225],
|
||||
extra_rows: 0,
|
||||
@@ -909,12 +918,14 @@
|
||||
min_rows: 15,
|
||||
max_size_x: false,
|
||||
autogrow_cols: false,
|
||||
max_rows: 15,
|
||||
autogenerate_stylesheet: true,
|
||||
avoid_overlapped_widgets: true,
|
||||
auto_init: true,
|
||||
center_widgets: false,
|
||||
responsive_breakpoint: false,
|
||||
scroll_container: window,
|
||||
shift_larger_widgets_down: true,
|
||||
serialize_params: function($w, wgd) {
|
||||
return {
|
||||
col: wgd.col,
|
||||
@@ -925,7 +936,7 @@
|
||||
},
|
||||
collision: {},
|
||||
draggable: {
|
||||
items: '.gs-w',
|
||||
items: '.gs-w:not(.static)',
|
||||
distance: 4,
|
||||
ignore_dragging: Draggable.defaults.ignore_dragging.slice(0)
|
||||
},
|
||||
@@ -1026,6 +1037,7 @@
|
||||
this.options.widget_selector).addClass('gs-w');
|
||||
this.widgets = [];
|
||||
this.$changed = $([]);
|
||||
this.w_queue = {};
|
||||
this.min_widget_width = this.options.widget_base_dimensions[0];
|
||||
this.min_widget_height = this.options.widget_base_dimensions[1];
|
||||
|
||||
@@ -1279,6 +1291,7 @@
|
||||
}).addClass('gs-w').appendTo(this.$el).hide();
|
||||
|
||||
this.$widgets = this.$widgets.add($w);
|
||||
this.$changed = this.$changed.add($w);
|
||||
|
||||
this.register_widget($w);
|
||||
|
||||
@@ -1852,9 +1865,12 @@
|
||||
size_y: size_y
|
||||
});
|
||||
|
||||
/*
|
||||
$nexts.not(exclude).each($.proxy(function(i, widget) {
|
||||
console.log("from_remove")
|
||||
this.move_widget_up( $(widget), size_y );
|
||||
}, this));
|
||||
*/
|
||||
|
||||
this.set_dom_grid_height();
|
||||
|
||||
@@ -1904,6 +1920,13 @@
|
||||
return false;
|
||||
};
|
||||
|
||||
fn.remove_by_grid = function(col, row){
|
||||
var $w = this.is_widget(col, row);
|
||||
if($w){
|
||||
this.remove_widget($w);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a widget from the grid.
|
||||
@@ -1980,14 +2003,14 @@
|
||||
*/
|
||||
fn.serialize = function($widgets) {
|
||||
$widgets || ($widgets = this.$widgets);
|
||||
|
||||
return $widgets.map($.proxy(function(i, widget) {
|
||||
var $w = $(widget);
|
||||
return this.options.serialize_params($w, $w.coords().grid);
|
||||
}, this)).get();
|
||||
var result = [];
|
||||
$widgets.each($.proxy(function(i, widget) {
|
||||
if(typeof($(widget).coords().grid) != "undefined"){
|
||||
result.push(this.options.serialize_params($w, $w.coords().grid) );
|
||||
}
|
||||
}, this));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns a serialized array of the widgets that have changed their
|
||||
* position.
|
||||
@@ -2050,15 +2073,19 @@
|
||||
!this.can_move_to(
|
||||
{size_x: wgd.size_x, size_y: wgd.size_y}, wgd.col, wgd.row)
|
||||
) {
|
||||
$.extend(wgd, this.next_position(wgd.size_x, wgd.size_y));
|
||||
$el.attr({
|
||||
'data-col': wgd.col,
|
||||
'data-row': wgd.row,
|
||||
'data-sizex': wgd.size_x,
|
||||
'data-sizey': wgd.size_y
|
||||
});
|
||||
posChanged = true;
|
||||
}
|
||||
if (!$el.hasClass('.disp_ad')) {
|
||||
$el.remove();
|
||||
return false;
|
||||
}
|
||||
$.extend(wgd, this.next_position(wgd.size_x, wgd.size_y));
|
||||
$el.attr({
|
||||
'data-col': wgd.col,
|
||||
'data-row': wgd.row,
|
||||
'data-sizex': wgd.size_x,
|
||||
'data-sizey': wgd.size_y
|
||||
});
|
||||
posChanged = true;
|
||||
}
|
||||
|
||||
// attach Coord object to player data-coord attribute
|
||||
$el.data('coords', $el.coords());
|
||||
@@ -2158,13 +2185,13 @@
|
||||
*/
|
||||
fn.add_to_gridmap = function(grid_data, value) {
|
||||
this.update_widget_position(grid_data, value || grid_data.el);
|
||||
|
||||
if (grid_data.el) {
|
||||
/*if (grid_data.el) {
|
||||
var $widgets = this.widgets_below(grid_data.el);
|
||||
$widgets.each($.proxy(function(i, widget) {
|
||||
console.log("from_add_to_gridmap");
|
||||
this.move_widget_up( $(widget));
|
||||
}, this));
|
||||
}
|
||||
} */
|
||||
};
|
||||
|
||||
|
||||
@@ -2204,8 +2231,8 @@
|
||||
}, 60)
|
||||
});
|
||||
|
||||
this.drag_api = this.$el.gridDraggable(draggable_options);
|
||||
return this;
|
||||
//this.drag_api = this.$el.gridDraggable(draggable_options);
|
||||
this.drag_api = this.$el.dragg(draggable_options).data('drag');
|
||||
};
|
||||
|
||||
|
||||
@@ -2258,6 +2285,7 @@
|
||||
'.' + this.resize_handle_class);
|
||||
}
|
||||
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -2434,6 +2462,7 @@
|
||||
this.player_grid_data = {};
|
||||
this.cells_occupied_by_placeholder = {};
|
||||
this.cells_occupied_by_player = {};
|
||||
this.w_queue = {};
|
||||
|
||||
this.set_dom_grid_height();
|
||||
this.set_dom_grid_width();
|
||||
@@ -2732,12 +2761,13 @@
|
||||
*/
|
||||
fn.set_player = function(col, row, no_player) {
|
||||
var self = this;
|
||||
var swap = false;
|
||||
if (!no_player) {
|
||||
this.empty_cells_player_occupies();
|
||||
}
|
||||
var cell = !no_player ? self.colliders_data[0].el.data : {col: col};
|
||||
var to_col = cell.col;
|
||||
var to_row = row || cell.row;
|
||||
var to_row = cell.row || row;
|
||||
|
||||
this.player_grid_data = {
|
||||
col: to_col,
|
||||
@@ -2749,13 +2779,93 @@
|
||||
this.cells_occupied_by_player = this.get_cells_occupied(
|
||||
this.player_grid_data);
|
||||
|
||||
//Added placeholder for more advanced movement.
|
||||
this.cells_occupied_by_placeholder = this.get_cells_occupied(
|
||||
this.placeholder_grid_data);
|
||||
|
||||
var $overlapped_widgets = this.get_widgets_overlapped(
|
||||
this.player_grid_data);
|
||||
|
||||
var constraints = this.widgets_constraints($overlapped_widgets);
|
||||
var player_size_y = this.player_grid_data.size_y;
|
||||
var player_size_x = this.player_grid_data.size_x;
|
||||
var placeholder_cells = this.cells_occupied_by_placeholder;
|
||||
var $gr = this;
|
||||
|
||||
this.manage_movements(constraints.can_go_up, to_col, to_row);
|
||||
this.manage_movements(constraints.can_not_go_up, to_col, to_row);
|
||||
|
||||
//Queue Swaps
|
||||
$overlapped_widgets.each($.proxy(function(i, w){
|
||||
var $w = $(w);
|
||||
var wgd = $w.coords().grid;
|
||||
var outside_col = placeholder_cells.cols[0]+player_size_x-1;
|
||||
var outside_row = placeholder_cells.rows[0]+player_size_y-1;
|
||||
if ($w.hasClass($gr.options.static_class)){
|
||||
//next iteration
|
||||
return true;
|
||||
}
|
||||
if(wgd.size_x <= player_size_x && wgd.size_y <= player_size_y){
|
||||
if(!$gr.is_swap_occupied(placeholder_cells.cols[0], wgd.row, wgd.size_x, wgd.size_y) && !$gr.is_player_in(placeholder_cells.cols[0], wgd.row) && !$gr.is_in_queue(placeholder_cells.cols[0], wgd.row, $w)){
|
||||
swap = $gr.queue_widget(placeholder_cells.cols[0], wgd.row, $w);
|
||||
}
|
||||
else if(!$gr.is_swap_occupied(outside_col, wgd.row, wgd.size_x, wgd.size_y) && !$gr.is_player_in(outside_col, wgd.row) && !$gr.is_in_queue(outside_col, wgd.row, $w)){
|
||||
swap = $gr.queue_widget(outside_col, wgd.row, $w);
|
||||
}
|
||||
else if(!$gr.is_swap_occupied(wgd.col, placeholder_cells.rows[0], wgd.size_x, wgd.size_y) && !$gr.is_player_in(wgd.col, placeholder_cells.rows[0]) && !$gr.is_in_queue(wgd.col, placeholder_cells.rows[0], $w)){
|
||||
swap = $gr.queue_widget(wgd.col, placeholder_cells.rows[0], $w);
|
||||
}
|
||||
else if(!$gr.is_swap_occupied(wgd.col, outside_row, wgd.size_x, wgd.size_y) && !$gr.is_player_in(wgd.col, outside_row) && !$gr.is_in_queue(wgd.col, outside_row, $w)){
|
||||
swap = $gr.queue_widget(wgd.col, outside_row, $w);
|
||||
}
|
||||
else if(!$gr.is_swap_occupied(placeholder_cells.cols[0],placeholder_cells.rows[0], wgd.size_x, wgd.size_y) && !$gr.is_player_in(placeholder_cells.cols[0],placeholder_cells.rows[0]) && !$gr.is_in_queue(placeholder_cells.cols[0],placeholder_cells.rows[0], $w)){
|
||||
swap = $gr.queue_widget(placeholder_cells.cols[0], placeholder_cells.rows[0], $w);
|
||||
} else {
|
||||
//in one last attempt we check for any other empty spaces
|
||||
for (var c = 0; c < player_size_x; c++){
|
||||
for (var r = 0; r < player_size_y; r++){
|
||||
var colc = placeholder_cells.cols[0]+c;
|
||||
var rowc = placeholder_cells.rows[0]+r;
|
||||
if (!$gr.is_swap_occupied(colc,rowc, wgd.size_x, wgd.size_y) && !$gr.is_player_in(colc,rowc) && !$gr.is_in_queue(colc, rowc, $w)){
|
||||
swap = $gr.queue_widget(colc, rowc, $w);
|
||||
c = player_size_x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else if ($gr.options.shift_larger_widgets_down && !swap) {
|
||||
$overlapped_widgets.each($.proxy(function(i, w){
|
||||
var $w = $(w);
|
||||
var wgd = $w.coords().grid;
|
||||
|
||||
if($gr.can_go_down($w)){
|
||||
$gr.move_widget_down($w, $gr.player_grid_data.size_y);
|
||||
$gr.set_placeholder(to_col, to_row);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
$gr.clean_up_changed();
|
||||
}));
|
||||
|
||||
|
||||
/* To show queued items in console
|
||||
for(var key in this.w_queue){
|
||||
console.log("key " +key);
|
||||
console.log(this.w_queue[key]);
|
||||
}
|
||||
*/
|
||||
|
||||
//Move queued widgets
|
||||
if(swap && this.can_placeholder_be_set(to_col, to_row, player_size_x, player_size_y)){
|
||||
for(var key in this.w_queue){
|
||||
var col = parseInt(key.split("_")[0]);
|
||||
var row = parseInt(key.split("_")[1]);
|
||||
if (this.w_queue[key] != "full"){
|
||||
this.new_move_widget_to(this.w_queue[key], col, row);
|
||||
}
|
||||
}
|
||||
this.set_placeholder(to_col, to_row);
|
||||
}
|
||||
|
||||
/* if there is not widgets overlapping in the new player position,
|
||||
* update the new placeholder position. */
|
||||
@@ -2764,9 +2874,13 @@
|
||||
if (pp !== false) {
|
||||
to_row = pp;
|
||||
}
|
||||
this.set_placeholder(to_col, to_row);
|
||||
if(this.can_placeholder_be_set(to_col, to_row, player_size_x, player_size_y)){
|
||||
this.set_placeholder(to_col, to_row);
|
||||
}
|
||||
}
|
||||
|
||||
this.w_queue = {};
|
||||
|
||||
return {
|
||||
col: to_col,
|
||||
row: to_row
|
||||
@@ -2774,6 +2888,151 @@
|
||||
};
|
||||
|
||||
|
||||
fn.is_swap_occupied = function(col, row, w_size_x, w_size_y) {
|
||||
var occupied = false;
|
||||
for (var c = 0; c < w_size_x; c++){
|
||||
for (var r = 0; r < w_size_y; r++){
|
||||
var colc = col + c;
|
||||
var rowc = row + r;
|
||||
var key = colc+"_"+rowc;
|
||||
if(this.is_occupied(colc,rowc)){
|
||||
occupied = true;
|
||||
} else if(key in this.w_queue){
|
||||
if(this.w_queue[key] == "full"){
|
||||
occupied = true;
|
||||
continue;
|
||||
}
|
||||
$tw = this.w_queue[key];
|
||||
tgd = $tw.coords().grid;
|
||||
//remove queued items if no longer under player.
|
||||
if(!this.is_widget_under_player(tgd.col,tgd.row)){
|
||||
delete this.w_queue[key];
|
||||
}
|
||||
}
|
||||
if(rowc > parseInt(this.options.max_rows)){
|
||||
occupied = true;
|
||||
}
|
||||
if(colc > parseInt(this.options.max_cols)){
|
||||
occupied = true;
|
||||
}
|
||||
if (this.is_player_in(colc,rowc)){
|
||||
occupied = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return occupied;
|
||||
}
|
||||
|
||||
fn.can_placeholder_be_set = function(col, row, player_size_x, player_size_y){
|
||||
var can_set = true;
|
||||
for (var c = 0; c < player_size_x; c++){
|
||||
for (var r = 0; r < player_size_y; r++){
|
||||
var colc = col + c;
|
||||
var rowc = row + r;
|
||||
var key = colc+"_"+rowc;
|
||||
var $tw = this.is_widget(colc, rowc);
|
||||
//if this space is occupied and not queued for move.
|
||||
if(rowc > parseInt(this.options.max_rows)){
|
||||
can_set = false;
|
||||
}
|
||||
if(colc > parseInt(this.options.max_cols)){
|
||||
can_set = false;
|
||||
}
|
||||
if(this.is_occupied(colc,rowc) && !this.is_widget_queued_and_can_move($tw)){
|
||||
can_set = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return can_set;
|
||||
}
|
||||
|
||||
fn.queue_widget = function(col, row, $widget){
|
||||
var $w = $widget
|
||||
var wgd = $w.coords().grid;
|
||||
var primary_key = col+"_"+row;
|
||||
if (primary_key in this.w_queue){
|
||||
return false;
|
||||
}
|
||||
|
||||
this.w_queue[primary_key] = $w;
|
||||
|
||||
for (var c = 0; c < wgd.size_x; c++){
|
||||
for (var r = 0; r < wgd.size_y; r++){
|
||||
var colc = col + c;
|
||||
var rowc = row + r;
|
||||
var key = colc+"_"+rowc;
|
||||
if (key == primary_key){
|
||||
continue;
|
||||
}
|
||||
this.w_queue[key] = "full";
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
fn.is_widget_queued_and_can_move = function($widget){
|
||||
var queued = false;
|
||||
if ($widget === false){
|
||||
return false;
|
||||
}
|
||||
|
||||
for(var key in this.w_queue){
|
||||
if(this.w_queue[key] == "full"){
|
||||
continue;
|
||||
}
|
||||
if(this.w_queue[key].attr("data-col") == $widget.attr("data-col") && this.w_queue[key].attr("data-row") == $widget.attr("data-row")){
|
||||
queued = true;
|
||||
//test whole space
|
||||
var $w = this.w_queue[key];
|
||||
var dcol = parseInt(key.split("_")[0]);
|
||||
var drow = parseInt(key.split("_")[1]);
|
||||
var wgd = $w.coords().grid;
|
||||
|
||||
for (var c = 0; c < wgd.size_x; c++){
|
||||
for (var r = 0; r < wgd.size_y; r++){
|
||||
var colc = dcol + c;
|
||||
var rowc = drow + r;
|
||||
if (this.is_player_in(colc,rowc)){
|
||||
queued = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return queued
|
||||
}
|
||||
|
||||
fn.is_in_queue = function(col,row, $widget){
|
||||
var queued = false;
|
||||
var key = col+"_"+row;
|
||||
|
||||
if ((key in this.w_queue)){
|
||||
if (this.w_queue[key] == "full"){
|
||||
queued = true;
|
||||
} else {
|
||||
$tw = this.w_queue[key];
|
||||
tgd = $tw.coords().grid;
|
||||
if(!this.is_widget_under_player(tgd.col,tgd.row)){
|
||||
delete this.w_queue[key]
|
||||
queued = false;
|
||||
} else if(this.w_queue[key].attr("data-col") == $widget.attr("data-col") && this.w_queue[key].attr("data-row") == $widget.attr("data-row")) {
|
||||
delete this.w_queue[key]
|
||||
queued = false;
|
||||
} else {
|
||||
queued = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return queued;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See which of the widgets in the $widgets param collection can go to
|
||||
* a upper row and which not.
|
||||
@@ -2813,6 +3072,8 @@
|
||||
/**
|
||||
* Sorts an Array of grid coords objects (representing the grid coords of
|
||||
* each widget) in descending way.
|
||||
|
||||
* Depreciated.
|
||||
*
|
||||
* @method manage_movements
|
||||
* @param {jQuery} $widgets A jQuery collection of HTMLElements
|
||||
@@ -2845,9 +3106,11 @@
|
||||
// so we need to move widget down to a position that dont
|
||||
// overlaps player
|
||||
var y = (to_row + this.player_grid_data.size_y) - wgd.row;
|
||||
|
||||
this.move_widget_down($w, y);
|
||||
this.set_placeholder(to_col, to_row);
|
||||
if (this.can_go_down($w)){
|
||||
console.log("In Move Down!")
|
||||
this.move_widget_down($w, y);
|
||||
this.set_placeholder(to_col, to_row);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, this));
|
||||
@@ -2979,6 +3242,32 @@
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines if widget is supposed to be static.
|
||||
* @method is_static
|
||||
* @param {Number} col The column to check.
|
||||
* @param {Number} row The row to check.
|
||||
* @return {Boolean} Returns true if widget exists and has static class,
|
||||
* else returns false
|
||||
*/
|
||||
|
||||
fn.is_static = function(col, row) {
|
||||
var cell = this.gridmap[col];
|
||||
if (!cell) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cell = cell[row];
|
||||
|
||||
if (cell) {
|
||||
if(cell.hasClass(this.options.static_class)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determines if there is a widget in the cell represented by col/row
|
||||
@@ -3061,8 +3350,16 @@
|
||||
|
||||
if (moved_down || changed_column) {
|
||||
$nexts.each($.proxy(function(i, widget) {
|
||||
this.move_widget_up(
|
||||
$(widget), this.placeholder_grid_data.col - col + phgd.size_y);
|
||||
//Make sure widget is at it's topmost position
|
||||
$w = $(widget);
|
||||
wgd = $w.coords().grid;
|
||||
|
||||
var can_go_widget_up = this.can_go_widget_up(wgd);
|
||||
|
||||
if (can_go_widget_up) {
|
||||
this.move_widget_to($w, can_go_widget_up);
|
||||
}
|
||||
|
||||
}, this));
|
||||
}
|
||||
|
||||
@@ -3329,13 +3626,14 @@
|
||||
* @return {jQuery} Returns a jQuery collection of HTMLElements.
|
||||
*/
|
||||
fn.on_stop_overlapping_column = function(col) {
|
||||
this.set_player(col, false);
|
||||
|
||||
//this.set_player(col, false);
|
||||
var self = this;
|
||||
this.for_each_widget_below(col, this.cells_occupied_by_player.rows[0],
|
||||
function(tcol, trow) {
|
||||
self.move_widget_up(this, self.player_grid_data.size_y);
|
||||
});
|
||||
if(this.options.shift_larger_widgets_down){
|
||||
this.for_each_widget_below(col, this.cells_occupied_by_player.rows[0],
|
||||
function(tcol, trow) {
|
||||
self.move_widget_up(this, self.player_grid_data.size_y);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -3347,17 +3645,37 @@
|
||||
* @return {jQuery} Returns a jQuery collection of HTMLElements.
|
||||
*/
|
||||
fn.on_stop_overlapping_row = function(row) {
|
||||
this.set_player(false, row);
|
||||
|
||||
//this.set_player(false, row);
|
||||
var self = this;
|
||||
var cols = this.cells_occupied_by_player.cols;
|
||||
for (var c = 0, cl = cols.length; c < cl; c++) {
|
||||
this.for_each_widget_below(cols[c], row, function(tcol, trow) {
|
||||
self.move_widget_up(this, self.player_grid_data.size_y);
|
||||
});
|
||||
if(this.options.shift_larger_widgets_down){
|
||||
for (var c = 0, cl = cols.length; c < cl; c++) {
|
||||
this.for_each_widget_below(cols[c], row, function(tcol, trow) {
|
||||
console.log("from_on_stop_overlapping_row");
|
||||
self.move_widget_up(this, self.player_grid_data.size_y);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//Not yet part of api - DM.
|
||||
fn.new_move_widget_to = function($widget, col, row){
|
||||
var self = this;
|
||||
var widget_grid_data = $widget.coords().grid;
|
||||
|
||||
this.remove_from_gridmap(widget_grid_data);
|
||||
widget_grid_data.row = row;
|
||||
widget_grid_data.col = col;
|
||||
|
||||
this.add_to_gridmap(widget_grid_data);
|
||||
$widget.attr('data-row', row);
|
||||
$widget.attr('data-col', col);
|
||||
this.update_widget_position(widget_grid_data, $widget);
|
||||
this.$changed = this.$changed.add($widget);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move a widget to a specific row and column.
|
||||
@@ -3476,9 +3794,10 @@
|
||||
|
||||
moved.push($widget);
|
||||
|
||||
$next_widgets.each($.proxy(function(i, widget) {
|
||||
/* $next_widgets.each($.proxy(function(i, widget) {
|
||||
console.log("from_within_move_widget_up");
|
||||
this.move_widget_up($(widget), y_units);
|
||||
}, this));
|
||||
}, this)); */
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3681,6 +4000,23 @@
|
||||
return this;
|
||||
};
|
||||
|
||||
fn.can_go_down = function($el) {
|
||||
var can_go_down = true;
|
||||
var $gr = this;
|
||||
|
||||
if ($el.hasClass(this.options.static_class)){
|
||||
can_go_down = false;
|
||||
}
|
||||
|
||||
this.widgets_below($el).each(function(){
|
||||
if ($(this).hasClass($gr.options.static_class)){
|
||||
can_go_down = false;
|
||||
}
|
||||
})
|
||||
|
||||
return can_go_down;
|
||||
}
|
||||
|
||||
|
||||
fn.can_go_up = function($el) {
|
||||
var el_grid_data = $el.coords().grid;
|
||||
@@ -3876,6 +4212,15 @@
|
||||
}
|
||||
};
|
||||
|
||||
fn.clean_up_changed = function(){
|
||||
$gr = this;
|
||||
$gr.$changed.each(function(){
|
||||
if($gr.options.shift_larger_widgets_down){
|
||||
$gr.move_widget_up($(this));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn._traversing_widgets = function(type, direction, col, row, callback) {
|
||||
@@ -3913,7 +4258,8 @@
|
||||
) {
|
||||
cr = callback.call(ga[col][trow], col, trow);
|
||||
matched.push(ga[col][trow]);
|
||||
if (cr) { break; }
|
||||
//break was causing problems, leaving for testing.
|
||||
//if (cr) { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4495,7 +4841,8 @@
|
||||
max_rows += (+$(w).attr('data-sizey'));
|
||||
});
|
||||
|
||||
this.rows = Math.max(max_rows, this.options.min_rows);
|
||||
//this.rows = Math.max(max_rows, this.options.min_rows);
|
||||
this.rows = this.options.max_rows;
|
||||
|
||||
this.baseX = ($window.width() - aw) / 2;
|
||||
this.baseY = this.$wrapper.offset().top;
|
||||
|
||||
Vendored
+1
-1
@@ -1,2 +1,2 @@
|
||||
/*! gridster.js - v0.6.6 - 2015-04-08 - * http://gridster.net/ - Copyright (c) 2015 decksterteam; Licensed MIT */
|
||||
/*! gridster.js - v0.6.6 - 2015-04-09 - * http://gridster.net/ - Copyright (c) 2015 decksterteam; Licensed MIT */
|
||||
.gridster{position:relative}.gridster>*{margin:0 auto;-webkit-transition:height .4s,width .4s;-moz-transition:height .4s,width .4s;-o-transition:height .4s,width .4s;-ms-transition:height .4s,width .4s;transition:height .4s,width .4s}.gridster .gs-w{z-index:2;position:absolute}.gridster.collapsed{height:auto!important}.gridster.collapsed .gs-w{position:static!important}.ready .gs-w:not(.preview-holder){-webkit-transition:opacity .3s,left .3s,top .3s;-moz-transition:opacity .3s,left .3s,top .3s;-o-transition:opacity .3s,left .3s,top .3s;transition:opacity .3s,left .3s,top .3s}.ready .gs-w:not(.preview-holder),.ready .resize-preview-holder{-webkit-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;-moz-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;-o-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;transition:opacity .3s,left .3s,top .3s,width .3s,height .3s}.gridster .preview-holder{z-index:1;position:absolute;background-color:#fff;border-color:#fff;opacity:.3}.gridster .player-revert{z-index:10!important;-webkit-transition:left .3s,top .3s!important;-moz-transition:left .3s,top .3s!important;-o-transition:left .3s,top .3s!important;transition:left .3s,top .3s!important}.gridster .dragging,.gridster .resizing{z-index:10!important;-webkit-transition:all 0s!important;-moz-transition:all 0s!important;-o-transition:all 0s!important;transition:all 0s!important}.gs-resize-handle{position:absolute;z-index:1}.gs-resize-handle-both{width:20px;height:20px;bottom:-8px;right:-8px;background-image:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pg08IS0tIEdlbmVyYXRvcjogQWRvYmUgRmlyZXdvcmtzIENTNiwgRXhwb3J0IFNWRyBFeHRlbnNpb24gYnkgQWFyb24gQmVhbGwgKGh0dHA6Ly9maXJld29ya3MuYWJlYWxsLmNvbSkgLiBWZXJzaW9uOiAwLjYuMSAgLS0+DTwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DTxzdmcgaWQ9IlVudGl0bGVkLVBhZ2UlMjAxIiB2aWV3Qm94PSIwIDAgNiA2IiBzdHlsZT0iYmFja2dyb3VuZC1jb2xvcjojZmZmZmZmMDAiIHZlcnNpb249IjEuMSINCXhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbDpzcGFjZT0icHJlc2VydmUiDQl4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjZweCIgaGVpZ2h0PSI2cHgiDT4NCTxnIG9wYWNpdHk9IjAuMzAyIj4NCQk8cGF0aCBkPSJNIDYgNiBMIDAgNiBMIDAgNC4yIEwgNCA0LjIgTCA0LjIgNC4yIEwgNC4yIDAgTCA2IDAgTCA2IDYgTCA2IDYgWiIgZmlsbD0iIzAwMDAwMCIvPg0JPC9nPg08L3N2Zz4=);background-position:top left;background-repeat:no-repeat;cursor:se-resize;z-index:20}.gs-resize-handle-x{top:0;bottom:13px;right:-5px;width:10px;cursor:e-resize}.gs-resize-handle-y{left:0;right:13px;bottom:-5px;height:10px;cursor:s-resize}.gs-w:hover .gs-resize-handle,.resizing .gs-resize-handle{opacity:1}.gs-resize-handle,.gs-w.dragging .gs-resize-handle{opacity:0}.gs-resize-disabled .gs-resize-handle{display:none!important}[data-max-sizex="1"] .gs-resize-handle-x,[data-max-sizey="1"] .gs-resize-handle-y,[data-max-sizey="1"][data-max-sizex="1"] .gs-resize-handle{display:none!important}
|
||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
Vendored
+395
-48
@@ -1,4 +1,4 @@
|
||||
/*! gridster.js - v0.6.6 - 2015-04-08
|
||||
/*! gridster.js - v0.6.6 - 2015-04-09
|
||||
* http://gridster.net/
|
||||
* Copyright (c) 2015 decksterteam; Licensed MIT */
|
||||
|
||||
@@ -879,6 +879,14 @@
|
||||
return new Draggable(this, options);
|
||||
};
|
||||
|
||||
$.fn.dragg = function (options) {
|
||||
return this.each(function () {
|
||||
if (!$.data(this, 'drag')) {
|
||||
$.data(this, 'drag', new Draggable(this, options));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return Draggable;
|
||||
|
||||
}));
|
||||
@@ -900,6 +908,7 @@
|
||||
defaults = {
|
||||
namespace: '',
|
||||
widget_selector: 'li',
|
||||
static_class: 'static',
|
||||
widget_margins: [10, 10],
|
||||
widget_base_dimensions: [400, 225],
|
||||
extra_rows: 0,
|
||||
@@ -909,12 +918,14 @@
|
||||
min_rows: 15,
|
||||
max_size_x: false,
|
||||
autogrow_cols: false,
|
||||
max_rows: 15,
|
||||
autogenerate_stylesheet: true,
|
||||
avoid_overlapped_widgets: true,
|
||||
auto_init: true,
|
||||
center_widgets: false,
|
||||
responsive_breakpoint: false,
|
||||
scroll_container: window,
|
||||
shift_larger_widgets_down: true,
|
||||
serialize_params: function($w, wgd) {
|
||||
return {
|
||||
col: wgd.col,
|
||||
@@ -925,7 +936,7 @@
|
||||
},
|
||||
collision: {},
|
||||
draggable: {
|
||||
items: '.gs-w',
|
||||
items: '.gs-w:not(.static)',
|
||||
distance: 4,
|
||||
ignore_dragging: Draggable.defaults.ignore_dragging.slice(0)
|
||||
},
|
||||
@@ -1026,6 +1037,7 @@
|
||||
this.options.widget_selector).addClass('gs-w');
|
||||
this.widgets = [];
|
||||
this.$changed = $([]);
|
||||
this.w_queue = {};
|
||||
this.min_widget_width = this.options.widget_base_dimensions[0];
|
||||
this.min_widget_height = this.options.widget_base_dimensions[1];
|
||||
|
||||
@@ -1279,6 +1291,7 @@
|
||||
}).addClass('gs-w').appendTo(this.$el).hide();
|
||||
|
||||
this.$widgets = this.$widgets.add($w);
|
||||
this.$changed = this.$changed.add($w);
|
||||
|
||||
this.register_widget($w);
|
||||
|
||||
@@ -1852,9 +1865,12 @@
|
||||
size_y: size_y
|
||||
});
|
||||
|
||||
/*
|
||||
$nexts.not(exclude).each($.proxy(function(i, widget) {
|
||||
console.log("from_remove")
|
||||
this.move_widget_up( $(widget), size_y );
|
||||
}, this));
|
||||
*/
|
||||
|
||||
this.set_dom_grid_height();
|
||||
|
||||
@@ -1904,6 +1920,13 @@
|
||||
return false;
|
||||
};
|
||||
|
||||
fn.remove_by_grid = function(col, row){
|
||||
var $w = this.is_widget(col, row);
|
||||
if($w){
|
||||
this.remove_widget($w);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a widget from the grid.
|
||||
@@ -1980,14 +2003,14 @@
|
||||
*/
|
||||
fn.serialize = function($widgets) {
|
||||
$widgets || ($widgets = this.$widgets);
|
||||
|
||||
return $widgets.map($.proxy(function(i, widget) {
|
||||
var $w = $(widget);
|
||||
return this.options.serialize_params($w, $w.coords().grid);
|
||||
}, this)).get();
|
||||
var result = [];
|
||||
$widgets.each($.proxy(function(i, widget) {
|
||||
if(typeof($(widget).coords().grid) != "undefined"){
|
||||
result.push(this.options.serialize_params($w, $w.coords().grid) );
|
||||
}
|
||||
}, this));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns a serialized array of the widgets that have changed their
|
||||
* position.
|
||||
@@ -2050,15 +2073,19 @@
|
||||
!this.can_move_to(
|
||||
{size_x: wgd.size_x, size_y: wgd.size_y}, wgd.col, wgd.row)
|
||||
) {
|
||||
$.extend(wgd, this.next_position(wgd.size_x, wgd.size_y));
|
||||
$el.attr({
|
||||
'data-col': wgd.col,
|
||||
'data-row': wgd.row,
|
||||
'data-sizex': wgd.size_x,
|
||||
'data-sizey': wgd.size_y
|
||||
});
|
||||
posChanged = true;
|
||||
}
|
||||
if (!$el.hasClass('.disp_ad')) {
|
||||
$el.remove();
|
||||
return false;
|
||||
}
|
||||
$.extend(wgd, this.next_position(wgd.size_x, wgd.size_y));
|
||||
$el.attr({
|
||||
'data-col': wgd.col,
|
||||
'data-row': wgd.row,
|
||||
'data-sizex': wgd.size_x,
|
||||
'data-sizey': wgd.size_y
|
||||
});
|
||||
posChanged = true;
|
||||
}
|
||||
|
||||
// attach Coord object to player data-coord attribute
|
||||
$el.data('coords', $el.coords());
|
||||
@@ -2158,13 +2185,13 @@
|
||||
*/
|
||||
fn.add_to_gridmap = function(grid_data, value) {
|
||||
this.update_widget_position(grid_data, value || grid_data.el);
|
||||
|
||||
if (grid_data.el) {
|
||||
/*if (grid_data.el) {
|
||||
var $widgets = this.widgets_below(grid_data.el);
|
||||
$widgets.each($.proxy(function(i, widget) {
|
||||
console.log("from_add_to_gridmap");
|
||||
this.move_widget_up( $(widget));
|
||||
}, this));
|
||||
}
|
||||
} */
|
||||
};
|
||||
|
||||
|
||||
@@ -2204,8 +2231,8 @@
|
||||
}, 60)
|
||||
});
|
||||
|
||||
this.drag_api = this.$el.gridDraggable(draggable_options);
|
||||
return this;
|
||||
//this.drag_api = this.$el.gridDraggable(draggable_options);
|
||||
this.drag_api = this.$el.dragg(draggable_options).data('drag');
|
||||
};
|
||||
|
||||
|
||||
@@ -2258,6 +2285,7 @@
|
||||
'.' + this.resize_handle_class);
|
||||
}
|
||||
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -2434,6 +2462,7 @@
|
||||
this.player_grid_data = {};
|
||||
this.cells_occupied_by_placeholder = {};
|
||||
this.cells_occupied_by_player = {};
|
||||
this.w_queue = {};
|
||||
|
||||
this.set_dom_grid_height();
|
||||
this.set_dom_grid_width();
|
||||
@@ -2732,12 +2761,13 @@
|
||||
*/
|
||||
fn.set_player = function(col, row, no_player) {
|
||||
var self = this;
|
||||
var swap = false;
|
||||
if (!no_player) {
|
||||
this.empty_cells_player_occupies();
|
||||
}
|
||||
var cell = !no_player ? self.colliders_data[0].el.data : {col: col};
|
||||
var to_col = cell.col;
|
||||
var to_row = row || cell.row;
|
||||
var to_row = cell.row || row;
|
||||
|
||||
this.player_grid_data = {
|
||||
col: to_col,
|
||||
@@ -2749,13 +2779,93 @@
|
||||
this.cells_occupied_by_player = this.get_cells_occupied(
|
||||
this.player_grid_data);
|
||||
|
||||
//Added placeholder for more advanced movement.
|
||||
this.cells_occupied_by_placeholder = this.get_cells_occupied(
|
||||
this.placeholder_grid_data);
|
||||
|
||||
var $overlapped_widgets = this.get_widgets_overlapped(
|
||||
this.player_grid_data);
|
||||
|
||||
var constraints = this.widgets_constraints($overlapped_widgets);
|
||||
var player_size_y = this.player_grid_data.size_y;
|
||||
var player_size_x = this.player_grid_data.size_x;
|
||||
var placeholder_cells = this.cells_occupied_by_placeholder;
|
||||
var $gr = this;
|
||||
|
||||
this.manage_movements(constraints.can_go_up, to_col, to_row);
|
||||
this.manage_movements(constraints.can_not_go_up, to_col, to_row);
|
||||
|
||||
//Queue Swaps
|
||||
$overlapped_widgets.each($.proxy(function(i, w){
|
||||
var $w = $(w);
|
||||
var wgd = $w.coords().grid;
|
||||
var outside_col = placeholder_cells.cols[0]+player_size_x-1;
|
||||
var outside_row = placeholder_cells.rows[0]+player_size_y-1;
|
||||
if ($w.hasClass($gr.options.static_class)){
|
||||
//next iteration
|
||||
return true;
|
||||
}
|
||||
if(wgd.size_x <= player_size_x && wgd.size_y <= player_size_y){
|
||||
if(!$gr.is_swap_occupied(placeholder_cells.cols[0], wgd.row, wgd.size_x, wgd.size_y) && !$gr.is_player_in(placeholder_cells.cols[0], wgd.row) && !$gr.is_in_queue(placeholder_cells.cols[0], wgd.row, $w)){
|
||||
swap = $gr.queue_widget(placeholder_cells.cols[0], wgd.row, $w);
|
||||
}
|
||||
else if(!$gr.is_swap_occupied(outside_col, wgd.row, wgd.size_x, wgd.size_y) && !$gr.is_player_in(outside_col, wgd.row) && !$gr.is_in_queue(outside_col, wgd.row, $w)){
|
||||
swap = $gr.queue_widget(outside_col, wgd.row, $w);
|
||||
}
|
||||
else if(!$gr.is_swap_occupied(wgd.col, placeholder_cells.rows[0], wgd.size_x, wgd.size_y) && !$gr.is_player_in(wgd.col, placeholder_cells.rows[0]) && !$gr.is_in_queue(wgd.col, placeholder_cells.rows[0], $w)){
|
||||
swap = $gr.queue_widget(wgd.col, placeholder_cells.rows[0], $w);
|
||||
}
|
||||
else if(!$gr.is_swap_occupied(wgd.col, outside_row, wgd.size_x, wgd.size_y) && !$gr.is_player_in(wgd.col, outside_row) && !$gr.is_in_queue(wgd.col, outside_row, $w)){
|
||||
swap = $gr.queue_widget(wgd.col, outside_row, $w);
|
||||
}
|
||||
else if(!$gr.is_swap_occupied(placeholder_cells.cols[0],placeholder_cells.rows[0], wgd.size_x, wgd.size_y) && !$gr.is_player_in(placeholder_cells.cols[0],placeholder_cells.rows[0]) && !$gr.is_in_queue(placeholder_cells.cols[0],placeholder_cells.rows[0], $w)){
|
||||
swap = $gr.queue_widget(placeholder_cells.cols[0], placeholder_cells.rows[0], $w);
|
||||
} else {
|
||||
//in one last attempt we check for any other empty spaces
|
||||
for (var c = 0; c < player_size_x; c++){
|
||||
for (var r = 0; r < player_size_y; r++){
|
||||
var colc = placeholder_cells.cols[0]+c;
|
||||
var rowc = placeholder_cells.rows[0]+r;
|
||||
if (!$gr.is_swap_occupied(colc,rowc, wgd.size_x, wgd.size_y) && !$gr.is_player_in(colc,rowc) && !$gr.is_in_queue(colc, rowc, $w)){
|
||||
swap = $gr.queue_widget(colc, rowc, $w);
|
||||
c = player_size_x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else if ($gr.options.shift_larger_widgets_down && !swap) {
|
||||
$overlapped_widgets.each($.proxy(function(i, w){
|
||||
var $w = $(w);
|
||||
var wgd = $w.coords().grid;
|
||||
|
||||
if($gr.can_go_down($w)){
|
||||
$gr.move_widget_down($w, $gr.player_grid_data.size_y);
|
||||
$gr.set_placeholder(to_col, to_row);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
$gr.clean_up_changed();
|
||||
}));
|
||||
|
||||
|
||||
/* To show queued items in console
|
||||
for(var key in this.w_queue){
|
||||
console.log("key " +key);
|
||||
console.log(this.w_queue[key]);
|
||||
}
|
||||
*/
|
||||
|
||||
//Move queued widgets
|
||||
if(swap && this.can_placeholder_be_set(to_col, to_row, player_size_x, player_size_y)){
|
||||
for(var key in this.w_queue){
|
||||
var col = parseInt(key.split("_")[0]);
|
||||
var row = parseInt(key.split("_")[1]);
|
||||
if (this.w_queue[key] != "full"){
|
||||
this.new_move_widget_to(this.w_queue[key], col, row);
|
||||
}
|
||||
}
|
||||
this.set_placeholder(to_col, to_row);
|
||||
}
|
||||
|
||||
/* if there is not widgets overlapping in the new player position,
|
||||
* update the new placeholder position. */
|
||||
@@ -2764,9 +2874,13 @@
|
||||
if (pp !== false) {
|
||||
to_row = pp;
|
||||
}
|
||||
this.set_placeholder(to_col, to_row);
|
||||
if(this.can_placeholder_be_set(to_col, to_row, player_size_x, player_size_y)){
|
||||
this.set_placeholder(to_col, to_row);
|
||||
}
|
||||
}
|
||||
|
||||
this.w_queue = {};
|
||||
|
||||
return {
|
||||
col: to_col,
|
||||
row: to_row
|
||||
@@ -2774,6 +2888,151 @@
|
||||
};
|
||||
|
||||
|
||||
fn.is_swap_occupied = function(col, row, w_size_x, w_size_y) {
|
||||
var occupied = false;
|
||||
for (var c = 0; c < w_size_x; c++){
|
||||
for (var r = 0; r < w_size_y; r++){
|
||||
var colc = col + c;
|
||||
var rowc = row + r;
|
||||
var key = colc+"_"+rowc;
|
||||
if(this.is_occupied(colc,rowc)){
|
||||
occupied = true;
|
||||
} else if(key in this.w_queue){
|
||||
if(this.w_queue[key] == "full"){
|
||||
occupied = true;
|
||||
continue;
|
||||
}
|
||||
$tw = this.w_queue[key];
|
||||
tgd = $tw.coords().grid;
|
||||
//remove queued items if no longer under player.
|
||||
if(!this.is_widget_under_player(tgd.col,tgd.row)){
|
||||
delete this.w_queue[key];
|
||||
}
|
||||
}
|
||||
if(rowc > parseInt(this.options.max_rows)){
|
||||
occupied = true;
|
||||
}
|
||||
if(colc > parseInt(this.options.max_cols)){
|
||||
occupied = true;
|
||||
}
|
||||
if (this.is_player_in(colc,rowc)){
|
||||
occupied = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return occupied;
|
||||
}
|
||||
|
||||
fn.can_placeholder_be_set = function(col, row, player_size_x, player_size_y){
|
||||
var can_set = true;
|
||||
for (var c = 0; c < player_size_x; c++){
|
||||
for (var r = 0; r < player_size_y; r++){
|
||||
var colc = col + c;
|
||||
var rowc = row + r;
|
||||
var key = colc+"_"+rowc;
|
||||
var $tw = this.is_widget(colc, rowc);
|
||||
//if this space is occupied and not queued for move.
|
||||
if(rowc > parseInt(this.options.max_rows)){
|
||||
can_set = false;
|
||||
}
|
||||
if(colc > parseInt(this.options.max_cols)){
|
||||
can_set = false;
|
||||
}
|
||||
if(this.is_occupied(colc,rowc) && !this.is_widget_queued_and_can_move($tw)){
|
||||
can_set = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return can_set;
|
||||
}
|
||||
|
||||
fn.queue_widget = function(col, row, $widget){
|
||||
var $w = $widget
|
||||
var wgd = $w.coords().grid;
|
||||
var primary_key = col+"_"+row;
|
||||
if (primary_key in this.w_queue){
|
||||
return false;
|
||||
}
|
||||
|
||||
this.w_queue[primary_key] = $w;
|
||||
|
||||
for (var c = 0; c < wgd.size_x; c++){
|
||||
for (var r = 0; r < wgd.size_y; r++){
|
||||
var colc = col + c;
|
||||
var rowc = row + r;
|
||||
var key = colc+"_"+rowc;
|
||||
if (key == primary_key){
|
||||
continue;
|
||||
}
|
||||
this.w_queue[key] = "full";
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
fn.is_widget_queued_and_can_move = function($widget){
|
||||
var queued = false;
|
||||
if ($widget === false){
|
||||
return false;
|
||||
}
|
||||
|
||||
for(var key in this.w_queue){
|
||||
if(this.w_queue[key] == "full"){
|
||||
continue;
|
||||
}
|
||||
if(this.w_queue[key].attr("data-col") == $widget.attr("data-col") && this.w_queue[key].attr("data-row") == $widget.attr("data-row")){
|
||||
queued = true;
|
||||
//test whole space
|
||||
var $w = this.w_queue[key];
|
||||
var dcol = parseInt(key.split("_")[0]);
|
||||
var drow = parseInt(key.split("_")[1]);
|
||||
var wgd = $w.coords().grid;
|
||||
|
||||
for (var c = 0; c < wgd.size_x; c++){
|
||||
for (var r = 0; r < wgd.size_y; r++){
|
||||
var colc = dcol + c;
|
||||
var rowc = drow + r;
|
||||
if (this.is_player_in(colc,rowc)){
|
||||
queued = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return queued
|
||||
}
|
||||
|
||||
fn.is_in_queue = function(col,row, $widget){
|
||||
var queued = false;
|
||||
var key = col+"_"+row;
|
||||
|
||||
if ((key in this.w_queue)){
|
||||
if (this.w_queue[key] == "full"){
|
||||
queued = true;
|
||||
} else {
|
||||
$tw = this.w_queue[key];
|
||||
tgd = $tw.coords().grid;
|
||||
if(!this.is_widget_under_player(tgd.col,tgd.row)){
|
||||
delete this.w_queue[key]
|
||||
queued = false;
|
||||
} else if(this.w_queue[key].attr("data-col") == $widget.attr("data-col") && this.w_queue[key].attr("data-row") == $widget.attr("data-row")) {
|
||||
delete this.w_queue[key]
|
||||
queued = false;
|
||||
} else {
|
||||
queued = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return queued;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See which of the widgets in the $widgets param collection can go to
|
||||
* a upper row and which not.
|
||||
@@ -2813,6 +3072,8 @@
|
||||
/**
|
||||
* Sorts an Array of grid coords objects (representing the grid coords of
|
||||
* each widget) in descending way.
|
||||
|
||||
* Depreciated.
|
||||
*
|
||||
* @method manage_movements
|
||||
* @param {jQuery} $widgets A jQuery collection of HTMLElements
|
||||
@@ -2845,9 +3106,11 @@
|
||||
// so we need to move widget down to a position that dont
|
||||
// overlaps player
|
||||
var y = (to_row + this.player_grid_data.size_y) - wgd.row;
|
||||
|
||||
this.move_widget_down($w, y);
|
||||
this.set_placeholder(to_col, to_row);
|
||||
if (this.can_go_down($w)){
|
||||
console.log("In Move Down!")
|
||||
this.move_widget_down($w, y);
|
||||
this.set_placeholder(to_col, to_row);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, this));
|
||||
@@ -2979,6 +3242,32 @@
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines if widget is supposed to be static.
|
||||
* @method is_static
|
||||
* @param {Number} col The column to check.
|
||||
* @param {Number} row The row to check.
|
||||
* @return {Boolean} Returns true if widget exists and has static class,
|
||||
* else returns false
|
||||
*/
|
||||
|
||||
fn.is_static = function(col, row) {
|
||||
var cell = this.gridmap[col];
|
||||
if (!cell) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cell = cell[row];
|
||||
|
||||
if (cell) {
|
||||
if(cell.hasClass(this.options.static_class)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determines if there is a widget in the cell represented by col/row
|
||||
@@ -3061,8 +3350,16 @@
|
||||
|
||||
if (moved_down || changed_column) {
|
||||
$nexts.each($.proxy(function(i, widget) {
|
||||
this.move_widget_up(
|
||||
$(widget), this.placeholder_grid_data.col - col + phgd.size_y);
|
||||
//Make sure widget is at it's topmost position
|
||||
$w = $(widget);
|
||||
wgd = $w.coords().grid;
|
||||
|
||||
var can_go_widget_up = this.can_go_widget_up(wgd);
|
||||
|
||||
if (can_go_widget_up) {
|
||||
this.move_widget_to($w, can_go_widget_up);
|
||||
}
|
||||
|
||||
}, this));
|
||||
}
|
||||
|
||||
@@ -3329,13 +3626,14 @@
|
||||
* @return {jQuery} Returns a jQuery collection of HTMLElements.
|
||||
*/
|
||||
fn.on_stop_overlapping_column = function(col) {
|
||||
this.set_player(col, false);
|
||||
|
||||
//this.set_player(col, false);
|
||||
var self = this;
|
||||
this.for_each_widget_below(col, this.cells_occupied_by_player.rows[0],
|
||||
function(tcol, trow) {
|
||||
self.move_widget_up(this, self.player_grid_data.size_y);
|
||||
});
|
||||
if(this.options.shift_larger_widgets_down){
|
||||
this.for_each_widget_below(col, this.cells_occupied_by_player.rows[0],
|
||||
function(tcol, trow) {
|
||||
self.move_widget_up(this, self.player_grid_data.size_y);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -3347,17 +3645,37 @@
|
||||
* @return {jQuery} Returns a jQuery collection of HTMLElements.
|
||||
*/
|
||||
fn.on_stop_overlapping_row = function(row) {
|
||||
this.set_player(false, row);
|
||||
|
||||
//this.set_player(false, row);
|
||||
var self = this;
|
||||
var cols = this.cells_occupied_by_player.cols;
|
||||
for (var c = 0, cl = cols.length; c < cl; c++) {
|
||||
this.for_each_widget_below(cols[c], row, function(tcol, trow) {
|
||||
self.move_widget_up(this, self.player_grid_data.size_y);
|
||||
});
|
||||
if(this.options.shift_larger_widgets_down){
|
||||
for (var c = 0, cl = cols.length; c < cl; c++) {
|
||||
this.for_each_widget_below(cols[c], row, function(tcol, trow) {
|
||||
console.log("from_on_stop_overlapping_row");
|
||||
self.move_widget_up(this, self.player_grid_data.size_y);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//Not yet part of api - DM.
|
||||
fn.new_move_widget_to = function($widget, col, row){
|
||||
var self = this;
|
||||
var widget_grid_data = $widget.coords().grid;
|
||||
|
||||
this.remove_from_gridmap(widget_grid_data);
|
||||
widget_grid_data.row = row;
|
||||
widget_grid_data.col = col;
|
||||
|
||||
this.add_to_gridmap(widget_grid_data);
|
||||
$widget.attr('data-row', row);
|
||||
$widget.attr('data-col', col);
|
||||
this.update_widget_position(widget_grid_data, $widget);
|
||||
this.$changed = this.$changed.add($widget);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move a widget to a specific row and column.
|
||||
@@ -3476,9 +3794,10 @@
|
||||
|
||||
moved.push($widget);
|
||||
|
||||
$next_widgets.each($.proxy(function(i, widget) {
|
||||
/* $next_widgets.each($.proxy(function(i, widget) {
|
||||
console.log("from_within_move_widget_up");
|
||||
this.move_widget_up($(widget), y_units);
|
||||
}, this));
|
||||
}, this)); */
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3681,6 +4000,23 @@
|
||||
return this;
|
||||
};
|
||||
|
||||
fn.can_go_down = function($el) {
|
||||
var can_go_down = true;
|
||||
var $gr = this;
|
||||
|
||||
if ($el.hasClass(this.options.static_class)){
|
||||
can_go_down = false;
|
||||
}
|
||||
|
||||
this.widgets_below($el).each(function(){
|
||||
if ($(this).hasClass($gr.options.static_class)){
|
||||
can_go_down = false;
|
||||
}
|
||||
})
|
||||
|
||||
return can_go_down;
|
||||
}
|
||||
|
||||
|
||||
fn.can_go_up = function($el) {
|
||||
var el_grid_data = $el.coords().grid;
|
||||
@@ -3876,6 +4212,15 @@
|
||||
}
|
||||
};
|
||||
|
||||
fn.clean_up_changed = function(){
|
||||
$gr = this;
|
||||
$gr.$changed.each(function(){
|
||||
if($gr.options.shift_larger_widgets_down){
|
||||
$gr.move_widget_up($(this));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn._traversing_widgets = function(type, direction, col, row, callback) {
|
||||
@@ -3913,7 +4258,8 @@
|
||||
) {
|
||||
cr = callback.call(ga[col][trow], col, trow);
|
||||
matched.push(ga[col][trow]);
|
||||
if (cr) { break; }
|
||||
//break was causing problems, leaving for testing.
|
||||
//if (cr) { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4495,7 +4841,8 @@
|
||||
max_rows += (+$(w).attr('data-sizey'));
|
||||
});
|
||||
|
||||
this.rows = Math.max(max_rows, this.options.min_rows);
|
||||
//this.rows = Math.max(max_rows, this.options.min_rows);
|
||||
this.rows = this.options.max_rows;
|
||||
|
||||
this.baseX = ($window.width() - aw) / 2;
|
||||
this.baseY = this.$wrapper.offset().top;
|
||||
|
||||
+2
-2
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user