Completed
Push — master ( cc50d0...0f8c33 )
by Yannick
09:46
created

script.js ➔ statsdatechange   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 19

Duplication

Lines 19
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
nc 8
nop 1
dl 19
loc 19
rs 8.8571
c 2
b 0
f 0
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 View Code Duplication
function statsdatechange(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
71
	var form = document.getElementById('changedate');
72
	var yearmonth = form.date.value.split("-");
73
	var pagename = location.pathname;
74
	pagename = pagename.split('/');
75
	var i = 0;
76
	var page = '';
77
	for (i = 0; i < pagename.length; i++) {
78
		if (pagename[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
	}
82
	if (typeof yearmonth[1] != 'undefined') {
83
		form.action = page+'/'+yearmonth[0]+'/'+yearmonth[1];
84
	} else {
85
		form.action = page;
86
	}
87
	form.submit();
88
}
89 View Code Duplication
function statsairlinechange(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
90
	var form = document.getElementById('changeairline');
91
	var airline = form.airline.value;
92
	var pagename = location.pathname;
93
	pagename = pagename.split('/');
94
	var i = 0;
95
	var page = '';
96
	var add = false;
97
	for (i = 0; i < pagename.length; i++) {
98
		if (pagename[i] != '') {
99
			if (pagename[i].length != 3) 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...
100
			else {
101
				add = true;
102
				if (airline != 'all') page = page+'/'+airline;
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...
103
			}
104
		}
105
	}
106
	if (add === false) page = page+'/'+airline;
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...
107
	form.action = page;
108
	form.submit();
109
}
110