From fccd72a74b8139ae2447cf636be901e66197b38b Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 30 Nov 2012 01:38:41 +0000 Subject: [PATCH] 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 git-svn-id: http://core.svn.wordpress.org/trunk@22937 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/media-editor.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/wp-includes/js/media-editor.js b/wp-includes/js/media-editor.js index 9f21a38cd1..7e9460ae46 100644 --- a/wp-includes/js/media-editor.js +++ b/wp-includes/js/media-editor.js @@ -9,7 +9,18 @@ // outputting the proper object format based on the // attachment's type. props: function( props, attachment ) { - var link, linkUrl, size, sizes; + var link, linkUrl, size, sizes, fallbacks; + + // Final fallbacks run after all processing has been completed. + fallbacks = function( props ) { + // Generate alt fallbacks and strip tags. + if ( 'image' === props.type && ! props.alt ) { + props.alt = props.caption || props.title || ''; + props.alt = props.alt.replace( /<\/?[^>]+>/g, '' ); + } + + return props; + }; props = props ? _.clone( props ) : {}; @@ -27,7 +38,9 @@ // All attachment-specific settings follow. if ( ! attachment ) - return props; + return fallbacks( props ); + + props.title = props.title || attachment.title; link = props.link || getUserSetting( 'urlbutton', 'post' ); if ( 'file' === link ) @@ -54,13 +67,11 @@ // Format properties for non-images. } else { - _.extend( props, { - title: attachment.title || attachment.filename, - rel: 'attachment wp-att-' + attachment.id - }); + props.title = props.title || attachment.filename; + props.rel = props.rel || 'attachment wp-att-' + attachment.id; } - return props; + return fallbacks( props ); }, link: function( props, attachment ) {