From 3c145e0d492572298937b6de0d9f11291070e483 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: https://develop.svn.wordpress.org/trunk@22937 602fd350-edb4-49c9-b593-d223f7449a82 --- 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 ) {