Created
March 15, 2024 16:06
-
-
Save jonasfrey/a4d59a32547c5afd7ebe89a24d645b69 to your computer and use it in GitHub Desktop.
geogebra input slider fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// o , how annoying it was to constantly stay over the slider with the mouse while moving it | |
let f_a_n_trn__relative_to_o_html = function( | |
a_n__trn_mouse, | |
o_el | |
){ | |
const o_brect = o_el.getBoundingClientRect(); | |
return [ | |
a_n__trn_mouse[0] - o_brect.left, | |
a_n__trn_mouse[1] - o_brect.top | |
] | |
} | |
let f_a_n_trn__relative_to_o_html__nor = function( | |
a_n__trn_mouse, | |
o_el | |
){ | |
const o_brect = o_el.getBoundingClientRect(); | |
let a_n_trn = f_a_n_trn__relative_to_o_html(a_n__trn_mouse, o_el); | |
return [ | |
a_n_trn[0] / o_brect.width, | |
a_n_trn[1] / o_brect.height, | |
] | |
} | |
let b_down = false; | |
let o_el = null; | |
document.addEventListener('pointerdown', (o_e)=>{ | |
let o2 = o_e?.target?.previousSibling; | |
if(o2){ | |
let s = o2.getAttribute('data-test'); | |
if(s?.includes('ItemSlider')){ | |
console.log(s) | |
b_down = true | |
o_el = o_e.target; | |
} | |
} | |
}) | |
document.addEventListener('pointerup', (o_e)=>{ | |
b_down = false; | |
}) | |
document.addEventListener('pointermove', (o_e)=>{ | |
if(b_down){ | |
let a_n_trn = f_a_n_trn__relative_to_o_html__nor( | |
[ | |
o_e.clientX, | |
o_e.clientY, | |
], | |
o_el | |
); | |
let n_min = parseFloat(o_el?.min); | |
let n_max = parseFloat(o_el?.max); | |
if(isNaN(n_min)){n_min = 0.;} | |
if(isNaN(n_max)){n_max = 1.;} | |
let n_range = n_max - n_min; | |
let n_new = parseFloat(a_n_trn[0]*n_range)+n_min | |
console.log(n_new) | |
o_el.value = n_new; | |
o_el.dispatchEvent(new Event('input')) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment