-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwidgets.html
More file actions
255 lines (239 loc) · 11.1 KB
/
widgets.html
File metadata and controls
255 lines (239 loc) · 11.1 KB
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>LunarCRUSH Embedded iFrame Widget Example</title>
<style>
body,
html {
margin: 0;
padding: 30;
width: 100%;
color: #fff;
background-color: #0f1722;
}
</style>
</head>
<body>
<!-- <h1>Parent Window</h1>
<p>Send Message: <button id="message_button">Hi there iframe</button></p>
<p>Got Message:</p>
<div id="results"></div>
<br /> -->
<script>
// addEventListener support for IE8
function bindEvent(element, eventName, eventHandler) {
if (element.addEventListener) {
element.addEventListener(eventName, eventHandler, false);
} else if (element.attachEvent) {
element.attachEvent('on' + eventName, eventHandler);
}
}
// helper function to create iframes
function createIframe(id, src, width, height) {
var iframeSource = src;
// Create the iframe
var iframe = document.createElement('iframe');
iframe.setAttribute('src', iframeSource);
iframe.setAttribute('id', id);
iframe.setAttribute('frameborder', 0);
iframe.setAttribute('border', 0);
iframe.setAttribute('cellspacing', 0);
iframe.setAttribute('scrolling', 'yes');
iframe.style.width = width || '100%';
iframe.style.height = height || '300px';
document.body.appendChild(iframe);
var iframeEl = document.getElementById(id);
return iframeEl;
}
// helper function to parse querystring params
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
console.log('Query variable %s not found', variable);
};
// Serialize theme object to pass in query string
function getTheme(widget) {
const theme = {
global: {
type: 'dark',
common: { black: 'rgba(0, 0, 0, 1)', white: 'rgba(255, 255, 255, 1)' },
background: { paper: '#202327', default: '#0e1722' },
primary: {
light: 'rgba(126,211,32, 1)',
main: 'rgba(126,211,32, 1)',
dark: 'rgba(126,211,32, 1)'
},
secondary: {
light: 'rgba(255,39,0, 1)',
main: 'rgba(255,39,0, 1)',
dark: 'rgba(255,39,0, 1)'
},
error: {
light: 'rgba(229, 115, 115, 1)',
main: 'rgba(244, 67, 54, 1)',
dark: 'rgba(211, 47, 47, 1)'
},
text: {
primary: 'rgba(255, 255, 255, 0.87)',
secondary: 'rgba(209, 209, 209, 0.54)',
disabled: 'rgba(134, 134, 134, 0.38)',
hint: 'rgba(0, 0, 0, 0.38)'
},
typography: {
fontFamily: "'Uniform', sans-serif",
fontWeight: 300
},
poweredByTextColor: '#69d8ee',
loadingIndicatorColor: 'rgba(133, 139, 146, 1)',
tooltipBackgroundColor: '#000',
tooltipTextColor: 'rgba(255,255,255,0.8)',
infoIconColor: 'rgba(133, 139, 146, 1)',
},
metricsWidget: {
yAxisTitleColor: '#fff',
yAxisLabelColor: 'rgba(255,255,255,0.5)',
xAxisLineColor: '#3c3f42',
xAxisTickColor: '#3c3f42',
xAxisLabelColor: 'rgba(255,255,255,0.5)',
pointLabelColor: '#fff',
gridLineColor: '#3c3f42',
tooltipBackgroundColor: '#000',
tooltipTextColor: 'rgba(255,255,255,0.8)',
priceCorrelationLineColor: '#69d8ee',
positiveAreaChartColor: 'rgba(126,211,32, 0.2)',
positiveLineColor: 'rgba(126,211,32, 1)',
negativeAreaChartColor: 'rgba(255,39,0, 0.2)',
negativeLineColor: 'rgba(255,39,0, 1)',
},
galaxyScoreWidget: {
titleColor: '#fff',
trackBackgroundColor: 'rgba(255,255,255,0.1)',
bullishBarColor: '#7ed31f',
neutralBarColor: 'rgba(133, 139, 146, 0.5)',
bearishBarColor: 'rgba(244, 67, 54, 1)',
bullishTextColor: '#7ed31f',
neutralTextColor: 'rgba(133, 139, 146, 1)',
bearishTextColor: 'rgba(244, 67, 54, 1)',
separatorColor: '#fff',
scoreTextColor: '#fff',
infoIconColor: 'rgba(133, 139, 146, 1)',
tooltipBackgroundColor: '#000',
tooltipTextColor: '#fff'
},
newsWidget: {
titleColor: '#fff',
articleTitleColor: '#69d8ee',
articleDescriptionColor: '#fff',
bullishTextColor: '#7ed31f',
neutralTextColor: 'rgba(133, 139, 146, 1)',
bearishTextColor: 'rgba(244, 67, 54, 1)',
dateTextColor: '#ccc',
thumbnailBackgroundColor: '#69d8ee',
thumbnailIconColor: '#000'
},
socialWidget: {
titleColor: '#fff',
postDateColor: '#6f7e82',
postTitleColor: '#ccc',
bullishTextColor: '#7ed31f',
neutralTextColor: 'rgba(133, 139, 146, 1)',
bearishTextColor: 'rgba(244, 67, 54, 1)',
},
wordCloudWidget: {
titleColor: '#fff',
width: '100%',
height: 400,
color1: '#fafafa',
color2: 'rgba(244, 67, 54, 1)',
color3: '#7ed31f',
color4: '#69d8ee',
},
candlestickWidget: {
yAxisTitleColor: '#fff',
yAxisLabelColor: 'rgba(255,255,255,0.5)',
xAxisLineColor: '#3c3f42',
xAxisTickColor: '#3c3f42',
xAxisLabelColor: 'rgba(255,255,255,0.5)',
pointLabelColor: '#fff',
gridLineColor: '#3c3f42',
metricLineColor: '#69d8ee',
highPriceBarColor: 'rgba(104,212, 131,0.8)',
highPriceLineColor: 'rgba(104,212, 131,0.8)',
lowPriceBarColor: 'rgba(243,69,80, 0.8)',
lowPriceLineColor: 'rgba(243,69,80, 0.8)',
volumeBarColor: 'rgba(133, 139, 146, 1)',
legendTextColor: 'rgba(255,255,255,0.5)',
legendTextHoverColor: '#fff',
legendTextHiddenColor: 'rgba(255,255,255,0.5)',
metricDropdownBackgroundColor: '#000'
}
}
let combined = theme.global;
combined[widget] = theme[widget];
return window.btoa(JSON.stringify(combined));
}
// Send a message to the child iframe
function sendMessage(msg) {
// Make sure you are sending a string, and to stringify JSON
// iframe.contentWindow.postMessage(msg, '*');
window.frames.forEach(function(frame) {
frame.contentWindow.postMessage(msg, '*');
})
};
function getWidgetUrl() {
if (local === true) {
return 'http://localhost:3000'
} else {
return 'https://lunarcrush-widgets.firebaseapp.com'
}
}
function getTestPageUrl() {
if (local === true) {
return 'http://localhost:5000'
} else {
return 'https://lunar-widget-test.firebaseapp.com'
}
}
var local = false;
window.onload = function () {
var symbol = getQueryVariable('symbol') || 'BTC';
var interval = getQueryVariable('interval') || '1 Week';
var priceCorrelation = getQueryVariable('price_correlation') || false;
var key = getQueryVariable('key');
var widgetUrl = getWidgetUrl();
var testPageUrl = getTestPageUrl();
// Create iFrames
var galaxyScoreWidget = createIframe('galaxy-score', widgetUrl + '/galaxy?key=' + key + '&stylesheet=' + testPageUrl + '/theme-dark.css&theme=' + getTheme('galaxyScoreWidget') + '&symbol=' + symbol + '&interval=' + interval + '&animation=false');
var newsWidget = createIframe('news', widgetUrl + '/news?key=' + key + '&stylesheet=' + testPageUrl + '/theme-dark.css&theme=' + getTheme('newsWidget') + '&symbol=' + symbol + '&interval=' + interval + '&animation=false&scrolling=false', '100%', '500px');
var socialWidget = createIframe('social', widgetUrl + '/social?key=' + key + '&stylesheet=' + testPageUrl + '/theme-dark.css&theme=' + getTheme('socialWidget') + '&symbol=' + symbol + '&interval=' + interval + '&animation=false&scrolling=false', '100%', '500px');
var wordCloudWidget = createIframe('wordCloud', widgetUrl + '/wordcloud?key=' + key + '&stylesheet=' + testPageUrl + '/theme-dark.css&theme=' + getTheme('wordCloudWidget') + '&symbol=' + symbol + '&interval=' + interval + '&animation=false', '100%', '500px');
var candleStickWidget = createIframe('candlestick', widgetUrl + '/candlestick?key=' + key + '&stylesheet=' + testPageUrl + '/theme-dark.css&theme=' + getTheme('candlestickWidget') + '&symbol=' + symbol + '&interval=' + interval + '&metric=galaxy_score&animation=false', '100%', '500px');
var metricsWidgetGalaxyScore = createIframe('metrics1', widgetUrl + '/metrics?key=' + key + '&stylesheet=' + testPageUrl + '/theme-dark.css&theme=' + getTheme('metricsWidget') + '&symbol=' + symbol + '&interval=' + interval + '&metric=galaxy_score&price_correlation=' + priceCorrelation + '&animation=false');
var metricsWidgetGalaxyScore2 = createIframe('metrics2', widgetUrl + '/metrics?key=' + key + '&stylesheet=' + testPageUrl + '/theme-dark.css&theme=' + getTheme('metricsWidget') + '&symbol=' + symbol + '&interval=' + interval + '&metric=galaxy_score&price_correlation=true&animation=false');
var metricsWidgetAverageSentiment = createIframe('metrics3', widgetUrl + '/metrics?key=' + key + '&stylesheet=' + testPageUrl + '/theme-dark.css&theme=' + getTheme('metricsWidget') + '&symbol=' + symbol + '&interval=' + interval + '&metric=average_sentiment&price_correlation=' + priceCorrelation + '&animation=false');
var metricsWidgetPriceScore = createIframe('metrics4', widgetUrl + '/metrics?key=' + key + '&stylesheet=' + testPageUrl + '/theme-dark.css&theme=' + getTheme('metricsWidget') + '&symbol=' + symbol + '&interval=' + interval + '&metric=price_score&price_correlation=' + priceCorrelation + '&animation=false');
var metricsWidgetSocialImpactScore = createIframe('metrics5', widgetUrl + '/metrics?key=' + key + '&stylesheet=' + testPageUrl + '/theme-dark.css&theme=' + getTheme('metricsWidget') + '&symbol=' + symbol + '&interval=' + interval + '&metric=social_impact_score&price_correlation=' + priceCorrelation + '&animation=false');
var metricsWidgetCorrelationRank = createIframe('metrics6', widgetUrl + '/metrics?key=' + key + '&stylesheet=' + testPageUrl + '/theme-dark.css&theme=' + getTheme('metricsWidget') + '&symbol=' + symbol + '&interval=' + interval + '&metric=correlation_rank&price_correlation=' + priceCorrelation + '&animation=false');
// var messageButton = document.getElementById('message_button');
// var results = document.getElementById('results');
// // Send random messge data on every button click
// bindEvent(messageButton, 'click', function (e) {
// var random = Math.random();
// sendMessage('' + random);
// });
// // Listen to message from child window
// bindEvent(window, 'message', function (e) {
// sendMessage('' + e.data);
// results.innerHTML = e.data;
// });
}
</script>
</body>
</html>