Make WordPress Core

Changeset 37908


Ignore:
Timestamp:
06/29/2016 12:57:19 PM (9 years ago)
Author:
ocean90
Message:

I18N: Localize the jQuery UI datepicker.

This provides some default data for the jQuery UI datepicker. The localized data is already available via WP_Locale and is only passed to the datepicker if the script is enqueued.

Props clubduece, swissspidy, barryceelen, ocean90.
Fixes #29420.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/default-filters.php

    r37708 r37908  
    405405// Script Loader
    406406add_action( 'wp_default_scripts', 'wp_default_scripts' );
     407add_action( 'wp_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 );
     408add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 );
    407409add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' );
    408410add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
  • trunk/src/wp-includes/script-loader.php

    r37891 r37908  
    883883        'blog_id' => get_current_blog_id(),
    884884    ) );
    885 
     885}
     886
     887/**
     888 * Localizes the jQuery UI datepicker.
     889 *
     890 * @since 4.6.0
     891 *
     892 * @link http://api.jqueryui.com/datepicker/#options
     893 * @global WP_Locale $wp_locale The WordPress date and time locale object.
     894 */
     895function wp_localize_jquery_ui_datepicker() {
     896    global $wp_locale;
     897
     898    if ( ! wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) {
     899        return;
     900    }
     901
     902    // Convert the PHP date format into jQuery UI's format.
     903    $datepicker_date_format = str_replace(
     904        array(
     905            'd', 'j', 'l', 'z', // Day.
     906            'F', 'M', 'n', 'm', // Month.
     907            'Y', 'y'            // Year.
     908        ),
     909        array(
     910            'dd', 'd', 'DD', 'o',
     911            'MM', 'M', 'm', 'mm',
     912            'yy', 'y'
     913        ),
     914        get_option( 'date_format' )
     915    );
     916
     917    $datepicker_defaults = wp_json_encode( array(
     918        'closeText'       => __( 'Close' ),
     919        'currentText'     => __( 'Today' ),
     920        'monthNames'      => array_values( $wp_locale->month ),
     921        'monthNamesShort' => array_values( $wp_locale->month_abbrev ),
     922        'nextText'        => __( 'Next' ),
     923        'prevText'        => __( 'Previous' ),
     924        'dayNames'        => array_values( $wp_locale->weekday ),
     925        'dayNamesShort'   => array_values( $wp_locale->weekday_abbrev ),
     926        'dayNamesMin'     => array_values( $wp_locale->weekday_initial ),
     927        'dateFormat'      => $datepicker_date_format,
     928        'firstDay'        => absint( get_option( 'start_of_week' ) ),
     929        'isRTL'           => $wp_locale->is_rtl(),
     930    ) );
     931
     932    wp_add_inline_script( 'jquery-ui-datepicker', "jQuery(document).ready(function(jQuery){jQuery.datepicker.setDefaults({$datepicker_defaults});});" );
    886933}
    887934
Note: See TracChangeset for help on using the changeset viewer.