Make WordPress Core

Changeset 23029


Ignore:
Timestamp:
12/04/2012 05:58:24 PM (12 years ago)
Author:
markjaquith
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/media-views.js

    r23028 r23029  
    18671867                container: document.body,
    18681868                title:     '',
    1869                 propagate: true
     1869                propagate: true,
     1870                freeze:    document.body
    18701871            });
    18711872        },
     
    19031904
    19041905        open: function() {
    1905             if ( this.$el.is(':visible') )
     1906            var $el = this.$el,
     1907                options = this.options,
     1908                $freeze;
     1909
     1910            if ( $el.is(':visible') )
    19061911                return this;
    19071912
     
    19091914                this.attach();
    19101915
    1911             this.$el.show().focus();
     1916            // If the `freeze` option is set, record the window's scroll
     1917            // position and the body's overflow, and then set overflow to hidden.
     1918            if ( options.freeze ) {
     1919                $freeze = $( options.freeze );
     1920                this._freeze = {
     1921                    overflow:  $freeze.css('overflow'),
     1922                    scrollTop: $( window ).scrollTop()
     1923                };
     1924                $freeze.css( 'overflow', 'hidden' );
     1925            }
     1926
     1927            $el.show().focus();
    19121928            return this.propagate('open');
    19131929        },
    19141930
    19151931        close: function( options ) {
     1932            var freeze = this._freeze;
     1933
    19161934            if ( ! this.views.attached || ! this.$el.is(':visible') )
    19171935                return this;
     
    19191937            this.$el.hide();
    19201938            this.propagate('close');
     1939
     1940            // If the `freeze` option is set, restore the container's scroll
     1941            // position and overflow property.
     1942            if ( freeze ) {
     1943                $( this.options.freeze ).css( 'overflow', freeze.overflow );
     1944                $( window ).scrollTop( freeze.scrollTop );
     1945            }
    19211946
    19221947            if ( options && options.escape )
Note: See TracChangeset for help on using the changeset viewer.