-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
233 lines (217 loc) · 8.95 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
231
232
233
<!DOCTYPE html>
<html>
<head>
<title>Happy or Grouchy?</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="stylesheets/jquery.mobile-1.3.2.min.css" />
<link href="jqplot/jquery.jqplot.min.css" rel="stylesheet">
<link href="stylesheets/application.css" rel="stylesheet">
<script src="javascript/jquery-2.0.3.min.js"></script>
<script src="javascript/jquery.mobile-1.3.2.min.js"></script>
<script src="jqplot/jquery.jqplot.min.js"></script>
<script class="include" type="text/javascript" src="jqplot/plugins/jqplot.dateAxisRenderer.min.js"></script>
<script class="include" type="text/javascript" src="jqplot/plugins/jqplot.logAxisRenderer.min.js"></script>
<script class="include" type="text/javascript" src="jqplot/plugins/jqplot.canvasTextRenderer.min.js"></script>
<script class="include" type="text/javascript" src="jqplot/plugins/jqplot.canvasAxisTickRenderer.min.js"></script>
<script class="include" type="text/javascript" src="jqplot/plugins/jqplot.highlighter.min.js"></script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '612174972140800', // App ID
channelUrl : '//happy-or-grumpy.herokuapp.com/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.authResponseChange', function(response) {
if (response.status === 'connected') {
testAPI();
} else if (response.status === 'not_authorized') {
// In this case, the person is logged into Facebook, but not into the app, so we call
// FB.login() to prompt them to do so.
// In real-life usage, you wouldn't want to immediately prompt someone to login
// like this, for two reasons:
// (1) JavaScript created popup windows are blocked by most browsers unless they
// result from direct interaction from people using the app (such as a mouse click)
// (2) it is a bad experience to be continually prompted to login upon page load.
FB.login();
} else {
FB.login();
}
});
};
// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) { return; }
js = d.createElement('script');
js.id = id;
js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
FB.login();
}(document));
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
}
</script>
<div data-role="page" id="page1">
<div data-role="header" data-theme="b">
<h1>Happy Mates</h1>
</div>
<br/> <br/>
<div data-role="content">
<select data-role="slider" id="source1" data-theme="b">
<option value="Facebook">Facebook</option>
<option value="Twitter">Twitter</option>
</select>
<br/> <br/> <br/> <br/> <br/>
<form action="http://" method="POST">
<a href="#page2" id="login" data-role="button">Login</a>
</form>
</div>
</div>
<div data-role="page" id="page2">
<div data-role="header" data-theme="b">
<h1>Happy Mates</h1>
</div>
<br/> <br/>
<div data-role="content">
<div class="chart-title">
Friend's mood in the past 30 days
</div>
<br/> <br/>
<div class="ui-widget ui-corner-all">
<div class="ui-widget-header ui-corner-top"></div>
<div class="ui-widget-content ui-corner-bottom" >
<div id="chart1"></div>
</div>
</div>
<br/> <br/> <br/> <br/> <br/>
<ul id="friend-list" data-role="listview" data-filter="true" data-filter-reveal="true"
data-filter-placeholder="Enter a friend's name" data-inset="true">
</ul>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#login').click(function() {
$('div.ui-slider').width("33%");
$('#friend-list').empty();
$.ajax({
url: 'http://happy-or-grumpy.herokuapp.com/friends',
type: 'GET',
dataType: 'jsonp',
success: function(data) {
$.each(data, function(index, item) {
$('#friend-list').append('<li class="ui-screen-hidden" id="' + item.id +
'" onclick="submit_user_id(this)">' + item.name + '</li>');
});
},
error : function(xhr, ajaxOptions, thrownError) {
alert('Somthing went wrong while fetching friends !!!');
alert(xhr.status);
alert(thrownError);
alert(ajaxOptions);
}
});
});
});
function submit_user_id(elem) {
// this is where the user types a name
var input = $(elem).parent().prev().find('input').first();
input.val($(elem).html());
// re-hide the list
$("ul li").addClass("ui-screen-hidden");
// now submit to the server
$.ajax({
url: 'http://happy-or-grumpy.herokuapp.com/friends/' + $(elem).attr("id") + '/messages.json',
type: 'GET',
dataType: 'jsonp',
error: function(xhr, ajaxOptions, thrownError) {
alert('Something went wrong in getting happiness numbers?!');
alert(xhr.status);
},
success: function(data) {
// use the data to render chart here ...
var arr = [];
var arr2 = [];
$.each(data, function(index, item) {
$('#mood-list').append('<li id="' + item.platform_message_id + '">'
+ item.sum + ' - ' + item.theday + '</li>');
arr.push([item.theday, item.sum]);
arr2.push(item.sum);
});
$.jqplot._noToImageButton = true;
$('#chart1').empty();
var plot1 = $.jqplot('chart1', [arr], {
seriesColors: ["rgb(211, 235, 59)"],
title: "",
highlighter: {
show: true,
sizeAdjust: 1,
tooltipOffset: 9
},
grid: {
background: 'rgba(57,57,57,0.0)',
drawBorder: false,
shadow: false,
gridLineColor: '#666666',
gridLineWidth: 2
},
seriesDefaults: {
rendererOptions: {
smooth: true,
animation: {
show: true
}
},
showMarker: true
},
axesDefaults: {
rendererOptions: {
baselineWidth: 1.5,
baselineColor: '#444444',
drawBaseline: false
}
},
axes: {
xaxis: {
renderer: $.jqplot.DateAxisRenderer,
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
tickOptions: {
formatString: "%b %e",
angle: -30,
textColor: '#dddddd'
},
tickInterval: "5 days",
drawMajorGridlines: false
},
yaxis: {
renderer: $.jqplot.LinearAxisRenderer,
rendererOptions: {
minorTicks: 0.01
},
tickOptions: {
formatString: "%'s",
showMark: false
},
forceTickAt0: true,
tickInterval: 10,
max: 50,
min: -20,
}
}
});
}
});
}
</script>
</body>
</html>