| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Admin\Form\ExtraFieldJS; |
| 4 |
|
| 5 |
class SetSliderFieldValue |
| 6 |
{ |
| 7 |
public static function init($fk, $field, $contentId) |
| 8 |
{ |
| 9 |
return <<<FUNCTIONDEF |
| 10 |
function setSliderFieldValue(formContentId = null) { |
| 11 |
const contentIds = formContentId ? [formContentId] : Object.keys(bf_globals); |
| 12 |
contentIds.forEach(contentId => { |
| 13 |
bfSelect("#form-"+contentId)?.querySelectorAll("input[type='range']").forEach(function(el){ |
| 14 |
el.addEventListener("input",function(e){ |
| 15 |
e.target.parentNode.style.setProperty('--bfv-fld-val', JSON.stringify(el.value)); |
| 16 |
const bfFill = ((el.value - (el.min || 0)) / ((el.max || 100) - (el.min || 0))) * 100; |
| 17 |
e.target.style.setProperty('--bfv-fill-lower-track', `\${bfFill}%`, 'important'); |
| 18 |
}); |
| 19 |
const style = window.getComputedStyle(el); |
| 20 |
el.style.setProperty('--bfv-track-dir', style.direction === 'rtl'? 'to left' : 'to right'); |
| 21 |
}); |
| 22 |
}) |
| 23 |
} |
| 24 |
|
| 25 |
FUNCTIONDEF; |
| 26 |
} |
| 27 |
} |
| 28 |
|