Make WordPress Core

Ticket #42373: 42373.6.diff

File 42373.6.diff, 8.7 KB (added by westonruter, 8 years ago)

Add radix to parseInt

  • src/wp-admin/js/customize-controls.js

    diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
    index 0504891969..d9554618f2 100644
     
    55425542                        control.inputElements = {};
    55435543                        control.invalidDate = false;
    55445544
    5545                         _.bindAll( control, 'populateSetting', 'updateDaysForMonth', 'updateMinutesForHour', 'populateDateInputs' );
     5545                        _.bindAll( control, 'populateSetting', 'updateDaysForMonth', 'populateDateInputs' );
    55465546
    55475547                        if ( ! control.setting ) {
    55485548                                throw new Error( 'Missing setting' );
     
    55525552                                var input = $( this ), component, element;
    55535553                                component = input.data( 'component' );
    55545554                                element = new api.Element( input );
    5555                                 if ( 'meridian' === component ) {
    5556                                         element.validate = function( value ) {
    5557                                                 if ( 'am' !== value && 'pm' !== value ) {
    5558                                                         return null;
    5559                                                 }
    5560                                                 return value;
    5561                                         };
    5562                                 } else {
    5563                                         element.validate = function( value ) {
    5564                                                 var val = parseInt( value, 10 );
    5565                                                 if ( isNaN( val ) ) {
    5566                                                         return null;
    5567                                                 }
    5568                                                 return val;
    5569                                         };
    5570                                 }
    5571                                 element.bind( control.populateSetting );
    55725555                                control.inputElements[ component ] = element;
    55735556                                control.elements.push( element );
     5557
     5558                                // Add invalid date error once user changes (and has blurred the input).
     5559                                input.on( 'change', function() {
     5560                                        if ( control.invalidDate ) {
     5561                                                control.notifications.add( new api.Notification( 'invalid_date', {
     5562                                                        message: api.l10n.invalidDate
     5563                                                } ) );
     5564                                        }
     5565                                } );
     5566
     5567                                // Remove the error immediately after validity change.
     5568                                input.on( 'input', _.debounce( function() {
     5569                                        if ( ! control.invalidDate ) {
     5570                                                control.notifications.remove( 'invalid_date' );
     5571                                        }
     5572                                } ) );
    55745573                        } );
    55755574
    55765575                        control.inputElements.month.bind( control.updateDaysForMonth );
    55775576                        control.inputElements.year.bind( control.updateDaysForMonth );
    5578                         if ( control.params.includeTime ) {
    5579                                 control.inputElements.hour.bind( control.updateMinutesForHour );
    5580                         }
    55815577                        control.populateDateInputs();
    55825578                        control.setting.bind( control.populateDateInputs );
     5579
     5580                        // Start populating setting after inputs have been populated.
     5581                        _.each( control.inputElements, function( element ) {
     5582                                element.bind( control.populateSetting );
     5583                        } );
    55835584                },
    55845585
    55855586                /**
     
    56295630                 * @return {boolean} If date input fields has error.
    56305631                 */
    56315632                validateInputs: function validateInputs() {
    5632                         var control = this, errorMessage, components;
     5633                        var control = this, components, validityInput;
    56335634
    56345635                        control.invalidDate = false;
    56355636
     
    56385639                                components.push( 'hour', 'minute' );
    56395640                        }
    56405641
    5641                         _.each( components, function( component ) {
    5642                                 var element, el, max, min, value;
     5642                        _.find( components, function( component ) {
     5643                                var element, max, min, value;
     5644
     5645                                element = control.inputElements[ component ];
     5646                                validityInput = element.element.get( 0 );
     5647                                max = parseInt( element.element.attr( 'max' ), 10 );
     5648                                min = parseInt( element.element.attr( 'min' ), 10 );
     5649                                value = parseInt( element(), 10 );
     5650                                control.invalidDate = isNaN( value ) || value > max || value < min;
    56435651
    56445652                                if ( ! control.invalidDate ) {
    5645                                         element = control.inputElements[ component ];
    5646                                         el = element.element.get( 0 );
    5647                                         max = parseInt( element.element.attr( 'max' ), 10 );
    5648                                         min = parseInt( element.element.attr( 'min' ), 10 );
    5649                                         value = element();
    5650                                         control.invalidDate = value > max || value < min;
    5651                                         errorMessage = control.invalidDate ? api.l10n.invalid + ' ' + component : '';
    5652 
    5653                                         el.setCustomValidity( errorMessage );
    5654                                         if ( ! control.section() || api.section.has( control.section() ) && api.section( control.section() ).expanded() ) {
    5655                                                 _.result( el, 'reportValidity' );
    5656                                         }
     5653                                        validityInput.setCustomValidity( '' );
    56575654                                }
     5655
     5656                                return control.invalidDate;
    56585657                        } );
    56595658
     5659                        if ( control.inputElements.meridian && ! control.invalidDate ) {
     5660                                validityInput = control.inputElements.meridian.element.get( 0 );
     5661                                if ( 'am' !== control.inputElements.meridian.get() && 'pm' !== control.inputElements.meridian.get() ) {
     5662                                        control.invalidDate = true;
     5663                                } else {
     5664                                        validityInput.setCustomValidity( '' );
     5665                                }
     5666                        }
     5667
     5668                        if ( control.invalidDate ) {
     5669                                validityInput.setCustomValidity( api.l10n.invalidValue );
     5670                        } else {
     5671                                validityInput.setCustomValidity( '' );
     5672                        }
     5673                        if ( ! control.section() || api.section.has( control.section() ) && api.section( control.section() ).expanded() ) {
     5674                                _.result( validityInput, 'reportValidity' );
     5675                        }
     5676
    56605677                        return control.invalidDate;
    56615678                },
    56625679
     
    56695686                updateDaysForMonth: function updateDaysForMonth() {
    56705687                        var control = this, daysInMonth, year, month, day;
    56715688
    5672                         month = control.inputElements.month();
    5673                         year = control.inputElements.year();
    5674                         day = control.inputElements.day();
     5689                        month = parseInt( control.inputElements.month(), 10 );
     5690                        year = parseInt( control.inputElements.year(), 10 );
     5691                        day = parseInt( control.inputElements.day(), 10 );
    56755692
    56765693                        if ( month && year ) {
    56775694                                daysInMonth = new Date( year, month, 0 ).getDate();
    56785695                                control.inputElements.day.element.attr( 'max', daysInMonth );
    56795696
    56805697                                if ( day > daysInMonth ) {
    5681                                         control.inputElements.day( daysInMonth );
     5698                                        control.inputElements.day( String( daysInMonth ) );
    56825699                                }
    56835700                        }
    56845701                },
    56855702
    5686                 /**
    5687                  * Updates number of minutes according to the hour selected.
    5688                  *
    5689                  * @since 4.9.0
    5690                  * @return {void}
    5691                  */
    5692                 updateMinutesForHour: function updateMinutesForHour() {
    5693                         var control = this, maxHours = 24, minuteEl;
    5694 
    5695                         if ( control.inputElements.meridian ) {
    5696                                 return;
    5697                         }
    5698 
    5699                         minuteEl = control.inputElements.minute.element;
    5700 
    5701                         if ( maxHours === control.inputElements.hour() ) {
    5702                                 control.inputElements.minute( 0 );
    5703                                 minuteEl.data( 'default-max', minuteEl.attr( 'max' ) );
    5704                                 minuteEl.attr( 'max', '0' );
    5705                         } else if ( minuteEl.data( 'default-max' ) ) {
    5706                                 minuteEl.attr( 'max', minuteEl.data( 'default-max' ) );
    5707                         }
    5708                 },
    5709 
    57105703                /**
    57115704                 * Populate setting value from the inputs.
    57125705                 *
     
    57455738                        };
    57465739
    57475740                        getElementValue = function( component ) {
    5748                                 var value = control.inputElements[ component ].get();
     5741                                var value = parseInt( control.inputElements[ component ].get(), 10 );
    57495742
    57505743                                if ( _.contains( [ 'month', 'day', 'hour', 'minute' ], component ) ) {
    57515744                                        value = pad( value, 2 );
     
    58225815                        }
    58235816
    58245817                        _.each( control.inputElements, function( element, component ) {
    5825                                 element.set( parsed[ component ] );
     5818                                if ( 'meridian' === component || parseInt( parsed[ component ], 10 ) !== parseInt( element(), 10 ) ) {
     5819                                        element.set( parsed[ component ] );
     5820                                }
    58265821                        } );
    58275822
    58285823                        return true;
  • src/wp-includes/customize/class-wp-customize-date-time-control.php

    diff --git src/wp-includes/customize/class-wp-customize-date-time-control.php src/wp-includes/customize/class-wp-customize-date-time-control.php
    index 0506910b61..d1e8d12500 100644
    class WP_Customize_Date_Time_Control extends WP_Customize_Control { 
    141141                                        <legend class="title-time"><?php esc_html_e( 'Time' ); ?></legend>
    142142                                        <div class="time-fields clear">
    143143                                                <label for="{{ idPrefix }}date-time-hour" class="screen-reader-text"><?php esc_html_e( 'Hour' ); ?></label>
    144                                                 <# var maxHour = data.twelveHourFormat ? 12 : 24; #>
    145                                                 <input id="{{ idPrefix }}date-time-hour" type="number" size="2" autocomplete="off" class="date-input hour" data-component="hour" min="1" max="{{ maxHour }}">
     144                                                <# var maxHour = data.twelveHourFormat ? 12 : 23; #>
     145                                                <# var minHour = data.twelveHourFormat ? 1 : 0; #>
     146                                                <input id="{{ idPrefix }}date-time-hour" type="number" size="2" autocomplete="off" class="date-input hour" data-component="hour" min="{{ minHour }}" max="{{ maxHour }}">
    146147                                                <span class="time-special-char date-time-separator">:</span>
    147148                                                <label for="{{ idPrefix }}date-time-minute" class="screen-reader-text"><?php esc_html_e( 'Minute' ); ?></label>
    148149                                                <input id="{{ idPrefix }}date-time-minute" type="number" size="2" autocomplete="off" class="date-input minute" data-component="minute" min="0" max="59">
  • src/wp-includes/script-loader.php

    diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php
    index c43659379d..e5204a7aa0 100644
    function wp_default_scripts( &$scripts ) { 
    599599                        esc_url( admin_url( 'theme-install.php' ) )
    600600                ),
    601601                'publishSettings' => __( 'Publish Settings' ),
     602                'invalidDate'     => __( 'Invalid date.' ),
     603                'invalidValue'    => __( 'Invalid value.' ),
    602604        ) );
    603605        $scripts->add( 'customize-selective-refresh', "/wp-includes/js/customize-selective-refresh$suffix.js", array( 'jquery', 'wp-util', 'customize-preview' ), false, 1 );
    604606