@@ -19,11 +19,16 @@ wp.customize.controlConstructor['kirki-gradient'] = wp.customize.Control.extend(
19
19
20
20
'use strict' ;
21
21
22
- var control = this ,
23
- value = control . getValue ( ) ,
24
- pickerStart = control . container . find ( '.kirki-gradient-control-start' ) ,
25
- pickerEnd = control . container . find ( '.kirki-gradient-control-end' ) ,
26
- angleElement = jQuery ( '.angle.gradient-' + control . id ) ;
22
+ var control = this ,
23
+ value = control . getValue ( ) ,
24
+ pickerStart = control . container . find ( '.kirki-gradient-control-start' ) ,
25
+ pickerEnd = control . container . find ( '.kirki-gradient-control-end' ) ,
26
+ angleElement = jQuery ( '.angle.gradient-' + control . id ) ,
27
+ throttledAngleChange ,
28
+ throttledPositionStartChange ,
29
+ throttledPositionEndChange ,
30
+ startPositionElement = jQuery ( '.position.gradient-' + control . id + '-start' ) ,
31
+ endPositionElement = jQuery ( '.position.gradient-' + control . id + '-end' ) ;
27
32
28
33
// If we have defined any extra choices, make sure they are passed-on to Iris.
29
34
if ( ! _ . isUndefined ( control . params . choices . iris ) ) {
@@ -56,30 +61,62 @@ wp.customize.controlConstructor['kirki-gradient'] = wp.customize.Control.extend(
56
61
} ) ;
57
62
} ) ;
58
63
59
- // Angle (-90° - 90°).
60
- angleElement . on ( 'change' , function ( ) {
64
+ jQuery ( control . container . find ( '.global .angle' ) ) . show ( ) ;
65
+ if ( ! _ . isUndefined ( value . mode && 'radial' === value . mode ) ) {
66
+ jQuery ( control . container . find ( '.global .angle' ) ) . hide ( ) ;
67
+ }
68
+
69
+ // Mode (linear/radial).
70
+ jQuery ( control . container . find ( '.mode .switch-input' ) ) . on ( 'click input' , function ( ) {
71
+ value . mode = jQuery ( this ) . val ( ) ;
72
+ control . updatePreview ( value ) ;
73
+ control . setValue ( value ) ;
74
+ jQuery ( control . container . find ( '.global .angle' ) ) . show ( ) ;
75
+ if ( 'radial' === value . mode ) {
76
+ jQuery ( control . container . find ( '.global .angle' ) ) . hide ( ) ;
77
+ }
78
+ } ) ;
79
+
80
+ // Angle (-90° -to 90°).
81
+ throttledAngleChange = _ . throttle ( function ( ) {
61
82
value . angle = angleElement . val ( ) ;
62
83
63
84
// Update the preview.
64
85
control . updatePreview ( value ) ;
65
86
66
87
// Set the value.
67
88
control . setValue ( value ) ;
89
+ } , 20 ) ;
90
+ angleElement . on ( 'input change oninput' , function ( ) {
91
+ throttledAngleChange ( ) ;
68
92
} ) ;
69
93
70
- // Position( 0% - 100%);
71
- _ . each ( [ 'start' , 'end' ] , function ( index ) {
72
- var positionElement = jQuery ( '.position.gradient-' + control . id + '-' + index ) ;
94
+ // Start Position( 0% - 100%);
95
+ throttledPositionStartChange = _ . throttle ( function ( ) {
96
+ value . start . position = startPositionElement . val ( ) ;
73
97
74
- positionElement . on ( 'change' , function ( ) {
75
- value [ index ] . position = positionElement . val ( ) ;
98
+ // Update the preview.
99
+ control . updatePreview ( value ) ;
76
100
77
- // Update the preview.
78
- control . updatePreview ( value ) ;
101
+ // Set the value.
102
+ control . setValue ( value ) ;
103
+ } , 20 ) ;
104
+ startPositionElement . on ( 'input change oninput' , function ( ) {
105
+ throttledPositionStartChange ( ) ;
106
+ } ) ;
79
107
80
- // Set the value.
81
- control . setValue ( value ) ;
82
- } ) ;
108
+ // End Position( 0% - 100%);
109
+ throttledPositionEndChange = _ . throttle ( function ( ) {
110
+ value . end . position = endPositionElement . val ( ) ;
111
+
112
+ // Update the preview.
113
+ control . updatePreview ( value ) ;
114
+
115
+ // Set the value.
116
+ control . setValue ( value ) ;
117
+ } , 20 ) ;
118
+ endPositionElement . on ( 'input change oninput' , function ( ) {
119
+ throttledPositionEndChange ( ) ;
83
120
} ) ;
84
121
} ,
85
122
@@ -115,10 +152,17 @@ wp.customize.controlConstructor['kirki-gradient'] = wp.customize.Control.extend(
115
152
var control = this ,
116
153
previewArea = control . container . find ( '.gradient-preview' ) ;
117
154
118
- jQuery ( previewArea ) . css (
119
- 'background' ,
120
- 'linear-gradient(' + value . angle + 'deg, ' + value . start . color + ' ' + value . start . position + '%,' + value . end . color + ' ' + value . end . position + '%)'
121
- ) ;
155
+ if ( ! _ . isUndefined ( value . mode ) && 'radial' === value . mode ) {
156
+ jQuery ( previewArea ) . css (
157
+ 'background' ,
158
+ 'radial-gradient(ellipse at center, ' + value . start . color + ' ' + value . start . position + '%,' + value . end . color + ' ' + value . end . position + '%)'
159
+ ) ;
160
+ } else {
161
+ jQuery ( previewArea ) . css (
162
+ 'background' ,
163
+ 'linear-gradient(' + value . angle + 'deg, ' + value . start . color + ' ' + value . start . position + '%,' + value . end . color + ' ' + value . end . position + '%)'
164
+ ) ;
165
+ }
122
166
} ,
123
167
124
168
/**
0 commit comments