Lot of changes in gridster

This commit is contained in:
harrybomrah authored and Rueshyna committed 2013-03-04 12:37:29 +08:00
1 parent ee4b94ace0
commit b8ee748723
7 files changed
+123 -37

No files matched your search

@@ -1328,6 +1328,7 @@
*/
fn.draggable = function() {
var self = this;
var draggable_options = $.extend(true, {}, this.options.draggable, {
offset_left: this.options.widget_margins[0],
start: function(event, ui) {
@@ -3204,6 +3205,7 @@
max_rows += (+$(w).attr('data-sizey'));
});
this.cols = Math.max(min_cols, cols, this.options.min_cols);
this.rows = Math.max(max_rows, this.options.min_rows);
+61 -9
View File
@@ -420,9 +420,10 @@ var orbitDesktop = function(dom){
$.getJSON("/desktop/getgroups",{sectionid:id},function(tiles){
tiles.sort(o.sortJSON("position",true,parseInt));
var tilecolors = o.themesettings.tilecolor;
var totaltiles_in_a_row = 4;
var opacity = ["op05","op06","op07","op08","op09"];
var row = 1,col = 1,x = 1,y = 1;
var $group = $('<div class="grid"></div>');
var $group = $('<div class="grid gridster"></div>');
var $ul = $('<ul style="margin: -6px 0 0 -6px;"></ul>');
$.each(tiles,function(i,tile){
@@ -436,21 +437,72 @@ var orbitDesktop = function(dom){
var tilecolor = tilecolors[Math.floor(Math.random()*tilecolors.length)];
var op = opacity[Math.floor(Math.random()*opacity.length)];
if(tile.data_category == "app")
$li = $('<li data-id="'+tile.id+'" class="element" data-row="'+row+'" data-col="'+col+'" data-sizex="'+x+'" data-sizey="'+y+'" data-category="'+tile.data_category+'" data-content="'+tile.data_content+'"><span class="tile '+tilecolor+' '+op+'"></span><a href="'+tile.data_content+'" class="appicon" onclick="return false;"><img src="'+o.iconPath+tile.data_content+'.png" alt="" ></a><h1 class="appname thmtxt">'+tile.title+'</h1></li>');
$li = $('<li data-id="'+tile.id+'" class="widget" data-row="'+row+'" data-col="'+col+'" data-sizex="'+x+'" data-sizey="'+y+'" data-category="'+tile.data_category+'" data-content="'+tile.data_content+'"><span class="tile '+tilecolor+' '+op+'"></span><a href="'+tile.data_content+'" class="appicon" onclick="return false;"><img src="'+o.iconPath+tile.data_content+'.png" alt="" ></a><h1 class="appname thmtxt">'+tile.title+'</h1></li>');
else
$li = $('<li data-id="'+tile.id+'" class="element" data-row="'+row+'" data-col="'+col+'" data-sizex="'+x+'" data-sizey="'+y+'" data-category="'+tile.data_category+'" data-content="'+tile.data_content+'" js-link="'+tile.js[0].url+'" css-link="'+tile.css.url+'"><span class="tile '+tilecolor+' '+op+'"></span><div class="appholder">Loading...</div><h1 class="appname thmtxt">'+tile.title+'</h1></li>');
$li = $('<li data-id="'+tile.id+'" class="widget" data-row="'+row+'" data-col="'+col+'" data-sizex="'+x+'" data-sizey="'+y+'" data-category="'+tile.data_category+'" data-content="'+tile.data_content+'" js-link="'+tile.js[0].url+'" css-link="'+tile.css.url+'"><span class="tile '+tilecolor+' '+op+'"></span><div class="appholder">Loading...</div><h1 class="appname thmtxt">'+tile.title+'</h1></li>');
row = row + y;
$ul.append($li);
})
$group.append($ul);
console.log($group);
$("div#desktop div#group_wrapper").append($group);
o.gridvar = $(".grid ul").gridster({
widget_margins: [6, 6],
widget_base_dimensions: [120, 120]
});
var dragged = null,draggable,lastpos = [];
o.gridvar = $(".grid ul").find("> li ").mousedown(function(e){
!draggable;
dragged = $(this);
lastpos = [];
$(".grid ul li").each(function(){
lastpos.push({"col":$(this).attr("data-col"),"row":$(this).attr("data-row")})
})
}).end()
.gridster({
widget_margins: [6, 6],
widget_base_dimensions: [120, 120],
avoid_overlapped_widgets: true,
draggable : {
stop: function(event, ui){
var widgetchanged_col = dragged.attr("data-col");
var total = 0;
// console.log(widgetchanged.col);
// console.log(o.gridvar.serialize_changed());
$(".grid ul li[data-col="+widgetchanged_col+"]").each(function(i,w){
var size = parseInt($(this).attr("data-sizey"));
if(!isNaN(size)){
total += size;
}
})
// other way to calculate the overflow is by top > height of div
if(total>totaltiles_in_a_row){
revertbacktiles();
}else{
console.log(widgetchanged_col-1);
$(".grid ul li[data-col="+(widgetchanged_col-1)+"]").each(function(i,w){
var sizey = parseInt($(this).attr("data-sizey"));
var sizex = parseInt($(this).attr("data-sizex"));
if(sizey==1){
sizex = sizex - 1;
}
console.log(sizex);
if(!isNaN(sizex)){
total += sizex;
}
})
if(total>totaltiles_in_a_row){
revertbacktiles();
}
}
}
}
}).data('gridster');
var revertbacktiles = function(){
lastpos.push({"col":"","row":""});
$(".grid ul li").each(function(i){
$(this).attr({"data-col":lastpos[i].col,"data-row":lastpos[i].row});
})
}
bindHandlers();
o.initializeWidgets();
})
@@ -1219,7 +1271,7 @@ var orbitDesktop = function(dom){
})
};
this.initializeWidgets = function(){ // this function will initialize all the widgets in the desktop
var elements = $("#group_wrapper li.element");
var elements = $("#group_wrapper li.widget");
$.each(elements,function(){
var widget = $(this);
if(widget.attr("data-category")=="widget"){