diff --git src/wp-admin/js/customize-widgets.js src/wp-admin/js/customize-widgets.js
index ba10a89..8134a98 100644
|
|
|
927 | 927 | }, |
928 | 928 | |
929 | 929 | /** |
930 | | * Get the property that represents the state of an input. |
| 930 | * Get the state for an input depending on its type. |
931 | 931 | * |
932 | | * @param {jQuery|DOMElement} input |
933 | | * @returns {string} |
| 932 | * @param {jQuery|Element} input |
| 933 | * @returns {string|boolean|array|*} |
934 | 934 | * @private |
935 | 935 | */ |
936 | | _getInputStatePropertyName: function( input ) { |
937 | | var $input = $( input ); |
| 936 | _getInputState: function( input ) { |
| 937 | input = $( input ); |
| 938 | if ( input.is( ':radio, :checkbox' ) ) { |
| 939 | return input.prop( 'checked' ); |
| 940 | } else if ( input.is( 'select[multiple]' ) ) { |
| 941 | return input.find( 'option:selected' ).map( function () { |
| 942 | return $( this ).val(); |
| 943 | } ).get(); |
| 944 | } else { |
| 945 | return input.val(); |
| 946 | } |
| 947 | }, |
938 | 948 | |
939 | | if ( $input.is( ':radio, :checkbox' ) ) { |
940 | | return 'checked'; |
| 949 | /** |
| 950 | * Update an input's state based on its type. |
| 951 | * |
| 952 | * @param {jQuery|Element} input |
| 953 | * @param {string|boolean|array|*} state |
| 954 | * @private |
| 955 | */ |
| 956 | _setInputState: function ( input, state ) { |
| 957 | input = $( input ); |
| 958 | if ( input.is( ':radio, :checkbox' ) ) { |
| 959 | input.prop( 'checked', state ); |
| 960 | } else if ( input.is( 'select[multiple]' ) ) { |
| 961 | if ( ! $.isArray( state ) ) { |
| 962 | state = []; |
| 963 | } else { |
| 964 | // Make sure all state items are strings since the DOM value is a string |
| 965 | state = _.map( state, function ( value ) { |
| 966 | return String( value ); |
| 967 | } ); |
| 968 | } |
| 969 | input.find( 'option' ).each( function () { |
| 970 | $( this ).prop( 'selected', -1 !== _.indexOf( state, String( this.value ) ) ); |
| 971 | } ); |
941 | 972 | } else { |
942 | | return 'value'; |
| 973 | input.val( state ); |
943 | 974 | } |
944 | 975 | }, |
945 | 976 | |
… |
… |
|
1016 | 1047 | // we know if it got sanitized; if there is no difference in the sanitized value, |
1017 | 1048 | // then we do not need to touch the UI and mess up the user's ongoing editing. |
1018 | 1049 | $inputs.each( function() { |
1019 | | var input = $( this ), |
1020 | | property = self._getInputStatePropertyName( this ); |
1021 | | input.data( 'state' + updateNumber, input.prop( property ) ); |
| 1050 | $( this ).data( 'state' + updateNumber, self._getInputState( this ) ); |
1022 | 1051 | } ); |
1023 | 1052 | |
1024 | 1053 | if ( instanceOverride ) { |
… |
… |
|
1071 | 1100 | $inputs.each( function( i ) { |
1072 | 1101 | var $input = $( this ), |
1073 | 1102 | $sanitizedInput = $( $sanitizedInputs[i] ), |
1074 | | property = self._getInputStatePropertyName( this ), |
1075 | 1103 | submittedState, sanitizedState, canUpdateState; |
1076 | 1104 | |
1077 | 1105 | submittedState = $input.data( 'state' + updateNumber ); |
1078 | | sanitizedState = $sanitizedInput.prop( property ); |
| 1106 | sanitizedState = self._getInputState( $sanitizedInput ); |
1079 | 1107 | $input.data( 'sanitized', sanitizedState ); |
1080 | 1108 | |
1081 | | canUpdateState = ( submittedState !== sanitizedState && ( args.ignoreActiveElement || ! $input.is( document.activeElement ) ) ); |
| 1109 | canUpdateState = ( ! _.isEqual( submittedState, sanitizedState ) && ( args.ignoreActiveElement || ! $input.is( document.activeElement ) ) ); |
1082 | 1110 | if ( canUpdateState ) { |
1083 | | $input.prop( property, sanitizedState ); |
| 1111 | self._setInputState( $input, sanitizedState ); |
1084 | 1112 | } |
1085 | 1113 | } ); |
1086 | 1114 | |