-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
54 lines (46 loc) · 1.61 KB
/
helpers.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
/**
* Exports the given object into the global context.
*/
var exportGlobal = function(name, object) {
if (typeof(GLOBAL) !== "undefined") {
// Node.js
GLOBAL[name] = object;
}
else if (typeof(window) !== "undefined") {
// JS with GUI (usually browser)
window[name] = object;
}
else {
throw new Error("Unkown run-time environment. Currently only browsers and Node.js are supported.");
}
};
/**
* Exports the Export function and a set of GLOBAL variables for the server address.
*/
exportGlobal("exportGlobal",exportGlobal);
// exportGlobal("SERVER_URL","http://127.0.0.1:8000/");
exportGlobal("SERVER_URL","http://crowdcur.com/");
exportGlobal("PLUGIN_URL","crowdcur/plugin_api/");
exportGlobal("DASHBOARD_URL","crowdcur/dashboard");
exportGlobal("STAT_URL","crowdcur/stats");
exportGlobal("clicks",5);
var getCookie = function (name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
};
var csrfSafeMethod = function (method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
};
var csrf = getCookie("csrftoken");