-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwot_stats_form.js
99 lines (76 loc) · 2.6 KB
/
wot_stats_form.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Description: Some functions to handle the visual/interactive part of forms and other elements for the site, Say Wot? - stats (http://saywotstats.net)
* Author: Johan "DaWoody" Wedfelt
* Author URL: https://github.com/DaWoody
* License: GNU General Public License, version 3(GPL-3.0) (http://opensource.org/licenses/GPL-3.0)
*
*
*/
jQuery(document).ready(function(){
/*
* Declaring some variables to access the label...
*/
var label = $("#search_player_form_section").find("label");
var about = $("#about");
var about_link = $("#about_link");
var textField = $("#search_player_form_section").find("input[type=text]");
var labelValue = label.text();
var version_link = $('#wot_stats_version_link');
var version_info = $('#wot_stats_version_info');
//Hiding the label from start and the info box
label.hide();
about.hide();
version_info.hide();
//Setting the value of the textfield equal to that of the label
textField.val(labelValue);
wotStatsVersionUrlXml = 'xml/wot_stats_version_info.xml';
var initWotStats = {
getVersion: function() {
$.ajax(wotStatsVersionUrlXml,{
dataType: 'xml',
success: function(data) {
//lets traverse through the data and build the DOM
var versionTitle = $(data).find('version_title').text();
var versionInfoHeader = $(data).find('version_info_title').text();
var versionInfo = $(data).find('version_info').text();
var dev_blog_url = $(data).find('dev_blog_url').text();
//console.log('Say Wot Stats Engine ' + versionTitle + ' up and running! ;)');
//Print it to the DOM
version_link.text(versionTitle);
version_info.html('<h3>' + versionInfoHeader + ' ' + versionTitle + '</h3>');
version_info.append(versionInfo);
version_info.append('Read more at the <a href="' + dev_blog_url + '">development blog</a>');
},
error: function(data) {
console.log('hhmm ok something went wrong with the XML parsing..');
}
});
}
}
//Create some functions
function RemoveName() {
textField.addClass('highlighted');
if(textField.val()=='Tanker Name'){
textField.val('');
}
}
function CheckField() {
if(textField.val()==''){
textField.removeClass('highlighted');
textField.val('Tanker Name');
}
}
function showAbout() {
about.toggle();
}
function showVersionInfo() {
version_info.toggle();
}
//Create some listeners for our
textField.on('blur', CheckField);
textField.on('focus', RemoveName);
about_link.on('click', showAbout);
version_link.on('click', showVersionInfo);
//Init our form listener
initWotStats.getVersion();
});