wp/wp-admin/includes/options.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    11  * Output JavaScript to toggle display of additional settings if avatars are disabled.
    11  * Output JavaScript to toggle display of additional settings if avatars are disabled.
    12  *
    12  *
    13  * @since 4.2.0
    13  * @since 4.2.0
    14  */
    14  */
    15 function options_discussion_add_js() {
    15 function options_discussion_add_js() {
    16 ?>
    16 	?>
    17 	<script>
    17 	<script>
    18 	(function($){
    18 	(function($){
    19 		var parent = $( '#show_avatars' ),
    19 		var parent = $( '#show_avatars' ),
    20 			children = $( '.avatar-settings' );
    20 			children = $( '.avatar-settings' );
    21 		parent.change(function(){
    21 		parent.change(function(){
    22 			children.toggleClass( 'hide-if-js', ! this.checked );
    22 			children.toggleClass( 'hide-if-js', ! this.checked );
    23 		});
    23 		});
    24 	})(jQuery);
    24 	})(jQuery);
    25 	</script>
    25 	</script>
    26 <?php
    26 	<?php
    27 }
    27 }
    28 
    28 
    29 /**
    29 /**
    30  * Display JavaScript on the page.
    30  * Display JavaScript on the page.
    31  *
    31  *
    32  * @since 3.5.0
    32  * @since 3.5.0
    33  */
    33  */
    34 function options_general_add_js() {
    34 function options_general_add_js() {
    35 ?>
    35 	?>
    36 <script type="text/javascript">
    36 <script type="text/javascript">
    37 	jQuery(document).ready(function($){
    37 	jQuery(document).ready(function($){
    38 		var $siteName = $( '#wp-admin-bar-site-name' ).children( 'a' ).first(),
    38 		var $siteName = $( '#wp-admin-bar-site-name' ).children( 'a' ).first(),
    39 			homeURL = ( <?php echo wp_json_encode( get_home_url() ); ?> || '' ).replace( /^(https?:\/\/)?(www\.)?/, '' );
    39 			homeURL = ( <?php echo wp_json_encode( get_home_url() ); ?> || '' ).replace( /^(https?:\/\/)?(www\.)?/, '' );
    40 
    40 
    59 
    59 
    60 		$("input[name='time_format']").click(function(){
    60 		$("input[name='time_format']").click(function(){
    61 			if ( "time_format_custom_radio" != $(this).attr("id") )
    61 			if ( "time_format_custom_radio" != $(this).attr("id") )
    62 				$( 'input[name="time_format_custom"]' ).val( $( this ).val() ).closest( 'fieldset' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() );
    62 				$( 'input[name="time_format_custom"]' ).val( $( this ).val() ).closest( 'fieldset' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() );
    63 		});
    63 		});
       
    64 
    64 		$( 'input[name="time_format_custom"]' ).on( 'click input', function() {
    65 		$( 'input[name="time_format_custom"]' ).on( 'click input', function() {
    65 			$( '#time_format_custom_radio' ).prop( 'checked', true );
    66 			$( '#time_format_custom_radio' ).prop( 'checked', true );
    66 		});
    67 		});
    67 		$("input[name='date_format_custom'], input[name='time_format_custom']").change( function() {
    68 
       
    69 		$( 'input[name="date_format_custom"], input[name="time_format_custom"]' ).on( 'input', function() {
    68 			var format = $( this ),
    70 			var format = $( this ),
    69 				fieldset = format.closest( 'fieldset' ),
    71 				fieldset = format.closest( 'fieldset' ),
    70 				example = fieldset.find( '.example' ),
    72 				example = fieldset.find( '.example' ),
    71 				spinner = fieldset.find( '.spinner' );
    73 				spinner = fieldset.find( '.spinner' );
    72 
    74 
    73 			spinner.addClass( 'is-active' );
    75 			// Debounce the event callback while users are typing.
       
    76 			clearTimeout( $.data( this, 'timer' ) );
       
    77 			$( this ).data( 'timer', setTimeout( function() {
       
    78 				// If custom date is not empty.
       
    79 				if ( format.val() ) {
       
    80 					spinner.addClass( 'is-active' );
    74 
    81 
    75 			$.post( ajaxurl, {
    82 					$.post( ajaxurl, {
    76 					action: 'date_format_custom' == format.attr( 'name' ) ? 'date_format' : 'time_format',
    83 						action: 'date_format_custom' == format.attr( 'name' ) ? 'date_format' : 'time_format',
    77 					date : format.val()
    84 						date 	: format.val()
    78 				}, function( d ) { spinner.removeClass( 'is-active' ); example.text( d ); } );
    85 					}, function( d ) { spinner.removeClass( 'is-active' ); example.text( d ); } );
    79 		});
    86 				}
       
    87 			}, 500 ) );
       
    88 		} );
    80 
    89 
    81 		var languageSelect = $( '#WPLANG' );
    90 		var languageSelect = $( '#WPLANG' );
    82 		$( 'form' ).submit( function() {
    91 		$( 'form' ).submit( function() {
    83 			// Don't show a spinner for English and installed languages,
    92 			// Don't show a spinner for English and installed languages,
    84 			// as there is nothing to download.
    93 			// as there is nothing to download.
    86 				$( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' );
    95 				$( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' );
    87 			}
    96 			}
    88 		});
    97 		});
    89 	});
    98 	});
    90 </script>
    99 </script>
    91 <?php
   100 	<?php
    92 }
   101 }
    93 
   102 
    94 /**
   103 /**
    95  * Display JavaScript on the page.
   104  * Display JavaScript on the page.
    96  *
   105  *
    97  * @since 3.5.0
   106  * @since 3.5.0
    98  */
   107  */
    99 function options_reading_add_js() {
   108 function options_reading_add_js() {
   100 ?>
   109 	?>
   101 <script type="text/javascript">
   110 <script type="text/javascript">
   102 	jQuery(document).ready(function($){
   111 	jQuery(document).ready(function($){
   103 		var section = $('#front-static-pages'),
   112 		var section = $('#front-static-pages'),
   104 			staticPage = section.find('input:radio[value="page"]'),
   113 			staticPage = section.find('input:radio[value="page"]'),
   105 			selects = section.find('select'),
   114 			selects = section.find('select'),
   106 			check_disabled = function(){
   115 			check_disabled = function(){
   107 				selects.prop( 'disabled', ! staticPage.prop('checked') );
   116 				selects.prop( 'disabled', ! staticPage.prop('checked') );
   108 			};
   117 			};
   109 		check_disabled();
   118 		check_disabled();
   110  		section.find('input:radio').change(check_disabled);
   119 		section.find( 'input:radio' ).change( check_disabled );
   111 	});
   120 	});
   112 </script>
   121 </script>
   113 <?php
   122 	<?php
   114 }
   123 }
   115 
   124 
   116 /**
   125 /**
   117  * Render the site charset setting.
   126  * Render the site charset setting.
   118  *
   127  *