johnny / jquery-sortable

A flexible, opinionated sorting plugin for jQuery
http://johnny.github.io/jquery-sortable/
Other
1.52k stars 441 forks source link

Update required for jQuery 3.x - jQuery.fn.offset() requires an element connected to a document #278

Open JamoCA opened 4 years ago

JamoCA commented 4 years ago

I was encountering the following warning while using jquery-sortable 0.9.13 (from 2015) with jQuery 3.2.1 and the unminified version of jQuery Migrate 3.1.0.

jQuery.fn.offset() requires an element connected to a document

I reviewed the sortable plugin, determined what jQuery Migrate was doing to provide fallback support and made the following edit to function getRelativePosition() on line 190.

function getRelativePosition(pointer, element) {
    var docElem = ( element.ownerDocument || window.document ).documentElement;
    var offset = { top: 0, left: 0 };
    if ( $.contains(docElem, element) ) {
        offset = element.offset();
    }
...

This appears to works correctly now with jQuery 3.x. Please review and determine if there are any problems with this approach. Thanks.