Make WordPress Core

Changeset 36167


Ignore:
Timestamp:
01/04/2016 12:40:51 AM (11 years ago)
Author:
azaozz
Message:

Media: when inserting an attachment in the editor and it is not an image, ensure the link is set to something else than none.

Props eherman24, azaozz.
Fixes #35153 for 4.4.1.

Location:
branches/4.4/src/wp-includes/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4/src/wp-includes/js/media-views.js

    r35019 r36167  
    12151215         */
    12161216        defaultDisplaySettings: function( attachment ) {
    1217                 var settings = this._defaultDisplaySettings;
     1217                var settings = _.clone( this._defaultDisplaySettings );
     1218
    12181219                if ( settings.canEmbed = this.canEmbed( attachment ) ) {
    12191220                        settings.link = 'embed';
    1220                 }
     1221                } else if ( ! this.isImageAttachment( attachment ) && settings.link === 'none' ) {
     1222                        settings.link = 'file';
     1223                }
     1224
    12211225                return settings;
     1226        },
     1227
     1228        /**
     1229         * Whether an attachment is image.
     1230         *
     1231         * @since 4.4.1
     1232         *
     1233         * @param {wp.media.model.Attachment} attachment
     1234         * @returns {Boolean}
     1235         */
     1236        isImageAttachment: function( attachment ) {
     1237                // If uploading, we know the filename but not the mime type.
     1238                if ( attachment.get('uploading') ) {
     1239                        return /\.(jpe?g|png|gif)$/i.test( attachment.get('filename') );
     1240                }
     1241
     1242                return attachment.get('type') === 'image';
    12221243        },
    12231244
  • branches/4.4/src/wp-includes/js/media/controllers/library.js

    r33729 r36167  
    172172         */
    173173        defaultDisplaySettings: function( attachment ) {
    174                 var settings = this._defaultDisplaySettings;
     174                var settings = _.clone( this._defaultDisplaySettings );
     175
    175176                if ( settings.canEmbed = this.canEmbed( attachment ) ) {
    176177                        settings.link = 'embed';
    177                 }
     178                } else if ( ! this.isImageAttachment( attachment ) && settings.link === 'none' ) {
     179                        settings.link = 'file';
     180                }
     181
    178182                return settings;
     183        },
     184
     185        /**
     186         * Whether an attachment is image.
     187         *
     188         * @since 4.4.1
     189         *
     190         * @param {wp.media.model.Attachment} attachment
     191         * @returns {Boolean}
     192         */
     193        isImageAttachment: function( attachment ) {
     194                // If uploading, we know the filename but not the mime type.
     195                if ( attachment.get('uploading') ) {
     196                        return /\.(jpe?g|png|gif)$/i.test( attachment.get('filename') );
     197                }
     198
     199                return attachment.get('type') === 'image';
    179200        },
    180201
Note: See TracChangeset for help on using the changeset viewer.