Skip to content

All: Resolve most jQuery.fn.offset Migrate warnings #1922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions ui/safe-offset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
( function( factory ) {
if ( typeof define === "function" && define.amd ) {

// AMD. Register as an anonymous module.
define( [ "jquery", "./version" ], factory );
} else {

// Browser globals
factory( jQuery );
}
} ( function( $ ) {
return $.ui.__safeOffset__ = function( element ) {

// Simulate a jQuery short-circuiting when there are no client rects reported
// which usually means a disconnected node. This check in jQuery is meant just
// for IE but UI depends on it.
if ( arguments.length < 2 && !element[ 0 ].getClientRects().length ) {
return { top: 0, left: 0 };
}

var args = Array.prototype.slice.call( arguments, 1 );
return element.offset.apply( element, args );
};

} ) );
3 changes: 2 additions & 1 deletion ui/widgets/draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"../plugin",
"../safe-active-element",
"../safe-blur",
"../safe-offset",
"../scroll-parent",
"../version",
"../widget"
Expand Down Expand Up @@ -431,7 +432,7 @@ $.widget( "ui.draggable", $.ui.mouse, {
_getParentOffset: function() {

//Get the offsetParent and cache its position
var po = this.offsetParent.offset(),
var po = $.ui.__safeOffset__( this.offsetParent ),
document = this.document[ 0 ];

// This is a special case where we need to modify a offset calculated on start, since the
Expand Down
3 changes: 2 additions & 1 deletion ui/widgets/droppable.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"jquery",
"./draggable",
"./mouse",
"../safe-offset",
"../version",
"../widget"
], factory );
Expand Down Expand Up @@ -341,7 +342,7 @@ $.ui.ddmanager = {
m[ i ]._activate.call( m[ i ], event );
}

m[ i ].offset = m[ i ].element.offset();
m[ i ].offset = $.ui.__safeOffset__( m[ i ].element );
m[ i ].proportions( {
width: m[ i ].element[ 0 ].offsetWidth,
height: m[ i ].element[ 0 ].offsetHeight
Expand Down
3 changes: 2 additions & 1 deletion ui/widgets/selectable.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
define( [
"jquery",
"./mouse",
"../safe-offset",
"../version",
"../widget"
], factory );
Expand Down Expand Up @@ -57,7 +58,7 @@ return $.widget( "ui.selectable", $.ui.mouse, {

// Cache selectee children based on filter
this.refresh = function() {
that.elementPos = $( that.element[ 0 ] ).offset();
that.elementPos = $.ui.__safeOffset__( $( that.element[ 0 ] ) );
that.selectees = $( that.options.filter, that.element[ 0 ] );
that._addClass( that.selectees, "ui-selectee" );
that.selectees.each( function() {
Expand Down
9 changes: 5 additions & 4 deletions ui/widgets/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"./mouse",
"../data",
"../ie",
"../safe-offset",
"../scroll-parent",
"../version",
"../widget"
Expand Down Expand Up @@ -94,7 +95,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
this.refresh();

//Let's determine the parent's offset
this.offset = this.element.offset();
this.offset = $.ui.__safeOffset__( this.element );

//Initialize mouse events for interaction
this._mouseInit();
Expand Down Expand Up @@ -870,7 +871,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
item.height = t.outerHeight();
}

p = t.offset();
p = $.ui.__safeOffset__( t );
item.left = p.left;
item.top = p.top;
}
Expand All @@ -893,7 +894,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
this.options.custom.refreshContainers.call( this );
} else {
for ( i = this.containers.length - 1; i >= 0; i-- ) {
p = this.containers[ i ].element.offset();
p = $.ui.__safeOffset__( this.containers[ i ].element );
this.containers[ i ].containerCache.left = p.left;
this.containers[ i ].containerCache.top = p.top;
this.containers[ i ].containerCache.width =
Expand Down Expand Up @@ -1176,7 +1177,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {

//Get the offsetParent and cache its position
this.offsetParent = this.helper.offsetParent();
var po = this.offsetParent.offset();
var po = $.ui.__safeOffset__( this.offsetParent );

// This is a special case where we need to modify a offset calculated on start, since the
// following happened:
Expand Down