I have a page where a user can call a slider to change the look of an image. There will only ever be one slider visible but maybe 10 total. Instead of writing js function for each I'm trying to streamline using HTML5 data- variables.
This is the the html of two sliders, only one visible at a time:
<div class="editSliderHolder" id="brightness">
<label>Brightness</label>
<div class="editSlider" data-minVal="-20" data-maxVal="20" data-editValue="curValB"></div>
</div>
<div class="editSliderHolder" id="contrast">
<label>Contrast</label>
<div class="editSlider" data-minVal="-40" data-maxVal="40" data-editValue="curValC"></div>
</div>
And the JQuery I'm trying:
$(document).ready(function () {
var div = $("div.editSlider");
div.slider({
value: 0,
min: div.data("minVal"),
max: div.data("maxVal"),
slide: function (event, ui) {
//alert(min); // check if value set
div.data("editValue", ui.value);
$(this).find('.ui-slider-handle').text(Math.round(ui.value));
},
stop: function(event, ui) {
div.data("editValue", ui.value);
Caman('#capEdit', function () {
this.revert(); // restore canvas
this.contrast(curValC); // add contrast
this.brightness(curValB); // add brightness
this.render(); // render it
});
}
});
});
So what happens is, the min and max values are set for each slider and also the ui.value which determines which effect to change i.e. in this case, brightness or contrast.
None of the values are being set and I have no idea why. Is there a better way to do this or is this code just wrong?