Make WordPress Core

Ticket #32746: 32746.patch

File 32746.patch, 2.9 KB (added by vivekbhusal, 11 years ago)

When filtering media attachment by type in wp.media.model.Attachments.filters.type(), checks for type being array or string and validades accordingly

  • src/wp-includes/js/media/models/attachments.js

     
    491491                 * @returns {Boolean}
    492492                 */
    493493                type: function( attachment ) {
    494                         var type = this.props.get('type'), atts = attachment.toJSON(), mime, found;
     494                        // Return of the type is not defined
     495            if( ! this.props.get("type") ) {
     496                return true;
     497            }
    495498
    496                         mime = atts.mime || ( atts.file && atts.file.type ) || '';
     499            var type = this.props.get('type'),
     500                attachmentType = attachment.get("type"), found;
    497501
    498                         if ( _.isArray( type ) ) {
    499                                 found = ! type.length || _.find( type, function (t) {
    500                                         return -1 !== mime.indexOf( t );
    501                                 } );
    502                         } else {
    503                                 found = ! type || -1 !== mime.indexOf( type );
    504                         }
     502            //Chek if the define mime type is array.
     503            //If yes, loop though each and compare
     504            if ( _.isArray( type ) ) {
     505                found = _.find( type, function (t) {
     506                        return -1 !== t.indexOf( attachmentType );
     507                } );
     508            } else {
     509                found = -1 !== type.indexOf( attachmentType );
     510            }
    505511
    506                         return found;
    507                 },
     512            return found;
     513
     514        },
    508515                /**
    509516                 * @static
    510517                 * @param {wp.media.model.Attachment} attachment
  • src/wp-includes/js/media-models.js

     
    895895                 * @returns {Boolean}
    896896                 */
    897897                type: function( attachment ) {
    898                         var type = this.props.get('type'), atts = attachment.toJSON(), mime, found;
     898            // Return of the type is not defined
     899            if( ! this.props.get("type") ) {
     900                return true;
     901            }
    899902
    900                         mime = atts.mime || ( atts.file && atts.file.type ) || '';
     903            var type = this.props.get('type'),
     904                attachmentType = attachment.get("type"), found;
    901905
    902                         if ( _.isArray( type ) ) {
    903                                 found = ! type.length || _.find( type, function (t) {
    904                                         return -1 !== mime.indexOf( t );
    905                                 } );
    906                         } else {
    907                                 found = ! type || -1 !== mime.indexOf( type );
    908                         }
     906            //Chek if the define mime type is array.
     907            //If yes, loop though each and compare
     908            if ( _.isArray( type ) ) {
     909                found = _.find( type, function (t) {
     910                        return -1 !== t.indexOf( attachmentType );
     911                } );
     912            } else {
     913                found = -1 !== type.indexOf( attachmentType );
     914            }
    909915
    910                         return found;
    911                 },
     916            return found;
     917
     918        },
    912919                /**
    913920                 * @static
    914921                 * @param {wp.media.model.Attachment} attachment