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

Serialize positions not working in your demo #394

Closed clinton4 closed 10 years ago

clinton4 commented 10 years ago

Hi, Serialize do not work in this demo. http://gridster.net/demos/serialize.html

mpenfield commented 10 years ago

Serialize not working on demo for chrome (is working with Firefox). In crome, error thrown is Uncaught TypeError: Converting circular structure to JSON

Daijobou commented 10 years ago

Here a workaround.

0.5.2 its working!:

    fn.serialize = function($widgets) {
        $widgets || ($widgets = this.$widgets);
        var result = [];
        $widgets.each($.proxy(function(i, widget) {
            result.push(this.options.serialize_params(
                $(widget), $(widget).coords().grid ) );
        }, this));

        return result;
    };

In 0.5.3 its not working in Chrome and in Firefox its looks wrong.

    fn.serialize = function($widgets) {
        $widgets || ($widgets = this.$widgets);

        return $widgets.map($.proxy(function(i, widget) {
            var $w = $(widget);
            return this.options.serialize_params($w, $w.coords().grid);
        }, this));
    };

See: https://github.com/ducksboard/gridster.js/commit/e837ded844b48394e2356029e35fbbdc6011757c#diff-ec53bd2d983667d369cfb841409bd1aeL1483

Cryrivers commented 10 years ago

Yes. serialize function is not working in 0.5.3.

I got this error:

Uncaught InvalidStateError: Failed to read the 'selectionDirection' property from 'HTMLInputElement': The input element's type ('button') does not support selection.

which is different from yours.

TheDigitalOrchard commented 10 years ago

The solution seems to be avoiding serializing elements that are already serialized. Only serialize "object" elements, as explained here:

http://stackoverflow.com/questions/9382167/serializing-object-that-contains-cyclic-object-value

Would that work?

vieron commented 10 years ago

The serialize method was working but returning the serialized array wrapped into a jQuery object. And the JSON.stringify method breaks trying to convert a jQuery object in some browser implementations.

Thanks for the notice!

Daijobou commented 10 years ago

Working fine now in 0.5.4. Thank you very much. :)