ducksboard / gridster.js

gridster.js is a jQuery plugin that makes building intuitive draggable layouts from elements spanning multiple columns
http://gridster.net/
MIT License
6.03k stars 1.2k forks source link

html5 data tags for settings #201

Open absentdream opened 11 years ago

absentdream commented 11 years ago

i adjusted my serialize_params to walk to attributes of the li and recover all html5 "data-" attributes.. i store these in database via "SON.stringify".. and load by simple foreach on data..a bit more dynamic.. :) note had to change your internal varibles size_y and sizex to sizex sizey as cuases issues with html5 data tages...

but just thought people might want to see this

calvin streeting


        var grid = $(".gridster ul").gridster({
            widget_margins: [5, 5],
            widget_base_dimensions: [200, 200],
            draggable: {
                stop: function(event, ui){ 
                    $("#desktop").val(JSON.stringify(grid.serialize()));
                    $("#desktopSave").show();
                    }
                },
            serialize_params: function ($w, wgd) {
                    var rtn = {};
                    $w.each(function() {
                        $.each(this.attributes, function(i, attrib){
                            var name = attrib.name;
                            if (name.substring(0,5)=="data-"){
                                var value = attrib.value;
                                rtn[name.substring(5)] = value;
                            }
                        });
                    });
                return rtn;
            }       
        }).data("gridster");