-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
294 lines (285 loc) · 10 KB
/
functions.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* functions.js - Javascript for Function data
*
* This file is part of the BlackOps3 Scripting API distribution (https://github.com/EHDSeven/BlackOps3-Scripting-API).
* Copyright (c) 2016 Michael "Seven" Larkin.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var functionListRaw = {};
var returnList = [];
var entityList = [];
var categoryList = [];
var clientserverList = [];
//Draw Function Data on Main
function showFunction(functionName) {
var functionData = {};
//Get Function data from SQL
$.getJSON( "api.php/get/function/"+functionName, function( data ) {
$.each(data[0], function (key, val) {
//Handle Vars to output as JSON - Offload to API?
functionData[key] = {};
if(key == "vars") {
functionData[key] = jQuery.parseJSON(val);
} else {
functionData[key] = val;
}
});
//Clear Main
$("#main").text("");
//Blank Funcion names array
var functionNames = [];
var title = "";
//Print void + Function name
if(functionData.entity === "") {
title = "void " + functionData.functionName+"(";
} else {
title = "void <" + functionData.entity + "> " + functionData.functionName+"(";
}
//Loop through each function and add to array
$.each(functionData.vars, function(index, val) {
if(val.mandatory) {
functionNames.push("<"+index+">");
} else {
functionNames.push("["+index+"]");
}
});
//Print funcitons with comma separation
title += functionNames.join(", ");
//Close Function
title +=")";
//Print Function Name
$("<h2 />").text(title).appendTo($("#main"));
//Create Function List
var li = $("<ul />").appendTo("#main");
//Loop and add variables
$(functionData.vars).each(function ()
{
$.each($(this)[0], function(index, val) {
var sub_li = $("<li/>")
.appendTo(li);
$("<span />").appendTo(sub_li);
if(val.mandatory)
{
$("<strong />")
.text("[MANDATORY]")
.appendTo(sub_li);
sub_li.append(" <" + index + "> " + val.description);
} else {
$("<strong />")
.text("[OPTIONAL]")
.appendTo(sub_li);
sub_li.append(" [" +index + "] " + val.description);
}
});
});
//Category
var div = $("<div />").appendTo(li);
$("<br />").appendTo(div);
$("<strong />")
.text("CATEGORY: ")
.appendTo(div);
div.append(functionData.category);
//ServerClient
div = $("<div />").appendTo(li);
$("<strong />")
.text("SERVER/CLIENT: ")
.appendTo(div);
div.append(functionData.clientserver);
//Summary
div = $("<div />").appendTo(li);
$("<strong />")
.text("SUMMARY: ")
.appendTo(div);
div.append(functionData.summary);
//ServerClient
div = $("<div />").appendTo(li);
$("<strong />")
.text("EXAMPLE: ")
.appendTo(div);
div.append(functionData.example);
});
}
//Update the list with our Filter Requirements
function filterList(navlist) {
var tmplist = {};
//Store our Filters in a variable for speed
var returnval = $('#return').val();
var entityval = $('#entity').val();
var categoryval = $('#category').val();
var clientserverval = $('#clientserver').val();
$(navlist).each(function () {
$.each(this, function(index, value) {
//Loop through each filter and skip if it does not meet the filter requirements
if(returnval != "none" && returnval != value.return) {
return true;
}
if(entityval != "none" && value.entity != entityval) {
return true;
}
if(categoryval != "none" && value.category != categoryval) {
return true;
}
if(clientserverval != "none" && value.clientserver != clientserverval) {
return true;
}
//If we get this car add the Function to the list
tmplist[value.functionName] = {};
tmplist[value.functionName].functionName = value.functionName;
});
});
return tmplist;
}
//Function for drawing from list
function loadNavigation(navlist) {
//Check List against filter
navlist = filterList(navlist);
//Clear any existing Functions
$("#navlist").empty();
//Create Functions header
var li = $("<li/>")
.appendTo("#navlist");
li.append("Functions");
var sub_ul = $("<ul/>")
.appendTo(li);
//List each Function
$(navlist).each(function () {
$.each(this, function(index, val) {
var sub_li = $("<li/>").appendTo(sub_ul);
$("<a />")
.text(val.functionName)
.attr("href", "#" + val.functionName)
.appendTo(sub_li)
.on("click", function () {
showFunction($( this ).text());
});
});
});
}
//Repeatitve addOption function
function addOption(list, text, val=text) {
$(list).append($('<option>', {
value: val,
text : text
}));
}
//Function for Populating filter options
function loadFilter() {
//Clear existing filter
$('#return').empty();
$('#entity').empty();
$('#category').empty();
$('#clientserver').empty();
//Add "No Filter" Type to Each box
addOption("#return", "No Filter", "none");
addOption("#entity", "No Filter", "none");
addOption("#category", "No Filter", "none");
addOption("#clientserver", "No Filter", "none");
//Get Return types
$.getJSON( "api.php/get/return", function( data ) {
$.each(data, function (key, val) {
returnList.push(val.return);
addOption("#return", val.return);
});
});
//Get Entity Types
$.getJSON( "api.php/get/entities", function( data ) {
$.each(data, function (key, val) {
entityList.push(val.entity);
addOption("#entity", val.entity);
});
});
//Get category Types
$.getJSON( "api.php/get/categories", function( data ) {
$.each(data, function (key, val) {
categoryList.push(val.category);
addOption("#category", val.category);
});
});
//Get Client / Server Types
$.getJSON( "api.php/get/clientserver", function( data ) {
$.each(data, function (key, val) {
clientserverList.push(val.clientserver);
addOption("#clientserver", val.clientserver);
});
});
}
//Wildcard search for Function list
function searchFunctions() {
var functionListSearch = {};
//Trim spaces
var search = $.trim($("#searchbox").val());
//Check if
if(search != ""){
//Use the list we already have to reduce SQL calls
$(functionListRaw).each(function () {
$.each(this, function(index, value) {
if(value.functionName.toLowerCase().search(search.toLowerCase()) >= 0) {
functionListSearch[value.functionName] = {};
functionListSearch[value.functionName].functionName = value.functionName;
}
});
});
//Draw results in navigation
loadNavigation(functionListSearch);
//Clear Search Object
functionListSearch = {};
} else {
//Draw full list
loadNavigation(functionListRaw);
}
}
//Get array from SQL Database
$(document).ready(function () {
loadFilter();
$.getJSON( "api.php/get/functionlist", function( data ) {
$.each(data, function (key, val) {
functionListRaw[val.functionName] = {};
functionListRaw[val.functionName].functionName = val.functionName;
functionListRaw[val.functionName].return = val.return;
functionListRaw[val.functionName].entity = val.entity;
functionListRaw[val.functionName].category = val.category;
functionListRaw[val.functionName].clientserver = val.clientserver;
});
//Draw results in navigation
loadNavigation(functionListRaw);
});
//Check if this was a direct link and load function
var hash = window.location.hash.substring(1);
if(hash != "") {
showFunction(hash);
}
});
//Monitor Keyup for Search
$("#searchbox").on("keyup", function() {
searchFunctions();
});
//Hook Filter button
$('#filter').on("click", function() {
if ( $("#filterlist").is( ":hidden" ) ) {
$("#filterlist").slideDown();
} else {
$("#filterlist").slideUp();
}
});
$('#return').change(function() {
searchFunctions();
});
$('#entity').change(function() {
searchFunctions();
});
$('#category').change(function() {
searchFunctions();
});
$('#clientserver').change(function() {
searchFunctions();
});