- Posts: 7
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
function reverseSlider(qID) { // Identify the question var thisQuestion = $('#question'+qID); //$('span.input', thisQuestion).show() // un-comment this to debug // Reverse the min/max displays $('.answer-item', thisQuestion).each(function(i) { var showMinText = $('.slider-showmin', this).text(); var showMaxText = $('.slider-showmax', this).text(); $('.slider-showmin', this).text(showMaxText); $('.slider-showmax', this).text(showMinText); }); // Initial slider positions $('span.input input[type="text"]', thisQuestion).each(function(i) { if($(this).val() != '') { var thisRow = $(this).closest('li.answer-item'); var thisSlider = $('.ui-slider', thisRow); var sliderValue = $(thisSlider).slider('option', 'max')+$(thisSlider).slider('option', 'min')-$(this).val(); $('.ui-slider', thisRow).slider('option', 'value', sliderValue); $('.slider-callout', thisRow).text($(this).val()); } }); // New slide function $('.ui-slider', thisQuestion).slider( 'option', 'slide', function(event, ui) { // Define a few vars var thisRow = $(this).closest('li.answer-item'); var thisSlider = $(this); var step = $(thisSlider).slider('option', 'step').toString(); var stepDecimals = ''; if(step.indexOf('.') != -1) { stepDecimals = step.length - (step.indexOf('.')+1); } var reverseValue = ''; // Calculate the "reverse" value if(ui.value > $(thisSlider).slider('option', 'max')) { reverseValue = $(thisSlider).slider('option', 'min'); } else if(ui.value < $(thisSlider).slider('option', 'min')) { reverseValue = $(thisSlider).slider('option', 'max'); } else if(stepDecimals > 0) { // Handle decimal places reverseValue = ($(thisSlider).slider('option', 'max')+$(thisSlider).slider('option', 'min')-ui.value).toFixed(stepDecimals); } else{ reverseValue = $(thisSlider).slider('option', 'max')+$(thisSlider).slider('option', 'min')-ui.value; } reverseValue = reverseValue.toString(); reverseValue = reverseValue.replace(/\./,LSvar.sLEMradix); // Load the callout $('.slider_callout', thisRow).text(reverseValue); // Set the data value $('input.text', thisRow).val(reverseValue); $('input.text', thisRow).triggerHandler("keyup"); }); }
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { reverseSlider({QID}); }); </script>