forked from miohtama/bitcoin-prices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
230 lines (180 loc) · 8.13 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>bitcoin-prices.js - show bitcoin prices on web and mobile HTML pages</title>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.no-icons.min.css" rel="stylesheet" />
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script src="bitcoinprices.js"></script>
<script>
$(document).ready(function() {
bitcoinprices.init({
// Where we get bitcoinaverage data
// or null if we run headless (not in browser)
url: "https://apiv2.bitcoinaverage.com/indices/global/ticker/all",
// Which of bitcoinaverages value we use to present prices
marketRateVariable: "24h_avg",
// Which currencies are in shown to the user
currencies: ["BTC", "USD", "EUR", "CNY"],
// Special currency symbol artwork
symbols: {
"BTC": "<i class='fa fa-btc'></i>"
},
// Which currency we show user by the default if
// no currency is selected
defaultCurrency: "BTC",
// How the user is able to interact with the prices
ux : {
// Make everything with data-btc-price HTML attribute clickable
clickPrices : true,
// Build Bootstrap dropdown menu for currency switching
menu : true
},
// Allows passing the explicit jQuery version to bitcoinprices.
// This is useful if you are using modular javascript (AMD/UMD/require()),
// but for most normal usage you don't need this
jQuery: jQuery
});
});
</script>
<script>
// Manual conversion example
$(document).on("marketdataavailable", function() {
var inputAmount = $("#input-amount");
var outputAmount = $("#output-amount");
var inputCurrency = $("#input-currency");
var outputCurrency = $("#output-currency");
function updateConversion() {
// Reset output in the case we run into exception
outputAmount.val("");
var input = inputCurrency.val();
var output = outputCurrency.val();
var amount = parseFloat(inputAmount.val(), 10);
try {
var val = bitcoinprices.convert(amount, input, output);
val = bitcoinprices.formatPrice(val, output, false);
outputAmount.val(val);
} catch(e) {
throw e;
}
}
inputAmount.change(updateConversion);
inputAmount.on("keyup", updateConversion);
inputCurrency.change(updateConversion);
outputCurrency.change(updateConversion);
// Initial take off
updateConversion();
});
</script>
<style type="text/css">
body {
padding-top: 60px;
}
.clickable-price {
cursor: pointer;
border-bottom: 1px #888 dashed;
}
.label[data-btc-price] {
border-bottom: none;
}
</style>
</head>
<body>
<div class="navbar navbar-fixed-top navbar-default" id="navbar-site">
<div class="navbar-inner">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">bitcoinprices.js</a>
</div>
<ul class="nav navbar-nav">
<li class="dropdown currency-dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-money"></i> <span class="currency-symbol">BTC</span><b class="caret"></b></a>
<ul class="dropdown-menu">
</ul>
</li>
</ul>
<div class="nav navbar-nav navbar-right">
<a class="navbar-brand" href="http://opensourcehacker.com"><i class="fa fa-star"></i> Fork By João Gabriel Junqueira</a>
<a class="navbar-brand" href="http://opensourcehacker.com"><i class="fa fa-rss"></i></a>
<a class="navbar-brand" href="http://twitter.com/moo9000"><i class="fa fa-twitter"></i></a>
<a class="navbar-brand" href="https://www.facebook.com/pages/Open-Source-Hacker/181710458567630"><i class="fa fa-facebook"></i></a>
</div>
</div>
</div>
</div>
<div class="container" style="min-height:480px;">
<div class="jumbotron">
<h1>bitcoinprices.js</h1>
<p>JavaScript library for human-friendly Bitcoin price presentation and conversion</p>
<p><a class="btn btn-primary btn-lg" role="button" href="https://github.com/miohtama/bitcoin-prices"><i class="fa fa-github"></i> View on Github</a></p>
</div>
<p>
<code>bitcoinprices.js</code> is a JavaScript library which you can drop on your web page.
It presents the Bitcoin prices in the fiat currency chosen by the user, making prices
friendly to read.
<code>bitcoinprices.js</code> works on any HTML page.
</p>
<h2>Price example</h2>
<p class="text text-muted">
Click the price to convert between BTC and fiat currency or choose from the menu above.
</p>
<p>
Selected currency: <strong class="current-currency-symbol text-primary"><i class="fa fa-btc"></i></strong>
</p>
<p>
<div>Example price: <span data-btc-price="1.0">1.0 BTC</span></div>
</p>
<p>
<span class="label label-danger">Example special price: <span data-btc-price="0.1">1.0 BTC</span></span>
</p>
<p>
Another Example special price: <span class="label label-warning" data-btc-price="0.1">1.0 BTC</span>
</p>
<p>
Price without currency symbols: <span class="label label-info" data-btc-price="0.1" data-price-symbol="off">1.0</span>
</p>
<h2>Manual currency conversion</h2>
<p class="text text-muted">
Demostrate <code>bitcoinprices.convert()</code> to convert between currencies.
</p>
<div class="row">
<div class="col-md-4">
<h2>Input</h2>
<h4>Amount</h4>
<p>
<input id="input-amount" value="1.0">
</p>
<h4>Currency</h4>
<select id="input-currency">
<option selected value="BTC">BTC</option>
<option value="USD">USD</option>
<option value="EUR">EUR</option>
</select>
</div>
<div class="col-md-4">
<h2>Output</h2>
<h4>Amount</h4>
<p>
<input id="output-amount" readonly>
</p>
<h4>Currency</h4>
<select id="output-currency">
<option value="BTC">BTC</option>
<option selected value="USD">USD</option>
<option value="EUR">EUR</option>
</select>
</div>
</div>
<div class="row">
<p class="text text-success lead text-center" style="margin-top: 3em">
<a href="https://github.com/miohtama/bitcoin-prices"><i class="fa fa-github"></i> Visit Github repository for more information</a>
</p>
</div>
</div>
</body>