2

I'm using Gridster to render a layout of tiles in my app, using NodeBB as a base.

The code is as follows:

<script src="/jquery.js"></script>
<script src="/gridster.js"></script>

<script>
$.noConflict();
jQuery(function () {
    jQuery(".gridster ul").gridster({
        widget_margins: [10, 10],
        widget_base_dimensions: [175, 175],

        serialize_params: function(wi, wgd) {
            console.log($(wi).attr('id'));
            return {
                id: $(wi).attr('id'),
                col: wgd.col,
                row: wgd.row,
                size_x: wgd.size_x,
                size_y: wgd.size_y
            };
        },

        draggable: {
            start: function () {
                dragged = 1;
            },
            stop: function () {
                setTimeout(function () {
                    dragged = 0;
                }, 5);
            }
        }
    });
});
</script>

As you can see, I've tried to initialise Gridster in a <script> tag, but when I run it I get:

Uncaught TypeError: undefined is not a function

when trying to access gridster ($('.gridster ul').gridster( \\ ..). jQuery is fine, it's just Gridster.

Why?

galexite
  • 177
  • 10

1 Answers1

2

Looks like perhaps you have used the sourcefile, rather than the compiled version of gridster. Did you download from GitHub? Use dist/jquery.gridster.min.js, rather than src/jquery.gridster.js

For future reference, the version in src/ is for use when being compiled by Grunt.

aboved
  • 45
  • 2
  • 5