Fix a Firefox "scroll to bottom" bug when launching the media modal.

* Records main document scroll position when launching media modal.
* Restores position when media modal is closed.
* Also locks background document scrolling while media modal is open, preventing inadvertent scrolling there.

props koopersmith. fixes #22716

git-svn-id: https://develop.svn.wordpress.org/trunk@23029 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Mark Jaquith 2012-12-04 17:58:24 +00:00
parent 4241d42dbe
commit 0f3c162db6
1 changed files with 28 additions and 3 deletions

View File

@ -1866,7 +1866,8 @@
_.defaults( this.options, {
container: document.body,
title: '',
propagate: true
propagate: true,
freeze: document.body
});
},
@ -1902,23 +1903,47 @@
},
open: function() {
if ( this.$el.is(':visible') )
var $el = this.$el,
options = this.options,
$freeze;
if ( $el.is(':visible') )
return this;
if ( ! this.views.attached )
this.attach();
this.$el.show().focus();
// If the `freeze` option is set, record the window's scroll
// position and the body's overflow, and then set overflow to hidden.
if ( options.freeze ) {
$freeze = $( options.freeze );
this._freeze = {
overflow: $freeze.css('overflow'),
scrollTop: $( window ).scrollTop()
};
$freeze.css( 'overflow', 'hidden' );
}
$el.show().focus();
return this.propagate('open');
},
close: function( options ) {
var freeze = this._freeze;
if ( ! this.views.attached || ! this.$el.is(':visible') )
return this;
this.$el.hide();
this.propagate('close');
// If the `freeze` option is set, restore the container's scroll
// position and overflow property.
if ( freeze ) {
$( this.options.freeze ).css( 'overflow', freeze.overflow );
$( window ).scrollTop( freeze.scrollTop );
}
if ( options && options.escape )
this.propagate('escape');