-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfund.js
165 lines (131 loc) · 3.68 KB
/
fund.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
var ejs = require('ejs');
var modal = require('modal');
var utils = require('./utils');
var createElement = utils.createElement;
var createElementNS = utils.createElementNS;
var attrs = utils.attrs;
var tmpl = {
fund: require('./fund.html')
};
var fund = module.exports = {};
// fund.campaigns = require('./campaigns');
fund.show = show;
fund.active = null;
function show(name){
if (name == fund.active) return;
if (fund.active) {
fund.modal.once('hide', fund.show.bind(fund, name));
fund.modal.hide();
return;
}
var about = require('./about');
if (about.active) {
about.modal.once('hide', fund.show.bind(fund, name));
about.modal.hide();
return;
}
fund.active = name;
var el = createElement('fund', 'modal');
var campaign;
fund.campaigns.forEach(function(c){
if (name === c.name) {
campaign = c;
}
});
el.innerHTML = ejs.render(tmpl.fund, { c: campaign });
// var progress = el.querySelector('.pledge-progress');
// var svg = createWave(campaign.percentage);
// progress.appendChild(svg);
/*var buttons = el.querySelector('.pledge-buttons');
buttons.querySelector('.pledge-bitcoin').onclick = onpledge;
buttons.querySelector('.pledge-dogecoin').onclick = onpledge;*/
function each(nodes, fn){
[].slice.call(nodes).forEach(fn);
}
// each(queryAll('.pledge-alter-bitcoin'), function(node){
// node.onclick = alter('bitcoin');
// });
// each(queryAll('.pledge-alter-dogecoin'), function(node){
// node.onclick = alter('dogecoin');
// });
// each(queryAll('.pledge-alter-paypal'), function(node){
// node.onclick = alter('paypal');
// });
// var details = query('.pledge-details');
// query('.pledge-show-info').onclick = function(){
// query('.fund-info').classList.remove('hide');
// query('.fund-campaign').classList.add('hide');
// return false;
// };
// query('.pledge-hide-info').onclick = function(){
// query('.fund-info').classList.add('hide');
// query('.fund-campaign').classList.remove('hide');
// return false;
// };
fund.modal = modal(el)
.overlay()
.closeable()
.effect('fade-and-scale')
.show()
.on('hide', function(){
fund.active = null;
});
// function alter(target){
// var targets = ['bitcoin', 'dogecoin', 'paypal'];
// return function onclick(){
// targets.forEach(function(t){
// if (target === t) query('.pledge-details-' + t).classList.remove('hide');
// else query('.pledge-details-' + t).classList.add('hide');
// })
// return false;
// };
// }
function query(sel){
return el.querySelector(sel);
}
function queryAll(sel){
return el.querySelectorAll(sel);
}
}
function createWave(percentage){
var svg = createElementNS('svg');
var bar = createElementNS('polyline');
var wave = createElementNS('polyline');
attrs(svg, {
width: '550px',
height: '50px'
});
attrs(bar, {
fill: 'none',
stroke: '#444',
'stroke-width': 6,
//'stroke-linecap': 'round'
});
attrs(wave, {
fill: 'none',
stroke: '#A0D92E',
'stroke-width': 6,
//'stroke-linecap': 'round'
});
svg.appendChild(bar);
svg.appendChild(wave);
var scaleY = 5;
var scaleX = 11;
var points = [];
var x, y;
var offset = 15;
for (var t = -5; t < 50; t += 0.1) {
y = offset + (scaleY * Math.sin(t));
points.push((t * scaleX) + ',' + y);
}
bar.setAttribute('points', points.join(' '));
var points = [];
var x, y;
var offset = 15;
for (var t = -5; t < 48 * (percentage / 100); t += 0.1) {
y = offset + (scaleY * Math.sin(t));
points.push((t * scaleX) + ',' + y);
}
wave.setAttribute('points', points.join(' '));
return svg;
}