-
Notifications
You must be signed in to change notification settings - Fork 0
/
KCViewerPanel.js
155 lines (125 loc) · 4.11 KB
/
KCViewerPanel.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Main file, initializer
(function () {
//Container for configurations
// Tabbing initialization
function tabInit() {
$('#info>div:not(:first)').hide();
$('#info-nav li:first').addClass('current');
$('#info-nav li').click(function (event) {
event.preventDefault();
$('#info>div').hide();
$('#info-nav .current').removeClass('current');
$(this).addClass('current');
var clicked = $(this).find('a').attr('href');
$('#info ' + clicked).fadeIn('fast');
});
}
// Extra options band init
function exOpsInit(){
var tmp =$('.exoptions li.opspanel');
$(tmp).each(function(){
var clicked = $(this).find('a').attr('href');
$(clicked).hide();
});
$(tmp).click(function(event) {
event.preventDefault();
var clicked = $(this).find('a').attr('href');
if ($(this).hasClass('current')) {
$(this).removeClass('current');
$('.exoptionspanel ').fadeOut('fast');
}else{
$(clicked).slideDown('slow');
var tmp = $('.exoptions li.opspanel.current');
$(tmp).each(function(){
var clicked = $(this).find('a').attr('href');
$(clicked).fadeOut('fast');
});
$(tmp).removeClass('current');
$(this).addClass('current');
}
});
}
// Fires when load
function listen() {
var reloadButton = document.querySelector('.reload-button');
reloadButton.addEventListener('click', kcDataReload);
// This is where to init html only controller
// Tabbing on the first line
tabInit();
// Extra options showing as buttons on the bottom bar
exOpsInit();
// load all data
kcLoadMasterData();
}
// When the first json arrives - time to parse & load everyting
// These init is only for pure form & logic generation
// Shouldn't include user data .. etc.
function contextFormInit()
{
Ship.init();
Timer.init();
Deck.init();
Dock.init();
}
// (re)loading user data
function kcDataReload()
{
$.getJSON("svdraw.json", updateJSON);
//Used for extension
// chrome.runtime.sendMessage({
// command: "loadKCData",
// tabId: chrome.devtools.tabId
//}, updateJSON);
}
// Parsing master data
function parseMasterData(json)
{
window.mst = json;
}
// load all data master & user
function kcLoadMasterData()
{
$.getJSON("api_start2.json",function (json)
{
parseMasterData(json);
contextFormInit();
kcDataReload();
});
//Used for extension
// chrome.runtime.sendMessage({
// command: "loadKCAPIData",
// tabId: chrome.devtools.tabId
//}, updateJSON);
}
// User data relevant UI update
// Anything coming form "loadKCData"
function updateUI()
{
//document.getElementById('content').textContent = JSON.stringify(window.rawsvd);
document.getElementById('name').textContent = window.rawsvd.port.api_basic.api_nickname;
document.getElementById('lv').textContent = window.rawsvd.port.api_basic.api_level;
Ship.update();
Resource.update();
Deck.update();
Dock.update();
Item.update();
}
function updateJSON(json)
{
window.rawsvd = json;
// Update the whole UI when new user data arrives
updateUI();
}
// start listen when load
window.addEventListener('load', listen);
// Used for extension
// chrome extension trigger when data available
//var port= chrome.runtime.connect({name:"KCView"});
//port.onMessage.addListener(function(request, sender, callback) {
// if (request.command == 'notifyNewKCData')
// {
// Console.warn("Data available reloading");
// kcDataReload();
// }
//});
})();