@@ -148,16 +148,14 @@ wp.customize.controlConstructor['kirki-image'] = wp.customize.Control.extend({
148
148
* Gets the value.
149
149
*/
150
150
getValue : function ( ) {
151
-
152
- 'use strict' ;
153
-
154
151
var control = this ,
155
- input = control . container . find ( '.image-hidden-value' ) ,
156
- value = jQuery ( input ) . val ( ) ,
152
+ value = control . setting . _value ,
157
153
saveAs = ( ! _ . isUndefined ( control . params . choices ) && ! _ . isUndefined ( control . params . choices . save_as ) ) ? control . params . choices . save_as : 'url' ;
158
154
159
- if ( 'array' === saveAs ) {
160
- return JSON . parse ( value ) ;
155
+ if ( 'array' === saveAs && _ . isString ( value ) ) {
156
+ value = {
157
+ url : value
158
+ } ;
161
159
}
162
160
return value ;
163
161
} ,
@@ -166,22 +164,20 @@ wp.customize.controlConstructor['kirki-image'] = wp.customize.Control.extend({
166
164
* Saves the value.
167
165
*/
168
166
saveValue : function ( property , value ) {
169
-
170
- 'use strict' ;
171
-
172
167
var control = this ,
173
- input = jQuery ( '#customize-control-' + control . id . replace ( '[' , '-' ) . replace ( ']' , '' ) + ' .image-hidden-value' ) ,
174
- valueJSON = jQuery ( input ) . val ( ) ,
175
- saveAs = ( ! _ . isUndefined ( control . params . choices ) && ! _ . isUndefined ( control . params . choices . save_as ) ) ? control . params . choices . save_as : 'url' ,
176
- valueObj = 'array' === saveAs ? JSON . parse ( valueJSON ) : { } ;
168
+ valueOld = control . setting . _value ,
169
+ saveAs = ( ! _ . isUndefined ( control . params . choices ) && ! _ . isUndefined ( control . params . choices . save_as ) ) ? control . params . choices . save_as : 'url' ;
177
170
178
171
if ( 'array' === saveAs ) {
179
- valueObj [ property ] = value ;
180
- control . setting . set ( valueObj ) ;
181
- jQuery ( input ) . attr ( 'value' , JSON . stringify ( valueObj ) ) . trigger ( 'change' ) ;
182
- } else {
183
- control . setting . set ( value ) ;
184
- jQuery ( input ) . attr ( 'value' , value ) . trigger ( 'change' ) ;
172
+ if ( _ . isString ( valueOld ) ) {
173
+ valueOld = { } ;
174
+ }
175
+ valueOld [ property ] = value ;
176
+ control . setting . set ( valueOld ) ;
177
+ control . container . find ( 'button' ) . trigger ( 'change' ) ;
178
+ return ;
185
179
}
180
+ control . setting . set ( value ) ;
181
+ control . container . find ( 'button' ) . trigger ( 'change' ) ;
186
182
}
187
183
} ) ;
0 commit comments