|
1
|
|
|
wp.customize.controlConstructor['kirki-slider'] = wp.customize.kirkiDynamicControl.extend({ |
|
2
|
|
|
|
|
3
|
|
|
initKirkiControl: function() { |
|
4
|
|
|
var control = this, |
|
5
|
|
|
changeAction = ( 'postMessage' === control.setting.transport ) ? 'mousemove change' : 'change', |
|
6
|
|
|
rangeInput = control.container.find( 'input[type="range"]' ), |
|
7
|
|
|
textInput = control.container.find( 'input[type="text"]' ), |
|
8
|
|
|
value = control.setting._value; |
|
9
|
|
|
|
|
10
|
|
|
// Set the initial value in the text input. |
|
11
|
|
|
textInput.attr( 'value', value ); |
|
12
|
|
|
|
|
13
|
|
|
// If the range input value changes copy the value to the text input. |
|
14
|
|
|
rangeInput.on( 'mousemove change', function() { |
|
15
|
|
|
textInput.attr( 'value', rangeInput.val() ); |
|
16
|
|
|
} ); |
|
17
|
|
|
|
|
18
|
|
|
// Save the value when the range input value changes. |
|
19
|
|
|
// This is separate from the above because of the postMessage differences. |
|
20
|
|
|
// If the control refreshes the preview pane, |
|
21
|
|
|
// we don't want a refresh for every change |
|
22
|
|
|
// but 1 final refresh when the value is changed. |
|
23
|
|
|
rangeInput.on( changeAction, function() { |
|
24
|
|
|
control.setting.set( rangeInput.val() ); |
|
25
|
|
|
} ); |
|
26
|
|
|
|
|
27
|
|
|
// If the text input value changes, |
|
28
|
|
|
// copy the value to the range input |
|
29
|
|
|
// and then save. |
|
30
|
|
|
textInput.on( 'input paste change', function() { |
|
31
|
|
|
rangeInput.attr( 'value', textInput.val() ); |
|
32
|
|
|
control.setting.set( textInput.val() ); |
|
33
|
|
|
} ); |
|
34
|
|
|
|
|
35
|
|
|
// If the reset button is clicked, |
|
36
|
|
|
// set slider and text input values to default |
|
37
|
|
|
// and hen save. |
|
38
|
|
|
control.container.find( '.slider-reset' ).on( 'click', function() { |
|
39
|
|
|
textInput.attr( 'value', control.params['default'] ); |
|
40
|
|
|
rangeInput.attr( 'value', control.params['default'] ); |
|
41
|
|
|
control.setting.set( textInput.val() ); |
|
42
|
|
|
} ); |
|
43
|
|
|
} |
|
44
|
|
|
}); |
|
45
|
|
|
|