From 0480fcbf6884860d23e5c590087a64855096ed0b Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Thu, 10 Jan 2008 20:19:58 +0000 Subject: [PATCH] Fixes for new categories interface from mdawaffe. fixes #5618 git-svn-id: https://develop.svn.wordpress.org/trunk@6591 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/admin-ajax.php | 2 +- wp-admin/edit-form-advanced.php | 2 +- wp-admin/includes/template.php | 2 +- wp-admin/js/post.js | 33 ++++++++++++++++++++------------- wp-admin/wp-admin.css | 5 +---- wp-includes/js/wp-lists.js | 25 +++++++------------------ wp-includes/script-loader.php | 4 ++-- 7 files changed, 33 insertions(+), 40 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 34e9a55896..0119678f93 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -173,7 +173,7 @@ case 'add-category' : // On the Fly if ( $parent ) // Do these all at once in a second continue; $category = get_category( $cat_id ); - $category->_is_checked = true; + $checked_categories[] = $cat_id; ob_start(); dropdown_categories( 0, $category ); $data = ob_get_contents(); diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index d09c052d50..365a1adabb 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -125,7 +125,7 @@ else

- + 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category') ) ); ?> diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index d7e009db44..2cf77fb239 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -144,7 +144,7 @@ function get_nested_categories( $default = 0, $parent = 0 ) { $root = array( 'children' => get_nested_categories( $default, $parent->term_id ), 'cat_ID' => $parent->term_id, - 'checked' => isset($parent->_is_checked) && $parent->_is_checked, + 'checked' => in_array( $parent->term_id, $checked_categories ), 'cat_name' => get_the_category_by_ID( $parent->term_id ) ); $result = array( $parent->term_id => $root ); diff --git a/wp-admin/js/post.js b/wp-admin/js/post.js index fa0d69b19b..0cb44c49ba 100644 --- a/wp-admin/js/post.js +++ b/wp-admin/js/post.js @@ -69,20 +69,16 @@ addLoadEvent( function() { jQuery('#tags-input').hide(); tag_update_quickclicks(); // add the quickadd form - jQuery('#jaxtag').prepend(''+postL10n.separate+''); + jQuery('#jaxtag').prepend(''+postL10n.separate+''); jQuery('#tagadd').click( tag_flush_to_text ); // jQuery('#newtag').keydown( tag_press_key ); jQuery('#newtag').focus(function() { - if ( this.value == postL10n.addTag ) { - this.value = ''; - this.style.color = '#333'; - } + if ( this.value == postL10n.addTag ) + jQuery(this).val( '' ).removeClass( 'form-input-tip' ); }); jQuery('#newtag').blur(function() { - if ( this.value == '' ) { - this.value = postL10n.addTag; - this.style.color = '#999' - } + if ( this.value == '' ) + jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' ); }); // auto-suggest stuff @@ -95,14 +91,25 @@ addLoadEvent( function() { var categoryTabs =jQuery('#category-tabs').tabs(); // Ajax Cat - var newCat = jQuery('#newcat').one( 'focus', function() { jQuery(this).val( '' ) } ); + var newCat = jQuery('#newcat').one( 'focus', function() { jQuery(this).val( '' ).removeClass( 'form-input-tip' ) } ); jQuery('#category-add-sumbit').click( function() { newCat.focus(); } ); + var newCatParent = false; + var newCatParentOption = false; var catAddAfter = function( r, s ) { + if ( !newCatParent ) newCatParent = jQuery('#newcat_parent'); + if ( !newCatParentOption ) newCatParentOption = newCatParent.find( 'option[value=-1]' ); jQuery(s.what + ' response_data', r).each( function() { var t = jQuery(jQuery(this).text()); - var o = jQuery( '' ); - o.text( jQuery.trim( t.text() ) ); - jQuery('#newcat_parent').prepend( o ); + t.find( 'label' ).each( function() { + var th = jQuery(this); + var id = th.find('input').val(); + if ( newCatParent.find( 'option[value=' + id + ']' ).size() ) + return; + var name = jQuery.trim( th.text() ); + var o = jQuery( '' ).text( name ); + newCatParent.prepend( o ); + newCatParentOption.attr( 'selected', true ); + } ); } ); }; jQuery('#categorychecklist').wpList( { diff --git a/wp-admin/wp-admin.css b/wp-admin/wp-admin.css index d7bc851939..f46d741d06 100644 --- a/wp-admin/wp-admin.css +++ b/wp-admin/wp-admin.css @@ -1090,10 +1090,6 @@ a.view-comment-post-link { background: url(images/xit.gif) no-repeat -10px 0; } -#newtag { - color: #999; -} - .howto { font-style: italic; display: block; @@ -1284,3 +1280,4 @@ ul.categorychecklist li { /* Global classes */ .wp-hidden-children .wp-hidden-child { display: none; } .ui-tabs-hide { display: none; } +.form-input-tip { color: #999; } diff --git a/wp-includes/js/wp-lists.js b/wp-includes/js/wp-lists.js index 58c3ac4079..de309bc534 100644 --- a/wp-includes/js/wp-lists.js +++ b/wp-includes/js/wp-lists.js @@ -267,25 +267,17 @@ var wpList = { list = $(this); e = $(e); - var old = false; var next = false; + var old = false; var _s = { pos: 0, id: 0, oldId: null }; if ( 'string' == typeof s ) { s = { what: s }; } s = $.extend(_s, this.wpList.settings, s); if ( !e.size() || !s.what ) { return false; } - if ( s.oldId ) { - old = $('#' + s.what + '-' + s.oldId); - next = old.next(); - old.remove(); - } - if ( s.id ) { $('#' + s.what + '-' + s.id).remove(); } + if ( s.oldId ) { old = $('#' + s.what + '-' + s.oldId); } + if ( s.id && ( s.id != s.oldId || !old || !old.size() ) ) { $('#' + s.what + '-' + s.id).remove(); } if ( old && old.size() ) { - if ( next && next.size() ) { - next.before(e); - } else { - list.append(e); - } + old.replaceWith(e); } else if ( isNaN(s.pos) ) { var ba = 'after'; if ( '-' == s.pos.substr(0,1) ) { @@ -331,8 +323,6 @@ var wpList = { process: function(el) { var list = this; - var bl = function() { currentFormEl = false; }; - var fo = function() { currentFormEl = this; }; var a = $("[@class^=add:" + list.id + ":]", el || null) .filter('form').submit( function() { return list.wpList.add(this); } ).end() .not('form').click( function() { return list.wpList.add(this); } ).each( function() { @@ -340,16 +330,15 @@ var wpList = { var c = wpList.parseClass(this,'add')[2] || addEl.id; if ( !c ) { return; } var forms = []; var ins = []; - $('#' + c + ' :input').click( function() { $(this).unbind( 'blur', bl ).unbind( 'focus', fo ).blur( bl ).focus( fo ).focus(); } ).each( function() { + $('#' + c + ' :input').focus( function() { currentFormEl = this; } ).blur( function() { currentFormEl = false; } ).each( function() { ins.push(this); $.merge(forms,$(this).parents('form')); forms = $.unique(forms); } ); $(forms).submit( function() { - var e = currentFormEl; - if ( 0 <= $.inArray(e,ins) ) { + if ( 0 <= $.inArray(currentFormEl,ins) ) { $(addEl).trigger( 'click' ); - $(e).focus(); + $(currentFormEl).focus(); return false; } } ); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 422b3d882f..9f8d7fd098 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -60,7 +60,7 @@ class WP_Scripts { 'delText' => __('Are you sure you want to delete this %thing%?') ) ); - $this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('jquery'), '20080109' ); + $this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('jquery'), '20080110' ); $this->localize( 'wp-lists', 'wpListL10n', array( 'url' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php' ) ); @@ -108,7 +108,7 @@ class WP_Scripts { $this->add( 'admin-forms', '/wp-admin/js/forms.js', array('wp-lists'), '20080108' ); $this->add( 'xfn', '/wp-admin/js/xfn.js', false, '3517' ); $this->add( 'upload', '/wp-admin/js/upload.js', array('jquery'), '20070518' ); - $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists'), '20080109' ); + $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists'), '20080110' ); $this->localize( 'post', 'postL10n', array( 'tagsUsed' => __('Tags used on this post:'), 'add' => attribute_escape(__('Add')),