forked from adlnet-archive/xapi-html5-data-attributes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
403 lines (372 loc) · 18.5 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="author" content="Tyler Mulligan">
<title>xAPI statements in HTML5 data-attributes</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css" rel="stylesheet" type="text/css" />
<style type="text/css" media="screen">
#editor {
width:530px;
height:460px;
border:1px solid #ccc;
margin-bottom:10px;
}
.tab-content {
border:1px solid #ccc;
border-top:0;
padding:15px 5px 5px;
}
.tooltip-inner {
max-width: 350px;
}
</style>
<!--[if lt IE 9]>
<script src="https://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="page-header">
<h1 class="text-primary">xAPI HTML5 data-attributes</h1>
<h3 class="text-muted">Using jQuery to send statements written in markup to a Learning Record Store (LRS)</h3>
</div>
<h2 class="text-info">About</h2>
<div class="alert alert-success">
<p>This tool demonstrates the use of xAPI statements within markup using HTML5 data-attributes. Example JSON is available in an external <a href="js/statements.js" target="_blank">statements.js <i class="glyphicon glyphicon-file"></i></a> file for your convenience. Inline JSON examples are also provided.</p>
<p><span class="label label-info">Tip: Open your browser's developer tools (F12) to see more info in the console.</span></p>
</div>
<h2 class="text-info">Using the Tool</h2>
<h3>Choose an LRS to send statements to</h3>
<p>Configuration to these LRSes can be found in the <a href="js/conf.js" target="_blank">conf.js <i class="glyphicon glyphicon-file"></i></a> file.</p>
<p>The ADL LRS should always work with these examples. Other LRSes may not work without having logged into through your browser. It's possible to fork this demo, enter your own credentials to one of those systems and have it work.</p>
<div class="btn-toolbar" role="toolbar">
<div id="change-lrs" class="btn-group">
<a class="btn btn-default active" rel="adl"><span class="glyphicon glyphicon-heart"></span> ADL LRS</a>
<a class="btn btn-default" rel="wax"><span class="glyphicon glyphicon-comment"></span> Wax LRS</a>
<a class="btn btn-default" rel="watershed"><span class="glyphicon glyphicon-tint"></span> Watershed LRS</a>
<a class="btn btn-default" rel="scormcloud"><span class="glyphicon glyphicon-cloud"></span> SCORM Cloud</a>
<a class="btn btn-default" rel="learninglocker"><span class="glyphicon glyphicon-lock"></span> Learning Locker</a>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<h3>Send a Statement</h3>
<p>There are multiple ways to send statements to your chosen LRS.</p>
<!-- tabs -->
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab-predefined" data-toggle="tab">Predefined JSON</a></li>
<li><a href="#tab-events" data-toggle="tab">Custom Events</a></li>
<li><a href="#tab-editor" data-toggle="tab">JSON Editor</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab-predefined">
<p>The links below contain data-xapi-statement attributes that will send an xAPI statement to the LRS you've chosen above when clicked. If you hover the link, a tooltip should display the value of the data-xapi-statement attribute. the <em class="text-info">stmt[0-9]+</em> is a reference to a javascript variable defined in the <a href="js/statements.js" target="_blank">statements.js <i class="glyphicon glyphicon-file"></i></a> file.</p>
<table id="send-statement" class="table table-hover">
<thead>
<tr>
<th>Verb</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#" data-xapi-statement="stmt1" data-toggle="tooltip" title='data-xapi-statement="stmt1"'>answered</a></td>
<td>javascript variable from statements.js</td>
</tr>
<tr>
<td><a href="#" data-xapi-statement="stmt2" data-toggle="tooltip" title='data-xapi-statement="stmt2"'>attempted</a></td>
<td>javascript variable from statements.js</td>
</tr>
<tr>
<td><a href="#" data-xapi-statement="stmt3" data-toggle="tooltip" title='data-xapi-statement="stmt3"'>attended</a></td>
<td>javascript variable from statements.js</td>
</tr>
<tr>
<td><a href="#" data-xapi-statement="stmt4" data-toggle="tooltip" title='data-xapi-statement="stmt4"'>completed</a></td>
<td>javascript variable from statements.js</td>
</tr>
<tr>
<td><a href="#" data-xapi-statement="stmt5" data-toggle="tooltip" title='data-xapi-statement="stmt5"'>created</a></td>
<td>javascript variable from statements.js</td>
</tr>
<tr>
<td><a href="#" data-xapi-statement="stmt6" data-toggle="tooltip" title='data-xapi-statement="stmt6"'>experienced</a></td>
<td>javascript variable from statements.js</td>
</tr>
<tr>
<td><a href="#" data-xapi-statement="stmt7" data-toggle="tooltip" title='data-xapi-statement="stmt7"'>failed</a></td>
<td>javascript variable from statements.js</td>
</tr>
<tr>
<td><a href="#" data-xapi-statement="stmt8" data-toggle="tooltip" title='data-xapi-statement="stmt8"'>imported</a></td>
<td>javascript variable from statements.js</td>
</tr>
<tr>
<td><a href="#" data-xapi-statement="stmt9" data-toggle="tooltip" title='data-xapi-statement="stmt9"'>interacted</a></td>
<td>javascript variable from statements.js</td>
</tr>
<tr>
<td><a href="#" data-xapi-statement="stmt10" data-toggle="tooltip" title='data-xapi-statement="stmt10"'>passed</a></td>
<td>javascript variable from statements.js</td>
</tr>
<tr>
<td><a href="#" data-xapi-statement='{"actor":{"mbox":"mailto:[email protected]","name":"Tyler Mulligan","objectType":"Agent"},"verb":{"id":"http://adlnet.gov/expapi/verbs/shared","display":{"en-US":"shared"}},"object":{"id":"http://z2.vc/xapi/activities/shared","objectType":"Activity","definition":{"name":{"en-US":"shared HTML5 data attribute"},"description":{"en-US":"Example generation of a shared activity using an HTML5 data attribute with unobtrusive js"}}}}' data-toggle="tooltip" title='data-xapi-statement='{"actor":{"mbox":"mailto:[email protected]","name":"Tyler Mulligan","objectType":"Agent"},"verb":{"id":"http://adlnet.gov/expapi/verbs/shared","display":{"en-US":"shared"}},"object":{"id":"http://z2.vc/xapi/activities/shared","objectType":"Activity","definition":{"name":{"en-US":"shared HTML5 data attribute"},"description":{"en-US":"Example generation of a shared activity using an HTML5 data attribute with unobtrusive js"}}}}''>shared</a></td>
<td>inline JSON</td>
</tr>
</tbody>
</table>
</div>
<div class="tab-pane" id="tab-events">
<p class="text-danger"><b>VERY</b> experimental custom event binding.</p>
<h5>On Change</h5>
<p>Select an option below to send a statement:</p>
<select data-xapi-change-event="change" id="test">
<option data-xapi-statement="stmt3">stmt3</option>
<option data-xapi-statement="stmt4">stmt4</option>
<option data-xapi-statement='{"actor":{"mbox":"mailto:[email protected]","name":"Custom Event","objectType":"Agent"},"verb":{"id":"http://adlnet.gov/expapi/verbs/passed","display":{"en-US":"passed"}},"object":{"id":"http://z2.vc/xapi/activities/passed/custom-event","objectType":"Activity","definition":{"name":{"en-US":"statement with a custom event on change"},"description":{"en-US":"custom statement with a custom on change event"}}}}'>inline statement</option>
</select>
<br />
<br />
<h5>On Hover</h5>
<p><a href="#" data-xapi-hover-event="hover" data-xapi-statement="stmt2">hover me to send <em class="text-info">stmt2</em></a></p>
</div>
<div class="tab-pane" id="tab-editor">
<p>This editor allows you to send a custom statement to the LRS you've chosen above.</p>
<div id="editor">{
"actor": {
"mbox": "mailto:[email protected]",
"name": "Custom",
"objectType": "Agent"
},
"verb": {
"id": "http://adlnet.gov/expapi/verbs/passed",
"display": {
"en-US": "passed"
}
},
"object": {
"id": "http://z2.vc/xapi/activities/passed-the-editor",
"objectType": "Activity",
"definition": {
"name": {
"en-US": "statement from Tyler's editor"
},
"description": {
"en-US": "passed a custom statement from Tyler's editor"
}
}
}
}</div>
<p><a id="send-custom-statement" class="btn btn-primary" data-xapi-statement="custom-statement" href="#">Send Custom Statement <i class="glyphicon glyphicon-share-alt"></i></a></p>
<p><a href="http://tincanapi.com/statement-generator/" target="_blank">you can generate a valid statement here <i class="glyphicon glyphicon-new-window"></i></a></p>
</div>
</div>
</div>
<!-- /tabs -->
</div><!-- .col-lg-6 -->
<div class="col-lg-6">
<h3>Statement Information</h3>
<p>Statements sent to the LRS, and response status from the LRS are displayed here.</p>
<div class="well">
<p id="lrs-response"></p>
<pre class="prettyprint lang-js" id="statement"></pre>
<p>You can view statements sent to the ADL LRS <a href="https://lrs.adlnet.gov/prototypes/StatementViewer/index.html" target="_blank">here <i class="glyphicon glyphicon-new-window"></i></a>.</p>
</div>
</div><!-- .col-lg-6 -->
</div><!-- .row -->
<h2 class="text-info">Technical Explanation</h2>
<p>xAPI statement data is included as a JSON object in a data-xapi-statement attribute</p>
<!-- tabs -->
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab-html" data-toggle="tab">HTML</a></li>
<li><a href="#tab-json" data-toggle="tab">JSON</a></li>
<li><a href="#tab-jquery" data-toggle="tab">jQuery</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab-html">
<p><em class="text-info">stmt1</em> is actually a javascript variable that you can see in the JSON tab.</p>
<pre class="prettyprint lang-html"><a data-xapi-statement="stmt1" href="#">answered</a></pre>
<p>Alternatively, <a href="http://jsonmate.com/" target="_blank">uglified JSON <i class="glyphicon glyphicon-new-window"></i></a> can be put directly into the data-xapi-statement attribute</p>
<pre class="prettyprint lang-html"><a data-xapi-statement='{"actor":{"mbox":"mailto:[email protected]","name":"Tyler Mulligan","objectType":"Agent"},"verb":{"id":"http://adlnet.gov/expapi/verbs/shared","display":{"en-US":"shared"}},"object":{"id":"http://z2.vc/xapi/activities/shared","objectType":"Activity","definition":{"name":{"en-US":"shared HTML5 data attribute"},"description":{"en-US":"Example generation of a shared activity using an HTML5 data attribute with unobtrusive js"}}}}' href="#">shared</a></pre>
</div>
<div class="tab-pane" id="tab-json">
<p>This is an example of a JSON variable referenced by the data-xapi-statement attribute in the HTML.</p>
<pre class="prettyprint lang-js">
var stmt1 = {
"actor": {
"mbox": "mailto:" + email,
"name": email,
"objectType": "Agent"
},
"verb": {
"id": "http://adlnet.gov/expapi/verbs/answered",
"display": {
"en-US": "answered"
}
},
"object": {
"id": "http://z2.vc/xapi/activities/answered",
"objectType": "Activity",
"definition": {
"name": {
"en-US": "HTML5 data attribute prototype"
},
"description": {
"en-US": "Example generation of a answered activity using an HTML5 data attribute with unobtrusive js"
}
}
}
};</pre>
</div>
<div class="tab-pane" id="tab-jquery">
<p>In this prototype, jQuery binds the click event, references the data-xapi-statement makes sense of it and sends it to an LRS using <a href="https://github.com/adlnet/xAPIWrapper" target="_blank">xapiwrapper.js <i class="glyphicon glyphicon-new-window"></i></a></p>
<pre class="prettyprint lang-js">
$('#send-statement a').click(function (e) {
e.preventDefault();
// don't get crazy with the sizzle
var $el = $(this);
// get the xapi-statement from the data atrribute
var stmt = $el.attr('data-xapi-statement');
// determine if the statement is inline or referencing a JSON object
if (stmt.indexOf('{') == 0) {
var xstmt = $.parseJSON(stmt);
} else {
var xstmt = statements[stmt];
}
ADL.XAPIWrapper.sendStatement(xstmt, function(resp, obj) {
console.log(resp.status);
console.log(obj.id);
});
});</pre>
</div>
</div>
</div>
<!-- /tabs -->
<h2 id="notes" class="text-info">Notes</h2>
<h3>Implementation in EPUB3</h3>
<p>Not all EPUB3 readers support scripting but if they do (<a href="https://chrome.google.com/webstore/detail/readium/fepbnnnkkadjhjahcafoaglimekefifl?hl=en-US" target="_blank">Readium</a> and <a href="http://calibre-ebook.com/download" target="_blank">Calibre</a> have been tested and <span class="text-success">confirmed to work</span>), they will send the statements. By keeping the javascript unobtrusive, we don't prevent the user from accessing content. An example of this behavior is possible by testing the one of these epubs on <a href="https://play.google.com/books/uploads" target="_blank">Google Play Books</a>, which currently disallows javascript execution.</p>
<p>The following epubs were generated with <a href="http://johnmacfarlane.net/pandoc/" target="_blank">pandoc</a> from markdown source.</p>
<ul>
<li><a href="xapi-data-book-minimal.epub">xapi-data-book-minimal.epub</a> [<a href="xapi-data-book-minimal.md">markdown source</a>]</li>
<li><a href="xapi-data-book.epub">xapi-data-book.epub</a> [<a href="xapi-data-book.md">markdown source</a>] (this includes a technical explanation an instructions to generate your own epub with pandoc)</li>
</ul>
<h3>TODO</h3>
<ul>
<li>rewrite logic of JSON indexing via data-xapi-statement</li>
<li>Refactor javascript and develop jQuery plugin to handle all data-xapi-* attributes</li>
<li>Allow users to setup their own LRS credentials</li>
<li>Provide more examples and break up into sections</li>
<li>Separate CSS styles out to separate file</li>
<li>Separate more JS into external files</li>
<li>Start versioning and tagging releases</li>
<li>Provide visual reports of statements</li>
<li>Possible build system for consolidation and compression</li>
<li>Statement builder and validator?</li>
</ul>
<p class="text-muted"><i class="glyphicon glyphicon-time
"></i> Last Updated: 05/01/2014 by <a href="mailto:[email protected]">Tyler Mulligan <i class="glyphicon glyphicon-send"></i></a></p>
</div><!-- /.container -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script type="text/javascript" src="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/xapiwrapper.min.js"></script><!-- https://github.com/adlnet/xAPIWrapper as of 05/01/2014 -->
<script type="text/javascript" src="js/conf.js"></script>
<script type="text/javascript" src="js/statements.js"></script>
<script type="text/javascript" src="js/dataAttributeEvents.js"></script><!-- credit to https://github.com/aCodeSmith/DataAttributeEvents -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ace.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var editor = ace.edit('editor');
editor.setOptions({
maxLines: 200
});
editor.getSession().setMode('ace/mode/javascript');
// A wrapper to process data-xapi-statements
function processStatement($el) {
var lrsn = $('#change-lrs a.active').text();
var $lrsr = $('#lrs-response');
// clean out the LRS response status
var $lrsr = $('#lrs-response');
$lrsr.html('').attr('class', '');
// get the xapi-statement from the data atrribute
var stmt = $el.attr('data-xapi-statement');
// determine if the statement is inline, using the editor, or referencing a JSON object
// come on, you can do this better
if ( stmt.indexOf('{') == 0 ) { // inline statement
var xstmt = $.parseJSON(stmt);
} else if ( stmt == 'custom-statement' ) { // editor
var xstmt = $.parseJSON(editor.getValue());
} else { // JSON object
var xstmt = statements[stmt];
}
// Console log the index and then the selected statement from the JSON object
console.log("stmt: " + stmt);
console.log("xstmt: ");
console.log(xstmt);
console.log("verb: " + xstmt.verb.display['en-US']);
ADL.XAPIWrapper.sendStatement(xstmt, function(resp, obj) {
console.log("response status: " + resp.status);
console.log("response obj id: " + obj.id);
// update the status in the HTML
if (resp.status == 200) {
$lrsr.html("<b><em>" + xstmt.verb.display['en-US'] + "</em></b> statement sent successfully to " + lrsn).attr("class", "alert alert-success");
} /*else { // xapiwrapper.js throws a javascript alert
$lrsr.html("LRS rejected the statement").attr("class", "text-warning");
}*/
});
// Update the DOM to show what was sent
$('#statement').removeClass('prettyprinted'); // have to do this to reinitalize prettyprinting
$('#statement').html(JSON.stringify(xstmt, undefined, 2));
PR.prettyPrint();
};
$(function(){
// apply default LRS config
ADL.XAPIWrapper.changeConfig(conf.adl);
// Handle click based sending of statements
$('#send-statement a, #send-custom-statement').click(function (e) {
e.preventDefault();
processStatement($(this));
});
// you can change the LRS with this
$lrsa = $('#change-lrs a');
$lrsa.click(function() {
$lrsa.removeClass('active');
var $el = $(this);
var lrs = $el.attr('rel');
$el.addClass('active');
ADL.XAPIWrapper.changeConfig(conf[lrs]);
});
// I feel pretty
$("[data-toggle=tooltip]").tooltip();
prettyPrint();
});
// Custom Event Binding -- need to consolidate and abstract this
$(window).dataTriggers([
{
dataAttribute: 'xapi-hover-event',
event: 'mouseover',
triggers: {
hover: function($el) { processStatement($el) }
}
},
{
dataAttribute:'xapi-change-event',
event:'change',
triggers: {
change: function($el)
{
var stmt = $el.val();
//console.log(stmt);
//console.log($el.children("option:selected").attr('data-xapi-statement'));
processStatement($el.children('option:selected'));
}
}
}
]);
</script>
</body>
</html>