-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
155 lines (138 loc) · 4.27 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
<!DOCTYPE html>
<!--
Created using JS Bin
http://jsbin.com
-->
<meta name="robots" content="noindex">
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" type="text/css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.16/vue.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Top Crypto Coins In CAD</title>
<style id="jsbin-css">
body{
padding: 1em;
}
</style>
</head>
<body class="container">
<h3 align="center">Top Crypto Coins in Canadian Dollars</h3>
<div class="row">
<div class=" col-xs-offset-2 col-xs-8">
<p align="center">
<a href="https://github.com/YesbitCanada/top-coins-cad">Yesbit Open Source</a>
Refesh every 5 min
</p>
</div>
</div>
<div id="app">
<div>Name Search: <input type="text" v-model="filter_name"></div>
<table class="table table-condensed">
<tr>
<th>#</th>
<th>Name</th>
<th>Price</th>
<th>1Hour </th>
<th>24Hour </th>
<th>7Day </th>
<th>Turnover </th>
</tr>
<tr v-for="r in rows
| filterBy filter_name in 'name'
| recordLength 'filteredRowCount'
| limitBy countOfPage pageStart ">
<td>{{ r.rank }}</td>
<td>{{ r.name }}</td>
<td>{{ r.price_cad | currency}}</td>
<td v-bind:style="getColor(r.percent_change_1h)">
<span v-if="r.percent_change_1h > 0">+</span>{{ r.percent_change_1h }}%
</td>
<td v-bind:style="getColor(r.percent_change_24h)">
<span v-if="r.percent_change_24h > 0">+</span>{{ r.percent_change_24h }}%
</td>
<td v-bind:style="getColor(r.percent_change_7d)">
<span v-if="r.percent_change_7d > 0">+</span>{{ r.percent_change_7d }}%
</td>
<td>{{100*r['24h_volume_cad']/r.market_cap_cad | percent }}%</td>
</tr>
</table>
<div class="pagination">
<ul>
<li v-bind:class="{'disabled': (currPage === 1)}"
@click.prevent="setPage(currPage-1)"><a href="#">Prev</a></li>
<li v-for="n in totalPage"
v-bind:class="{'active': (currPage === (n+1))}"
@click.prevent="setPage(n+1)"><a href="#">{{n+1}}</a></li>
<li v-bind:class="{'disabled': (currPage === totalPage)}"
@click.prevent="setPage(currPage+1)"><a href="#">Next</a></li>
</ul>
</div>
</div>
<script id="jsbin-javascript">
Vue.filter('recordLength', function (result, key) {
this.$set(key, result.length);
return result;
});
Vue.filter('currency', function (data) {
return '$'+parseFloat(data.toString().substring(0,5));
});
Vue.filter('percent', function (data) {
return parseFloat(data.toString().substring(0,4));
});
var app = new Vue({
el: '#app',
data: {
rows: [],
countOfPage: 50,
currPage: 1,
filter_name: '',
filteredRowCount: null
},
computed: {
pageStart: function(){
return (this.currPage - 1) * this.countOfPage;
},
totalPage: function(){
if( this.filter_name.trim() === '' ) {
return Math.il(this.rows.length / this.countOfPage);
}
else{
return Math.il(this.filteredRowCount / this.countOfPage);
}
}
},
methods: {
setPage: function(idx){
if( idx <= 0 || idx > this.totalPage ){
return;
}
this.currPage = idx;
},
getCoins: function(){
var self = this;
$.get('https://api.coinmarketcap.com/v1/ticker/?convert=CAD&limit=450', function(data){
self.rows = data;
});
},
/**
* Return a CSS color (either red or green) depending on whether or
* not the value passed in is negative or positive.
*/
getColor: function (num) {
return num > 0 ? "color:green;" : "color:red;";
}
},
created: function(){
this.getCoins();
}
});
setInterval(() => {
app.getCoins();
}, 100*1000);
//table from http://jsbin.com/bimawidora/1/edit?html,js,output
</script>
</body>
</html>