Draggable: Added in iframeFix option

This commit is contained in:
Dave Stein 2011-11-06 17:42:35 -05:00
parent 7941f7c13f
commit 1ca93b4a6c

View File

@ -20,7 +20,8 @@ $.widget( "ui.draggable", {
options: {
helper: false,
scrollSensitivity: 20,
scrollSpeed: 20
scrollSpeed: 20,
iframeFix: false
},
// dragEl: element being dragged (original or helper)
@ -33,6 +34,36 @@ $.widget( "ui.draggable", {
// overflowOffset: offset of scroll parent
// overflow: object containing width and height keys of scroll parent
_blockFrames: function() {
var iframes = $('iframe'),
widget = this;
this.iframeBlocks = $('');
iframes.each( function() {
var iframe = $(this),
width = iframe.outerWidth(),
height = iframe.outerHeight(),
iframeOffset = iframe.offset(),
block = $('<div />');
block.css({
position: 'absolute',
width: width+'px',
height: height+'px',
top: iframeOffset.top+'px',
left: iframeOffset.left+'px'
})
.appendTo( widget.document[0].body );
widget.iframeBlocks = widget.iframeBlocks.add( block );
});
},
_create: function() {
this.scrollParent = this.element.scrollParent();
@ -131,6 +162,10 @@ $.widget( "ui.draggable", {
// The actual dragging element, should always be a jQuery object
this.dragEl = this.element;
if ( this.options.iframeFix === true ) {
this._blockFrames();
}
// Helper required
if ( this.options.helper ) {
// clone
@ -238,6 +273,11 @@ $.widget( "ui.draggable", {
}
this.document.unbind( "." + this.widgetName );
if ( this.options.iframeFix === true ) {
this._unblockFrames();
}
},
// Uses event to determine new position of draggable, before any override from callbacks
@ -303,6 +343,20 @@ $.widget( "ui.draggable", {
return ret;
},
_unblockFrames: function() {
if ( !this.iframeBlocks || !this.iframeBlocks.length ) {
return;
}
this.iframeBlocks.each( function() {
$(this).remove();
});
}
});