fix styling
This commit is contained in:
parent
2b4d15e26c
commit
4bca887447
@ -1,7 +1,3 @@
|
|||||||
/*! gridster.js - v0.1.0 - 2012-10-20
|
|
||||||
* http://gridster.net/
|
|
||||||
* Copyright (c) 2012 ducksboard; Licensed MIT */
|
|
||||||
|
|
||||||
.gridster {
|
.gridster {
|
||||||
position:relative;
|
position:relative;
|
||||||
}
|
}
|
||||||
|
4
assets/css/jquery.gridster.min.css
vendored
4
assets/css/jquery.gridster.min.css
vendored
@ -1,3 +1 @@
|
|||||||
/*! gridster.js - v0.1.0 - 2012-10-20
|
.gridster{position:relative}.gridster>*{margin:0 auto;-webkit-transition:height .4s;-moz-transition:height .4s;-o-transition:height .4s;-ms-transition:height .4s;transition:height .4s}.gridster .gs_w{z-index:2;position:absolute}.ready .gs_w:not(.preview-holder){-webkit-transition:opacity .3s,left .3s,top .3s;-moz-transition:opacity .3s,left .3s,top .3s;-o-transition:opacity .3s,left .3s,top .3s;transition:opacity .3s,left .3s,top .3s}.ready .gs_w:not(.preview-holder){-webkit-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;-moz-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;-o-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;transition:opacity .3s,left .3s,top .3s,width .3s,height .3s}.gridster .preview-holder{z-index:1;position:absolute;background-color:#fff;border-color:#fff;opacity:.3}.gridster .player-revert{z-index:10!important;-webkit-transition:left .3s,top .3s!important;-moz-transition:left .3s,top .3s!important;-o-transition:left .3s,top .3s!important;transition:left .3s,top .3s!important}.gridster .dragging{z-index:10!important;-webkit-transition:all 0s!important;-moz-transition:all 0s!important;-o-transition:all 0s!important;transition:all 0s!important}
|
||||||
* http://gridster.net/
|
|
||||||
* Copyright (c) 2012 ducksboard; Licensed MIT */.gridster{position:relative}.gridster>*{margin:0 auto;-webkit-transition:height .4s;-moz-transition:height .4s;-o-transition:height .4s;-ms-transition:height .4s;transition:height .4s}.gridster .gs_w{z-index:2;position:absolute}.ready .gs_w:not(.preview-holder){-webkit-transition:opacity .3s,left .3s,top .3s;-moz-transition:opacity .3s,left .3s,top .3s;-o-transition:opacity .3s,left .3s,top .3s;transition:opacity .3s,left .3s,top .3s}.ready .gs_w:not(.preview-holder){-webkit-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;-moz-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;-o-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;transition:opacity .3s,left .3s,top .3s,width .3s,height .3s}.gridster .preview-holder{z-index:1;position:absolute;background-color:#fff;border-color:#fff;opacity:.3}.gridster .player-revert{z-index:10!important;-webkit-transition:left .3s,top .3s!important;-moz-transition:left .3s,top .3s!important;-o-transition:left .3s,top .3s!important;transition:left .3s,top .3s!important}.gridster .dragging{z-index:10!important;-webkit-transition:all 0s!important;-moz-transition:all 0s!important;-o-transition:all 0s!important;transition:all 0s!important}
|
|
@ -32,7 +32,7 @@ h3 {
|
|||||||
.demo {
|
.demo {
|
||||||
margin: 3em 0;
|
margin: 3em 0;
|
||||||
padding: 7.5em 0 5.5em;
|
padding: 7.5em 0 5.5em;
|
||||||
/* background: #004756; */
|
background: #004756;
|
||||||
}
|
}
|
||||||
|
|
||||||
.demo:hover .gridster {
|
.demo:hover .gridster {
|
||||||
@ -53,8 +53,8 @@ h3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.gridster .gs_w {
|
.gridster .gs_w {
|
||||||
/* background: #FFF; */
|
background: #FFF;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
-webkit-box-shadow: 0 0 5px rgba(0,0,0,0.3);
|
-webkit-box-shadow: 0 0 5px rgba(0,0,0,0.3);
|
||||||
/* box-shadow: 0 0 5px rgba(0,0,0,0.3); */
|
box-shadow: 0 0 5px rgba(0,0,0,0.3);
|
||||||
}
|
}
|
@ -34,8 +34,8 @@
|
|||||||
var grid_canvas = $(".gridster > ul").gridster({
|
var grid_canvas = $(".gridster > ul").gridster({
|
||||||
widget_margins: [3, 3],
|
widget_margins: [3, 3],
|
||||||
widget_base_dimensions: [140, 140],
|
widget_base_dimensions: [140, 140],
|
||||||
max_cols: [2],
|
max_cols: [5],
|
||||||
max_rows: [2],
|
max_rows: [4],
|
||||||
|
|
||||||
// serialize_params: function($w, wgd) { return { id: $($w).attr('id'),col: wgd.col, row: wgd.row,size_x: wgd.size_x,size_y: wgd.size_y }
|
// serialize_params: function($w, wgd) { return { id: $($w).attr('id'),col: wgd.col, row: wgd.row,size_x: wgd.size_x,size_y: wgd.size_y }
|
||||||
// A function to return serialized data for each each widget, used when calling the serialize method. Two arguments are passed:
|
// A function to return serialized data for each each widget, used when calling the serialize method. Two arguments are passed:
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
/*! gridster.js - v0.1.0 - 2012-10-20
|
/*
|
||||||
* http://gridster.net/
|
* jquery.coords
|
||||||
* Copyright (c) 2012 ducksboard; Licensed MIT */
|
* https://github.com/ducksboard/gridster.js
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012 ducksboard
|
||||||
|
* Licensed under the MIT licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
;(function($, window, document, undefined){
|
;(function($, window, document, undefined){
|
||||||
/**
|
/**
|
||||||
@ -103,6 +107,14 @@
|
|||||||
|
|
||||||
}(jQuery, window, document));
|
}(jQuery, window, document));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* jquery.collision
|
||||||
|
* https://github.com/ducksboard/gridster.js
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012 ducksboard
|
||||||
|
* Licensed under the MIT licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
;(function($, window, document, undefined){
|
;(function($, window, document, undefined){
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
@ -274,7 +286,7 @@
|
|||||||
|
|
||||||
if (self.options.on_overlap_stop || self.options.on_overlap_start) {
|
if (self.options.on_overlap_stop || self.options.on_overlap_start) {
|
||||||
this.manage_colliders_start_stop(colliders_coords,
|
this.manage_colliders_start_stop(colliders_coords,
|
||||||
self.options.on_overlap_stop, self.options.on_overlap_start);
|
self.options.on_overlap_start, self.options.on_overlap_stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.last_colliders_coords = colliders_coords;
|
this.last_colliders_coords = colliders_coords;
|
||||||
@ -358,6 +370,14 @@
|
|||||||
|
|
||||||
})(window);
|
})(window);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* jquery.draggable
|
||||||
|
* https://github.com/ducksboard/gridster.js
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012 ducksboard
|
||||||
|
* Licensed under the MIT licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
;(function($, window, document, undefined){
|
;(function($, window, document, undefined){
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
@ -368,7 +388,7 @@
|
|||||||
autoscroll: true,
|
autoscroll: true,
|
||||||
ignore_dragging: ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'],
|
ignore_dragging: ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'],
|
||||||
handle: null
|
handle: null
|
||||||
// ,drag: function(e){},
|
// drag: function(e){},
|
||||||
// start : function(e, ui){},
|
// start : function(e, ui){},
|
||||||
// stop : function(e){}
|
// stop : function(e){}
|
||||||
};
|
};
|
||||||
@ -425,24 +445,26 @@
|
|||||||
this.disabled = false;
|
this.disabled = false;
|
||||||
this.events();
|
this.events();
|
||||||
|
|
||||||
$(window).bind('resize',
|
this.on_window_resize = throttle($.proxy(this.calculate_positions, this), 200);
|
||||||
throttle($.proxy(this.calculate_positions, this), 200));
|
$(window).bind('resize', this.on_window_resize);
|
||||||
};
|
};
|
||||||
|
|
||||||
fn.events = function() {
|
fn.events = function() {
|
||||||
this.$container.on('selectstart', $.proxy(this.on_select_start, this));
|
this.proxied_on_select_start = $.proxy(this.on_select_start, this);
|
||||||
|
this.$container.on('selectstart', this.proxied_on_select_start);
|
||||||
|
|
||||||
this.$container.on(pointer_events.start, this.options.items, $.proxy(
|
this.proxied_drag_handler = $.proxy(this.drag_handler, this);
|
||||||
this.drag_handler, this));
|
this.$container.on(pointer_events.start, this.options.items, this.proxied_drag_handler);
|
||||||
|
|
||||||
this.$body.on(pointer_events.end, $.proxy(function(e) {
|
this.proxied_pointer_events_end = $.proxy(function(e) {
|
||||||
this.is_dragging = false;
|
this.is_dragging = false;
|
||||||
if (this.disabled) { return; }
|
if (this.disabled) { return; }
|
||||||
this.$body.off(pointer_events.move);
|
this.$body.off(pointer_events.move);
|
||||||
if (this.drag_start) {
|
if (this.drag_start) {
|
||||||
this.on_dragstop(e);
|
this.on_dragstop(e);
|
||||||
}
|
}
|
||||||
}, this));
|
}, this);
|
||||||
|
this.$body.on(pointer_events.end, this.proxied_pointer_events_end);
|
||||||
};
|
};
|
||||||
|
|
||||||
fn.get_actual_pos = function($el) {
|
fn.get_actual_pos = function($el) {
|
||||||
@ -549,7 +571,7 @@
|
|||||||
this.mouse_init_pos = this.get_mouse_pos(e);
|
this.mouse_init_pos = this.get_mouse_pos(e);
|
||||||
this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top;
|
this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top;
|
||||||
|
|
||||||
this.$body.on(pointer_events.move, function(mme){
|
this.on_pointer_events_move = function(mme){
|
||||||
var mouse_actual_pos = self.get_mouse_pos(mme);
|
var mouse_actual_pos = self.get_mouse_pos(mme);
|
||||||
var diff_x = Math.abs(
|
var diff_x = Math.abs(
|
||||||
mouse_actual_pos.left - self.mouse_init_pos.left);
|
mouse_actual_pos.left - self.mouse_init_pos.left);
|
||||||
@ -572,7 +594,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
};
|
||||||
|
|
||||||
|
this.$body.on(pointer_events.move, this.on_pointer_events_move);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
@ -678,6 +702,13 @@
|
|||||||
|
|
||||||
fn.destroy = function(){
|
fn.destroy = function(){
|
||||||
this.disable();
|
this.disable();
|
||||||
|
|
||||||
|
this.$container.off('selectstart', this.proxied_on_select_start);
|
||||||
|
this.$container.off(pointer_events.start, this.proxied_drag_handler);
|
||||||
|
this.$body.off(pointer_events.end, this.proxied_pointer_events_end);
|
||||||
|
this.$body.off(pointer_events.move, this.on_pointer_events_move);
|
||||||
|
$(window).unbind('resize', this.on_window_resize);
|
||||||
|
|
||||||
$.removeData(this.$container, 'drag');
|
$.removeData(this.$container, 'drag');
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -690,7 +721,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
//jQuery adapter
|
//jQuery adapter
|
||||||
$.fn.drag = function ( options ) {
|
$.fn.dragg = function ( options ) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
if (!$.data(this, 'drag')) {
|
if (!$.data(this, 'drag')) {
|
||||||
$.data(this, 'drag', new Draggable( this, options ));
|
$.data(this, 'drag', new Draggable( this, options ));
|
||||||
@ -701,20 +732,32 @@
|
|||||||
|
|
||||||
}(jQuery, window, document));
|
}(jQuery, window, document));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* jquery.gridster
|
||||||
|
* https://github.com/ducksboard/gridster.js
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012 ducksboard
|
||||||
|
* Licensed under the MIT licenses.
|
||||||
|
*/
|
||||||
;(function($, window, document, undefined) {
|
;(function($, window, document, undefined) {
|
||||||
|
|
||||||
|
//ToDo Max_cols and Max_size_x conflict.. need to unify
|
||||||
var defaults = {
|
var defaults = {
|
||||||
namespace: '',
|
namespace: '',
|
||||||
widget_selector: 'li',
|
widget_selector: 'li',
|
||||||
|
static_class: 'static',
|
||||||
widget_margins: [10, 10],
|
widget_margins: [10, 10],
|
||||||
widget_base_dimensions: [400, 225],
|
widget_base_dimensions: [400, 225],
|
||||||
extra_rows: 0,
|
extra_rows: 0,
|
||||||
extra_cols: 0,
|
extra_cols: 0,
|
||||||
min_cols: 1,
|
min_cols: 1,
|
||||||
|
max_cols: 60,
|
||||||
min_rows: 15,
|
min_rows: 15,
|
||||||
|
max_rows: 15,
|
||||||
max_size_x: 6,
|
max_size_x: 6,
|
||||||
autogenerate_stylesheet: true,
|
autogenerate_stylesheet: true,
|
||||||
avoid_overlapped_widgets: true,
|
avoid_overlapped_widgets: true,
|
||||||
|
shift_larger_widgets_down: true,
|
||||||
serialize_params: function($w, wgd) {
|
serialize_params: function($w, wgd) {
|
||||||
return {
|
return {
|
||||||
col: wgd.col,
|
col: wgd.col,
|
||||||
@ -725,7 +768,8 @@
|
|||||||
},
|
},
|
||||||
collision: {},
|
collision: {},
|
||||||
draggable: {
|
draggable: {
|
||||||
distance: 4
|
distance: 4,
|
||||||
|
items: ".gs_w:not(.static)"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -783,6 +827,7 @@
|
|||||||
this.$widgets = this.$el.children(this.options.widget_selector).addClass('gs_w');
|
this.$widgets = this.$el.children(this.options.widget_selector).addClass('gs_w');
|
||||||
this.widgets = [];
|
this.widgets = [];
|
||||||
this.$changed = $([]);
|
this.$changed = $([]);
|
||||||
|
this.w_queue = {};
|
||||||
this.wrapper_width = this.$wrapper.width();
|
this.wrapper_width = this.$wrapper.width();
|
||||||
this.min_widget_width = (this.options.widget_margins[0] * 2) +
|
this.min_widget_width = (this.options.widget_margins[0] * 2) +
|
||||||
this.options.widget_base_dimensions[0];
|
this.options.widget_base_dimensions[0];
|
||||||
@ -869,6 +914,7 @@
|
|||||||
}).addClass('gs_w').appendTo(this.$el).hide();
|
}).addClass('gs_w').appendTo(this.$el).hide();
|
||||||
|
|
||||||
this.$widgets = this.$widgets.add($w);
|
this.$widgets = this.$widgets.add($w);
|
||||||
|
this.$changed = this.$changed.add($w);
|
||||||
|
|
||||||
this.register_widget($w);
|
this.register_widget($w);
|
||||||
|
|
||||||
@ -1071,9 +1117,12 @@
|
|||||||
size_y: size_y
|
size_y: size_y
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
$nexts.not(exclude).each($.proxy(function(i, widget) {
|
$nexts.not(exclude).each($.proxy(function(i, widget) {
|
||||||
|
console.log("from_remove")
|
||||||
this.move_widget_up( $(widget), size_y );
|
this.move_widget_up( $(widget), size_y );
|
||||||
}, this));
|
}, this));
|
||||||
|
*/
|
||||||
|
|
||||||
this.set_dom_grid_height();
|
this.set_dom_grid_height();
|
||||||
|
|
||||||
@ -1123,6 +1172,13 @@
|
|||||||
return false;
|
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.
|
* Remove a widget from the grid.
|
||||||
@ -1199,14 +1255,15 @@
|
|||||||
$widgets || ($widgets = this.$widgets);
|
$widgets || ($widgets = this.$widgets);
|
||||||
var result = [];
|
var result = [];
|
||||||
$widgets.each($.proxy(function(i, widget) {
|
$widgets.each($.proxy(function(i, widget) {
|
||||||
|
if(typeof($(widget).coords().grid) != "undefined"){
|
||||||
result.push(this.options.serialize_params(
|
result.push(this.options.serialize_params(
|
||||||
$(widget), $(widget).coords().grid ) );
|
$(widget), $(widget).coords().grid ) );
|
||||||
|
}
|
||||||
}, this));
|
}, this));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a serialized array of the widgets that have changed their
|
* Returns a serialized array of the widgets that have changed their
|
||||||
* position.
|
* position.
|
||||||
@ -1241,6 +1298,10 @@
|
|||||||
!this.can_move_to(
|
!this.can_move_to(
|
||||||
{size_x: wgd.size_x, size_y: wgd.size_y}, wgd.col, wgd.row)
|
{size_x: wgd.size_x, size_y: wgd.size_y}, wgd.col, wgd.row)
|
||||||
) {
|
) {
|
||||||
|
/*if(!$el.hasClass('.disp_ad')){
|
||||||
|
$el.remove();
|
||||||
|
return false;
|
||||||
|
}*/
|
||||||
wgd = this.next_position(wgd.size_x, wgd.size_y);
|
wgd = this.next_position(wgd.size_x, wgd.size_y);
|
||||||
wgd.el = $el;
|
wgd.el = $el;
|
||||||
$el.attr({
|
$el.attr({
|
||||||
@ -1309,13 +1370,13 @@
|
|||||||
*/
|
*/
|
||||||
fn.add_to_gridmap = function(grid_data, value) {
|
fn.add_to_gridmap = function(grid_data, value) {
|
||||||
this.update_widget_position(grid_data, value || grid_data.el);
|
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);
|
var $widgets = this.widgets_below(grid_data.el);
|
||||||
$widgets.each($.proxy(function(i, widget) {
|
$widgets.each($.proxy(function(i, widget) {
|
||||||
|
console.log("from_add_to_gridmap");
|
||||||
this.move_widget_up( $(widget));
|
this.move_widget_up( $(widget));
|
||||||
}, this));
|
}, this));
|
||||||
}
|
} */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -1352,7 +1413,7 @@
|
|||||||
}, 60)
|
}, 60)
|
||||||
});
|
});
|
||||||
|
|
||||||
this.drag_api = this.$el.drag(draggable_options).data('drag');
|
this.drag_api = this.$el.dragg(draggable_options).data('drag');
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1507,6 +1568,7 @@
|
|||||||
this.player_grid_data = {};
|
this.player_grid_data = {};
|
||||||
this.cells_occupied_by_placeholder = {};
|
this.cells_occupied_by_placeholder = {};
|
||||||
this.cells_occupied_by_player = {};
|
this.cells_occupied_by_player = {};
|
||||||
|
this.w_queue = {};
|
||||||
|
|
||||||
this.set_dom_grid_height();
|
this.set_dom_grid_height();
|
||||||
};
|
};
|
||||||
@ -1600,12 +1662,13 @@
|
|||||||
*/
|
*/
|
||||||
fn.set_player = function(col, row, no_player) {
|
fn.set_player = function(col, row, no_player) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var swap = false;
|
||||||
if (!no_player) {
|
if (!no_player) {
|
||||||
this.empty_cells_player_occupies();
|
this.empty_cells_player_occupies();
|
||||||
}
|
}
|
||||||
var cell = !no_player ? self.colliders_data[0].el.data : {col: col};
|
var cell = !no_player ? self.colliders_data[0].el.data : {col: col};
|
||||||
var to_col = cell.col;
|
var to_col = cell.col;
|
||||||
var to_row = row || cell.row;
|
var to_row = cell.row || row;
|
||||||
|
|
||||||
this.player_grid_data = {
|
this.player_grid_data = {
|
||||||
col: to_col,
|
col: to_col,
|
||||||
@ -1617,13 +1680,102 @@
|
|||||||
this.cells_occupied_by_player = this.get_cells_occupied(
|
this.cells_occupied_by_player = this.get_cells_occupied(
|
||||||
this.player_grid_data);
|
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(
|
var $overlapped_widgets = this.get_widgets_overlapped(
|
||||||
this.player_grid_data);
|
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;
|
||||||
|
|
||||||
|
// Ensure all values are in integer format
|
||||||
|
wgd.col = parseInt(wgd.col);
|
||||||
|
wgd.row = parseInt(wgd.row);
|
||||||
|
wgd.size_x = parseInt(wgd.size_x);
|
||||||
|
wgd.size_y = parseInt(wgd.size_y);
|
||||||
|
player_size_x = parseInt(player_size_x);
|
||||||
|
player_size_y = parseInt(player_size_y);
|
||||||
|
|
||||||
|
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,
|
/* if there is not widgets overlapping in the new player position,
|
||||||
* update the new placeholder position. */
|
* update the new placeholder position. */
|
||||||
@ -1632,8 +1784,12 @@
|
|||||||
if (pp !== false) {
|
if (pp !== false) {
|
||||||
to_row = pp;
|
to_row = pp;
|
||||||
}
|
}
|
||||||
|
if(this.can_placeholder_be_set(to_col, to_row, player_size_x, player_size_y)){
|
||||||
this.set_placeholder(to_col, to_row);
|
this.set_placeholder(to_col, to_row);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.w_queue = {};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
col: to_col,
|
col: to_col,
|
||||||
@ -1642,6 +1798,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
|
* See which of the widgets in the $widgets param collection can go to
|
||||||
* a upper row and which not.
|
* a upper row and which not.
|
||||||
@ -1765,6 +2066,8 @@
|
|||||||
/**
|
/**
|
||||||
* Sorts an Array of grid coords objects (representing the grid coords of
|
* Sorts an Array of grid coords objects (representing the grid coords of
|
||||||
* each widget) in descending way.
|
* each widget) in descending way.
|
||||||
|
|
||||||
|
* Depreciated.
|
||||||
*
|
*
|
||||||
* @method manage_movements
|
* @method manage_movements
|
||||||
* @param {HTMLElements} $widgets A jQuery collection of HTMLElements
|
* @param {HTMLElements} $widgets A jQuery collection of HTMLElements
|
||||||
@ -1797,11 +2100,13 @@
|
|||||||
// so we need to move widget down to a position that dont
|
// so we need to move widget down to a position that dont
|
||||||
// overlaps player
|
// overlaps player
|
||||||
var y = (to_row + this.player_grid_data.size_y) - wgd.row;
|
var y = (to_row + this.player_grid_data.size_y) - wgd.row;
|
||||||
|
if (this.can_go_down($w)){
|
||||||
|
console.log("In Move Down!")
|
||||||
this.move_widget_down($w, y);
|
this.move_widget_down($w, y);
|
||||||
this.set_placeholder(to_col, to_row);
|
this.set_placeholder(to_col, to_row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, this));
|
}, this));
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -1929,6 +2234,32 @@
|
|||||||
return false;
|
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
|
* Determines if there is a widget in the cell represented by col/row
|
||||||
@ -1990,7 +2321,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Prevents widgets go out of the grid
|
// Prevents widgets go out of the grid
|
||||||
var right_col = (col + phgd.size_x - 1);
|
var right_col = (col + parseInt(phgd.size_x) - 1);
|
||||||
if (right_col > this.cols) {
|
if (right_col > this.cols) {
|
||||||
col = col - (right_col - col);
|
col = col - (right_col - col);
|
||||||
}
|
}
|
||||||
@ -2011,8 +2342,16 @@
|
|||||||
|
|
||||||
if (moved_down || changed_column) {
|
if (moved_down || changed_column) {
|
||||||
$nexts.each($.proxy(function(i, widget) {
|
$nexts.each($.proxy(function(i, widget) {
|
||||||
this.move_widget_up(
|
//Make sure widget is at it's topmost position
|
||||||
$(widget), this.placeholder_grid_data.col - col + phgd.size_y);
|
$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));
|
}, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2274,13 +2613,14 @@
|
|||||||
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
|
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
|
||||||
*/
|
*/
|
||||||
fn.on_stop_overlapping_column = function(col) {
|
fn.on_stop_overlapping_column = function(col) {
|
||||||
this.set_player(col, false);
|
//this.set_player(col, false);
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
if(this.options.shift_larger_widgets_down){
|
||||||
this.for_each_widget_below(col, this.cells_occupied_by_player.rows[0],
|
this.for_each_widget_below(col, this.cells_occupied_by_player.rows[0],
|
||||||
function(tcol, trow) {
|
function(tcol, trow) {
|
||||||
self.move_widget_up(this, self.player_grid_data.size_y);
|
self.move_widget_up(this, self.player_grid_data.size_y);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -2292,17 +2632,37 @@
|
|||||||
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
|
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
|
||||||
*/
|
*/
|
||||||
fn.on_stop_overlapping_row = function(row) {
|
fn.on_stop_overlapping_row = function(row) {
|
||||||
this.set_player(false, row);
|
//this.set_player(false, row);
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var cols = this.cells_occupied_by_player.cols;
|
var cols = this.cells_occupied_by_player.cols;
|
||||||
|
if(this.options.shift_larger_widgets_down){
|
||||||
for (var c = 0, cl = cols.length; c < cl; c++) {
|
for (var c = 0, cl = cols.length; c < cl; c++) {
|
||||||
this.for_each_widget_below(cols[c], row, function(tcol, trow) {
|
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);
|
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. The cell or cells must be empty.
|
* Move a widget to a specific row. The cell or cells must be empty.
|
||||||
@ -2386,9 +2746,10 @@
|
|||||||
|
|
||||||
moved.push($widget);
|
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.move_widget_up($(widget), y_units);
|
||||||
}, this));
|
}, this)); */
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2587,6 +2948,23 @@
|
|||||||
return this;
|
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) {
|
fn.can_go_up = function($el) {
|
||||||
var el_grid_data = $el.coords().grid;
|
var el_grid_data = $el.coords().grid;
|
||||||
@ -2783,6 +3161,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) {
|
fn._traversing_widgets = function(type, direction, col, row, callback) {
|
||||||
@ -2820,7 +3207,8 @@
|
|||||||
) {
|
) {
|
||||||
cr = callback.call(ga[col][trow], col, trow);
|
cr = callback.call(ga[col][trow], col, trow);
|
||||||
matched.push(ga[col][trow]);
|
matched.push(ga[col][trow]);
|
||||||
if (cr) { break; }
|
//break was causing problems, leaving for testing.
|
||||||
|
//if (cr) { break; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3205,7 +3593,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.cols = Math.max(min_cols, cols, this.options.min_cols);
|
this.cols = Math.max(min_cols, cols, this.options.min_cols);
|
||||||
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.baseX = ($(window).width() - aw) / 2;
|
||||||
this.baseY = this.$wrapper.offset().top;
|
this.baseY = this.$wrapper.offset().top;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user