WordPress.org

Make WordPress Core

Changeset 22937


Ignore:
Timestamp:
11/30/2012 01:38:41 AM (9 years ago)
Author:
ryan
Message:

In the add media modal, fallback back to caption if alt is not set. Falback to title if neither caption nor alt are set.

Props koopersmith
see #18984

File:
1 edited

Legend:

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

    r22927 r22937  
    1010        // attachment's type.
    1111        props: function( props, attachment ) {
    12             var link, linkUrl, size, sizes;
     12            var link, linkUrl, size, sizes, fallbacks;
     13
     14            // Final fallbacks run after all processing has been completed.
     15            fallbacks = function( props ) {
     16                // Generate alt fallbacks and strip tags.
     17                if ( 'image' === props.type && ! props.alt ) {
     18                    props.alt = props.caption || props.title || '';
     19                    props.alt = props.alt.replace( /<\/?[^>]+>/g, '' );
     20                }
     21
     22                return props;
     23            };
    1324
    1425            props = props ? _.clone( props ) : {};
     
    2839            // All attachment-specific settings follow.
    2940            if ( ! attachment )
    30                 return props;
     41                return fallbacks( props );
     42
     43            props.title = props.title || attachment.title;
    3144
    3245            link = props.link || getUserSetting( 'urlbutton', 'post' );
     
    5568            // Format properties for non-images.
    5669            } else {
    57                 _.extend( props, {
    58                     title:   attachment.title || attachment.filename,
    59                     rel:     'attachment wp-att-' + attachment.id
    60                 });
    61             }
    62 
    63             return props;
     70                props.title = props.title || attachment.filename;
     71                props.rel = props.rel || 'attachment wp-att-' + attachment.id;
     72            }
     73
     74            return fallbacks( props );
    6475        },
    6576
Note: See TracChangeset for help on using the changeset viewer.