forked from dsias/blockchain.info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firefox.js
101 lines (74 loc) · 3 KB
/
firefox.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
min = false;
isExtension = true;
APP_NAME = 'javascript_firefox';
var superSetLanguage = MyWallet.setLanguage;
MyWallet.setLanguage = function(language) {
if (MyWallet.getLanguage()) {
superSetLanguage(language);
MyWallet.makeNotice('success', 'misc-success', 'Changing Language ' + language + '. Please Wait...');
setTimeout(function() {
window.location.href = '/blockchain/data/index.html';
}, 1000);
} else {
superSetLanguage(language);
}
}
$(document).ready(function() {
$.ajax = function(obj) {
var requests = {};
var initd = false;
function sendRequest(obj) {
var customEvent = document.createEvent('Event');
customEvent.initEvent('ajax_request', true, true);
if (Object.keys(requests).length == 0) {
$(document).trigger("ajaxStart");
}
var request_id = ''+Math.floor((Math.random()*10000)+1);
requests[request_id] = obj;
obj.request_id = request_id;
document.body.setAttribute('data-ajax-request', JSON.stringify(obj));
document.body.dispatchEvent(customEvent);
}
if (!initd) {
document.body.addEventListener('ajax_response', function() {
console.log(document.body.getAttribute('data-ajax-response'));
var obj = JSON.parse(document.body.getAttribute('data-ajax-response'));
var request = requests[obj.request_id];
if (!request) {
throw 'Unknown Request ID ' + obj.request_id;
}
if (obj.status == 200) {
if (obj.dataType == 'json') {
try {
request.success(JSON.parse(obj.response));
} catch (e) {
request.error({responseText : e.toString(), status : obj.status});
}
} else {
request.success(obj.response);
}
} else {
request.error({responseText : obj.response, status : obj.status});
}
delete requests[obj.request_id];
if (Object.keys(requests).length == 0) {
$(document).trigger("ajaxStop");
}
});
initd = true;
}
sendRequest(obj);
};
var body = $(document.body);
var data_root = body.data('root');
if (data_root)
root = data_root;
var data_resource = body.data('resource');
if (data_resource) {
var path = document.location.pathname;
var index = path.lastIndexOf("/") + 1;
var filename = path.substr(0, index);
resource = filename + data_resource;
}
$('head').append('<style type="text/css">.external { background: url('+resource+'external.png); }\n span.qrcodeicon span { background: url("'+resource+'qrcode.png"); };</style>');
});