3

I have a strange bug concerning the jQuery UI selectable. If I use a transform (scale + translate) within the selectable container, the lasso seems to be incorrect for selecting objects. Visually the lasso works perfecly!

Here is my coding example: Fiddle

Working case:

enter image description here enter image description here

Not working case:

enter image description here

Apparently this is a limitation of jQuery UI who is disregarding CSS-transformations in functions like offset(). In jQuery UI I found the part of the selectable where the calcualtion is being made for selecting items, but I can't seem to adjust it in a correct way:

_create: function() {
        var that = this;

        this._addClass( "ui-selectable" );

        this.dragged = false;

        // Cache selectee children based on filter
        this.refresh = function() {
            that.elementPos = $( that.element[ 0 ] ).offset();
            that.selectees = $( that.options.filter, that.element[ 0 ] );
            that._addClass( that.selectees, "ui-selectee" );
            that.selectees.each( function() {
                var $this = $( this ),
                    selecteeOffset = $this.offset(),
                    pos = {
                        left: selecteeOffset.left - that.elementPos.left,
                        top: selecteeOffset.top - that.elementPos.top
                    };
                $.data( this, "selectable-item", {
                    element: this,
                    $element: $this,
                    left: pos.left,
                    top: pos.top,
                    right: pos.left + $this.outerWidth(),
                    bottom: pos.top + $this.outerHeight(),
                    startselected: false,
                    selected: $this.hasClass( "ui-selected" ),
                    selecting: $this.hasClass( "ui-selecting" ),
                    unselecting: $this.hasClass( "ui-unselecting" )
                } );
            } );
        };
        this.refresh();

        this._mouseInit();

        this.helper = $( "<div>" );
        this._addClass( this.helper, "ui-selectable-helper" );
    },

Did anyone experience this issue before? Is there a fix, workaround or core adjustment known?

1
  • nobody has a clue how to fix it? Commented Jan 5, 2018 at 15:03

1 Answer 1

4

I found out the solution by myself and amended the jsFiddle.

$fixedRect = $(this)[0].getBoundingClientRect();

I marked the changed jQuery UI core code in red.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Excellent, It work perfect. Saved a lot of time for me.
Great! It works. Only answer I found on this issue!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.