Completed
Push — master ( 9aeaea...0f3eb5 )
by Yannick
07:01
created

js/script.js   A

Complexity

Total Complexity 13
Complexity/F 1.44

Size

Lines of Code 82
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
nc 1
dl 0
loc 82
rs 10
c 2
b 0
f 0
wmc 13
mnd 2
bc 14
fnc 9
bpm 1.5555
cpm 1.4443
noi 3

5 Functions

Rating   Name   Duplication   Size   Complexity  
A script.js ➔ language 0 6 1
A script.js ➔ showSearchContainers 0 4 1
A script.js ➔ showSubMenu 0 4 1
A script.js ➔ populate 0 20 1
A script.js ➔ statsdatechange 0 14 3
1
2
$( document ).ready(function() {
3
/*	
4
	//gets the current date information to be used in the datepicker
5
	var date = new Date();
6
	var currentMonth = date.getMonth();
7
	var currentDate = date.getDate();
8
	var currentYear = date.getFullYear();
9
10
  $( "#start_date" ).datetimepicker({ dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true, minDate: new Date(2014, 04 - 1, 12), maxDate: new Date(currentYear, currentMonth, currentDate, 23, 59) });
11
  $( "#end_date" ).datetimepicker({ dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true, minDate: new Date(2014, 04 - 1, 12), maxDate: new Date(currentYear, currentMonth, currentDate, 23, 59) });
12
  $( "#date" ).datepicker({ dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true, minDate: new Date(2014, 04 - 1, 12), maxDate: new Date(currentYear, currentMonth, currentDate) });
13
*/  
14
  //custom select boxes
15
  if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
0 ignored issues
show
Bug introduced by
The variable navigator seems to be never declared. If this is a global, consider adding a /** global: navigator */ 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...
16
    $('.selectpicker').selectpicker('mobile');
17
	} else {
18
	  $('.selectpicker').selectpicker();
19
	}
20
  
21
  //search
22
  $("body.page-search .sub-menu input[type=text]").click(function(){
23
	    this.select();
24
	});
25
    
26
  //bootstrap popover
27
  $('[data-toggle="popover"]').popover({
28
    trigger: 'hover',
29
    'placement': 'bottom'
30
  });
31
  
32
  
33
});
34
35
function showSearchContainers(){
36
	$(".search-explore").hide();
37
	$(".search-containers").slideDown();
38
}
39
40
function showSubMenu(){
41
	$(".sub-menu-statistic").hide();
42
	$(".sub-menu-container").slideDown();
43
}
44
function language(selectObj) {
45
    var idx = selectObj.selectedIndex;
46
    var lang = selectObj.options[idx].value;
47
    document.cookie =  'language='+lang+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
48
    window.location.reload();
49
}
50
function populate(obj,str,selected) {
51
	//console.log('populate');
52
	$.ajax({
53
		url:'search-ajax.php',
54
		type:'GET',
55
		data: 'ask=' + str,
56
		dataType: 'json',
57
		success: function( json ) {
58
			var options = "";
59
			$.each(json, function(i, item){
60
				if ($.inArray(item.id,selected) != -1) {
61
					options += "<option value="+item.id+" selected>"+item.value+"</option>";
62
				} else {
63
					options += "<option value="+item.id+">"+item.value+"</option>";
64
				}
65
			});
66
			obj.append(options);
67
		}
68
	});
69
}
70
function statsdatechange(e) {
71
	console.log(e);
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...
72
	var form = document.getElementById('changedate');
73
	var yearmonth = form.date.value.split("-");
74
	var pagename = location.pathname;
75
	pagename = pagename.split('/');
76
	var i = 0;
77
	var page = '';
78
	for (i = 0; i < pagename.length; i++) {
79
		if (isNaN(pagename[i])) page = page +'/'+ pagename[i];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
80
	}
81
	form.action = page+'/'+yearmonth[0]+'/'+yearmonth[1];
82
	form.submit();
83
}
84