Skip to content

Commit eacb8e3

Browse files
committed
All: Resolve most jQuery.fn.offset Migrate warnings
1 parent ada1604 commit eacb8e3

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

ui/safe-offset.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
( function( factory ) {
2+
if ( typeof define === "function" && define.amd ) {
3+
4+
// AMD. Register as an anonymous module.
5+
define( [ "jquery", "./version" ], factory );
6+
} else {
7+
8+
// Browser globals
9+
factory( jQuery );
10+
}
11+
} ( function( $ ) {
12+
return $.ui.__safeOffset__ = function( element ) {
13+
// Simulate a jQuery short-circuiting when there are no client rects reported
14+
// which usually means a disconnected node. This check in jQuery is meant just
15+
// for IE but UI depends on it.
16+
if ( arguments.length < 2 && !element[ 0 ].getClientRects().length ) {
17+
return { top: 0, left: 0 };
18+
}
19+
20+
var args = Array.prototype.slice.call( arguments, 1 );
21+
return element.offset.apply( element, args );
22+
};
23+
24+
} ) );

ui/widgets/draggable.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"../plugin",
2626
"../safe-active-element",
2727
"../safe-blur",
28+
"../safe-offset",
2829
"../scroll-parent",
2930
"../version",
3031
"../widget"
@@ -431,7 +432,7 @@ $.widget( "ui.draggable", $.ui.mouse, {
431432
_getParentOffset: function() {
432433

433434
//Get the offsetParent and cache its position
434-
var po = this.offsetParent.offset(),
435+
var po = $.ui.__safeOffset__( this.offsetParent ),
435436
document = this.document[ 0 ];
436437

437438
// This is a special case where we need to modify a offset calculated on start, since the

ui/widgets/droppable.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"jquery",
2222
"./draggable",
2323
"./mouse",
24+
"../safe-offset",
2425
"../version",
2526
"../widget"
2627
], factory );
@@ -341,7 +342,7 @@ $.ui.ddmanager = {
341342
m[ i ]._activate.call( m[ i ], event );
342343
}
343344

344-
m[ i ].offset = m[ i ].element.offset();
345+
m[ i ].offset = $.ui.__safeOffset__( m[ i ].element );
345346
m[ i ].proportions( {
346347
width: m[ i ].element[ 0 ].offsetWidth,
347348
height: m[ i ].element[ 0 ].offsetHeight

ui/widgets/selectable.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
define( [
2222
"jquery",
2323
"./mouse",
24+
"../safe-offset",
2425
"../version",
2526
"../widget"
2627
], factory );
@@ -57,7 +58,7 @@ return $.widget( "ui.selectable", $.ui.mouse, {
5758

5859
// Cache selectee children based on filter
5960
this.refresh = function() {
60-
that.elementPos = $( that.element[ 0 ] ).offset();
61+
that.elementPos = $.ui.__safeOffset__( $( that.element[ 0 ] ) );
6162
that.selectees = $( that.options.filter, that.element[ 0 ] );
6263
that._addClass( that.selectees, "ui-selectee" );
6364
that.selectees.each( function() {

ui/widgets/sortable.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"./mouse",
2424
"../data",
2525
"../ie",
26+
"../safe-offset",
2627
"../scroll-parent",
2728
"../version",
2829
"../widget"
@@ -94,7 +95,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
9495
this.refresh();
9596

9697
//Let's determine the parent's offset
97-
this.offset = this.element.offset();
98+
this.offset = $.ui.__safeOffset__( this.element );
9899

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

873-
p = t.offset();
874+
p = $.ui.__safeOffset__( t );
874875
item.left = p.left;
875876
item.top = p.top;
876877
}
@@ -893,7 +894,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
893894
this.options.custom.refreshContainers.call( this );
894895
} else {
895896
for ( i = this.containers.length - 1; i >= 0; i-- ) {
896-
p = this.containers[ i ].element.offset();
897+
p = $.ui.__safeOffset__( this.containers[ i ].element );
897898
this.containers[ i ].containerCache.left = p.left;
898899
this.containers[ i ].containerCache.top = p.top;
899900
this.containers[ i ].containerCache.width =
@@ -1176,7 +1177,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
11761177

11771178
//Get the offsetParent and cache its position
11781179
this.offsetParent = this.helper.offsetParent();
1179-
var po = this.offsetParent.offset();
1180+
var po = $.ui.__safeOffset__( this.offsetParent );
11801181

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

0 commit comments

Comments
 (0)