-
-
Save elvispt/fa3bd79434e48f3aeef4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(["jquery", | |
"jquery.gridster"], function($) { | |
var gridster = $(".gridster").gridster({ | |
widget_margins: [5, 5], | |
widget_base_dimensions: [200, 200], | |
widget_selector:"section.widget", | |
draggable: { | |
handle: '.ui-sortable-handle, .ui-sortable-handle > h5', | |
stop: function() { | |
//trigger a serialize event | |
} | |
}, | |
resize: { | |
enabled: true, | |
resize: function(e, ui, widget) { | |
//trigger a resize event | |
}, | |
stop: function(e, ui, widget) { | |
//trigger a resize event | |
//trigger a serialize event | |
} | |
}, | |
serialize_params: function($w, wgd) { | |
return { | |
id: $w.attr("id"), | |
value: { | |
col: wgd.col, | |
row: wgd.row, | |
sizex: wgd.size_x, | |
sizey: wgd.size_y | |
} | |
}; | |
} | |
}).data('gridster'); | |
function concatenate(initial, current) { | |
initial[current.id] = current.value; | |
return initial; | |
} | |
return function(storage, layout) { | |
this.start = function() { | |
if(storage.enabled() && storage.contains("grid")) { | |
var grid = storage.get("grid"); | |
$.each(grid, function(key, value){ | |
gridster.add_widget($("#"+key), value.sizex, value.sizey, value.col, value.row); | |
}); | |
} | |
else { | |
layout.defaultPositions(gridster); | |
} | |
//trigger a resize-all-widgets event | |
}; | |
this.store = function() { | |
var result = gridster.serialize() | |
.reduce(concatenate, {}); | |
storage.store("grid", result); | |
}; | |
this.resizeAll = function(){ | |
layout.widgets.forEach(function(widget) { | |
if(widget.resize && typeof widget.resize === "function") { | |
widget.resize(); | |
} | |
}); | |
}; | |
this.resize = function(target) { | |
layout.widgets.filter(function(widget) { | |
return (widget.resize && typeof widget.resize === "function") && | |
(widget.element && widget.element[0] === target[0]); | |
}) | |
.forEach(function(widget) { | |
widget.resize(); | |
}); | |
}; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment