PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.5
4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 All 203 releases
betterdocs / react-src / admin / customizer / customizer-range-value-control.js

customizer-range-value-control.js in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.5, at react-src/admin/customizer/customizer-range-value-control.js

97 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Script run inside a Customizer control sidebar
3 */
4 (function($) {
5 // An empty setting means "unset" — the control emits no CSS and the
6 // stylesheet's own value stands. That state is not representable in an
7 // <input type="range">: the HTML value-sanitization algorithm turns a
8 // non-numeric value into min + (max-min)/2, so an unset control would park
9 // its thumb on a meaningless midpoint. Controls that can be unset therefore
10 // ship a `data-unset-val` holding the value the stylesheet actually paints.
11 // Sliders with a numeric default have no such attribute and are untouched by
12 // any of the branches below.
13 var isUnset = function($range) {
14 var id = $range.attr('data-customize-setting-link');
15 if (!id || !wp.customize.has(id)) {
16 return false;
17 }
18 var val = wp.customize(id).get();
19 return val === '' || val === null || typeof val === 'undefined';
20 };
21
22 // Park the thumb on the unset fallback without touching the setting.
23 // Assigning .value directly fires no change event, so nothing is published
24 // and the control keeps emitting zero CSS.
25 var applyUnsetVal = function($range) {
26 var unset = $range.attr('data-unset-val');
27 if (typeof unset !== 'undefined' && isUnset($range)) {
28 $range.val(unset);
29 return true;
30 }
31 return false;
32 };
33
34 wp.customize.bind('ready', function() {
35 rangeSlider();
36
37 var rangeValReset = jQuery('.betterdocs-customizer-reset.betterdocs-range-value');
38 rangeValReset.each(function() {
39 $(rangeValReset).on( 'click', function (e) {
40 e.preventDefault();
41 var nextRangeselector = $(this).next('.betterdcos-range-slider');
42 var nextRangeDefaultVal = $(this).next('.betterdcos-range-slider').data('default-val');
43 var $range = nextRangeselector.find('.betterdcos-range-slider__range');
44 var suffix = $range.attr('suffix') ? $range.attr('suffix') : '';
45
46 if (nextRangeDefaultVal === '' || nextRangeDefaultVal === null || typeof nextRangeDefaultVal === 'undefined') {
47 // Round-tripping '' through the range input would coerce it to
48 // the midpoint and then publish that number, so Reset would
49 // apply styling instead of clearing it. Write the setting
50 // directly and re-park the thumb on the stylesheet value.
51 var id = $range.attr('data-customize-setting-link');
52 if (id && wp.customize.has(id)) {
53 wp.customize(id).set('');
54 }
55 var unset = $range.attr('data-unset-val');
56 if (typeof unset !== 'undefined') {
57 $range.val(unset);
58 }
59 nextRangeselector.find('.betterdcos-range-slider__value').html($range.val() + suffix);
60 return;
61 }
62
63 $range.val(nextRangeDefaultVal).trigger('change');
64 nextRangeselector.find('.betterdcos-range-slider__value').html(nextRangeDefaultVal + suffix);
65
66 });
67 });
68 });
69
70 var rangeSlider = function() {
71 var slider = $('.betterdcos-range-slider'),
72 range = $('.betterdcos-range-slider__range'),
73 value = $('.betterdcos-range-slider__value');
74
75 slider.each(function() {
76
77 value.each(function() {
78 var $range = $(this).prev();
79 // WP core's linkElements() has already pushed the saved setting
80 // into the input by the time 'ready' fires, so read the live value
81 // rather than the rendered attribute — otherwise an unset control
82 // renders a bare suffix with no number in front of it.
83 applyUnsetVal($range);
84 var value = $range.val();
85 var suffix = ($range.attr('suffix')) ? $range.attr('suffix') : '';
86 $(this).html(value + suffix);
87 });
88
89 range.on('input', function() {
90 var suffix = ($(this).attr('suffix')) ? $(this).attr('suffix') : '';
91 $(this).next(value).html(this.value + suffix );
92 });
93 });
94 };
95
96 })(jQuery);
97