diff --git a/ui/safe-offset.js b/ui/safe-offset.js index e69de29bb2d..06368b040ca 100644 --- a/ui/safe-offset.js +++ b/ui/safe-offset.js @@ -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 ); +}; + +} ) ); diff --git a/ui/widgets/draggable.js b/ui/widgets/draggable.js index 5f41d24081a..90baa81d9b1 100644 --- a/ui/widgets/draggable.js +++ b/ui/widgets/draggable.js @@ -25,6 +25,7 @@ "../plugin", "../safe-active-element", "../safe-blur", + "../safe-offset", "../scroll-parent", "../version", "../widget" @@ -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 diff --git a/ui/widgets/droppable.js b/ui/widgets/droppable.js index f98ff2714e7..9e2998cb9c7 100644 --- a/ui/widgets/droppable.js +++ b/ui/widgets/droppable.js @@ -21,6 +21,7 @@ "jquery", "./draggable", "./mouse", + "../safe-offset", "../version", "../widget" ], factory ); @@ -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 diff --git a/ui/widgets/selectable.js b/ui/widgets/selectable.js index ed980cc493e..df040619367 100644 --- a/ui/widgets/selectable.js +++ b/ui/widgets/selectable.js @@ -21,6 +21,7 @@ define( [ "jquery", "./mouse", + "../safe-offset", "../version", "../widget" ], factory ); @@ -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() { diff --git a/ui/widgets/sortable.js b/ui/widgets/sortable.js index b7daf00bfa0..d5976aa21d9 100644 --- a/ui/widgets/sortable.js +++ b/ui/widgets/sortable.js @@ -23,6 +23,7 @@ "./mouse", "../data", "../ie", + "../safe-offset", "../scroll-parent", "../version", "../widget" @@ -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(); @@ -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; } @@ -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 = @@ -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: