I'll try and keep this straightforward. I am using jQuery sliders and trying to initialize them all at once using an array:
sliders.push(new slider('paletteControl','pSlider',0,255,100,sliderChange()));
function slider (context, id, min, max, defaultvalue, changeFunc) {
this.context = context;
this.id = id;
this.min = min;
this.max = max;
this.defaultvalue = defaultvalue;
this.changeFunc = changeFunc;
$(id).slider({
range: "min",
min: sliders[i].min,
max: sliders[i].max,
value: sliders[i].defaultvalue,
create: function() {
handle.text( $( this ).slider( "value" ) );
},
change: function() {
sliders[i].changeFunc();
}
});
function parcelSliderFunction(caller, value)
{
for (var x = 0; x < sliders.length; x++)
{
if(sliders[x].id == caller) {
sliders[x].callback(value);
return;
}
}
console.log("id " + caller + " not found, you done screwed up.");
return;
}
First you have to remove parentheses of the function as parameter, in this line
sliders.push(new slider('paletteControl','pSlider',0,255,100,sliderChange()));
It becomes
sliders.push(new slider('paletteControl','pSlider',0,255,100,sliderChange));
Then you get the change function like this (without parentheses)
$(id).slider({
range: "min",
min: sliders[i].min,
max: sliders[i].max,
value: sliders[i].defaultvalue,
create: function() {
handle.text( $( this ).slider( "value" ) );
},
change: sliders[i].changeFunc
});
OR
$(id).slider({
range: "min",
min: sliders[i].min,
max: sliders[i].max,
value: sliders[i].defaultvalue,
create: function() {
handle.text( $( this ).slider( "value" ) );
}
});
$( id ).on( "slidechange", function( event, ui ) {} );