Fix up the 'Attach' dialog on upload.php.

We are de-emphasising attaching (see [22630]) but this is existing
core functionality and will remain for now. This commit just cleans
it up a bit so as to be less embarrassing.

props lessbloat, helenyhou.
fixes #20164.



git-svn-id: http://core.svn.wordpress.org/trunk@22723 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2012-11-20 18:50:15 +00:00
parent a2edda4b6a
commit 3da5e3a7fc
7 changed files with 130 additions and 77 deletions

View File

@ -20,13 +20,18 @@ TABLE OF CONTENTS:
1.0 - Left to Right Styles 1.0 - Left to Right Styles
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
.find-box-search { .find-box-search,
border-color: #dfdfdf; .find-box-buttons {
background-color: #f1f1f1; background-color: #eff8ff;
border-top: 1px solid #dce6f8;
} }
.find-box { .find-box {
background-color: #f1f1f1; background-color: #5589aa;
}
.find-box-head {
color: #fff;
} }
.find-box-inside { .find-box-inside {
@ -167,7 +172,6 @@ textarea.disabled {
h3.dashboard-widget-title, h3.dashboard-widget-title,
h3.dashboard-widget-title span, h3.dashboard-widget-title span,
h3.dashboard-widget-title small, h3.dashboard-widget-title small,
.find-box-head,
.sidebar-name, .sidebar-name,
#nav-menu-header, #nav-menu-header,
#nav-menu-footer, #nav-menu-footer,
@ -475,8 +479,7 @@ a.page-numbers {
.widefat tfoot tr th, .widefat tfoot tr th,
h3.dashboard-widget-title, h3.dashboard-widget-title,
h3.dashboard-widget-title span, h3.dashboard-widget-title span,
h3.dashboard-widget-title small, h3.dashboard-widget-title small {
.find-box-head {
color: #333; color: #333;
} }

View File

@ -20,13 +20,18 @@ TABLE OF CONTENTS:
1.0 - Left to Right Styles 1.0 - Left to Right Styles
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
.find-box-search { .find-box-search,
border-color: #dfdfdf; .find-box-buttons {
background-color: #f1f1f1; background-color: #f7f7f7;
border-top: 1px solid #ddd;
} }
.find-box { .find-box {
background-color: #f1f1f1; background-color: #444;
}
.find-box-head {
color: #eee;
} }
.find-box-inside { .find-box-inside {
@ -170,7 +175,6 @@ textarea.disabled {
h3.dashboard-widget-title, h3.dashboard-widget-title,
h3.dashboard-widget-title span, h3.dashboard-widget-title span,
h3.dashboard-widget-title small, h3.dashboard-widget-title small,
.find-box-head,
.sidebar-name, .sidebar-name,
#nav-menu-header, #nav-menu-header,
#nav-menu-footer, #nav-menu-footer,
@ -477,8 +481,7 @@ a.page-numbers {
.widefat tfoot tr th, .widefat tfoot tr th,
h3.dashboard-widget-title, h3.dashboard-widget-title,
h3.dashboard-widget-title span, h3.dashboard-widget-title span,
h3.dashboard-widget-title small, h3.dashboard-widget-title small {
.find-box-head {
color: #333; color: #333;
} }

View File

@ -1083,6 +1083,21 @@ span.description,
14.1 - Media Uploader 14.1 - Media Uploader
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
#find-posts-input {
float: right;
}
#find-posts-search {
float: right;
margin-right: 3px;
margin-left: 4px;
}
.find-box-search .spinner {
left: auto;
right: 115px;
}
#find-posts-response .found-radio { #find-posts-response .found-radio {
padding: 5px 8px 0 0; padding: 5px 8px 0 0;
} }

View File

@ -3963,10 +3963,10 @@ abbr.required {
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
.find-box { .find-box {
width: 500px; width: 600px;
height: 300px; height: 300px;
overflow: hidden; overflow: hidden;
padding: 33px 5px 40px; padding: 33px 0 51px;
position: absolute; position: absolute;
z-index: 1000; z-index: 1000;
} }
@ -3984,19 +3984,37 @@ abbr.required {
.find-box-inside { .find-box-inside {
overflow: auto; overflow: auto;
width: 100%; padding: 6px;
height: 100%; height: 100%;
} }
.find-box-search { .find-box-search {
padding: 12px; overflow: hidden;
border-width: 1px; padding: 9px;
border-style: none none solid; position: relative;
}
.find-box-search .spinner {
float: none;
left: 125px;
position: absolute;
top: 9px;
}
#find-posts-input {
float: left;
width: 140px;
height: 24px;
}
#find-posts-search {
float: left;
margin: 1px 4px 0 3px;
} }
#find-posts-response { #find-posts-response {
margin: 8px 0; margin: 8px 0;
padding: 0 1px; padding: 0 1px 6px;
} }
#find-posts-response table { #find-posts-response table {
@ -4004,17 +4022,13 @@ abbr.required {
} }
#find-posts-response .found-radio { #find-posts-response .found-radio {
padding: 5px 0 0 8px; padding: 3px 0 0 8px;
width: 15px; width: 15px;
} }
.find-box-buttons { .find-box-buttons {
width: 480px; padding: 8px;
margin: 8px; overflow: hidden;
}
.find-box-search label {
padding-right: 6px;
} }
.find-box #resize-se { .find-box #resize-se {
@ -4023,6 +4037,15 @@ abbr.required {
bottom: 1px; bottom: 1px;
} }
.ui-find-overlay {
position: absolute;
top: 0;
left: 0;
background-color: #000;
opacity: 0.6;
filter: alpha(opacity=60);
}
ul#dismissed-updates { ul#dismissed-updates {
display: none; display: none;
} }

View File

@ -1421,37 +1421,27 @@ function wp_ajax_find_posts() {
check_ajax_referer( 'find-posts' ); check_ajax_referer( 'find-posts' );
if ( empty($_POST['ps']) ) $post_types = get_post_types( array( 'public' => true ), 'objects' );
wp_die(); unset( $post_types['attachment'] );
if ( !empty($_POST['post_type']) && in_array( $_POST['post_type'], get_post_types() ) )
$what = $_POST['post_type'];
else
$what = 'post';
$s = stripslashes($_POST['ps']);
preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
$search_terms = array_map('_search_terms_tidy', $matches[0]);
$s = stripslashes( $_POST['ps'] );
$searchand = $search = ''; $searchand = $search = '';
foreach ( (array) $search_terms as $term ) { $args = array(
$term = esc_sql( like_escape( $term ) ); 'post_type' => array_keys( $post_types ),
$search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))"; 'post_status' => 'any',
$searchand = ' AND '; 'posts_per_page' => 50,
} );
$term = esc_sql( like_escape( $s ) ); if ( '' !== $s )
if ( count($search_terms) > 1 && $search_terms[0] != $s ) $args['s'] = $s;
$search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
$posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND post_status IN ('draft', 'publish') AND ($search) ORDER BY post_date_gmt DESC LIMIT 50" ); $posts = get_posts( $args );
if ( ! $posts ) { if ( ! $posts )
$posttype = get_post_type_object($what); wp_die( __('No items found.') );
wp_die( $posttype->labels->not_found );
}
$html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th>'.__('Date').'</th><th>'.__('Status').'</th></tr></thead><tbody>'; $html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th class="no-break">'.__('Type').'</th><th class="no-break">'.__('Date').'</th><th class="no-break">'.__('Status').'</th></tr></thead><tbody>';
foreach ( $posts as $post ) { foreach ( $posts as $post ) {
$title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' );
switch ( $post->post_status ) { switch ( $post->post_status ) {
case 'publish' : case 'publish' :
@ -1477,17 +1467,16 @@ function wp_ajax_find_posts() {
} }
$html .= '<tr class="found-posts"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>'; $html .= '<tr class="found-posts"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>';
$html .= '<td><label for="found-'.$post->ID.'">'.esc_html( $post->post_title ).'</label></td><td>'.esc_html( $time ).'</td><td>'.esc_html( $stat ).'</td></tr>'."\n\n"; $html .= '<td><label for="found-'.$post->ID.'">' . esc_html( $title ) . '</label></td><td class="no-break">' . esc_html( $post_types[$post->post_type]->labels->singular_name ) . '</td><td class="no-break">'.esc_html( $time ) . '</td><td class="no-break">' . esc_html( $stat ). ' </td></tr>' . "\n\n";
} }
$html .= '</tbody></table>'; $html .= '</tbody></table>';
$x = new WP_Ajax_Response(); $x = new WP_Ajax_Response();
$x->add( array( $x->add( array(
'what' => $what,
'data' => $html 'data' => $html
)); ));
$x->send(); $x->send();
} }
function wp_ajax_widgets_order() { function wp_ajax_widgets_order() {

View File

@ -1278,18 +1278,8 @@ function find_posts_div($found_action = '') {
<?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?> <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
<label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label> <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
<input type="text" id="find-posts-input" name="ps" value="" /> <input type="text" id="find-posts-input" name="ps" value="" />
<input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br /> <span class="spinner"></span>
<input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" />
<?php
$post_types = get_post_types( array('public' => true), 'objects' );
foreach ( $post_types as $post ) {
if ( 'attachment' == $post->name )
continue;
?>
<input type="radio" name="find-posts-what" id="find-posts-<?php echo esc_attr($post->name); ?>" value="<?php echo esc_attr($post->name); ?>" <?php checked($post->name, 'post'); ?> />
<label for="find-posts-<?php echo esc_attr($post->name); ?>"><?php echo $post->label; ?></label>
<?php
} ?>
</div> </div>
<div id="find-posts-response"></div> <div id="find-posts-response"></div>
</div> </div>

View File

@ -3,41 +3,63 @@ var findPosts;
(function($){ (function($){
findPosts = { findPosts = {
open : function(af_name, af_val) { open : function(af_name, af_val) {
var st = document.documentElement.scrollTop || $(document).scrollTop(); var st = document.documentElement.scrollTop || $(document).scrollTop(),
overlay = $( '.ui-find-overlay' );
if ( overlay.length == 0 ) {
$( 'body' ).append( '<div class="ui-find-overlay"></div>' );
findPosts.overlay();
}
overlay.show();
if ( af_name && af_val ) { if ( af_name && af_val ) {
$('#affected').attr('name', af_name).val(af_val); $('#affected').attr('name', af_name).val(af_val);
} }
$('#find-posts').show().draggable({ $('#find-posts').show().draggable({
handle: '#find-posts-head' handle: '#find-posts-head'
}).css({'top':st + 50 + 'px','left':'50%','marginLeft':'-250px'}); }).css({'top':st + 50 + 'px','left':'50%','marginLeft':'-328px'});
$('#find-posts-input').focus().keyup(function(e){ $('#find-posts-input').focus().keyup(function(e){
if (e.which == 27) { findPosts.close(); } // close on Escape if (e.which == 27) { findPosts.close(); } // close on Escape
}); });
// Pull some results up by default
findPosts.send();
return false; return false;
}, },
close : function() { close : function() {
$('#find-posts-response').html(''); $('#find-posts-response').html('');
$('#find-posts').draggable('destroy').hide(); $('#find-posts').draggable('destroy').hide();
$( '.ui-find-overlay' ).hide();
},
overlay : function() {
$( '.ui-find-overlay' ).css(
{ 'z-index': '999', 'width': $( document ).width() + 'px', 'height': $( document ).height() + 'px' }
).on('click', function () {
findPosts.close();
});
}, },
send : function() { send : function() {
var post = { var post = {
ps: $('#find-posts-input').val(), ps: $('#find-posts-input').val(),
action: 'find_posts', action: 'find_posts',
_ajax_nonce: $('#_ajax_nonce').val(), _ajax_nonce: $('#_ajax_nonce').val()
post_type: $('input[name="find-posts-what"]:checked').val() },
}; spinner = $( '.find-box-search .spinner' );
spinner.show();
$.ajax({ $.ajax({
type : 'POST', type : 'POST',
url : ajaxurl, url : ajaxurl,
data : post, data : post,
success : function(x) { findPosts.show(x); }, success : function(x) { findPosts.show(x); spinner.hide(); },
error : function(r) { findPosts.error(r); } error : function(r) { findPosts.error(r); spinner.hide(); }
}); });
}, },
@ -55,6 +77,11 @@ var findPosts;
} }
r = r.responses[0]; r = r.responses[0];
$('#find-posts-response').html(r.data); $('#find-posts-response').html(r.data);
// Enable whole row to be clicked
$( '.found-posts td' ).on( 'click', function () {
$( this ).parent().find( '.found-radio input' ).prop( 'checked', true );
});
}, },
error : function(r) { error : function(r) {
@ -91,4 +118,7 @@ var findPosts;
}); });
}); });
}); });
$(window).resize(function() {
findPosts.overlay();
});
})(jQuery); })(jQuery);