options_general_add_js

Display JavaScript on the page.

Description

options_general_add_js(); 

Usage

  1. if ( !function_exists( 'options_general_add_js' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/options.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = options_general_add_js(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/options.php  
  1. function options_general_add_js() { 
  2. ?> 
  3. <script type="text/javascript"> 
  4. jQuery(document).ready(function($) { 
  5. var $siteName = $( '#wp-admin-bar-site-name' ).children( 'a' ).first(),  
  6. homeURL = ( <?php echo wp_json_encode( get_home_url() ); ?> || '' ).replace( /^(https?:\/\/)?(www\.)?/, '' ); 
  7.  
  8. $( '#blogname' ).on( 'input', function() { 
  9. var title = $.trim( $( this ).val() ) || homeURL; 
  10.  
  11. // Truncate to 40 characters. 
  12. if ( 40 < title.length ) { 
  13. title = title.substring( 0, 40 ) + '\u2026'; 
  14.  
  15. $siteName.text( title ); 
  16. }); 
  17.  
  18. $("input[name='date_format']").click(function() { 
  19. if ( "date_format_custom_radio" != $(this).attr("id") ) 
  20. $( "input[name='date_format_custom']" ).val( $( this ).val() ).siblings( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() ); 
  21. }); 
  22. $("input[name='date_format_custom']").focus(function() { 
  23. $( '#date_format_custom_radio' ).prop( 'checked', true ); 
  24. }); 
  25.  
  26. $("input[name='time_format']").click(function() { 
  27. if ( "time_format_custom_radio" != $(this).attr("id") ) 
  28. $( "input[name='time_format_custom']" ).val( $( this ).val() ).siblings( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() ); 
  29. }); 
  30. $("input[name='time_format_custom']").focus(function() { 
  31. $( '#time_format_custom_radio' ).prop( 'checked', true ); 
  32. }); 
  33. $("input[name='date_format_custom'], input[name='time_format_custom']").change( function() { 
  34. var format = $(this); 
  35. format.siblings( '.spinner' ).addClass( 'is-active' ); 
  36. $.post(ajaxurl, { 
  37. action: 'date_format_custom' == format.attr('name') ? 'date_format' : 'time_format',  
  38. date : format.val() 
  39. }, function(d) { format.siblings( '.spinner' ).removeClass( 'is-active' ); format.siblings('.example').text(d); } ); 
  40. }); 
  41.  
  42. var languageSelect = $( '#WPLANG' ); 
  43. $( 'form' ).submit( function() { 
  44. // Don't show a spinner for English and installed languages,  
  45. // as there is nothing to download. 
  46. if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) { 
  47. $( '#submit', this ).after( '<span class="spinner language-install-spinner" />' ); 
  48. }); 
  49. }); 
  50. </script> 
  51. <?php