Skip to content

Commit

Permalink
New Feature #07371: Allow to reset slider answer
Browse files Browse the repository at this point in the history
Dev: add attribute, default to no.
Dev: image from Tango Project (Public Domain)
Dev: All can be replaced by template css and js
  • Loading branch information
Shnoulle committed May 23, 2013
1 parent 79d9f07 commit 8b81381
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 30 deletions.
28 changes: 20 additions & 8 deletions application/helpers/common_helper.php
Expand Up @@ -3840,44 +3840,44 @@ function questionAttributes($returnByName=false)
$qattributes["slider_min"]=array(
"types"=>"K",
'category'=>$clang->gT('Slider'),
'sortorder'=>100,
'sortorder'=>10,
'inputtype'=>'text',
"help"=>$clang->gT('Slider minimum value'),
"caption"=>$clang->gT('Slider minimum value'));

$qattributes["slider_max"]=array(
"types"=>"K",
'category'=>$clang->gT('Slider'),
'sortorder'=>100,
'sortorder'=>11,
'inputtype'=>'text',
"help"=>$clang->gT('Slider maximum value'),
"caption"=>$clang->gT('Slider maximum value'));

$qattributes["slider_accuracy"]=array(
"types"=>"K",
'category'=>$clang->gT('Slider'),
'sortorder'=>100,
'sortorder'=>30,
'inputtype'=>'text',
"help"=>$clang->gT('Slider accuracy'),
"caption"=>$clang->gT('Slider accuracy'));

$qattributes["slider_default"]=array(
"types"=>"K",
'category'=>$clang->gT('Slider'),
'sortorder'=>100,
'sortorder'=>50,
'inputtype'=>'text',
"help"=>$clang->gT('Slider initial value'),
"help"=>$clang->gT('Slider start as this value (this will set the initial value).'),
"caption"=>$clang->gT('Slider initial value'));

$qattributes["slider_middlestart"]=array(
"types"=>"K",
'category'=>$clang->gT('Slider'),
'sortorder'=>10,
'sortorder'=>40,
'inputtype'=>'singleselect',
'options'=>array(0=>$clang->gT('No'),
1=>$clang->gT('Yes')),
'default'=>0,
"help"=>$clang->gT('The handle is displayed at the middle of the slider (this will not set the initial value)'),
"help"=>$clang->gT('The handle is displayed at the middle of the slider except if Slider initial value is set (this will not set the initial value).'),
"caption"=>$clang->gT('Slider starts at the middle position'));

$qattributes["slider_rating"]=array(
Expand All @@ -3894,6 +3894,18 @@ function questionAttributes($returnByName=false)
"help"=>$clang->gT('Use slider layout'),
"caption"=>$clang->gT('Use slider layout'));

$qattributes["slider_reset"]=array(
"types"=>"K",
'category'=>$clang->gT('Slider'),
'sortorder'=>50,
'inputtype'=>'singleselect',
'options'=>array(
0=>$clang->gT('No'),
1=>$clang->gT('Yes'),
),
'default'=>0,
"help"=>$clang->gT('Add a button to reset the slider. If you choose an start value, it reset at start value, else empty the answer.'),
"caption"=>$clang->gT('Allow reset the slider'));

$qattributes["slider_showminmax"]=array(
"types"=>"K",
Expand All @@ -3909,7 +3921,7 @@ function questionAttributes($returnByName=false)
$qattributes["slider_separator"]=array(
"types"=>"K",
'category'=>$clang->gT('Slider'),
'sortorder'=>100,
'sortorder'=>110,
'inputtype'=>'text',
"help"=>$clang->gT('Answer|Left-slider-text|Right-slider-text separator character'),
"caption"=>$clang->gT('Slider left/right text separator'));
Expand Down
27 changes: 10 additions & 17 deletions application/helpers/qanda_helper.php
Expand Up @@ -3089,14 +3089,8 @@ function do_multiplenumeric($ia)
$slider_maxtext = "100";
$slider_max = 100 * $slider_divisor;
}
if (trim($aQuestionAttributes['slider_default'])!='')
{
$slider_default = $aQuestionAttributes['slider_default'];
}
else
{
$slider_default = '';
}
$slider_default= (trim($aQuestionAttributes['slider_default'])!='')?$aQuestionAttributes['slider_default']:"";

if ($slider_default == '' && $aQuestionAttributes['slider_middlestart']==1)
{
$slider_middlestart = intval(($slider_max + $slider_min)/2);
Expand All @@ -3106,14 +3100,8 @@ function do_multiplenumeric($ia)
$slider_middlestart = '';
}

if (trim($aQuestionAttributes['slider_separator'])!='')
{
$slider_separator = $aQuestionAttributes['slider_separator'];
}
else
{
$slider_separator = '';
}
$slider_separator= (trim($aQuestionAttributes['slider_separator'])!='')?$aQuestionAttributes['slider_separator']:"";
$slider_reset=($aQuestionAttributes['slider_reset'])?1:0;
}
else
{
Expand Down Expand Up @@ -3228,7 +3216,7 @@ function do_multiplenumeric($ia)
$question_tip = '';
if(!$hidetip)
{
$question_tip .= '<p class="tip">'.$clang->gT('Only numbers may be entered in these fields')."</p>\n";
$question_tip .= '<p class="tip default">'.$clang->gT('Only numbers may be entered in these fields')."</p>\n";
}

if (trim($aQuestionAttributes['equals_num_value']) != ''
Expand Down Expand Up @@ -3285,6 +3273,9 @@ function do_multiplenumeric($ia)
}
$slider_showminmax=($aQuestionAttributes['slider_showminmax']==1)?1:0;
//some var for slider
$aJsLang=array(
'reset' => $clang->gT('Reset'),
);
$aJsVar=array(
'slider_showminmax'=>$slider_showminmax,
'slider_min' => $slider_min,
Expand All @@ -3297,6 +3288,8 @@ function do_multiplenumeric($ia)
'slider_displaycallout'=>$slider_displaycallout,
'slider_prefix' => $prefix,
'slider_suffix' => $suffix,
'slider_reset' => $slider_reset,
'lang'=> $aJsLang,
);
$answer .= "<script type='text/javascript'><!--\n"
. " doNumericSlider({$ia[0]},".ls_json_encode($aJsVar).");\n"
Expand Down
29 changes: 24 additions & 5 deletions scripts/numeric-slider.js
Expand Up @@ -16,14 +16,17 @@ function doNumericSlider(qID,jsonOptions) {
var havevalue,startvalue;
if(slider_list)
{
$("#question"+qID+" .em_value_range").remove();
$("#question"+qID+" .tip.default").remove();
var htmlSlider="<div id='container-myfname' class='multinum-slider'>\n"
+ "<div id='slider-myfname' class='ui-slider-1'>\n"
+ ((jsonOptions.slider_showminmax==1)? "<div id='slider-left-myfname' class='slider_showmin'>"+jsonOptions.slider_mintext+"</div>\n" : "")
+ "<div class='slider_callout' id='slider-callout-myfname'></div>\n"
+ "<div class='ui-slider-handle' id='slider-handle-myfname'></div>\n"
+ ((jsonOptions.slider_showminmax==1)? "<div id='slider-right-myfname' class='slider_showmax'>"+jsonOptions.slider_maxtext+"</div>\n" : "")
+ ((jsonOptions.slider_showminmax==1)? "<div id='slider-left-myfname' class='slider_showmin slider-showmin'>"+jsonOptions.slider_mintext+"</div>\n" : "")
+ "<div id='slider-callout-myfname' class='slider_callout slider-callout'></div>\n"
+ "<div id='slider-handle-myfname' class='ui-slider-handle'></div>\n"
+ ((jsonOptions.slider_showminmax==1)? "<div id='slider-right-myfname' class='slider_showmax slider-showmax'>"+jsonOptions.slider_maxtext+"</div>\n" : "")
+ "</div>\n"
+ "</div>\n";
var htmlSliderResest=((jsonOptions.slider_reset==1)? "<a id='slider-reset-myfname' class='slider-reset' title='"+jsonOptions.lang.reset+"'>"+jsonOptions.lang.reset+"</a>\n" : "");
$("#question"+qID+" .slider-list").children('.answer-item').each(function(){
var thisinput=$(this).children(".input").children('input.text');
var myfname=$(thisinput).attr('name');
Expand All @@ -41,7 +44,7 @@ function doNumericSlider(qID,jsonOptions) {
}
$(this).children(".input").hide();
$(htmlSlider.replace(/myfname/g,myfname)).insertAfter($(this).children(".input"));

$(htmlSliderResest.replace(/myfname/g,myfname)).appendTo($(this));
$("#container-"+myfname).slider({
value:startvalue,
min: jsonOptions.slider_min,
Expand All @@ -63,7 +66,23 @@ function doNumericSlider(qID,jsonOptions) {
$(thisinput).triggerHandler("keyup");
});
}
$(this).on("click",".slider-reset",function(){
if(jsonOptions.slider_startvalue=="NULL"){
$( "#container-"+myfname ).slider( "option", "value", "" );
}else{
$( "#container-"+myfname ).slider( "option", "value", jsonOptions.slider_startvalue );
}
if(jsonOptions.slider_displaycallout && jsonOptions.slider_startvalue!="NULL"){
$('#slider-callout-'+myfname).text(jsonOptions.slider_prefix + jsonOptions.slider_startvalue + jsonOptions.slider_suffix);
$(thisinput).val(jsonOptions.slider_startvalue);
}else{
$('#slider-callout-'+myfname).text("");
$(thisinput).val("");
}
$(thisinput).triggerHandler("keyup");
});
});
}

}

Binary file added styles-public/img/reset.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions styles-public/numeric-slider.css
@@ -0,0 +1,20 @@
/* This file is part of LimeSurvey - http://www.limesurvey.org */
/* reset.png is part of Tango Project - http://tango.freedesktop.org/ */
.slider-reset{
float:right;
height:1.4em;min-height:20px;
width:20px;
margin-left:2em;
text-indent: -9999999px;
background: url("img/reset.png") no-repeat scroll 0 0 transparent;
cursor: pointer;
}
.slider-reset:hover,.slider-reset:focus{
background-position:-20px 0;
}
.slider-reset:active{
background-position:-40px 0;
}
.slider-reset{
transition: all 100ms ease;
}

0 comments on commit 8b81381

Please sign in to comment.