Completed
Push — master ( c38c9f...6d2c0d )
by Josh
06:54
created

SliderAPI.getFrequencySliderLabel   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
var SliderAPI = {
2
    multi_btn_group_width:112, //width in em
3
    selectOption : function(parentElementId,optionNum){
4
        var parentElement = document.getElementById(parentElementId);
5
        parentElement.style.left = SliderAPI.multi_btn_group_width * optionNum + "px";
6
    },
7
    selectOptionByValue : function(groupName, selectedValue, sliderId){
8
        //console.log(groupName);
9
        //get radio group collection
10
        var group = document.getElementsByName(groupName);
11
        
12
        //get slider overlay div
13
        var slider = document.getElementById(sliderId);
14
        //iternate through group
15
        for(var g = 0; g < group.length; g++){
16
            var option = group[g];
17
            option.checked = false;
18
            //if radio button value = data driven value or selected value change slider style to the option index and ensure it is checked.
19
            console.log(option.value === selectedValue);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
20
            if(option.value === selectedValue) {
21
                option.checked = true;
22
                slider.className = 'option'+g;
23
            }
24
        }
25
    },
26
    toggle : function (elemId, optionNum) {
27
        var bgcolor = document.getElementById(elemId);
28
29
        if (optionNum == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing optionNum to 0 using the == operator is not safe. Consider using === instead.
Loading history...
Coding Style introduced by
It is recommended to use === to compare with 0.

Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.

Read more about comparison operations.

Loading history...
30
            bgcolor.setAttribute("class", "left");
31
        } else {
32
            bgcolor.setAttribute("class", "right");
33
        }
34
    },
35
    
36
    getYesNoSliderLabel : function(value) {
37
        var labelMap = {
38
            'option0':siteContent.yes, 
0 ignored issues
show
Bug introduced by
The variable siteContent seems to be never declared. If this is a global, consider adding a /** global: siteContent */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
39
            'option1':siteContent.no
40
        };
41
        return labelMap[value];
42
    },
43
    
44
    getFrequencySliderLabel : function(value) {
45
        var labelMap = {
46
            'option0':siteContent.almostNever,
0 ignored issues
show
Bug introduced by
The variable siteContent seems to be never declared. If this is a global, consider adding a /** global: siteContent */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
47
            'option1':siteContent.rarely,
48
            'option2':siteContent.sometimes,
49
            'option3':siteContent.usually,
50
            'option4':siteContent.almostAlways
51
        };
52
        return labelMap[value];
53
    }
54
};
55