Set additional fields when searching. Fixes #15211

git-svn-id: http://svn.automattic.com/wordpress/trunk@16022 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
scribu 2010-10-27 20:17:00 +00:00
parent 4eb0f634b2
commit 0ca1e83f76
3 changed files with 52 additions and 22 deletions

View File

@ -37,16 +37,6 @@ window.listTable = {
this.update_rows({'paged': paged});
},
// searching
change_search: function(s) {
this.update_rows({'s': s}, true, function() {
$('h2 .subtitle').remove();
if ( s )
$('h2').eq(0).append($('<span class="subtitle">').html(listTableL10n.search.replace('%s', this.htmlencode(s))));
});
},
htmlencode: function(value) {
return $('<div/>').text(value).html();
},
@ -216,20 +206,26 @@ listTable.init();
});
// searchbox
$('.search-box :submit').click(function() {
listTable.change_search($(this).parent('.search-box').find(':text').val());
return false;
});
$('.search-box :text').keypress(function(e) {
if ( 13 != e.keyCode )
function change_search(ev) {
if ( 'keypress' == ev.type && 13 != e.keyCode )
return;
listTable.change_search($(this).val());
ev.preventDefault();
ev.stopImmediatePropagation();
return false;
});
var data = $(this).parent('.search-box').find(':input').serializeObject();
listTable.update_rows(data, true, function() {
$('h2 .subtitle').remove();
if ( data.s )
$('h2').append($('<span class="subtitle">').html(
listTableL10n.search.replace('%s', this.htmlencode(data.s))
));
});
}
$('.search-box :submit').click(change_search);
$('.search-box :text').keypress(change_search);
// tablenav dropdowns
$('#post-query-submit').click(function() {

View File

@ -0,0 +1,31 @@
/*!
* jQuery serializeObject - v0.2 - 1/20/2010
* http://benalman.com/projects/jquery-misc-plugins/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// Whereas .serializeArray() serializes a form into an array, .serializeObject()
// serializes a form into an (arguably more useful) object.
(function($,undefined){
'$:nomunge'; // Used by YUI compressor.
$.fn.serializeObject = function(){
var obj = {};
$.each( this.serializeArray(), function(i,o){
var n = o.name,
v = o.value;
obj[n] = obj[n] === undefined ? v
: $.isArray( obj[n] ) ? obj[n].concat( v )
: [ obj[n], v ];
});
return obj;
};
})(jQuery);

View File

@ -171,6 +171,9 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'jquery-query', "/wp-includes/js/jquery/jquery.query.js", array('jquery'), '2.1.7' );
$scripts->add_data( 'jquery-query', 'group', 1 );
$scripts->add( 'jquery-serialize-object', "/wp-includes/js/jquery/jquery.serialize-object.js", array('jquery'), '0.2' );
$scripts->add_data( 'jquery-serialize-object', 'group', 1 );
$scripts->add( 'jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys$suffix.js", array('jquery'), '0.0.2m' );
$scripts->add_data( 'jquery-hotkeys', 'group', 1 );
@ -354,7 +357,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'theme-preview', "/wp-admin/js/theme-preview$suffix.js", array( 'thickbox', 'jquery' ), '20100407' );
$scripts->add_data( 'theme-preview', 'group', 1 );
$scripts->add( 'list-table', "/wp-admin/js/list-table$suffix.js", array( 'jquery', 'jquery-query' ), '20101023' );
$scripts->add( 'list-table', "/wp-admin/js/list-table$suffix.js", array( 'jquery-query', 'jquery-serialize-object' ), '20101027' );
$scripts->add_data( 'list-table', 'group', 1 );
$scripts->localize( 'list-table', 'listTableL10n', array(
'loading' => __('Loading...'),