@@ -54,6 +54,17 @@ jQuery( function($) {
5454 $ ( 'select#parent option[value="' + data . match ( / t a g _ I D = ( \d + ) / ) [ 1 ] + '"]' ) . remove ( ) ;
5555 $ ( 'a.tag-link-' + data . match ( / t a g _ I D = ( \d + ) / ) [ 1 ] ) . remove ( ) ;
5656
57+ /**
58+ * Updates the term count on deletion.
59+ */
60+ var termCountWrapper = $ ( '#posts-filter .displaying-num' ) ;
61+ if ( termCountWrapper . length ) {
62+ termCountWrapper . each ( function ( ) {
63+ $ ( this ) . text ( $ ( this ) . text ( ) . replace ( / ^ \d + / , function ( match ) {
64+ return parseInt ( match , 10 ) - 1 ;
65+ } ) ) ;
66+ } ) ;
67+ }
5768 } else if ( '-1' == r ) {
5869 $ ( '#ajax-response' ) . empty ( ) . append ( '<div class="notice notice-error"><p>' + wp . i18n . __ ( 'Sorry, you are not allowed to do that.' ) + '</p></div>' ) ;
5970 tr . children ( ) . css ( 'backgroundColor' , '' ) ;
@@ -117,7 +128,7 @@ jQuery( function($) {
117128 * @return {void }
118129 */
119130 $ . post ( ajaxurl , $ ( '#addtag' ) . serialize ( ) , function ( r ) {
120- var res , parent , term , indent , i ;
131+ var res , parent , term , indent , i , termCountWrapper , termCount ;
121132
122133 addingTerm = false ;
123134 form . find ( '.submit .spinner' ) . removeClass ( 'is-active' ) ;
@@ -158,6 +169,19 @@ jQuery( function($) {
158169 form . find ( 'select#parent option:selected' ) . after ( '<option value="' + term . term_id + '">' + indent + term . name + '</option>' ) ;
159170 }
160171
172+ termCountWrapper = $ ( '#posts-filter .displaying-num' ) ;
173+ termCount = res . responses [ 2 ] . supplemental . count ? res . responses [ 2 ] . supplemental . count : null ;
174+
175+ /**
176+ * Updates the term count if we get count and the term count wrapper exists.
177+ */
178+ if ( termCountWrapper . length && null !== termCount ) {
179+ termCountWrapper . each ( function ( ) {
180+ console . log ( $ ( this ) . text ( ) . match ( / ^ \d + / ) ) ;
181+ $ ( this ) . text ( $ ( this ) . text ( ) . replace ( / ^ \d + / , termCount ) ) ;
182+ } ) ;
183+ }
184+
161185 $ ( 'input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):visible, textarea:visible' , form ) . val ( '' ) ;
162186 } ) ;
163187
0 commit comments