~canonical-sysadmins/wordpress/5.0

« back to all changes in this revision

Viewing changes to wp-includes/js/media-views.js

  • Committer: Barry Price
  • Date: 2018-03-12 09:10:47 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: barry.price@canonical.com-20180312091047-rhie6qpndx5nwlo1
Merge WP4.9.4 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
4173
4173
        tagName:  'div',
4174
4174
        template: wp.template('media-modal'),
4175
4175
 
4176
 
        attributes: {
4177
 
                tabindex: 0
4178
 
        },
4179
 
 
4180
4176
        events: {
4181
4177
                'click .media-modal-backdrop, .media-modal-close': 'escapeHandler',
4182
4178
                'keydown': 'keydown'
4188
4184
                _.defaults( this.options, {
4189
4185
                        container: document.body,
4190
4186
                        title:     '',
4191
 
                        propagate: true,
4192
 
                        freeze:    true
 
4187
                        propagate: true
4193
4188
                });
4194
4189
 
4195
4190
                this.focusManager = new wp.media.view.FocusManager({
4244
4239
         */
4245
4240
        open: function() {
4246
4241
                var $el = this.$el,
4247
 
                        options = this.options,
4248
4242
                        mceEditor;
4249
4243
 
4250
4244
                if ( $el.is(':visible') ) {
4257
4251
                        this.attach();
4258
4252
                }
4259
4253
 
4260
 
                // If the `freeze` option is set, record the window's scroll position.
4261
 
                if ( options.freeze ) {
4262
 
                        this._freeze = {
4263
 
                                scrollTop: $( window ).scrollTop()
4264
 
                        };
4265
 
                }
4266
 
 
4267
4254
                // Disable page scrolling.
4268
4255
                $( 'body' ).addClass( 'modal-open' );
4269
4256
 
4271
4258
 
4272
4259
                // Try to close the onscreen keyboard
4273
4260
                if ( 'ontouchend' in document ) {
4274
 
                        if ( ( mceEditor = window.tinymce && window.tinymce.activeEditor )  && ! mceEditor.isHidden() && mceEditor.iframeElement ) {
 
4261
                        if ( ( mceEditor = window.tinymce && window.tinymce.activeEditor ) && ! mceEditor.isHidden() && mceEditor.iframeElement ) {
4275
4262
                                mceEditor.iframeElement.focus();
4276
4263
                                mceEditor.iframeElement.blur();
4277
4264
 
4281
4268
                        }
4282
4269
                }
4283
4270
 
4284
 
                this.$el.focus();
 
4271
                // Set initial focus on the content instead of this view element, to avoid page scrolling.
 
4272
                this.$( '.media-modal' ).focus();
4285
4273
 
4286
4274
                return this.propagate('open');
4287
4275
        },
4291
4279
         * @returns {wp.media.view.Modal} Returns itself to allow chaining
4292
4280
         */
4293
4281
        close: function( options ) {
4294
 
                var freeze = this._freeze;
4295
 
 
4296
4282
                if ( ! this.views.attached || ! this.$el.is(':visible') ) {
4297
4283
                        return this;
4298
4284
                }
4312
4298
 
4313
4299
                this.propagate('close');
4314
4300
 
4315
 
                // If the `freeze` option is set, restore the container's scroll position.
4316
 
                if ( freeze ) {
4317
 
                        $( window ).scrollTop( freeze.scrollTop );
4318
 
                }
4319
 
 
4320
4301
                if ( options && options.escape ) {
4321
4302
                        this.propagate('escape');
4322
4303
                }
8957
8938
                imgOptions = _.extend(imgOptions, {
8958
8939
                        parent: this.$el,
8959
8940
                        onInit: function() {
8960
 
                                this.parent.children().on( 'mousedown touchstart', function( e ){
8961
 
 
8962
 
                                        if ( e.shiftKey ) {
 
8941
 
 
8942
                                // Store the set ratio.
 
8943
                                var setRatio = imgSelect.getOptions().aspectRatio;
 
8944
 
 
8945
                                // On mousedown, if no ratio is set and the Shift key is down, use a 1:1 ratio.
 
8946
                                this.parent.children().on( 'mousedown touchstart', function( e ) {
 
8947
 
 
8948
                                        // If no ratio is set and the shift key is down, use a 1:1 ratio.
 
8949
                                        if ( ! setRatio && e.shiftKey ) {
8963
8950
                                                imgSelect.setOptions( {
8964
8951
                                                        aspectRatio: '1:1'
8965
8952
                                                } );
8966
 
                                        } else {
8967
 
                                                imgSelect.setOptions( {
8968
 
                                                        aspectRatio: false
8969
 
                                                } );
8970
8953
                                        }
8971
8954
                                } );
 
8955
 
 
8956
                                this.parent.children().on( 'mouseup touchend', function() {
 
8957
 
 
8958
                                        // Restore the set ratio.
 
8959
                                        imgSelect.setOptions( {
 
8960
                                                aspectRatio: setRatio ? setRatio : false
 
8961
                                        } );
 
8962
                                } );
8972
8963
                        }
8973
8964
                } );
8974
8965
                this.trigger('image-loaded');