wp/wp-admin/includes/options.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
--- a/wp/wp-admin/includes/options.php	Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-admin/includes/options.php	Mon Oct 14 18:28:13 2019 +0200
@@ -13,7 +13,7 @@
  * @since 4.2.0
  */
 function options_discussion_add_js() {
-?>
+	?>
 	<script>
 	(function($){
 		var parent = $( '#show_avatars' ),
@@ -23,7 +23,7 @@
 		});
 	})(jQuery);
 	</script>
-<?php
+	<?php
 }
 
 /**
@@ -32,7 +32,7 @@
  * @since 3.5.0
  */
 function options_general_add_js() {
-?>
+	?>
 <script type="text/javascript">
 	jQuery(document).ready(function($){
 		var $siteName = $( '#wp-admin-bar-site-name' ).children( 'a' ).first(),
@@ -61,22 +61,31 @@
 			if ( "time_format_custom_radio" != $(this).attr("id") )
 				$( 'input[name="time_format_custom"]' ).val( $( this ).val() ).closest( 'fieldset' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() );
 		});
+
 		$( 'input[name="time_format_custom"]' ).on( 'click input', function() {
 			$( '#time_format_custom_radio' ).prop( 'checked', true );
 		});
-		$("input[name='date_format_custom'], input[name='time_format_custom']").change( function() {
+
+		$( 'input[name="date_format_custom"], input[name="time_format_custom"]' ).on( 'input', function() {
 			var format = $( this ),
 				fieldset = format.closest( 'fieldset' ),
 				example = fieldset.find( '.example' ),
 				spinner = fieldset.find( '.spinner' );
 
-			spinner.addClass( 'is-active' );
+			// Debounce the event callback while users are typing.
+			clearTimeout( $.data( this, 'timer' ) );
+			$( this ).data( 'timer', setTimeout( function() {
+				// If custom date is not empty.
+				if ( format.val() ) {
+					spinner.addClass( 'is-active' );
 
-			$.post( ajaxurl, {
-					action: 'date_format_custom' == format.attr( 'name' ) ? 'date_format' : 'time_format',
-					date : format.val()
-				}, function( d ) { spinner.removeClass( 'is-active' ); example.text( d ); } );
-		});
+					$.post( ajaxurl, {
+						action: 'date_format_custom' == format.attr( 'name' ) ? 'date_format' : 'time_format',
+						date 	: format.val()
+					}, function( d ) { spinner.removeClass( 'is-active' ); example.text( d ); } );
+				}
+			}, 500 ) );
+		} );
 
 		var languageSelect = $( '#WPLANG' );
 		$( 'form' ).submit( function() {
@@ -88,7 +97,7 @@
 		});
 	});
 </script>
-<?php
+	<?php
 }
 
 /**
@@ -97,7 +106,7 @@
  * @since 3.5.0
  */
 function options_reading_add_js() {
-?>
+	?>
 <script type="text/javascript">
 	jQuery(document).ready(function($){
 		var section = $('#front-static-pages'),
@@ -107,10 +116,10 @@
 				selects.prop( 'disabled', ! staticPage.prop('checked') );
 			};
 		check_disabled();
- 		section.find('input:radio').change(check_disabled);
+		section.find( 'input:radio' ).change( check_disabled );
 	});
 </script>
-<?php
+	<?php
 }
 
 /**